Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
i,S,m;main(n){for(;~scanf("%d",&n);i||(S=m=0))++i>0?i>3?i=-n:(S+=n*n,m=n>m?n:m):puts(S-m*m<n*n*4?"OK":"NA");}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	i
	.bss
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	S
	.align 4
	.type	S, @object
	.size	S, 4
S:
	.zero	4
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.section	.rodata
.LC0:
	.string	"OK"
.LC1:
	.string	"NA"
.LC2:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	jmp	.L2
.L11:
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
	movl	i(%rip), %eax
	testl	%eax, %eax
	jle	.L3
	movl	i(%rip), %eax
	cmpl	$3, %eax
	jle	.L4
	movl	-4(%rbp), %eax
	negl	%eax
	movl	%eax, i(%rip)
	jmp	.L6
.L4:
	movl	-4(%rbp), %edx
	movl	-4(%rbp), %eax
	imull	%eax, %edx
	movl	S(%rip), %eax
	addl	%edx, %eax
	movl	%eax, S(%rip)
	movl	m(%rip), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, m(%rip)
	jmp	.L6
.L3:
	movl	S(%rip), %eax
	movl	m(%rip), %ecx
	movl	m(%rip), %edx
	imull	%ecx, %edx
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	-4(%rbp), %edx
	movl	-4(%rbp), %eax
	imull	%edx, %eax
	sall	$2, %eax
	cmpl	%eax, %ecx
	jge	.L7
	leaq	.LC0(%rip), %rax
	jmp	.L8
.L7:
	leaq	.LC1(%rip), %rax
.L8:
	movq	%rax, %rdi
	call	puts@PLT
.L6:
	movl	i(%rip), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, m(%rip)
	movl	m(%rip), %eax
	movl	%eax, S(%rip)
	movl	S(%rip), %eax
	testl	%eax, %eax
