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

```c
#include<stdio.h>

int main(){
	int N, i, ave, val;
	int ret, b;
	ret = 0;
	b = 0;
	scanf("%d\n", &N);
	int a[N];
	for(i = 0; i < N; i++){
		scanf("%d",&a[i]);
		ave += a[i];
	}
	ave = ave/N;
	for(i = 0; i < N; i++){
		val = (a[i] - ave);
		ret += val*val;
	}
	for(i = 0; i < N; i++){
		val = (a[i] - ave - 1);
		b += val*val;
	}
	if(ret > b) ret = b;
	b = 0;
	for(i = 0; i < N; i++){
		val = (a[i] - ave + 1);
		b += val*val;
	}
	if(ret > b) ret = b;
	printf("%d\n", ret);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d\n"
.LC1:
	.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
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %rbx
	movl	$0, -84(%rbp)
	movl	$0, -80(%rbp)
	leaq	-96(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-96(%rbp), %eax
	movslq	%eax, %rdx
	subq	$1, %rdx
	movq	%rdx, -72(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	movslq	%eax, %rdx
	movq	%rdx, %r12
	movl	$0, %r13d
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L2:
	cmpq	%rdx, %rsp
	je	.L3
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L2
.L3:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L4
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L4:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -64(%rbp)
	movl	$0, -92(%rbp)
	jmp	.L5
.L6:
	movl	-92(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-64(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-64(%rbp), %rax
	movl	-92(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	addl	%eax, -88(%rbp)
	addl	$1, -92(%rbp)
.L5:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L6
	movl	-96(%rbp), %esi
	movl	-88(%rbp), %eax
	cltd
	idivl	%esi
	movl	%eax, -88(%rbp)
	movl	$0, -92(%rbp)
	jmp	.L7
.L8:
	movq	-64(%rbp), %rax
	movl	-92(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	subl	-88(%rbp), %eax
	movl	%eax, -76(%rbp)
	movl	-76(%rbp), %eax
	imull	%eax, %eax
	addl	%eax, -84(%rbp)
	addl	$1, -92(%rbp)
.L7:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L8
	movl	$0, -92(%rbp)
	jmp	.L9
.L10:
	movq	-64(%rbp), %rax
	movl	-92(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	subl	-88(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -76(%rbp)
	movl	-76(%rbp), %eax
	imull	%eax, %eax
	addl	%eax, -80(%rbp)
	addl	$1, -92(%rbp)
.L9:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L10
	movl	-84(%rbp), %eax
	cmpl	-80(%rbp), %eax
	jle	.L11
	movl	-80(%rbp), %eax
	movl	%eax, -84(%rbp)
.L11:
	movl	$0, -80(%rbp)
	movl	$0, -92(%rbp)
	jmp	.L12
.L13:
	movq	-64(%rbp), %rax
	movl	-92(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	subl	-88(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -76(%rbp)
	movl	-76(%rbp), %eax
	imull	%eax, %eax
	addl	%eax, -80(%rbp)
	addl	$1, -92(%rbp)
.L12:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L13
	movl	-84(%rbp), %eax
	cmpl	-80(%rbp), %eax
	jle	.L14
	movl	-80(%rbp), %eax
	movl	%eax, -84(%rbp)
.L14:
	movl	-84(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%rbx, %rsp
	movq	-56(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.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	"%d\n"
.LC1:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdi
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	leaq	-60(%rbp), %rsi
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$40, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	-60(%rbp), %rax
	movq	%rsp, %rsi
	movq	%rax, %rcx
	leaq	15(,%rax,4), %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	subq	%rax, %rsi
	andq	$-16, %rdx
	cmpq	%rsi, %rsp
	je	.L3
.L36:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rsi, %rsp
	jne	.L36
.L3:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	jne	.L37
.L4:
	movq	%rsp, %rbx
	movq	%rbx, -72(%rbp)
	testl	%ecx, %ecx
	jle	.L5
	movq	%rbx, %r15
	xorl	%r14d, %r14d
	leaq	.LC1(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%rbx, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %r14d
	call	__isoc99_scanf@PLT
	movl	-60(%rbp), %ecx
	addl	(%rbx), %r12d
	addq	$4, %rbx
	cmpl	%r14d, %ecx
	jg	.L6
	movl	%r12d, %eax
	cltd
	idivl	%ecx
	testl	%ecx, %ecx
	jle	.L5
	leal	-1(%rcx), %r9d
	cmpl	$2, %r9d
	jbe	.L22
	movl	%ecx, %esi
	movq	-72(%rbp), %rdx
	movd	%eax, %xmm5
	pxor	%xmm3, %xmm3
	shrl	$2, %esi
	pshufd	$0, %xmm5, %xmm2
	salq	$4, %rsi
	addq	%rdx, %rsi
	.p2align 4,,10
	.p2align 3
.L8:
	movdqu	(%rdx), %xmm0
	addq	$16, %rdx
	psubd	%xmm2, %xmm0
	movdqa	%xmm0, %xmm1
	pmuludq	%xmm0, %xmm1
	psrlq	$32, %xmm0
	pmuludq	%xmm0, %xmm0
	pshufd	$8, %xmm1, %xmm1
	pshufd	$8, %xmm0, %xmm0
	punpckldq	%xmm0, %xmm1
	paddd	%xmm1, %xmm3
	cmpq	%rsi, %rdx
	jne	.L8
	movdqa	%xmm3, %xmm0
	movl	%ecx, %edi
	psrldq	$8, %xmm0
	andl	$-4, %edi
	paddd	%xmm0, %xmm3
	movdqa	%xmm3, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm3
	movd	%xmm3, %esi
	testb	$3, %cl
	je	.L9
.L7:
	movq	-72(%rbp), %rbx
	movslq	%edi, %rdx
	leaq	(%rbx,%rdx,4), %r10
	movl	(%r10), %edx
	subl	%eax, %edx
	imull	%edx, %edx
	addl	%edx, %esi
	leal	1(%rdi), %edx
	cmpl	%edx, %ecx
	jle	.L10
	movl	4(%r10), %edx
	addl	$2, %edi
	subl	%eax, %edx
	imull	%edx, %edx
	addl	%edx, %esi
	cmpl	%edi, %ecx
	jle	.L10
	movl	8(%r10), %edx
	subl	%eax, %edx
	imull	%edx, %edx
	addl	%edx, %esi
.L10:
	cmpl	$2, %r9d
	jbe	.L23
	movd	%eax, %xmm6
	pshufd	$0, %xmm6, %xmm2
.L9:
	movl	%ecx, %edi
	movq	-72(%rbp), %rdx
	pxor	%xmm3, %xmm3
	pcmpeqd	%xmm4, %xmm4
	shrl	$2, %edi
	salq	$4, %rdi
	addq	%rdx, %rdi
	.p2align 4,,10
	.p2align 3
.L12:
	movdqu	(%rdx), %xmm0
	addq	$16, %rdx
	psubd	%xmm2, %xmm0
	paddd	%xmm4, %xmm0
	movdqa	%xmm0, %xmm1
	pmuludq	%xmm0, %xmm1
	psrlq	$32, %xmm0
	pmuludq	%xmm0, %xmm0
	pshufd	$8, %xmm1, %xmm1
	pshufd	$8, %xmm0, %xmm0
	punpckldq	%xmm0, %xmm1
	paddd	%xmm1, %xmm3
	cmpq	%rdi, %rdx
	jne	.L12
	movdqa	%xmm3, %xmm0
	movl	%ecx, %edi
	psrldq	$8, %xmm0
	andl	$-4, %edi
	paddd	%xmm0, %xmm3
	movdqa	%xmm3, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm3
	movd	%xmm3, %edx
	cmpl	%ecx, %edi
	je	.L38
.L11:
	movq	-72(%rbp), %rbx
	movslq	%edi, %r10
	leaq	(%rbx,%r10,4), %r11
	movl	%eax, %r10d
	notl	%r10d
	addl	(%r11), %r10d
	imull	%r10d, %r10d
	addl	%r10d, %edx
	leal	1(%rdi), %r10d
	cmpl	%r10d, %ecx
	jle	.L14
	movl	%eax, %r10d
	addl	$2, %edi
	notl	%r10d
	addl	4(%r11), %r10d
	imull	%r10d, %r10d
	addl	%r10d, %edx
	cmpl	%edi, %ecx
	jle	.L14
	movl	%eax, %edi
	notl	%edi
	addl	8(%r11), %edi
	imull	%edi, %edi
	addl	%edi, %edx
.L14:
	cmpl	%edx, %esi
	cmovg	%edx, %esi
	cmpl	$2, %r9d
	jbe	.L24
	movd	%eax, %xmm7
	pshufd	$0, %xmm7, %xmm2
.L20:
	movl	%ecx, %edx
	movdqa	.LC2(%rip), %xmm4
	pxor	%xmm3, %xmm3
	shrl	$2, %edx
	salq	$4, %rdx
	addq	-72(%rbp), %rdx
	.p2align 4,,10
	.p2align 3
.L16:
	movdqu	(%r15), %xmm0
	addq	$16, %r15
	psubd	%xmm2, %xmm0
	paddd	%xmm4, %xmm0
	movdqa	%xmm0, %xmm1
	pmuludq	%xmm0, %xmm1
	psrlq	$32, %xmm0
	pmuludq	%xmm0, %xmm0
	pshufd	$8, %xmm1, %xmm1
	pshufd	$8, %xmm0, %xmm0
	punpckldq	%xmm0, %xmm1
	paddd	%xmm1, %xmm3
	cmpq	%r15, %rdx
	jne	.L16
	movdqa	%xmm3, %xmm0
	movl	%ecx, %r8d
	psrldq	$8, %xmm0
	andl	$-4, %r8d
	paddd	%xmm0, %xmm3
	movdqa	%xmm3, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm3
	movd	%xmm3, %edx
	testb	$3, %cl
	je	.L19
.L18:
	movq	-72(%rbp), %rbx
	movslq	%r8d, %rdi
	leaq	(%rbx,%rdi,4), %r9
	movl	(%r9), %edi
	subl	%eax, %edi
	addl	$1, %edi
	imull	%edi, %edi
	addl	%edi, %edx
	leal	1(%r8), %edi
	cmpl	%edi, %ecx
	jle	.L19
	movl	4(%r9), %edi
	addl	$2, %r8d
	subl	%eax, %edi
	addl	$1, %edi
	imull	%edi, %edi
	addl	%edi, %edx
	cmpl	%r8d, %ecx
	jle	.L19
	movl	8(%r9), %ecx
	subl	%eax, %ecx
	leal	1(%rcx), %eax
	imull	%eax, %eax
	addl	%eax, %edx
.L19:
	cmpl	%edx, %esi
	movl	$1, %edi
	cmovle	%esi, %edx
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rsi
	call	__printf_chk@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L39
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L38:
	.cfi_restore_state
	cmpl	%edx, %esi
	cmovg	%edx, %esi
	jmp	.L20
.L37:
	orq	$0, -8(%rsp,%rdx)
	jmp	.L4
.L5:
	xorl	%esi, %esi
	xorl	%edx, %edx
	jmp	.L19
.L22:
	xorl	%esi, %esi
	xorl	%edi, %edi
	jmp	.L7
.L24:
	xorl	%edx, %edx
	xorl	%r8d, %r8d
	jmp	.L18
.L23:
	xorl	%edx, %edx
	xorl	%edi, %edi
	jmp	.L11
.L39:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC2:
	.long	1
	.long	1
	.long	1
	.long	1
	.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	"%d\n"
.LC1:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdi
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	leaq	-60(%rbp), %rsi
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$40, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	-60(%rbp), %rax
	movq	%rsp, %rsi
	movq	%rax, %rcx
	leaq	15(,%rax,4), %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	subq	%rax, %rsi
	andq	$-16, %rdx
	cmpq	%rsi, %rsp
	je	.L3
.L36:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rsi, %rsp
	jne	.L36
.L3:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	jne	.L37
.L4:
	movq	%rsp, %rbx
	movq	%rbx, -72(%rbp)
	testl	%ecx, %ecx
	jle	.L5
	movq	%rbx, %r15
	xorl	%r14d, %r14d
	leaq	.LC1(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%rbx, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %r14d
	call	__isoc99_scanf@PLT
	movl	-60(%rbp), %ecx
	addl	(%rbx), %r12d
	addq	$4, %rbx
	cmpl	%r14d, %ecx
	jg	.L6
	movl	%r12d, %eax
	cltd
	idivl	%ecx
	testl	%ecx, %ecx
	jle	.L5
	leal	-1(%rcx), %r9d
	cmpl	$2, %r9d
	jbe	.L22
	movl	%ecx, %esi
	movq	-72(%rbp), %rdx
	movd	%eax, %xmm5
	pxor	%xmm3, %xmm3
	shrl	$2, %esi
	pshufd	$0, %xmm5, %xmm2
	salq	$4, %rsi
	addq	%rdx, %rsi
	.p2align 4,,10
	.p2align 3
.L8:
	movdqu	(%rdx), %xmm0
	addq	$16, %rdx
	psubd	%xmm2, %xmm0
	movdqa	%xmm0, %xmm1
	pmuludq	%xmm0, %xmm1
	psrlq	$32, %xmm0
	pmuludq	%xmm0, %xmm0
	pshufd	$8, %xmm1, %xmm1
	pshufd	$8, %xmm0, %xmm0
	punpckldq	%xmm0, %xmm1
	paddd	%xmm1, %xmm3
	cmpq	%rsi, %rdx
	jne	.L8
	movdqa	%xmm3, %xmm0
	movl	%ecx, %edi
	psrldq	$8, %xmm0
	andl	$-4, %edi
	paddd	%xmm0, %xmm3
	movdqa	%xmm3, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm3
	movd	%xmm3, %esi
	testb	$3, %cl
	je	.L9
.L7:
	movq	-72(%rbp), %rbx
	movslq	%edi, %rdx
	leaq	(%rbx,%rdx,4), %r10
	movl	(%r10), %edx
	subl	%eax, %edx
	imull	%edx, %edx
	addl	%edx, %esi
	leal	1(%rdi), %edx
	cmpl	%edx, %ecx
	jle	.L10
	movl	4(%r10), %edx
	addl	$2, %edi
	subl	%eax, %edx
	imull	%edx, %edx
	addl	%edx, %esi
	cmpl	%edi, %ecx
	jle	.L10
	movl	8(%r10), %edx
	subl	%eax, %edx
	imull	%edx, %edx
	addl	%edx, %esi
.L10:
	cmpl	$2, %r9d
	jbe	.L23
	movd	%eax, %xmm6
	pshufd	$0, %xmm6, %xmm2
.L9:
	movl	%ecx, %edi
	movq	-72(%rbp), %rdx
	pxor	%xmm3, %xmm3
	pcmpeqd	%xmm4, %xmm4
	shrl	$2, %edi
	salq	$4, %rdi
	addq	%rdx, %rdi
	.p2align 4,,10
	.p2align 3
.L12:
	movdqu	(%rdx), %xmm0
	addq	$16, %rdx
	psubd	%xmm2, %xmm0
	paddd	%xmm4, %xmm0
	movdqa	%xmm0, %xmm1
	pmuludq	%xmm0, %xmm1
	psrlq	$32, %xmm0
	pmuludq	%xmm0, %xmm0
	pshufd	$8, %xmm1, %xmm1
	pshufd	$8, %xmm0, %xmm0
	punpckldq	%xmm0, %xmm1
	paddd	%xmm1, %xmm3
	cmpq	%rdi, %rdx
	jne	.L12
	movdqa	%xmm3, %xmm0
	movl	%ecx, %edi
	psrldq	$8, %xmm0
	andl	$-4, %edi
	paddd	%xmm0, %xmm3
	movdqa	%xmm3, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm3
	movd	%xmm3, %edx
	cmpl	%ecx, %edi
	je	.L38
.L11:
	movq	-72(%rbp), %rbx
	movslq	%edi, %r10
	leaq	(%rbx,%r10,4), %r11
	movl	%eax, %r10d
	notl	%r10d
	addl	(%r11), %r10d
	imull	%r10d, %r10d
	addl	%r10d, %edx
	leal	1(%rdi), %r10d
	cmpl	%r10d, %ecx
	jle	.L14
	movl	%eax, %r10d
	addl	$2, %edi
	notl	%r10d
	addl	4(%r11), %r10d
	imull	%r10d, %r10d
	addl	%r10d, %edx
	cmpl	%edi, %ecx
	jle	.L14
	movl	%eax, %edi
	notl	%edi
	addl	8(%r11), %edi
	imull	%edi, %edi
	addl	%edi, %edx
.L14:
	cmpl	%edx, %esi
	cmovg	%edx, %esi
	cmpl	$2, %r9d
	jbe	.L24
	movd	%eax, %xmm7
	pshufd	$0, %xmm7, %xmm2
.L20:
	movl	%ecx, %edx
	movdqa	.LC2(%rip), %xmm4
	pxor	%xmm3, %xmm3
	shrl	$2, %edx
	salq	$4, %rdx
	addq	-72(%rbp), %rdx
	.p2align 4,,10
	.p2align 3
.L16:
	movdqu	(%r15), %xmm0
	addq	$16, %r15
	psubd	%xmm2, %xmm0
	paddd	%xmm4, %xmm0
	movdqa	%xmm0, %xmm1
	pmuludq	%xmm0, %xmm1
	psrlq	$32, %xmm0
	pmuludq	%xmm0, %xmm0
	pshufd	$8, %xmm1, %xmm1
	pshufd	$8, %xmm0, %xmm0
	punpckldq	%xmm0, %xmm1
	paddd	%xmm1, %xmm3
	cmpq	%r15, %rdx
	jne	.L16
	movdqa	%xmm3, %xmm0
	movl	%ecx, %r8d
	psrldq	$8, %xmm0
	andl	$-4, %r8d
	paddd	%xmm0, %xmm3
	movdqa	%xmm3, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm3
	movd	%xmm3, %edx
	testb	$3, %cl
	je	.L19
.L18:
	movq	-72(%rbp), %rbx
	movslq	%r8d, %rdi
	leaq	(%rbx,%rdi,4), %r9
	movl	(%r9), %edi
	subl	%eax, %edi
	addl	$1, %edi
	imull	%edi, %edi
	addl	%edi, %edx
	leal	1(%r8), %edi
	cmpl	%edi, %ecx
	jle	.L19
	movl	4(%r9), %edi
	addl	$2, %r8d
	subl	%eax, %edi
	addl	$1, %edi
	imull	%edi, %edi
	addl	%edi, %edx
	cmpl	%r8d, %ecx
	jle	.L19
	movl	8(%r9), %ecx
	subl	%eax, %ecx
	leal	1(%rcx), %eax
	imull	%eax, %eax
	addl	%eax, %edx
.L19:
	cmpl	%edx, %esi
	movl	$1, %edi
	cmovle	%esi, %edx
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rsi
	call	__printf_chk@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L39
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L38:
	.cfi_restore_state
	cmpl	%edx, %esi
	cmovg	%edx, %esi
	jmp	.L20
.L37:
	orq	$0, -8(%rsp,%rdx)
	jmp	.L4
.L5:
	xorl	%esi, %esi
	xorl	%edx, %edx
	jmp	.L19
.L22:
	xorl	%esi, %esi
	xorl	%edi, %edi
	jmp	.L7
.L24:
	xorl	%edx, %edx
	xorl	%r8d, %r8d
	jmp	.L18
.L23:
	xorl	%edx, %edx
	xorl	%edi, %edi
	jmp	.L11
.L39:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC2:
	.long	1
	.long	1
	.long	1
	.long	1
	.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:

#include<stdio.h>

int main(){
	int N, i, ave, val;
	int ret, b;
	ret = 0;
	b = 0;
	scanf("%d\n", &N);
	int a[N];
	for(i = 0; i < N; i++){
		scanf("%d",&a[i]);
		ave += a[i];
	}
	ave = ave/N;
	for(i = 0; i < N; i++){
		val = (a[i] - ave);
		ret += val*val;
	}
	for(i = 0; i < N; i++){
		val = (a[i] - ave - 1);
		b += val*val;
	}
	if(ret > b) ret = b;
	b = 0;
	for(i = 0; i < N; i++){
		val = (a[i] - ave + 1);
		b += val*val;
	}
	if(ret > b) ret = b;
	printf("%d\n", ret);
	return 0;
}
2
5 8
 3
1 1 6
 3
4 3 5
 4
-100 -45 -100 -100
 2
5 11
 3
1 1 8
 3
3 3 5
 3
0 1 8
 3
3 0 5
 2
10 6

-453206435
 1805005977
 -2140532978
 -1197127553
 329791140
 -2081196807
 -2053286525
 -1399713838
 -806886130
 -993273974

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

```c
#include<stdio.h>

int main(){
	int N, i, ave, val;
	int ret, b;
	ret = 0;
	b = 0;
	scanf("%d\n", &N);
	int a[N];
	for(i = 0; i < N; i++){
		scanf("%d",&a[i]);
		ave += a[i];
	}
	ave = ave/N;
	for(i = 0; i < N; i++){
		val = (a[i] - ave);
		ret += val*val;
	}
	for(i = 0; i < N; i++){
		val = (a[i] - ave - 1);
		b += val*val;
	}
	if(ret > b) ret = b;
	b = 0;
	for(i = 0; i < N; i++){
		val = (a[i] - ave + 1);
		b += val*val;
	}
	if(ret > b) ret = b;
	printf("%d\n", ret);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d\n"
.LC1:
	.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
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %rbx
	movl	$0, -84(%rbp)
	movl	$0, -80(%rbp)
	leaq	-96(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-96(%rbp), %eax
	movslq	%eax, %rdx
	subq	$1, %rdx
	movq	%rdx, -72(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	movslq	%eax, %rdx
	movq	%rdx, %r12
	movl	$0, %r13d
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L2:
	cmpq	%rdx, %rsp
	je	.L3
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L2
.L3:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L4
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L4:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -64(%rbp)
	movl	$0, -92(%rbp)
	jmp	.L5
.L6:
	movl	-92(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-64(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-64(%rbp), %rax
	movl	-92(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	addl	%eax, -88(%rbp)
	addl	$1, -92(%rbp)
.L5:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L6
	movl	-96(%rbp), %esi
	movl	-88(%rbp), %eax
	cltd
	idivl	%esi
	movl	%eax, -88(%rbp)
	movl	$0, -92(%rbp)
	jmp	.L7
.L8:
	movq	-64(%rbp), %rax
	movl	-92(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	subl	-88(%rbp), %eax
	movl	%eax, -76(%rbp)
	movl	-76(%rbp), %eax
	imull	%eax, %eax
	addl	%eax, -84(%rbp)
	addl	$1, -92(%rbp)
.L7:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L8
	movl	$0, -92(%rbp)
	jmp	.L9
.L10:
	movq	-64(%rbp), %rax
	movl	-92(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	subl	-88(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -76(%rbp)
	movl	-76(%rbp), %eax
	imull	%eax, %eax
	addl	%eax, -80(%rbp)
	addl	$1, -92(%rbp)
.L9:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L10
	movl	-84(%rbp), %eax
	cmpl	-80(%rbp), %eax
	jle	.L11
	movl	-80(%rbp), %eax
	movl	%eax, -84(%rbp)
.L11:
	movl	$0, -80(%rbp)
	movl	$0, -92(%rbp)
	jmp	.L12
.L13:
	movq	-64(%rbp), %rax
	movl	-92(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	subl	-88(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -76(%rbp)
	movl	-76(%rbp), %eax
	imull	%eax, %eax
	addl	%eax, -80(%rbp)
	addl	$1, -92(%rbp)
.L12:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L13
	movl	-84(%rbp), %eax
	cmpl	-80(%rbp), %eax
	jle	.L14
	movl	-80(%rbp), %eax
	movl	%eax, -84(%rbp)
.L14:
	movl	-84(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%rbx, %rsp
	movq	-56(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.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
	.section	.rodata
.LC0:
	.string	"%d\n"
.LC1:
	.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
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %rbx
	movl	$0, -84(%rbp)
	movl	$0, -80(%rbp)
	leaq	-96(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-96(%rbp), %eax
	movslq	%eax, %rdx
	subq	$1, %rdx
	movq	%rdx, -72(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	movslq	%eax, %rdx
	movq	%rdx, %r12
	movl	$0, %r13d
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L2:
	cmpq	%rdx, %rsp
	je	.L3
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L2
.L3:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L4
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L4:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -64(%rbp)
	movl	$0, -92(%rbp)
	jmp	.L5
.L6:
	movl	-92(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-64(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-64(%rbp), %rax
	movl	-92(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	addl	%eax, -88(%rbp)
	addl	$1, -92(%rbp)
.L5:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L6
	movl	-96(%rbp), %esi
	movl	-88(%rbp), %eax
	cltd
	idivl	%esi
	movl	%eax, -88(%rbp)
	movl	$0, -92(%rbp)
	jmp	.L7
.L8:
	movq	-64(%rbp), %rax
	movl	-92(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	subl	-88(%rbp), %eax
	movl	%eax, -76(%rbp)
	movl	-76(%rbp), %eax
	imull	%eax, %eax
	addl	%eax, -84(%rbp)
	addl	$1, -92(%rbp)
.L7:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L8
	movl	$0, -92(%rbp)
	jmp	.L9
.L10:
	movq	-64(%rbp), %rax
	movl	-92(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	subl	-88(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -76(%rbp)
	movl	-76(%rbp), %eax
	imull	%eax, %eax
	addl	%eax, -80(%rbp)
	addl	$1, -92(%rbp)
.L9:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L10
	movl	-84(%rbp), %eax
	cmpl	-80(%rbp), %eax
	jle	.L11
	movl	-80(%rbp), %eax
	movl	%eax, -84(%rbp)
.L11:
	movl	$0, -80(%rbp)
	movl	$0, -92(%rbp)
	jmp	.L12
.L13:
	movq	-64(%rbp), %rax
	movl	-92(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	subl	-88(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -76(%rbp)
	movl	-76(%rbp), %eax
	imull	%eax, %eax
	addl	%eax, -80(%rbp)
	addl	$1, -92(%rbp)
.L12:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L13
	movl	-84(%rbp), %eax
	cmpl	-80(%rbp), %eax
	jle	.L14
	movl	-80(%rbp), %eax
	movl	%eax, -84(%rbp)
.L14:
	movl	-84(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%rbx, %rsp
	movq	-56(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.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:
