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

```c
#include<stdio.h>
int main(){
    int n;
    int a[1000];
    int max=0;
    int min=9999;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        if(max<=a[i]){
            max=a[i];
        }
    }
    for(int i=0;i<n;i++){
        if(a[i]<=min){
            min=a[i];
        }
    }
    int x=max-min;
    printf("%d\n",x);
}```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC1(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%r13, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$4040, %rsp
	.cfi_def_cfa_offset 4080
	movq	%fs:40, %rax
	movq	%rax, 4024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L2
	leaq	16(%rsp), %r12
	xorl	%ebx, %ebx
	movq	%r12, %rbp
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	addq	$4, %rbp
	cmpl	%ebx, %eax
	jg	.L3
	testl	%eax, %eax
	jle	.L2
	leal	-1(%rax), %edi
	cmpl	$2, %edi
	jbe	.L4
	movl	%eax, %edx
	movq	%r12, %rcx
	pxor	%xmm0, %xmm0
	shrl	$2, %edx
	leal	-1(%rdx), %esi
	leaq	16(%r12), %rdx
	salq	$4, %rsi
	addq	%rdx, %rsi
	.p2align 4,,10
	.p2align 3
.L5:
	movdqa	%xmm0, %xmm1
	addq	$16, %rcx
	pcmpgtd	-16(%rcx), %xmm1
	pand	%xmm1, %xmm0
	pandn	-16(%rcx), %xmm1
	por	%xmm1, %xmm0
	cmpq	%rsi, %rcx
	jne	.L5
	movdqa	%xmm0, %xmm2
	movl	%eax, %esi
	psrldq	$8, %xmm2
	andl	$-4, %esi
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	movdqa	%xmm1, %xmm0
	por	%xmm2, %xmm0
	movdqa	%xmm0, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	por	%xmm2, %xmm1
	movd	%xmm1, %ecx
	testb	$3, %al
	je	.L6
	movslq	%esi, %r8
	movl	16(%rsp,%r8,4), %r8d
	cmpl	%r8d, %ecx
	cmovl	%r8d, %ecx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L6
.L14:
	movslq	%esi, %rdx
	movl	16(%rsp,%rdx,4), %edx
	cmpl	%edx, %ecx
	cmovl	%edx, %ecx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L8
	movslq	%esi, %rsi
	movl	16(%rsp,%rsi,4), %edx
	cmpl	%edx, %ecx
	cmovl	%edx, %ecx
.L8:
	cmpl	$2, %edi
	jbe	.L13
	leaq	16(%r12), %rdx
.L6:
	movl	%eax, %esi
	movdqa	.LC0(%rip), %xmm2
	shrl	$2, %esi
	subl	$1, %esi
	salq	$4, %rsi
	addq	%rdx, %rsi
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L26:
	addq	$16, %rdx
.L9:
	movdqa	(%r12), %xmm0
	movdqa	%xmm2, %xmm1
	movq	%rdx, %r12
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	movdqa	%xmm1, %xmm2
	por	%xmm0, %xmm2
	cmpq	%rdx, %rsi
	jne	.L26
	movdqa	%xmm2, %xmm0
	movl	%eax, %esi
	psrldq	$8, %xmm0
	andl	$-4, %esi
	movdqa	%xmm0, %xmm1
	pcmpgtd	%xmm2, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	por	%xmm2, %xmm1
	movdqa	%xmm1, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm0
	pcmpgtd	%xmm1, %xmm0
	pand	%xmm0, %xmm1
	pandn	%xmm2, %xmm0
	por	%xmm1, %xmm0
	movd	%xmm0, %edx
	testb	$3, %al
	je	.L11
.L15:
	movslq	%esi, %rdi
	movl	16(%rsp,%rdi,4), %edi
	cmpl	%edi, %edx
	cmovg	%edi, %edx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L11
.L12:
	movslq	%esi, %rdi
	movl	16(%rsp,%rdi,4), %edi
	cmpl	%edi, %edx
	cmovg	%edi, %edx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L11
	movslq	%esi, %rsi
	movl	16(%rsp,%rsi,4), %eax
	cmpl	%eax, %edx
	cmovg	%eax, %edx
.L11:
	subl	%edx, %ecx
	xorl	%eax, %eax
	movl	$1, %edi
	movl	%ecx, %edx
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	4024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L27
	addq	$4040, %rsp
	.cfi_remember_state
	.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
.L2:
	.cfi_restore_state
	xorl	%ecx, %ecx
	movl	$9999, %edx
	jmp	.L11
.L4:
	movl	16(%rsp), %ecx
	xorl	%edx, %edx
	movl	$1, %esi
	testl	%ecx, %ecx
	cmovs	%edx, %ecx
	cmpl	$1, %eax
	jne	.L14
	xorl	%esi, %esi
	movl	$9999, %edx
	jmp	.L15
.L13:
	movl	16(%rsp), %edx
	movl	$9999, %esi
	cmpl	%esi, %edx
	cmovg	%esi, %edx
	movl	$1, %esi
	jmp	.L12
.L27:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	9999
	.long	9999
	.long	9999
	.long	9999
	.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.
Optimized Assembly Code:

user
```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC1(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%r13, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$4040, %rsp
	.cfi_def_cfa_offset 4080
	movq	%fs:40, %rax
	movq	%rax, 4024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L2
	leaq	16(%rsp), %r12
	xorl	%ebx, %ebx
	movq	%r12, %rbp
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	addq	$4, %rbp
	cmpl	%ebx, %eax
	jg	.L3
	testl	%eax, %eax
	jle	.L2
	leal	-1(%rax), %edi
	cmpl	$2, %edi
	jbe	.L4
	movl	%eax, %edx
	movq	%r12, %rcx
	pxor	%xmm0, %xmm0
	shrl	$2, %edx
	leal	-1(%rdx), %esi
	leaq	16(%r12), %rdx
	salq	$4, %rsi
	addq	%rdx, %rsi
	.p2align 4,,10
	.p2align 3
.L5:
	movdqa	%xmm0, %xmm1
	addq	$16, %rcx
	pcmpgtd	-16(%rcx), %xmm1
	pand	%xmm1, %xmm0
	pandn	-16(%rcx), %xmm1
	por	%xmm1, %xmm0
	cmpq	%rsi, %rcx
	jne	.L5
	movdqa	%xmm0, %xmm2
	movl	%eax, %esi
	psrldq	$8, %xmm2
	andl	$-4, %esi
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	movdqa	%xmm1, %xmm0
	por	%xmm2, %xmm0
	movdqa	%xmm0, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	por	%xmm2, %xmm1
	movd	%xmm1, %ecx
	testb	$3, %al
	je	.L6
	movslq	%esi, %r8
	movl	16(%rsp,%r8,4), %r8d
	cmpl	%r8d, %ecx
	cmovl	%r8d, %ecx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L6
.L14:
	movslq	%esi, %rdx
	movl	16(%rsp,%rdx,4), %edx
	cmpl	%edx, %ecx
	cmovl	%edx, %ecx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L8
	movslq	%esi, %rsi
	movl	16(%rsp,%rsi,4), %edx
	cmpl	%edx, %ecx
	cmovl	%edx, %ecx
.L8:
	cmpl	$2, %edi
	jbe	.L13
	leaq	16(%r12), %rdx
.L6:
	movl	%eax, %esi
	movdqa	.LC0(%rip), %xmm2
	shrl	$2, %esi
	subl	$1, %esi
	salq	$4, %rsi
	addq	%rdx, %rsi
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L26:
	addq	$16, %rdx
.L9:
	movdqa	(%r12), %xmm0
	movdqa	%xmm2, %xmm1
	movq	%rdx, %r12
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	movdqa	%xmm1, %xmm2
	por	%xmm0, %xmm2
	cmpq	%rdx, %rsi
	jne	.L26
	movdqa	%xmm2, %xmm0
	movl	%eax, %esi
	psrldq	$8, %xmm0
	andl	$-4, %esi
	movdqa	%xmm0, %xmm1
	pcmpgtd	%xmm2, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	por	%xmm2, %xmm1
	movdqa	%xmm1, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm0
	pcmpgtd	%xmm1, %xmm0
	pand	%xmm0, %xmm1
	pandn	%xmm2, %xmm0
	por	%xmm1, %xmm0
	movd	%xmm0, %edx
	testb	$3, %al
	je	.L11
.L15:
	movslq	%esi, %rdi
	movl	16(%rsp,%rdi,4), %edi
	cmpl	%edi, %edx
	cmovg	%edi, %edx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L11
.L12:
	movslq	%esi, %rdi
	movl	16(%rsp,%rdi,4), %edi
	cmpl	%edi, %edx
	cmovg	%edi, %edx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L11
	movslq	%esi, %rsi
	movl	16(%rsp,%rsi,4), %eax
	cmpl	%eax, %edx
	cmovg	%eax, %edx
.L11:
	subl	%edx, %ecx
	xorl	%eax, %eax
	movl	$1, %edi
	movl	%ecx, %edx
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	4024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L27
	addq	$4040, %rsp
	.cfi_remember_state
	.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
.L2:
	.cfi_restore_state
	xorl	%ecx, %ecx
	movl	$9999, %edx
	jmp	.L11
.L4:
	movl	16(%rsp), %ecx
	xorl	%edx, %edx
	movl	$1, %esi
	testl	%ecx, %ecx
	cmovs	%edx, %ecx
	cmpl	$1, %eax
	jne	.L14
	xorl	%esi, %esi
	movl	$9999, %edx
	jmp	.L15
.L13:
	movl	16(%rsp), %edx
	movl	$9999, %esi
	cmpl	%esi, %edx
	cmovg	%esi, %edx
	movl	$1, %esi
	jmp	.L12
.L27:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	9999
	.long	9999
	.long	9999
	.long	9999
	.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
```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC1(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%r13, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$4040, %rsp
	.cfi_def_cfa_offset 4080
	movq	%fs:40, %rax
	movq	%rax, 4024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L2
	leaq	16(%rsp), %r12
	xorl	%ebx, %ebx
	movq	%r12, %rbp
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	addq	$4, %rbp
	cmpl	%ebx, %eax
	jg	.L3
	testl	%eax, %eax
	jle	.L2
	leal	-1(%rax), %edi
	cmpl	$2, %edi
	jbe	.L4
	movl	%eax, %edx
	movq	%r12, %rcx
	pxor	%xmm0, %xmm0
	shrl	$2, %edx
	leal	-1(%rdx), %esi
	leaq	16(%r12), %rdx
	salq	$4, %rsi
	addq	%rdx, %rsi
	.p2align 4,,10
	.p2align 3
.L5:
	movdqa	%xmm0, %xmm1
	addq	$16, %rcx
	pcmpgtd	-16(%rcx), %xmm1
	pand	%xmm1, %xmm0
	pandn	-16(%rcx), %xmm1
	por	%xmm1, %xmm0
	cmpq	%rsi, %rcx
	jne	.L5
	movdqa	%xmm0, %xmm2
	movl	%eax, %esi
	psrldq	$8, %xmm2
	andl	$-4, %esi
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	movdqa	%xmm1, %xmm0
	por	%xmm2, %xmm0
	movdqa	%xmm0, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	por	%xmm2, %xmm1
	movd	%xmm1, %ecx
	testb	$3, %al
	je	.L6
	movslq	%esi, %r8
	movl	16(%rsp,%r8,4), %r8d
	cmpl	%r8d, %ecx
	cmovl	%r8d, %ecx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L6
.L14:
	movslq	%esi, %rdx
	movl	16(%rsp,%rdx,4), %edx
	cmpl	%edx, %ecx
	cmovl	%edx, %ecx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L8
	movslq	%esi, %rsi
	movl	16(%rsp,%rsi,4), %edx
	cmpl	%edx, %ecx
	cmovl	%edx, %ecx
.L8:
	cmpl	$2, %edi
	jbe	.L13
	leaq	16(%r12), %rdx
.L6:
	movl	%eax, %esi
	movdqa	.LC0(%rip), %xmm2
	shrl	$2, %esi
	subl	$1, %esi
	salq	$4, %rsi
	addq	%rdx, %rsi
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L26:
	addq	$16, %rdx
.L9:
	movdqa	(%r12), %xmm0
	movdqa	%xmm2, %xmm1
	movq	%rdx, %r12
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	movdqa	%xmm1, %xmm2
	por	%xmm0, %xmm2
	cmpq	%rdx, %rsi
	jne	.L26
	movdqa	%xmm2, %xmm0
	movl	%eax, %esi
	psrldq	$8, %xmm0
	andl	$-4, %esi
	movdqa	%xmm0, %xmm1
	pcmpgtd	%xmm2, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	por	%xmm2, %xmm1
	movdqa	%xmm1, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm0
	pcmpgtd	%xmm1, %xmm0
	pand	%xmm0, %xmm1
	pandn	%xmm2, %xmm0
	por	%xmm1, %xmm0
	movd	%xmm0, %edx
	testb	$3, %al
	je	.L11
.L15:
	movslq	%esi, %rdi
	movl	16(%rsp,%rdi,4), %edi
	cmpl	%edi, %edx
	cmovg	%edi, %edx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L11
.L12:
	movslq	%esi, %rdi
	movl	16(%rsp,%rdi,4), %edi
	cmpl	%edi, %edx
	cmovg	%edi, %edx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L11
	movslq	%esi, %rsi
	movl	16(%rsp,%rsi,4), %eax
	cmpl	%eax, %edx
	cmovg	%eax, %edx
.L11:
	subl	%edx, %ecx
	xorl	%eax, %eax
	movl	$1, %edi
	movl	%ecx, %edx
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	4024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L27
	addq	$4040, %rsp
	.cfi_remember_state
	.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
.L2:
	.cfi_restore_state
	xorl	%ecx, %ecx
	movl	$9999, %edx
	jmp	.L11
.L4:
	movl	16(%rsp), %ecx
	xorl	%edx, %edx
	movl	$1, %esi
	testl	%ecx, %ecx
	cmovs	%edx, %ecx
	cmpl	$1, %eax
	jne	.L14
	xorl	%esi, %esi
	movl	$9999, %edx
	jmp	.L15
.L13:
	movl	16(%rsp), %edx
	movl	$9999, %esi
	cmpl	%esi, %edx
	cmovg	%esi, %edx
	movl	$1, %esi
	jmp	.L12
.L27:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	9999
	.long	9999
	.long	9999
	.long	9999
	.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:
```
```c
#include<stdio.h>
int main(){
    int n;
    int a[1000];
    int max=0;
    int min=9999;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        if(max<=a[i]){
            max=a[i];
        }
    }
    for(int i=0;i<n;i++){
        if(a[i]<=min){
            min=a[i];
        }
    }
    int x=max-min;
    printf("%d\n",x);
}```
Given the following C code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include<stdio.h>
int main(){
    int n;
    int a[1000];
    int max=0;
    int min=9999;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        if(max<=a[i]){
            max=a[i];
        }
    }
    for(int i=0;i<n;i++){
        if(a[i]<=min){
            min=a[i];
        }
    }
    int x=max-min;
    printf("%d\n",x);
}```

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.
Optimized Assembly Code:

4
2 3 9 9
 8
3 1 4 1 5 18 2 6
 4
2 3 13 9
 4
4 4 13 9
 8
3 1 1 1 5 15 1 6
 4
4 4 8 9
 4
0 4 8 18
 8
1 1 1 2 5 14 1 6
 4
-1 2 4 18
 4
-1 2 4 31

7
 17
 11
 9
 14
 5
 18
 13
 19
 32

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

```c
#include<stdio.h>
int main(){
    int n;
    int a[1000];
    int max=0;
    int min=9999;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        if(max<=a[i]){
            max=a[i];
        }
    }
    for(int i=0;i<n;i++){
        if(a[i]<=min){
            min=a[i];
        }
    }
    int x=max-min;
    printf("%d\n",x);
}```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC1(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%r13, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$4040, %rsp
	.cfi_def_cfa_offset 4080
	movq	%fs:40, %rax
	movq	%rax, 4024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L2
	leaq	16(%rsp), %r12
	xorl	%ebx, %ebx
	movq	%r12, %rbp
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	addq	$4, %rbp
	cmpl	%ebx, %eax
	jg	.L3
	testl	%eax, %eax
	jle	.L2
	leal	-1(%rax), %edi
	cmpl	$2, %edi
	jbe	.L4
	movl	%eax, %edx
	movq	%r12, %rcx
	pxor	%xmm0, %xmm0
	shrl	$2, %edx
	leal	-1(%rdx), %esi
	leaq	16(%r12), %rdx
	salq	$4, %rsi
	addq	%rdx, %rsi
	.p2align 4,,10
	.p2align 3
.L5:
	movdqa	%xmm0, %xmm1
	addq	$16, %rcx
	pcmpgtd	-16(%rcx), %xmm1
	pand	%xmm1, %xmm0
	pandn	-16(%rcx), %xmm1
	por	%xmm1, %xmm0
	cmpq	%rsi, %rcx
	jne	.L5
	movdqa	%xmm0, %xmm2
	movl	%eax, %esi
	psrldq	$8, %xmm2
	andl	$-4, %esi
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	movdqa	%xmm1, %xmm0
	por	%xmm2, %xmm0
	movdqa	%xmm0, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	por	%xmm2, %xmm1
	movd	%xmm1, %ecx
	testb	$3, %al
	je	.L6
	movslq	%esi, %r8
	movl	16(%rsp,%r8,4), %r8d
	cmpl	%r8d, %ecx
	cmovl	%r8d, %ecx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L6
.L14:
	movslq	%esi, %rdx
	movl	16(%rsp,%rdx,4), %edx
	cmpl	%edx, %ecx
	cmovl	%edx, %ecx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L8
	movslq	%esi, %rsi
	movl	16(%rsp,%rsi,4), %edx
	cmpl	%edx, %ecx
	cmovl	%edx, %ecx
.L8:
	cmpl	$2, %edi
	jbe	.L13
	leaq	16(%r12), %rdx
.L6:
	movl	%eax, %esi
	movdqa	.LC0(%rip), %xmm2
	shrl	$2, %esi
	subl	$1, %esi
	salq	$4, %rsi
	addq	%rdx, %rsi
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L26:
	addq	$16, %rdx
.L9:
	movdqa	(%r12), %xmm0
	movdqa	%xmm2, %xmm1
	movq	%rdx, %r12
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	movdqa	%xmm1, %xmm2
	por	%xmm0, %xmm2
	cmpq	%rdx, %rsi
	jne	.L26
	movdqa	%xmm2, %xmm0
	movl	%eax, %esi
	psrldq	$8, %xmm0
	andl	$-4, %esi
	movdqa	%xmm0, %xmm1
	pcmpgtd	%xmm2, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	por	%xmm2, %xmm1
	movdqa	%xmm1, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm0
	pcmpgtd	%xmm1, %xmm0
	pand	%xmm0, %xmm1
	pandn	%xmm2, %xmm0
	por	%xmm1, %xmm0
	movd	%xmm0, %edx
	testb	$3, %al
	je	.L11
.L15:
	movslq	%esi, %rdi
	movl	16(%rsp,%rdi,4), %edi
	cmpl	%edi, %edx
	cmovg	%edi, %edx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L11
.L12:
	movslq	%esi, %rdi
	movl	16(%rsp,%rdi,4), %edi
	cmpl	%edi, %edx
	cmovg	%edi, %edx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L11
	movslq	%esi, %rsi
	movl	16(%rsp,%rsi,4), %eax
	cmpl	%eax, %edx
	cmovg	%eax, %edx
.L11:
	subl	%edx, %ecx
	xorl	%eax, %eax
	movl	$1, %edi
	movl	%ecx, %edx
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	4024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L27
	addq	$4040, %rsp
	.cfi_remember_state
	.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
.L2:
	.cfi_restore_state
	xorl	%ecx, %ecx
	movl	$9999, %edx
	jmp	.L11
.L4:
	movl	16(%rsp), %ecx
	xorl	%edx, %edx
	movl	$1, %esi
	testl	%ecx, %ecx
	cmovs	%edx, %ecx
	cmpl	$1, %eax
	jne	.L14
	xorl	%esi, %esi
	movl	$9999, %edx
	jmp	.L15
.L13:
	movl	16(%rsp), %edx
	movl	$9999, %esi
	cmpl	%esi, %edx
	cmovg	%esi, %edx
	movl	$1, %esi
	jmp	.L12
.L27:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	9999
	.long	9999
	.long	9999
	.long	9999
	.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.
Optimized Assembly Code:

train
```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC1(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%r13, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$4040, %rsp
	.cfi_def_cfa_offset 4080
	movq	%fs:40, %rax
	movq	%rax, 4024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L2
	leaq	16(%rsp), %r12
	xorl	%ebx, %ebx
	movq	%r12, %rbp
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	addq	$4, %rbp
	cmpl	%ebx, %eax
	jg	.L3
	testl	%eax, %eax
	jle	.L2
	leal	-1(%rax), %edi
	cmpl	$2, %edi
	jbe	.L4
	movl	%eax, %edx
	movq	%r12, %rcx
	pxor	%xmm0, %xmm0
	shrl	$2, %edx
	leal	-1(%rdx), %esi
	leaq	16(%r12), %rdx
	salq	$4, %rsi
	addq	%rdx, %rsi
	.p2align 4,,10
	.p2align 3
.L5:
	movdqa	%xmm0, %xmm1
	addq	$16, %rcx
	pcmpgtd	-16(%rcx), %xmm1
	pand	%xmm1, %xmm0
	pandn	-16(%rcx), %xmm1
	por	%xmm1, %xmm0
	cmpq	%rsi, %rcx
	jne	.L5
	movdqa	%xmm0, %xmm2
	movl	%eax, %esi
	psrldq	$8, %xmm2
	andl	$-4, %esi
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	movdqa	%xmm1, %xmm0
	por	%xmm2, %xmm0
	movdqa	%xmm0, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	por	%xmm2, %xmm1
	movd	%xmm1, %ecx
	testb	$3, %al
	je	.L6
	movslq	%esi, %r8
	movl	16(%rsp,%r8,4), %r8d
	cmpl	%r8d, %ecx
	cmovl	%r8d, %ecx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L6
.L14:
	movslq	%esi, %rdx
	movl	16(%rsp,%rdx,4), %edx
	cmpl	%edx, %ecx
	cmovl	%edx, %ecx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L8
	movslq	%esi, %rsi
	movl	16(%rsp,%rsi,4), %edx
	cmpl	%edx, %ecx
	cmovl	%edx, %ecx
.L8:
	cmpl	$2, %edi
	jbe	.L13
	leaq	16(%r12), %rdx
.L6:
	movl	%eax, %esi
	movdqa	.LC0(%rip), %xmm2
	shrl	$2, %esi
	subl	$1, %esi
	salq	$4, %rsi
	addq	%rdx, %rsi
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L26:
	addq	$16, %rdx
.L9:
	movdqa	(%r12), %xmm0
	movdqa	%xmm2, %xmm1
	movq	%rdx, %r12
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	movdqa	%xmm1, %xmm2
	por	%xmm0, %xmm2
	cmpq	%rdx, %rsi
	jne	.L26
	movdqa	%xmm2, %xmm0
	movl	%eax, %esi
	psrldq	$8, %xmm0
	andl	$-4, %esi
	movdqa	%xmm0, %xmm1
	pcmpgtd	%xmm2, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	por	%xmm2, %xmm1
	movdqa	%xmm1, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm0
	pcmpgtd	%xmm1, %xmm0
	pand	%xmm0, %xmm1
	pandn	%xmm2, %xmm0
	por	%xmm1, %xmm0
	movd	%xmm0, %edx
	testb	$3, %al
	je	.L11
.L15:
	movslq	%esi, %rdi
	movl	16(%rsp,%rdi,4), %edi
	cmpl	%edi, %edx
	cmovg	%edi, %edx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L11
.L12:
	movslq	%esi, %rdi
	movl	16(%rsp,%rdi,4), %edi
	cmpl	%edi, %edx
	cmovg	%edi, %edx
	addl	$1, %esi
	cmpl	%esi, %eax
	jle	.L11
	movslq	%esi, %rsi
	movl	16(%rsp,%rsi,4), %eax
	cmpl	%eax, %edx
	cmovg	%eax, %edx
.L11:
	subl	%edx, %ecx
	xorl	%eax, %eax
	movl	$1, %edi
	movl	%ecx, %edx
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	4024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L27
	addq	$4040, %rsp
	.cfi_remember_state
	.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
.L2:
	.cfi_restore_state
	xorl	%ecx, %ecx
	movl	$9999, %edx
	jmp	.L11
.L4:
	movl	16(%rsp), %ecx
	xorl	%edx, %edx
	movl	$1, %esi
	testl	%ecx, %ecx
	cmovs	%edx, %ecx
	cmpl	$1, %eax
	jne	.L14
	xorl	%esi, %esi
	movl	$9999, %edx
	jmp	.L15
.L13:
	movl	16(%rsp), %edx
	movl	$9999, %esi
	cmpl	%esi, %edx
	cmovg	%esi, %edx
	movl	$1, %esi
	jmp	.L12
.L27:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	9999
	.long	9999
	.long	9999
	.long	9999
	.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:
```