.L2:
	leaq	-4(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	cmpl	$-1, %eax
	jne	.L11
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
user
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"OK"
.LC1:
	.string	"NA"
.LC2:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	.LC1(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	.LC2(%rip), %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movl	%edi, 12(%rsp)
	leaq	12(%rsp), %rbp
	.p2align 4,,10
	.p2align 3
.L9:
	xorl	%eax, %eax
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	call	scanf@PLT
	cmpl	$-1, %eax
	je	.L14
	movl	i(%rip), %eax
	leal	1(%rax), %edx
	movl	12(%rsp), %eax
	movl	%edx, i(%rip)
	testl	%edx, %edx
	jle	.L3
	cmpl	$3, %edx
	jle	.L4
	negl	%eax
	movl	%eax, i(%rip)
.L5:
	testl	%eax, %eax
	jne	.L9
	movl	$0, m(%rip)
	movl	$0, S(%rip)
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L3:
	movl	m(%rip), %edx
	imull	%eax, %eax
	movl	S(%rip), %ecx
	movq	%r12, %rdi
	imull	%edx, %edx
	sall	$2, %eax
	subl	%edx, %ecx
	cmpl	%eax, %ecx
	cmovl	%r13, %rdi
	call	puts@PLT
	movl	i(%rip), %eax
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%eax, %edx
	imull	%eax, %edx
	addl	%edx, S(%rip)
	movl	m(%rip), %edx
	cmpl	%eax, %edx
	cmovl	%eax, %edx
	movl	%edx, m(%rip)
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L14:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	m
	.bss
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	S
	.align 4
	.type	S, @object
	.size	S, 4
S:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

rule
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"OK"
.LC1:
	.string	"NA"
.LC2:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	.LC1(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	.LC2(%rip), %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movl	%edi, 12(%rsp)
	leaq	12(%rsp), %rbp
	.p2align 4,,10
	.p2align 3
.L9:
	xorl	%eax, %eax
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	call	scanf@PLT
	cmpl	$-1, %eax
	je	.L14
	movl	i(%rip), %eax
	leal	1(%rax), %edx
	movl	12(%rsp), %eax
	movl	%edx, i(%rip)
	testl	%edx, %edx
	jle	.L3
	cmpl	$3, %edx
	jle	.L4
	negl	%eax
	movl	%eax, i(%rip)
.L5:
	testl	%eax, %eax
	jne	.L9
	movl	$0, m(%rip)
	movl	$0, S(%rip)
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L3:
	movl	m(%rip), %edx
	imull	%eax, %eax
	movl	S(%rip), %ecx
	movq	%r12, %rdi
	imull	%edx, %edx
	sall	$2, %eax
	subl	%edx, %ecx
	cmpl	%eax, %ecx
	cmovl	%r13, %rdi
	call	puts@PLT
	movl	i(%rip), %eax
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%eax, %edx
	imull	%eax, %edx
	addl	%edx, S(%rip)
	movl	m(%rip), %edx
	cmpl	%eax, %edx
	cmovl	%eax, %edx
	movl	%edx, m(%rip)
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L14:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	m
	.bss
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	S
	.align 4
	.type	S, @object
	.size	S, 4
S:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

i,S,m;main(n){for(;~scanf("%d",&n);i||(S=m=0))++i>0?i>3?i=-n:(S+=n*n,m=n>m?n:m):puts(S-m*m<n*n*4?"OK":"NA");}
10 6 8
5
4
1
6
2
5
0 0 0
 10 6 8
5
4
0
0
2
5
0 0 0
 10 6 8
5
4
0
0
2
7
0 0 0
 10 6 8
5
1
8
6
2
5
0 0 0
 10 6 4
5
4
0
-1
2
7
0 0 0
 10 6 4
5
4
0
-1
4
7
0 0 0
 10 3 8
5
4
0
6
2
5
0 0 0
 10 6 8
5
1
8
3
2
5
0 0 0
 10 2 8
5
1
8
11
2
5
0 0 0
 10 6 7
5
4
1
-2
8
7
0 0 0

NA
NA
OK
NA
NA
 NA
NA
NA
NA
NA
 NA
NA
NA
NA
OK
 NA
OK
OK
NA
NA
 OK
NA
NA
NA
OK
 OK
NA
NA
OK
OK
 NA
NA
OK
NA
OK
 NA
OK
NA
NA
NA
 NA
OK
OK
NA
OK
 NA
NA
NA
OK
OK

Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
i,S,m;main(n){for(;~scanf("%d",&n);i||(S=m=0))++i>0?i>3?i=-n:(S+=n*n,m=n>m?n:m):puts(S-m*m<n*n*4?"OK":"NA");}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	i
	.bss
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	S
	.align 4
	.type	S, @object
	.size	S, 4
S:
	.zero	4
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.section	.rodata
.LC0:
	.string	"OK"
.LC1:
	.string	"NA"
.LC2:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	jmp	.L2
.L11:
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
	movl	i(%rip), %eax
	testl	%eax, %eax
	jle	.L3
	movl	i(%rip), %eax
	cmpl	$3, %eax
	jle	.L4
	movl	-4(%rbp), %eax
	negl	%eax
	movl	%eax, i(%rip)
	jmp	.L6
.L4:
	movl	-4(%rbp), %edx
	movl	-4(%rbp), %eax
	imull	%eax, %edx
	movl	S(%rip), %eax
	addl	%edx, %eax
	movl	%eax, S(%rip)
	movl	m(%rip), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, m(%rip)
	jmp	.L6
.L3:
	movl	S(%rip), %eax
	movl	m(%rip), %ecx
	movl	m(%rip), %edx
	imull	%ecx, %edx
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	-4(%rbp), %edx
	movl	-4(%rbp), %eax
	imull	%edx, %eax
	sall	$2, %eax
	cmpl	%eax, %ecx
	jge	.L7
	leaq	.LC0(%rip), %rax
	jmp	.L8
.L7:
	leaq	.LC1(%rip), %rax
.L8:
	movq	%rax, %rdi
	call	puts@PLT
.L6:
	movl	i(%rip), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, m(%rip)
	movl	m(%rip), %eax
	movl	%eax, S(%rip)
	movl	S(%rip), %eax
	testl	%eax, %eax
.L2:
	leaq	-4(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	cmpl	$-1, %eax
	jne	.L11
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
train
	.file	"temp.c"
	.text
	.globl	i
	.bss
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	S
	.align 4
	.type	S, @object
	.size	S, 4
S:
	.zero	4
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.section	.rodata
.LC0:
	.string	"OK"
.LC1:
	.string	"NA"
.LC2:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	jmp	.L2
.L11:
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
	movl	i(%rip), %eax
	testl	%eax, %eax
	jle	.L3
	movl	i(%rip), %eax
	cmpl	$3, %eax
	jle	.L4
	movl	-4(%rbp), %eax
	negl	%eax
	movl	%eax, i(%rip)
	jmp	.L6
.L4:
	movl	-4(%rbp), %edx
	movl	-4(%rbp), %eax
	imull	%eax, %edx
	movl	S(%rip), %eax
	addl	%edx, %eax
	movl	%eax, S(%rip)
	movl	m(%rip), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, m(%rip)
	jmp	.L6
.L3:
	movl	S(%rip), %eax
	movl	m(%rip), %ecx
	movl	m(%rip), %edx
	imull	%ecx, %edx
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	-4(%rbp), %edx
	movl	-4(%rbp), %eax
	imull	%edx, %eax
	sall	$2, %eax
	cmpl	%eax, %ecx
	jge	.L7
	leaq	.LC0(%rip), %rax
	jmp	.L8
.L7:
	leaq	.LC1(%rip), %rax
.L8:
	movq	%rax, %rdi
	call	puts@PLT
.L6:
	movl	i(%rip), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, m(%rip)
	movl	m(%rip), %eax
	movl	%eax, S(%rip)
	movl	S(%rip), %eax
	testl	%eax, %eax
.L2:
	leaq	-4(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	cmpl	$-1, %eax
	jne	.L11
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
