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 cost(int n, int* a, int x){
    int sum = 0;
    for(int i=0; i<n; i++){
        sum += (*(a+i) - x) * (*(a+i) - x);
    }
    return  sum;
}

int main(){
    int n, min = 101;
    scanf("%d", &n);
    int a[n];
    for(int i=0; i<n; i++){
        scanf("%d", &a[i]);
        if(min > a[i]){
            min = a[i];
        }
    }
    int target = min;
    while(cost(n, a, target) > cost(n, a, target+1)){
        target++;
    }
    printf("%d", cost(n, a, target));

    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	cost
	.type	cost, @function
cost:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movq	%rsi, -32(%rbp)
	movl	%edx, -24(%rbp)
	movl	$0, -8(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L2
.L3:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	subl	-24(%rbp), %eax
	movl	%eax, %edx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	subl	-24(%rbp), %eax
	imull	%edx, %eax
	addl	%eax, -8(%rbp)
	addl	$1, -4(%rbp)
.L2:
	movl	-4(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jl	.L3
	movl	-8(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	cost, .-cost
	.section	.rodata
.LC0:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.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	%r12
	pushq	%rbx
	subq	$64, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 12, -40
	.cfi_offset 3, -48
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %r12
	movl	$101, -68(%rbp)
	leaq	-72(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-72(%rbp), %eax
	movslq	%eax, %rdx
	subq	$1, %rdx
	movq	%rdx, -56(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, -96(%rbp)
	movq	$0, -88(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %ebx
	movl	$0, %edx
	divq	%rbx
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L6:
	cmpq	%rdx, %rsp
	je	.L7
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L6
.L7:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L8
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L8:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -48(%rbp)
	movl	$0, -64(%rbp)
	jmp	.L9
.L11:
	movl	-64(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-48(%rbp), %rax
	movl	-64(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	cmpl	%eax, -68(%rbp)
	jle	.L10
	movq	-48(%rbp), %rax
	movl	-64(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	movl	%eax, -68(%rbp)
.L10:
	addl	$1, -64(%rbp)
.L9:
	movl	-72(%rbp), %eax
	cmpl	%eax, -64(%rbp)
	jl	.L11
	movl	-68(%rbp), %eax
	movl	%eax, -60(%rbp)
	jmp	.L12
.L13:
	addl	$1, -60(%rbp)
.L12:
	movl	-72(%rbp), %eax
	movl	-60(%rbp), %edx
	movq	-48(%rbp), %rcx
	movq	%rcx, %rsi
	movl	%eax, %edi
	call	cost
	movl	%eax, %ebx
	movl	-60(%rbp), %eax
	leal	1(%rax), %edx
	movl	-72(%rbp), %eax
	movq	-48(%rbp), %rcx
	movq	%rcx, %rsi
	movl	%eax, %edi
	call	cost
	cmpl	%eax, %ebx
	jg	.L13
	movl	-72(%rbp), %eax
	movl	-60(%rbp), %edx
	movq	-48(%rbp), %rcx
	movq	%rcx, %rsi
	movl	%eax, %edi
	call	cost
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%r12, %rsp
	movq	-40(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	leaq	-32(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.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
	.p2align 4
	.globl	cost
	.type	cost, @function
cost:
.LFB23:
	.cfi_startproc
	endbr64
	movl	%edi, %ecx
	testl	%edi, %edi
	jle	.L7
	leal	-1(%rdi), %eax
	cmpl	$2, %eax
	jbe	.L8
	shrl	$2, %edi
	movd	%edx, %xmm4
	pxor	%xmm2, %xmm2
	movq	%rsi, %rax
	subl	$1, %edi
	pshufd	$0, %xmm4, %xmm3
	salq	$4, %rdi
	leaq	16(%rsi,%rdi), %rdi
	.p2align 4,,10
	.p2align 3
.L4:
	movdqu	(%rax), %xmm0
	addq	$16, %rax
	psubd	%xmm3, %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, %xmm2
	cmpq	%rdi, %rax
	jne	.L4
	movdqa	%xmm2, %xmm0
	movl	%ecx, %r8d
	psrldq	$8, %xmm0
	andl	$-4, %r8d
	paddd	%xmm0, %xmm2
	movdqa	%xmm2, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm2
	movd	%xmm2, %eax
	testb	$3, %cl
	je	.L11
.L3:
	movslq	%r8d, %rdi
	leaq	0(,%rdi,4), %r9
	movl	(%rsi,%rdi,4), %edi
	subl	%edx, %edi
	imull	%edi, %edi
	addl	%edi, %eax
	leal	1(%r8), %edi
	cmpl	%edi, %ecx
	jle	.L1
	movl	4(%rsi,%r9), %edi
	addl	$2, %r8d
	subl	%edx, %edi
	imull	%edi, %edi
	addl	%edi, %eax
	cmpl	%r8d, %ecx
	jle	.L1
	movl	8(%rsi,%r9), %ecx
	subl	%edx, %ecx
	imull	%ecx, %ecx
	addl	%ecx, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L7:
	xorl	%eax, %eax
.L1:
	ret
	.p2align 4,,10
	.p2align 3
.L11:
	ret
.L8:
	xorl	%r8d, %r8d
	xorl	%eax, %eax
	jmp	.L3
	.cfi_endproc
.LFE23:
	.size	cost, .-cost
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.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
	leaq	-60(%rbp), %rsi
	pushq	%r13
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	leaq	.LC0(%rip), %r13
	pushq	%r12
	movq	%r13, %rdi
	pushq	%rbx
	subq	$40, %rsp
	.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, %rcx
	movq	%rax, %rsi
	leaq	15(,%rax,4), %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	subq	%rax, %rcx
	andq	$-16, %rdx
	cmpq	%rcx, %rsp
	je	.L14
.L54:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rcx, %rsp
	jne	.L54
.L14:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	jne	.L55
.L15:
	movq	%rsp, %r12
	testl	%esi, %esi
	jle	.L37
	movq	%r12, %r14
	xorl	%r15d, %r15d
	movl	$101, %ebx
	.p2align 4,,10
	.p2align 3
.L17:
	movq	%r14, %rsi
	xorl	%eax, %eax
	movq	%r13, %rdi
	call	__isoc99_scanf@PLT
	movl	(%r14), %eax
	movl	-60(%rbp), %esi
	cmpl	%eax, %ebx
	cmovg	%eax, %ebx
	addl	$1, %r15d
	addq	$4, %r14
	cmpl	%r15d, %esi
	jg	.L17
.L16:
	movl	%esi, %eax
	movl	%esi, %r10d
	leal	-1(%rsi), %r15d
	movq	%r12, %r11
	shrl	$2, %eax
	andl	$-4, %r10d
	subl	$1, %eax
	movl	%r10d, -68(%rbp)
	salq	$4, %rax
	leaq	16(%r12,%rax), %rcx
	.p2align 4,,10
	.p2align 3
.L27:
	movl	%ebx, %r9d
	addl	$1, %ebx
	testl	%esi, %esi
	jle	.L40
	cmpl	$2, %r15d
	jbe	.L38
	movd	%r9d, %xmm4
	movq	%r12, %rax
	pxor	%xmm2, %xmm2
	pshufd	$0, %xmm4, %xmm3
	.p2align 4,,10
	.p2align 3
.L20:
	movdqu	(%rax), %xmm0
	addq	$16, %rax
	psubd	%xmm3, %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, %xmm2
	cmpq	%rcx, %rax
	jne	.L20
	movdqa	%xmm2, %xmm0
	movl	%r10d, %edi
	psrldq	$8, %xmm0
	paddd	%xmm0, %xmm2
	movdqa	%xmm2, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm2
	movd	%xmm2, %edx
	cmpl	%r10d, %esi
	je	.L21
.L19:
	movslq	%edi, %rax
	leaq	0(,%rax,4), %r8
	movl	(%r12,%rax,4), %eax
	subl	%r9d, %eax
	imull	%eax, %eax
	addl	%eax, %edx
	leal	1(%rdi), %eax
	cmpl	%eax, %esi
	jle	.L22
	movl	4(%r12,%r8), %eax
	addl	$2, %edi
	subl	%r9d, %eax
	imull	%eax, %eax
	addl	%eax, %edx
	cmpl	%edi, %esi
	jle	.L23
	movl	8(%r12,%r8), %eax
	subl	%r9d, %eax
	imull	%eax, %eax
	addl	%eax, %edx
.L23:
	cmpl	$2, %r15d
	jbe	.L56
.L21:
	movd	%ebx, %xmm5
	movq	%r12, %rax
	pxor	%xmm2, %xmm2
	pshufd	$0, %xmm5, %xmm3
	.p2align 4,,10
	.p2align 3
.L25:
	movdqu	(%rax), %xmm0
	addq	$16, %rax
	psubd	%xmm3, %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, %xmm2
	cmpq	%rcx, %rax
	jne	.L25
	movdqa	%xmm2, %xmm0
	movl	%r10d, %edi
	psrldq	$8, %xmm0
	paddd	%xmm0, %xmm2
	movdqa	%xmm2, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm2
	movd	%xmm2, %eax
	cmpl	%r10d, %esi
	je	.L28
.L24:
	movslq	%edi, %r8
	addl	$1, %edi
	leaq	0(,%r8,4), %r14
	movl	(%r12,%r8,4), %r8d
	subl	%ebx, %r8d
	imull	%r8d, %r8d
	addl	%r8d, %eax
	cmpl	%esi, %edi
	jge	.L28
.L34:
	movl	4(%r12,%r14), %r8d
	addl	$1, %edi
	subl	%ebx, %r8d
	imull	%r8d, %r8d
	addl	%r8d, %eax
	cmpl	%edi, %esi
	jle	.L28
	movl	8(%r12,%r14), %edi
	subl	%ebx, %edi
	imull	%edi, %edi
	addl	%edi, %eax
.L28:
	cmpl	%eax, %edx
	jg	.L27
	testl	%esi, %esi
	jle	.L40
	cmpl	$2, %r15d
	jbe	.L41
	movd	%r9d, %xmm6
	pxor	%xmm2, %xmm2
	pshufd	$0, %xmm6, %xmm3
	.p2align 4,,10
	.p2align 3
.L31:
	movdqu	(%r11), %xmm0
	addq	$16, %r11
	psubd	%xmm3, %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, %xmm2
	cmpq	%rcx, %r11
	jne	.L31
	movdqa	%xmm2, %xmm0
	psrldq	$8, %xmm0
	paddd	%xmm0, %xmm2
	movdqa	%xmm2, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm2
	movd	%xmm2, %edx
	cmpl	%r10d, %esi
	je	.L29
.L30:
	movslq	-68(%rbp), %rax
	movq	%rax, %rbx
	leaq	0(,%rax,4), %rcx
	movl	(%r12,%rax,4), %eax
	subl	%r9d, %eax
	imull	%eax, %eax
	addl	%eax, %edx
	leal	1(%rbx), %eax
	cmpl	%esi, %eax
	jge	.L29
	movl	4(%r12,%rcx), %eax
	subl	%r9d, %eax
	imull	%eax, %eax
	addl	%eax, %edx
	movl	%ebx, %eax
	addl	$2, %eax
	cmpl	%esi, %eax
	jge	.L29
	movl	8(%r12,%rcx), %eax
	subl	%r9d, %eax
	imull	%eax, %eax
	addl	%eax, %edx
	jmp	.L29
.L38:
	xorl	%edx, %edx
	xorl	%edi, %edi
	jmp	.L19
.L56:
	movl	(%r12), %eax
	xorl	%r14d, %r14d
	movl	$1, %edi
	subl	%ebx, %eax
	imull	%eax, %eax
	jmp	.L34
.L22:
	cmpl	$2, %r15d
	ja	.L21
	xorl	%eax, %eax
	xorl	%edi, %edi
	jmp	.L24
.L55:
	orq	$0, -8(%rsp,%rdx)
	jmp	.L15
.L40:
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L29:
	xorl	%eax, %eax
	movq	%r13, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L57
	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
.L37:
	.cfi_restore_state
	movl	$101, %ebx
	jmp	.L16
.L57:
	call	__stack_chk_fail@PLT
.L41:
	movl	$0, -68(%rbp)
	xorl	%edx, %edx
	jmp	.L30
	.cfi_endproc
.LFE24:
	.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:

rule
	.file	"temp.c"
	.text
	.p2align 4
	.globl	cost
	.type	cost, @function
cost:
.LFB23:
	.cfi_startproc
	endbr64
	movl	%edi, %ecx
	testl	%edi, %edi
	jle	.L7
	leal	-1(%rdi), %eax
	cmpl	$2, %eax
	jbe	.L8
	shrl	$2, %edi
	movd	%edx, %xmm4
	pxor	%xmm2, %xmm2
	movq	%rsi, %rax
	subl	$1, %edi
	pshufd	$0, %xmm4, %xmm3
	salq	$4, %rdi
	leaq	16(%rsi,%rdi), %rdi
	.p2align 4,,10
	.p2align 3
.L4:
	movdqu	(%rax), %xmm0
	addq	$16, %rax
	psubd	%xmm3, %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, %xmm2
	cmpq	%rdi, %rax
	jne	.L4
	movdqa	%xmm2, %xmm0
	movl	%ecx, %r8d
	psrldq	$8, %xmm0
	andl	$-4, %r8d
	paddd	%xmm0, %xmm2
	movdqa	%xmm2, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm2
	movd	%xmm2, %eax
	testb	$3, %cl
	je	.L11
.L3:
	movslq	%r8d, %rdi
	leaq	0(,%rdi,4), %r9
	movl	(%rsi,%rdi,4), %edi
	subl	%edx, %edi
	imull	%edi, %edi
	addl	%edi, %eax
	leal	1(%r8), %edi
	cmpl	%edi, %ecx
	jle	.L1
	movl	4(%rsi,%r9), %edi
	addl	$2, %r8d
	subl	%edx, %edi
	imull	%edi, %edi
	addl	%edi, %eax
	cmpl	%r8d, %ecx
	jle	.L1
	movl	8(%rsi,%r9), %ecx
	subl	%edx, %ecx
	imull	%ecx, %ecx
	addl	%ecx, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L7:
	xorl	%eax, %eax
.L1:
	ret
	.p2align 4,,10
	.p2align 3
.L11:
	ret
.L8:
	xorl	%r8d, %r8d
	xorl	%eax, %eax
	jmp	.L3
	.cfi_endproc
.LFE23:
	.size	cost, .-cost
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.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
	leaq	-60(%rbp), %rsi
	pushq	%r13
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	leaq	.LC0(%rip), %r13
	pushq	%r12
	movq	%r13, %rdi
	pushq	%rbx
	subq	$40, %rsp
	.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, %rcx
	movq	%rax, %rsi
	leaq	15(,%rax,4), %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	subq	%rax, %rcx
	andq	$-16, %rdx
	cmpq	%rcx, %rsp
	je	.L14
.L54:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rcx, %rsp
	jne	.L54
.L14:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	jne	.L55
.L15:
	movq	%rsp, %r12
	testl	%esi, %esi
	jle	.L37
	movq	%r12, %r14
	xorl	%r15d, %r15d
	movl	$101, %ebx
	.p2align 4,,10
	.p2align 3
.L17:
	movq	%r14, %rsi
	xorl	%eax, %eax
	movq	%r13, %rdi
	call	__isoc99_scanf@PLT
	movl	(%r14), %eax
	movl	-60(%rbp), %esi
	cmpl	%eax, %ebx
	cmovg	%eax, %ebx
	addl	$1, %r15d
	addq	$4, %r14
	cmpl	%r15d, %esi
	jg	.L17
.L16:
	movl	%esi, %eax
	movl	%esi, %r10d
	leal	-1(%rsi), %r15d
	movq	%r12, %r11
	shrl	$2, %eax
	andl	$-4, %r10d
	subl	$1, %eax
	movl	%r10d, -68(%rbp)
	salq	$4, %rax
	leaq	16(%r12,%rax), %rcx
	.p2align 4,,10
	.p2align 3
.L27:
	movl	%ebx, %r9d
	addl	$1, %ebx
	testl	%esi, %esi
	jle	.L40
	cmpl	$2, %r15d
	jbe	.L38
	movd	%r9d, %xmm4
	movq	%r12, %rax
	pxor	%xmm2, %xmm2
	pshufd	$0, %xmm4, %xmm3
	.p2align 4,,10
	.p2align 3
.L20:
	movdqu	(%rax), %xmm0
	addq	$16, %rax
	psubd	%xmm3, %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, %xmm2
	cmpq	%rcx, %rax
	jne	.L20
	movdqa	%xmm2, %xmm0
	movl	%r10d, %edi
	psrldq	$8, %xmm0
	paddd	%xmm0, %xmm2
	movdqa	%xmm2, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm2
	movd	%xmm2, %edx
	cmpl	%r10d, %esi
	je	.L21
.L19:
	movslq	%edi, %rax
	leaq	0(,%rax,4), %r8
	movl	(%r12,%rax,4), %eax
	subl	%r9d, %eax
	imull	%eax, %eax
	addl	%eax, %edx
	leal	1(%rdi), %eax
	cmpl	%eax, %esi
	jle	.L22
	movl	4(%r12,%r8), %eax
	addl	$2, %edi
	subl	%r9d, %eax
	imull	%eax, %eax
	addl	%eax, %edx
	cmpl	%edi, %esi
	jle	.L23
	movl	8(%r12,%r8), %eax
	subl	%r9d, %eax
	imull	%eax, %eax
	addl	%eax, %edx
.L23:
	cmpl	$2, %r15d
	jbe	.L56
.L21:
	movd	%ebx, %xmm5
	movq	%r12, %rax
	pxor	%xmm2, %xmm2
	pshufd	$0, %xmm5, %xmm3
	.p2align 4,,10
	.p2align 3
.L25:
	movdqu	(%rax), %xmm0
	addq	$16, %rax
	psubd	%xmm3, %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, %xmm2
	cmpq	%rcx, %rax
	jne	.L25
	movdqa	%xmm2, %xmm0
	movl	%r10d, %edi
	psrldq	$8, %xmm0
	paddd	%xmm0, %xmm2
	movdqa	%xmm2, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm2
	movd	%xmm2, %eax
	cmpl	%r10d, %esi
	je	.L28
.L24:
	movslq	%edi, %r8
	addl	$1, %edi
	leaq	0(,%r8,4), %r14
	movl	(%r12,%r8,4), %r8d
	subl	%ebx, %r8d
	imull	%r8d, %r8d
	addl	%r8d, %eax
	cmpl	%esi, %edi
	jge	.L28
.L34:
	movl	4(%r12,%r14), %r8d
	addl	$1, %edi
	subl	%ebx, %r8d
	imull	%r8d, %r8d
	addl	%r8d, %eax
	cmpl	%edi, %esi
	jle	.L28
	movl	8(%r12,%r14), %edi
	subl	%ebx, %edi
	imull	%edi, %edi
	addl	%edi, %eax
.L28:
	cmpl	%eax, %edx
	jg	.L27
	testl	%esi, %esi
	jle	.L40
	cmpl	$2, %r15d
	jbe	.L41
	movd	%r9d, %xmm6
	pxor	%xmm2, %xmm2
	pshufd	$0, %xmm6, %xmm3
	.p2align 4,,10
	.p2align 3
.L31:
	movdqu	(%r11), %xmm0
	addq	$16, %r11
	psubd	%xmm3, %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, %xmm2
	cmpq	%rcx, %r11
	jne	.L31
	movdqa	%xmm2, %xmm0
	psrldq	$8, %xmm0
	paddd	%xmm0, %xmm2
	movdqa	%xmm2, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm2
	movd	%xmm2, %edx
	cmpl	%r10d, %esi
	je	.L29
.L30:
	movslq	-68(%rbp), %rax
	movq	%rax, %rbx
	leaq	0(,%rax,4), %rcx
	movl	(%r12,%rax,4), %eax
	subl	%r9d, %eax
	imull	%eax, %eax
	addl	%eax, %edx
	leal	1(%rbx), %eax
	cmpl	%esi, %eax
	jge	.L29
	movl	4(%r12,%rcx), %eax
	subl	%r9d, %eax
	imull	%eax, %eax
	addl	%eax, %edx
	movl	%ebx, %eax
	addl	$2, %eax
	cmpl	%esi, %eax
	jge	.L29
	movl	8(%r12,%rcx), %eax
	subl	%r9d, %eax
	imull	%eax, %eax
	addl	%eax, %edx
	jmp	.L29
.L38:
	xorl	%edx, %edx
	xorl	%edi, %edi
	jmp	.L19
.L56:
	movl	(%r12), %eax
	xorl	%r14d, %r14d
	movl	$1, %edi
	subl	%ebx, %eax
	imull	%eax, %eax
	jmp	.L34
.L22:
	cmpl	$2, %r15d
	ja	.L21
	xorl	%eax, %eax
	xorl	%edi, %edi
	jmp	.L24
.L55:
	orq	$0, -8(%rsp,%rdx)
	jmp	.L15
.L40:
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L29:
	xorl	%eax, %eax
	movq	%r13, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L57
	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
.L37:
	.cfi_restore_state
	movl	$101, %ebx
	jmp	.L16
.L57:
	call	__stack_chk_fail@PLT
.L41:
	movl	$0, -68(%rbp)
	xorl	%edx, %edx
	jmp	.L30
	.cfi_endproc
.LFE24:
	.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:

#include<stdio.h>

int cost(int n, int* a, int x){
    int sum = 0;
    for(int i=0; i<n; i++){
        sum += (*(a+i) - x) * (*(a+i) - x);
    }
    return  sum;
}

int main(){
    int n, min = 101;
    scanf("%d", &n);
    int a[n];
    for(int i=0; i<n; i++){
        scanf("%d", &a[i]);
        if(min > a[i]){
            min = a[i];
        }
    }
    int target = min;
    while(cost(n, a, target) > cost(n, a, target+1)){
        target++;
    }
    printf("%d", cost(n, a, target));

    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

5 17 2 2269 18 33 3 38 13 8
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 cost(int n, int* a, int x){
    int sum = 0;
    for(int i=0; i<n; i++){
        sum += (*(a+i) - x) * (*(a+i) - x);
    }
    return  sum;
}

int main(){
    int n, min = 101;
    scanf("%d", &n);
    int a[n];
    for(int i=0; i<n; i++){
        scanf("%d", &a[i]);
        if(min > a[i]){
            min = a[i];
        }
    }
    int target = min;
    while(cost(n, a, target) > cost(n, a, target+1)){
        target++;
    }
    printf("%d", cost(n, a, target));

    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	cost
	.type	cost, @function
cost:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movq	%rsi, -32(%rbp)
	movl	%edx, -24(%rbp)
	movl	$0, -8(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L2
.L3:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	subl	-24(%rbp), %eax
	movl	%eax, %edx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	subl	-24(%rbp), %eax
	imull	%edx, %eax
	addl	%eax, -8(%rbp)
	addl	$1, -4(%rbp)
.L2:
	movl	-4(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jl	.L3
	movl	-8(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	cost, .-cost
	.section	.rodata
.LC0:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.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	%r12
	pushq	%rbx
	subq	$64, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 12, -40
	.cfi_offset 3, -48
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %r12
	movl	$101, -68(%rbp)
	leaq	-72(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-72(%rbp), %eax
	movslq	%eax, %rdx
	subq	$1, %rdx
	movq	%rdx, -56(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, -96(%rbp)
	movq	$0, -88(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %ebx
	movl	$0, %edx
	divq	%rbx
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L6:
	cmpq	%rdx, %rsp
	je	.L7
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L6
.L7:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L8
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L8:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -48(%rbp)
	movl	$0, -64(%rbp)
	jmp	.L9
.L11:
	movl	-64(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-48(%rbp), %rax
	movl	-64(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	cmpl	%eax, -68(%rbp)
	jle	.L10
	movq	-48(%rbp), %rax
	movl	-64(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	movl	%eax, -68(%rbp)
.L10:
	addl	$1, -64(%rbp)
.L9:
	movl	-72(%rbp), %eax
	cmpl	%eax, -64(%rbp)
	jl	.L11
	movl	-68(%rbp), %eax
	movl	%eax, -60(%rbp)
	jmp	.L12
.L13:
	addl	$1, -60(%rbp)
.L12:
	movl	-72(%rbp), %eax
	movl	-60(%rbp), %edx
	movq	-48(%rbp), %rcx
	movq	%rcx, %rsi
	movl	%eax, %edi
	call	cost
	movl	%eax, %ebx
	movl	-60(%rbp), %eax
	leal	1(%rax), %edx
	movl	-72(%rbp), %eax
	movq	-48(%rbp), %rcx
	movq	%rcx, %rsi
	movl	%eax, %edi
	call	cost
	cmpl	%eax, %ebx
	jg	.L13
	movl	-72(%rbp), %eax
	movl	-60(%rbp), %edx
	movq	-48(%rbp), %rcx
	movq	%rcx, %rsi
	movl	%eax, %edi
	call	cost
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%r12, %rsp
	movq	-40(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	leaq	-32(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.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	cost
	.type	cost, @function
cost:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movq	%rsi, -32(%rbp)
	movl	%edx, -24(%rbp)
	movl	$0, -8(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L2
.L3:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	subl	-24(%rbp), %eax
	movl	%eax, %edx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	subl	-24(%rbp), %eax
	imull	%edx, %eax
	addl	%eax, -8(%rbp)
	addl	$1, -4(%rbp)
.L2:
	movl	-4(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jl	.L3
	movl	-8(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	cost, .-cost
	.section	.rodata
.LC0:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.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	%r12
	pushq	%rbx
	subq	$64, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 12, -40
	.cfi_offset 3, -48
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %r12
	movl	$101, -68(%rbp)
	leaq	-72(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-72(%rbp), %eax
	movslq	%eax, %rdx
	subq	$1, %rdx
	movq	%rdx, -56(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, -96(%rbp)
	movq	$0, -88(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %ebx
	movl	$0, %edx
	divq	%rbx
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L6:
	cmpq	%rdx, %rsp
	je	.L7
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L6
.L7:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L8
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L8:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -48(%rbp)
	movl	$0, -64(%rbp)
	jmp	.L9
.L11:
	movl	-64(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-48(%rbp), %rax
	movl	-64(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	cmpl	%eax, -68(%rbp)
	jle	.L10
	movq	-48(%rbp), %rax
	movl	-64(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	movl	%eax, -68(%rbp)
.L10:
	addl	$1, -64(%rbp)
.L9:
	movl	-72(%rbp), %eax
	cmpl	%eax, -64(%rbp)
	jl	.L11
	movl	-68(%rbp), %eax
	movl	%eax, -60(%rbp)
	jmp	.L12
.L13:
	addl	$1, -60(%rbp)
.L12:
	movl	-72(%rbp), %eax
	movl	-60(%rbp), %edx
	movq	-48(%rbp), %rcx
	movq	%rcx, %rsi
	movl	%eax, %edi
	call	cost
	movl	%eax, %ebx
	movl	-60(%rbp), %eax
	leal	1(%rax), %edx
	movl	-72(%rbp), %eax
	movq	-48(%rbp), %rcx
	movq	%rcx, %rsi
	movl	%eax, %edi
	call	cost
	cmpl	%eax, %ebx
	jg	.L13
	movl	-72(%rbp), %eax
	movl	-60(%rbp), %edx
	movq	-48(%rbp), %rcx
	movq	%rcx, %rsi
	movl	%eax, %edi
	call	cost
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%r12, %rsp
	movq	-40(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	leaq	-32(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.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:
