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,h,a=0,r=1,i,s[200010]={};
  scanf("%d",&n);
  while(n--){
    scanf("%d",&h);
    while(s[r-1]>=h){
      r--;
      if(s[r]-h)a++;
    }
    s[r++]=h;
    //for(i=0;i<r;i++)printf("%d ",s[i]);printf(":%d\n",a);
  }
  printf("%d\n",a+r-1);
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1344, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -800056(%rbp)
	movl	$1, -800052(%rbp)
	leaq	-800048(%rbp), %rax
	movl	$800040, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	-800064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L2
.L5:
	leaq	-800060(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L3
.L4:
	subl	$1, -800052(%rbp)
	movl	-800052(%rbp), %eax
	cltq
	movl	-800048(%rbp,%rax,4), %edx
	movl	-800060(%rbp), %eax
	cmpl	%eax, %edx
	je	.L3
	addl	$1, -800056(%rbp)
.L3:
	movl	-800052(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-800048(%rbp,%rax,4), %edx
	movl	-800060(%rbp), %eax
	cmpl	%eax, %edx
	jge	.L4
	movl	-800052(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -800052(%rbp)
	movl	-800060(%rbp), %edx
	cltq
	movl	%edx, -800048(%rbp,%rax,4)
.L2:
	movl	-800064(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -800064(%rbp)
	testl	%eax, %eax
	jne	.L5
	movl	-800056(%rbp), %edx
	movl	-800052(%rbp), %eax
	addl	%edx, %eax
	subl	$1, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	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\n"
	.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	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798768
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1344, %rsp
	.cfi_def_cfa_offset 800112
	movl	$800040, %edx
	xorl	%esi, %esi
	leaq	.LC0(%rip), %rbx
	movl	$1, %r14d
	movq	%fs:40, %rax
	movq	%rax, 800056(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %r13
	movq	%r13, %rdi
	call	memset@PLT
	leaq	8(%rsp), %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	8(%rsp), %r12d
	leal	-1(%r12), %eax
	movl	%eax, 8(%rsp)
	testl	%r12d, %r12d
	je	.L2
	xorl	%r12d, %r12d
	leaq	12(%rsp), %rbp
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	leal	-1(%r14), %eax
	movl	12(%rsp), %ecx
	cltq
	movl	16(%rsp,%rax,4), %edx
	cmpl	%ecx, %edx
	jl	.L9
	.p2align 4,,10
	.p2align 3
.L5:
	cmpl	%ecx, %edx
	movslq	%eax, %rsi
	setne	%dl
	subq	$1, %rax
	movzbl	%dl, %edx
	addl	%edx, %r12d
	movl	0(%r13,%rax,4), %edx
	cmpl	%ecx, %edx
	jge	.L5
.L3:
	movl	8(%rsp), %eax
	movl	%ecx, 16(%rsp,%rsi,4)
	leal	1(%rsi), %r14d
	leal	-1(%rax), %edx
	movl	%edx, 8(%rsp)
	testl	%eax, %eax
	jne	.L6
.L2:
	xorl	%eax, %eax
	leal	-1(%r12,%r14), %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	800056(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L14
	addq	$800064, %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
.L9:
	.cfi_restore_state
	movslq	%r14d, %rsi
	jmp	.L3
.L14:
	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\n"
	.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	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798768
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1344, %rsp
	.cfi_def_cfa_offset 800112
	movl	$800040, %edx
	xorl	%esi, %esi
	leaq	.LC0(%rip), %rbx
	movl	$1, %r14d
	movq	%fs:40, %rax
	movq	%rax, 800056(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %r13
	movq	%r13, %rdi
	call	memset@PLT
	leaq	8(%rsp), %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	8(%rsp), %r12d
	leal	-1(%r12), %eax
	movl	%eax, 8(%rsp)
	testl	%r12d, %r12d
	je	.L2
	xorl	%r12d, %r12d
	leaq	12(%rsp), %rbp
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	leal	-1(%r14), %eax
	movl	12(%rsp), %ecx
	cltq
	movl	16(%rsp,%rax,4), %edx
	cmpl	%ecx, %edx
	jl	.L9
	.p2align 4,,10
	.p2align 3
.L5:
	cmpl	%ecx, %edx
	movslq	%eax, %rsi
	setne	%dl
	subq	$1, %rax
	movzbl	%dl, %edx
	addl	%edx, %r12d
	movl	0(%r13,%rax,4), %edx
	cmpl	%ecx, %edx
	jge	.L5
.L3:
	movl	8(%rsp), %eax
	movl	%ecx, 16(%rsp,%rsi,4)
	leal	1(%rsi), %r14d
	leal	-1(%rax), %edx
	movl	%edx, 8(%rsp)
	testl	%eax, %eax
	jne	.L6
.L2:
	xorl	%eax, %eax
	leal	-1(%r12,%r14), %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	800056(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L14
	addq	$800064, %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
.L9:
	.cfi_restore_state
	movslq	%r14d, %rsi
	jmp	.L3
.L14:
	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 n,h,a=0,r=1,i,s[200010]={};
  scanf("%d",&n);
  while(n--){
    scanf("%d",&h);
    while(s[r-1]>=h){
      r--;
      if(s[r]-h)a++;
    }
    s[r++]=h;
    //for(i=0;i<r;i++)printf("%d ",s[i]);printf(":%d\n",a);
  }
  printf("%d\n",a+r-1);
  return 0;
}
3
1 2 1

2

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,h,a=0,r=1,i,s[200010]={};
  scanf("%d",&n);
  while(n--){
    scanf("%d",&h);
    while(s[r-1]>=h){
      r--;
      if(s[r]-h)a++;
    }
    s[r++]=h;
    //for(i=0;i<r;i++)printf("%d ",s[i]);printf(":%d\n",a);
  }
  printf("%d\n",a+r-1);
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1344, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -800056(%rbp)
	movl	$1, -800052(%rbp)
	leaq	-800048(%rbp), %rax
	movl	$800040, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	-800064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L2
.L5:
	leaq	-800060(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L3
.L4:
	subl	$1, -800052(%rbp)
	movl	-800052(%rbp), %eax
	cltq
	movl	-800048(%rbp,%rax,4), %edx
	movl	-800060(%rbp), %eax
	cmpl	%eax, %edx
	je	.L3
	addl	$1, -800056(%rbp)
.L3:
	movl	-800052(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-800048(%rbp,%rax,4), %edx
	movl	-800060(%rbp), %eax
	cmpl	%eax, %edx
	jge	.L4
	movl	-800052(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -800052(%rbp)
	movl	-800060(%rbp), %edx
	cltq
	movl	%edx, -800048(%rbp,%rax,4)
.L2:
	movl	-800064(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -800064(%rbp)
	testl	%eax, %eax
	jne	.L5
	movl	-800056(%rbp), %edx
	movl	-800052(%rbp), %eax
	addl	%edx, %eax
	subl	$1, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	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\n"
	.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	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1344, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -800056(%rbp)
	movl	$1, -800052(%rbp)
	leaq	-800048(%rbp), %rax
	movl	$800040, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	-800064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L2
.L5:
	leaq	-800060(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L3
.L4:
	subl	$1, -800052(%rbp)
	movl	-800052(%rbp), %eax
	cltq
	movl	-800048(%rbp,%rax,4), %edx
	movl	-800060(%rbp), %eax
	cmpl	%eax, %edx
	je	.L3
	addl	$1, -800056(%rbp)
.L3:
	movl	-800052(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-800048(%rbp,%rax,4), %edx
	movl	-800060(%rbp), %eax
	cmpl	%eax, %edx
	jge	.L4
	movl	-800052(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -800052(%rbp)
	movl	-800060(%rbp), %edx
	cltq
	movl	%edx, -800048(%rbp,%rax,4)
.L2:
	movl	-800064(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -800064(%rbp)
	testl	%eax, %eax
	jne	.L5
	movl	-800056(%rbp), %edx
	movl	-800052(%rbp), %eax
	addl	%edx, %eax
	subl	$1, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	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:
