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 i,j,k,n,left,right;
  left=249999;
  right=250001;
  int A[500000];
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d ",&k);
    if(i==0){
      A[250000]=k;
    }
    else{
      if(n%2 == (i+1)%2){
        A[left--]=k;
      }
      else
        A[right++]=k;
    }
  }
  
  for(i=left+1;i<right;i++)
    printf("%d ",A[i]);
  puts("");
  return 0;
}
    ```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d "
.LC2:
	.string	""
	.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
	leaq	-1998848(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1200, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$249999, -2000024(%rbp)
	movl	$250001, -2000020(%rbp)
	leaq	-2000032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -2000028(%rbp)
	jmp	.L2
.L6:
	leaq	-2000036(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$0, -2000028(%rbp)
	jne	.L3
	movl	-2000036(%rbp), %eax
	movl	%eax, -1000016(%rbp)
	jmp	.L4
.L3:
	movl	-2000032(%rbp), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	-2000028(%rbp), %eax
	addl	$1, %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	cmpl	%eax, %ecx
	jne	.L5
	movl	-2000024(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -2000024(%rbp)
	movl	-2000036(%rbp), %edx
	cltq
	movl	%edx, -2000016(%rbp,%rax,4)
	jmp	.L4
.L5:
	movl	-2000020(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -2000020(%rbp)
	movl	-2000036(%rbp), %edx
	cltq
	movl	%edx, -2000016(%rbp,%rax,4)
.L4:
	addl	$1, -2000028(%rbp)
.L2:
	movl	-2000032(%rbp), %eax
	cmpl	%eax, -2000028(%rbp)
	jl	.L6
	movl	-2000024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -2000028(%rbp)
	jmp	.L7
.L8:
	movl	-2000028(%rbp), %eax
	cltq
	movl	-2000016(%rbp,%rax,4), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -2000028(%rbp)
.L7:
	movl	-2000028(%rbp), %eax
	cmpl	-2000020(%rbp), %eax
	jl	.L8
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	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	"%d"
.LC1:
	.string	"%d "
.LC2:
	.string	""
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	-1998848(%rsp), %r11
	.cfi_def_cfa 11, 1998896
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1184, %rsp
	.cfi_def_cfa_offset 2000080
	leaq	.LC0(%rip), %rdi
	movl	$250001, %r12d
	movl	$249999, %r14d
	leaq	.LC1(%rip), %rbp
	movq	%fs:40, %rax
	movq	%rax, 2000024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L2
	xorl	%ebx, %ebx
	leaq	8(%rsp), %r13
	leaq	.LC1(%rip), %rbp
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L14:
	movl	8(%rsp), %eax
	movl	%eax, 1000016(%rsp)
.L4:
	cmpl	%ebx, 12(%rsp)
	jle	.L2
.L6:
	movq	%r13, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	cmpl	$1, %ebx
	je	.L14
	movl	12(%rsp), %eax
	movl	8(%rsp), %ecx
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%ebx, %edx
	andl	$1, %edx
	cmpl	%edx, %eax
	je	.L15
	movslq	%r12d, %rax
	addl	$1, %r12d
	movl	%ecx, 16(%rsp,%rax,4)
	cmpl	%ebx, 12(%rsp)
	jg	.L6
.L2:
	subl	$2, %r12d
	movslq	%r14d, %rax
	subl	%r14d, %r12d
	leaq	16(%rsp,%rax,4), %rbx
	addq	%rax, %r12
	leaq	20(%rsp,%r12,4), %r12
	.p2align 4,,10
	.p2align 3
.L7:
	movl	4(%rbx), %edx
	movq	%rbp, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	addq	$4, %rbx
	call	__printf_chk@PLT
	cmpq	%r12, %rbx
	jne	.L7
	leaq	.LC2(%rip), %rdi
	call	puts@PLT
	movq	2000024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L16
	addq	$2000032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L15:
	.cfi_restore_state
	movslq	%r14d, %rax
	subl	$1, %r14d
	movl	%ecx, 16(%rsp,%rax,4)
	jmp	.L4
.L16:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d "
.LC2:
	.string	""
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	-1998848(%rsp), %r11
	.cfi_def_cfa 11, 1998896
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1184, %rsp
	.cfi_def_cfa_offset 2000080
	leaq	.LC0(%rip), %rdi
	movl	$250001, %r12d
	movl	$249999, %r14d
	leaq	.LC1(%rip), %rbp
	movq	%fs:40, %rax
	movq	%rax, 2000024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L2
	xorl	%ebx, %ebx
	leaq	8(%rsp), %r13
	leaq	.LC1(%rip), %rbp
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L14:
	movl	8(%rsp), %eax
	movl	%eax, 1000016(%rsp)
.L4:
	cmpl	%ebx, 12(%rsp)
	jle	.L2
.L6:
	movq	%r13, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	cmpl	$1, %ebx
	je	.L14
	movl	12(%rsp), %eax
	movl	8(%rsp), %ecx
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%ebx, %edx
	andl	$1, %edx
	cmpl	%edx, %eax
	je	.L15
	movslq	%r12d, %rax
	addl	$1, %r12d
	movl	%ecx, 16(%rsp,%rax,4)
	cmpl	%ebx, 12(%rsp)
	jg	.L6
.L2:
	subl	$2, %r12d
	movslq	%r14d, %rax
	subl	%r14d, %r12d
	leaq	16(%rsp,%rax,4), %rbx
	addq	%rax, %r12
	leaq	20(%rsp,%r12,4), %r12
	.p2align 4,,10
	.p2align 3
.L7:
	movl	4(%rbx), %edx
	movq	%rbp, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	addq	$4, %rbx
	call	__printf_chk@PLT
	cmpq	%r12, %rbx
	jne	.L7
	leaq	.LC2(%rip), %rdi
	call	puts@PLT
	movq	2000024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L16
	addq	$2000032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L15:
	.cfi_restore_state
	movslq	%r14d, %rax
	subl	$1, %r14d
	movl	%ecx, 16(%rsp,%rax,4)
	jmp	.L4
.L16:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.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 main(){
  int i,j,k,n,left,right;
  left=249999;
  right=250001;
  int A[500000];
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d ",&k);
    if(i==0){
      A[250000]=k;
    }
    else{
      if(n%2 == (i+1)%2){
        A[left--]=k;
      }
      else
        A[right++]=k;
    }
  }
  
  for(i=left+1;i<right;i++)
    printf("%d ",A[i]);
  puts("");
  return 0;
}
    
4
1 2 3 4

4 2 1 3 

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 i,j,k,n,left,right;
  left=249999;
  right=250001;
  int A[500000];
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d ",&k);
    if(i==0){
      A[250000]=k;
    }
    else{
      if(n%2 == (i+1)%2){
        A[left--]=k;
      }
      else
        A[right++]=k;
    }
  }
  
  for(i=left+1;i<right;i++)
    printf("%d ",A[i]);
  puts("");
  return 0;
}
    ```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d "
.LC2:
	.string	""
	.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
	leaq	-1998848(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1200, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$249999, -2000024(%rbp)
	movl	$250001, -2000020(%rbp)
	leaq	-2000032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -2000028(%rbp)
	jmp	.L2
.L6:
	leaq	-2000036(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$0, -2000028(%rbp)
	jne	.L3
	movl	-2000036(%rbp), %eax
	movl	%eax, -1000016(%rbp)
	jmp	.L4
.L3:
	movl	-2000032(%rbp), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	-2000028(%rbp), %eax
	addl	$1, %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	cmpl	%eax, %ecx
	jne	.L5
	movl	-2000024(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -2000024(%rbp)
	movl	-2000036(%rbp), %edx
	cltq
	movl	%edx, -2000016(%rbp,%rax,4)
	jmp	.L4
.L5:
	movl	-2000020(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -2000020(%rbp)
	movl	-2000036(%rbp), %edx
	cltq
	movl	%edx, -2000016(%rbp,%rax,4)
.L4:
	addl	$1, -2000028(%rbp)
.L2:
	movl	-2000032(%rbp), %eax
	cmpl	%eax, -2000028(%rbp)
	jl	.L6
	movl	-2000024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -2000028(%rbp)
	jmp	.L7
.L8:
	movl	-2000028(%rbp), %eax
	cltq
	movl	-2000016(%rbp,%rax,4), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -2000028(%rbp)
.L7:
	movl	-2000028(%rbp), %eax
	cmpl	-2000020(%rbp), %eax
	jl	.L8
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	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
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d "
.LC2:
	.string	""
	.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
	leaq	-1998848(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1200, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$249999, -2000024(%rbp)
	movl	$250001, -2000020(%rbp)
	leaq	-2000032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -2000028(%rbp)
	jmp	.L2
.L6:
	leaq	-2000036(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$0, -2000028(%rbp)
	jne	.L3
	movl	-2000036(%rbp), %eax
	movl	%eax, -1000016(%rbp)
	jmp	.L4
.L3:
	movl	-2000032(%rbp), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	-2000028(%rbp), %eax
	addl	$1, %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	cmpl	%eax, %ecx
	jne	.L5
	movl	-2000024(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -2000024(%rbp)
	movl	-2000036(%rbp), %edx
	cltq
	movl	%edx, -2000016(%rbp,%rax,4)
	jmp	.L4
.L5:
	movl	-2000020(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -2000020(%rbp)
	movl	-2000036(%rbp), %edx
	cltq
	movl	%edx, -2000016(%rbp,%rax,4)
.L4:
	addl	$1, -2000028(%rbp)
.L2:
	movl	-2000032(%rbp), %eax
	cmpl	%eax, -2000028(%rbp)
	jl	.L6
	movl	-2000024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -2000028(%rbp)
	jmp	.L7
.L8:
	movl	-2000028(%rbp), %eax
	cltq
	movl	-2000016(%rbp,%rax,4), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -2000028(%rbp)
.L7:
	movl	-2000028(%rbp), %eax
	cmpl	-2000020(%rbp), %eax
	jl	.L8
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	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:
