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 MIN(int a,int b){return a < b ? a : b;}

int main()
{
    int n,h[200000],i,j,min,ans = 0,left,right;
    scanf("%d",&n);
    for (i = 0; i < n; i++)scanf("%d",&h[i]);

    for(j = 0; j < n; j++)
    {
        for (i = 0; i < n; i++)if(h[i] != 0)break;
        left = i;
        for (i = left; i < n; i++)if(h[i] == 0)break;
        right = i;
        min = h[left];
        for (i = left + 1; i < right; i++)min = MIN(min,h[i]);
        for (i = left; i < right; i++)h[i] -= min;
        ans += min;
    }
    printf("%d",ans);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	MIN
	.type	MIN, @function
MIN:
.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, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	MIN, .-MIN
	.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
	leaq	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1328, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -800028(%rbp)
	leaq	-800044(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -800040(%rbp)
	jmp	.L4
.L5:
	leaq	-800016(%rbp), %rdx
	movl	-800040(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -800040(%rbp)
.L4:
	movl	-800044(%rbp), %eax
	cmpl	%eax, -800040(%rbp)
	jl	.L5
	movl	$0, -800036(%rbp)
	jmp	.L6
.L19:
	movl	$0, -800040(%rbp)
	jmp	.L7
.L10:
	movl	-800040(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L22
	addl	$1, -800040(%rbp)
.L7:
	movl	-800044(%rbp), %eax
	cmpl	%eax, -800040(%rbp)
	jl	.L10
	jmp	.L9
.L22:
	nop
.L9:
	movl	-800040(%rbp), %eax
	movl	%eax, -800024(%rbp)
	movl	-800024(%rbp), %eax
	movl	%eax, -800040(%rbp)
	jmp	.L11
.L14:
	movl	-800040(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	testl	%eax, %eax
	je	.L23
	addl	$1, -800040(%rbp)
.L11:
	movl	-800044(%rbp), %eax
	cmpl	%eax, -800040(%rbp)
	jl	.L14
	jmp	.L13
.L23:
	nop
.L13:
	movl	-800040(%rbp), %eax
	movl	%eax, -800020(%rbp)
	movl	-800024(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	movl	%eax, -800032(%rbp)
	movl	-800024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -800040(%rbp)
	jmp	.L15
.L16:
	movl	-800040(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %edx
	movl	-800032(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	MIN
	movl	%eax, -800032(%rbp)
	addl	$1, -800040(%rbp)
.L15:
	movl	-800040(%rbp), %eax
	cmpl	-800020(%rbp), %eax
	jl	.L16
	movl	-800024(%rbp), %eax
	movl	%eax, -800040(%rbp)
	jmp	.L17
.L18:
	movl	-800040(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	subl	-800032(%rbp), %eax
	movl	%eax, %edx
	movl	-800040(%rbp), %eax
	cltq
	movl	%edx, -800016(%rbp,%rax,4)
	addl	$1, -800040(%rbp)
.L17:
	movl	-800040(%rbp), %eax
	cmpl	-800020(%rbp), %eax
	jl	.L18
	movl	-800032(%rbp), %eax
	addl	%eax, -800028(%rbp)
	addl	$1, -800036(%rbp)
.L6:
	movl	-800044(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L19
	movl	-800028(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	leave
	.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	MIN
	.type	MIN, @function
MIN:
.LFB23:
	.cfi_startproc
	endbr64
	cmpl	%edi, %esi
	movl	%edi, %eax
	cmovle	%esi, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	MIN, .-MIN
	.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	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798760
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1320, %rsp
	.cfi_def_cfa_offset 800080
	leaq	.LC0(%rip), %rbp
	movq	%rbp, %rdi
	movq	%fs:40, %rax
	movq	%rax, 800024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r9d
	testl	%r9d, %r9d
	jle	.L4
	leaq	16(%rsp), %rbx
	xorl	%r12d, %r12d
	movq	%rbx, %r13
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%r13, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	addl	$1, %r12d
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %edi
	addq	$4, %r13
	cmpl	%r12d, %edi
	jg	.L5
	testl	%edi, %edi
	jle	.L4
	xorl	%r10d, %r10d
	xorl	%r9d, %r9d
	movslq	%edi, %r11
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%rbx, %rcx
	xorl	%eax, %eax
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L41:
	addq	$4, %rcx
	cmpl	%eax, %edi
	je	.L40
.L8:
	movl	(%rcx), %edx
	movl	%eax, %esi
	addl	$1, %eax
	testl	%edx, %edx
	je	.L41
	cmpl	%esi, %edi
	jle	.L28
	movslq	%esi, %rax
	leaq	(%rbx,%rax,4), %rcx
	movl	%esi, %eax
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L42:
	addl	$1, %eax
	addq	$4, %rcx
	cmpl	%eax, %edi
	je	.L11
.L12:
	movl	(%rcx), %r8d
	testl	%r8d, %r8d
	jne	.L42
.L11:
	leal	1(%rsi), %r12d
	movl	%r12d, %ecx
	cmpl	%eax, %r12d
	jge	.L13
.L25:
	movl	%eax, %r8d
	subl	%esi, %r8d
	leal	-1(%r8), %r13d
	subl	$2, %r8d
	cmpl	$2, %r8d
	jbe	.L14
	movd	%edx, %xmm3
	movslq	%r12d, %rdx
	leaq	(%rbx,%rdx,4), %rcx
	movl	%r13d, %edx
	pshufd	$0, %xmm3, %xmm0
	shrl	$2, %edx
	leal	-1(%rdx), %r8d
	leaq	16(%rcx), %rdx
	salq	$4, %r8
	addq	%rdx, %r8
	jmp	.L15
	.p2align 4,,10
	.p2align 3
.L43:
	addq	$16, %rdx
.L15:
	movdqu	(%rcx), %xmm2
	movq	%rdx, %rcx
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	por	%xmm1, %xmm0
	cmpq	%r8, %rdx
	jne	.L43
	movdqa	%xmm0, %xmm2
	movl	%r13d, %r8d
	psrldq	$8, %xmm2
	andl	$-4, %r8d
	movdqa	%xmm2, %xmm1
	leal	(%r12,%r8), %ecx
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	por	%xmm1, %xmm0
	movdqa	%xmm0, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	por	%xmm0, %xmm1
	movd	%xmm1, %edx
	cmpl	%r8d, %r13d
	je	.L13
.L14:
	movslq	%ecx, %r8
	movl	16(%rsp,%r8,4), %r8d
	cmpl	%r8d, %edx
	cmovg	%r8d, %edx
	leal	1(%rcx), %r8d
	cmpl	%r8d, %eax
	jle	.L13
	movslq	%r8d, %r8
	movl	16(%rsp,%r8,4), %r8d
	cmpl	%r8d, %edx
	cmovg	%r8d, %edx
	addl	$2, %ecx
	cmpl	%ecx, %eax
	jle	.L13
	movslq	%ecx, %rcx
	movl	16(%rsp,%rcx,4), %ecx
	cmpl	%ecx, %edx
	cmovg	%ecx, %edx
.L13:
	cmpl	%eax, %esi
	jge	.L23
	movl	%eax, %r13d
	subl	%esi, %r13d
	leal	-1(%r13), %ecx
	cmpl	$2, %ecx
	jbe	.L20
	movslq	%esi, %rcx
	movd	%edx, %xmm4
	leaq	(%rbx,%rcx,4), %r8
	movl	%r13d, %ecx
	pshufd	$0, %xmm4, %xmm1
	shrl	$2, %ecx
	leal	-1(%rcx), %r12d
	leaq	16(%r8), %rcx
	salq	$4, %r12
	addq	%rcx, %r12
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L44:
	addq	$16, %rcx
.L21:
	movdqu	(%r8), %xmm0
	psubd	%xmm1, %xmm0
	movups	%xmm0, (%r8)
	movq	%rcx, %r8
	cmpq	%rcx, %r12
	jne	.L44
	movl	%r13d, %ecx
	andl	$-4, %ecx
	addl	%ecx, %esi
	cmpl	%ecx, %r13d
	je	.L23
	leal	1(%rsi), %r12d
.L20:
	movslq	%esi, %rcx
	subl	%edx, 16(%rsp,%rcx,4)
	cmpl	%eax, %r12d
	jge	.L23
	movslq	%r12d, %r12
	addl	$2, %esi
	subl	%edx, 16(%rsp,%r12,4)
	cmpl	%eax, %esi
	jge	.L23
	movslq	%esi, %rsi
	subl	%edx, 16(%rsp,%rsi,4)
.L23:
	addl	$1, %r9d
	addl	%edx, %r10d
	cmpl	%r9d, %edi
	jne	.L6
.L19:
	xorl	%eax, %eax
	movl	%r10d, %edx
	movq	%rbp, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	800024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L45
	addq	$800040, %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
	.p2align 4,,10
	.p2align 3
.L40:
	.cfi_restore_state
	movl	16(%rsp,%r11,4), %edx
	movl	%edi, %esi
.L10:
	leal	1(%rsi), %r12d
	movl	%r12d, %ecx
	cmpl	%r12d, %eax
	jg	.L25
	jmp	.L23
.L4:
	xorl	%r10d, %r10d
	jmp	.L19
.L28:
	movl	%esi, %eax
	jmp	.L10
.L45:
	call	__stack_chk_fail@PLT
	.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	MIN
	.type	MIN, @function
MIN:
.LFB23:
	.cfi_startproc
	endbr64
	cmpl	%edi, %esi
	movl	%edi, %eax
	cmovle	%esi, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	MIN, .-MIN
	.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	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798760
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1320, %rsp
	.cfi_def_cfa_offset 800080
	leaq	.LC0(%rip), %rbp
	movq	%rbp, %rdi
	movq	%fs:40, %rax
	movq	%rax, 800024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r9d
	testl	%r9d, %r9d
	jle	.L4
	leaq	16(%rsp), %rbx
	xorl	%r12d, %r12d
	movq	%rbx, %r13
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%r13, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	addl	$1, %r12d
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %edi
	addq	$4, %r13
	cmpl	%r12d, %edi
	jg	.L5
	testl	%edi, %edi
	jle	.L4
	xorl	%r10d, %r10d
	xorl	%r9d, %r9d
	movslq	%edi, %r11
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%rbx, %rcx
	xorl	%eax, %eax
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L41:
	addq	$4, %rcx
	cmpl	%eax, %edi
	je	.L40
.L8:
	movl	(%rcx), %edx
	movl	%eax, %esi
	addl	$1, %eax
	testl	%edx, %edx
	je	.L41
	cmpl	%esi, %edi
	jle	.L28
	movslq	%esi, %rax
	leaq	(%rbx,%rax,4), %rcx
	movl	%esi, %eax
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L42:
	addl	$1, %eax
	addq	$4, %rcx
	cmpl	%eax, %edi
	je	.L11
.L12:
	movl	(%rcx), %r8d
	testl	%r8d, %r8d
	jne	.L42
.L11:
	leal	1(%rsi), %r12d
	movl	%r12d, %ecx
	cmpl	%eax, %r12d
	jge	.L13
.L25:
	movl	%eax, %r8d
	subl	%esi, %r8d
	leal	-1(%r8), %r13d
	subl	$2, %r8d
	cmpl	$2, %r8d
	jbe	.L14
	movd	%edx, %xmm3
	movslq	%r12d, %rdx
	leaq	(%rbx,%rdx,4), %rcx
	movl	%r13d, %edx
	pshufd	$0, %xmm3, %xmm0
	shrl	$2, %edx
	leal	-1(%rdx), %r8d
	leaq	16(%rcx), %rdx
	salq	$4, %r8
	addq	%rdx, %r8
	jmp	.L15
	.p2align 4,,10
	.p2align 3
.L43:
	addq	$16, %rdx
.L15:
	movdqu	(%rcx), %xmm2
	movq	%rdx, %rcx
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	por	%xmm1, %xmm0
	cmpq	%r8, %rdx
	jne	.L43
	movdqa	%xmm0, %xmm2
	movl	%r13d, %r8d
	psrldq	$8, %xmm2
	andl	$-4, %r8d
	movdqa	%xmm2, %xmm1
	leal	(%r12,%r8), %ecx
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	por	%xmm1, %xmm0
	movdqa	%xmm0, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	por	%xmm0, %xmm1
	movd	%xmm1, %edx
	cmpl	%r8d, %r13d
	je	.L13
.L14:
	movslq	%ecx, %r8
	movl	16(%rsp,%r8,4), %r8d
	cmpl	%r8d, %edx
	cmovg	%r8d, %edx
	leal	1(%rcx), %r8d
	cmpl	%r8d, %eax
	jle	.L13
	movslq	%r8d, %r8
	movl	16(%rsp,%r8,4), %r8d
	cmpl	%r8d, %edx
	cmovg	%r8d, %edx
	addl	$2, %ecx
	cmpl	%ecx, %eax
	jle	.L13
	movslq	%ecx, %rcx
	movl	16(%rsp,%rcx,4), %ecx
	cmpl	%ecx, %edx
	cmovg	%ecx, %edx
.L13:
	cmpl	%eax, %esi
	jge	.L23
	movl	%eax, %r13d
	subl	%esi, %r13d
	leal	-1(%r13), %ecx
	cmpl	$2, %ecx
	jbe	.L20
	movslq	%esi, %rcx
	movd	%edx, %xmm4
	leaq	(%rbx,%rcx,4), %r8
	movl	%r13d, %ecx
	pshufd	$0, %xmm4, %xmm1
	shrl	$2, %ecx
	leal	-1(%rcx), %r12d
	leaq	16(%r8), %rcx
	salq	$4, %r12
	addq	%rcx, %r12
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L44:
	addq	$16, %rcx
.L21:
	movdqu	(%r8), %xmm0
	psubd	%xmm1, %xmm0
	movups	%xmm0, (%r8)
	movq	%rcx, %r8
	cmpq	%rcx, %r12
	jne	.L44
	movl	%r13d, %ecx
	andl	$-4, %ecx
	addl	%ecx, %esi
	cmpl	%ecx, %r13d
	je	.L23
	leal	1(%rsi), %r12d
.L20:
	movslq	%esi, %rcx
	subl	%edx, 16(%rsp,%rcx,4)
	cmpl	%eax, %r12d
	jge	.L23
	movslq	%r12d, %r12
	addl	$2, %esi
	subl	%edx, 16(%rsp,%r12,4)
	cmpl	%eax, %esi
	jge	.L23
	movslq	%esi, %rsi
	subl	%edx, 16(%rsp,%rsi,4)
.L23:
	addl	$1, %r9d
	addl	%edx, %r10d
	cmpl	%r9d, %edi
	jne	.L6
.L19:
	xorl	%eax, %eax
	movl	%r10d, %edx
	movq	%rbp, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	800024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L45
	addq	$800040, %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
	.p2align 4,,10
	.p2align 3
.L40:
	.cfi_restore_state
	movl	16(%rsp,%r11,4), %edx
	movl	%edi, %esi
.L10:
	leal	1(%rsi), %r12d
	movl	%r12d, %ecx
	cmpl	%r12d, %eax
	jg	.L25
	jmp	.L23
.L4:
	xorl	%r10d, %r10d
	jmp	.L19
.L28:
	movl	%esi, %eax
	jmp	.L10
.L45:
	call	__stack_chk_fail@PLT
	.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 MIN(int a,int b){return a < b ? a : b;}

int main()
{
    int n,h[200000],i,j,min,ans = 0,left,right;
    scanf("%d",&n);
    for (i = 0; i < n; i++)scanf("%d",&h[i]);

    for(j = 0; j < n; j++)
    {
        for (i = 0; i < n; i++)if(h[i] != 0)break;
        left = i;
        for (i = left; i < n; i++)if(h[i] == 0)break;
        right = i;
        min = h[left];
        for (i = left + 1; i < right; i++)min = MIN(min,h[i]);
        for (i = left; i < right; i++)h[i] -= min;
        ans += min;
    }
    printf("%d",ans);
}
4
1 4 2 1
 8
4 23 75 1 23 96 50 100
 5
1 1 2 3 1
 4
1 8 2 1
 8
4 23 75 0 23 97 50 100
 4
1 12 2 1
 8
4 23 136 0 23 97 50 100
 4
1 12 0 2
 8
4 39 136 0 23 97 50 101
 8
4 39 136 0 23 108 50 101

4 220 3 8 222 12 283 14 284 295
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 MIN(int a,int b){return a < b ? a : b;}

int main()
{
    int n,h[200000],i,j,min,ans = 0,left,right;
    scanf("%d",&n);
    for (i = 0; i < n; i++)scanf("%d",&h[i]);

    for(j = 0; j < n; j++)
    {
        for (i = 0; i < n; i++)if(h[i] != 0)break;
        left = i;
        for (i = left; i < n; i++)if(h[i] == 0)break;
        right = i;
        min = h[left];
        for (i = left + 1; i < right; i++)min = MIN(min,h[i]);
        for (i = left; i < right; i++)h[i] -= min;
        ans += min;
    }
    printf("%d",ans);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	MIN
	.type	MIN, @function
MIN:
.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, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	MIN, .-MIN
	.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
	leaq	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1328, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -800028(%rbp)
	leaq	-800044(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -800040(%rbp)
	jmp	.L4
.L5:
	leaq	-800016(%rbp), %rdx
	movl	-800040(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -800040(%rbp)
.L4:
	movl	-800044(%rbp), %eax
	cmpl	%eax, -800040(%rbp)
	jl	.L5
	movl	$0, -800036(%rbp)
	jmp	.L6
.L19:
	movl	$0, -800040(%rbp)
	jmp	.L7
.L10:
	movl	-800040(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L22
	addl	$1, -800040(%rbp)
.L7:
	movl	-800044(%rbp), %eax
	cmpl	%eax, -800040(%rbp)
	jl	.L10
	jmp	.L9
.L22:
	nop
.L9:
	movl	-800040(%rbp), %eax
	movl	%eax, -800024(%rbp)
	movl	-800024(%rbp), %eax
	movl	%eax, -800040(%rbp)
	jmp	.L11
.L14:
	movl	-800040(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	testl	%eax, %eax
	je	.L23
	addl	$1, -800040(%rbp)
.L11:
	movl	-800044(%rbp), %eax
	cmpl	%eax, -800040(%rbp)
	jl	.L14
	jmp	.L13
.L23:
	nop
.L13:
	movl	-800040(%rbp), %eax
	movl	%eax, -800020(%rbp)
	movl	-800024(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	movl	%eax, -800032(%rbp)
	movl	-800024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -800040(%rbp)
	jmp	.L15
.L16:
	movl	-800040(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %edx
	movl	-800032(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	MIN
	movl	%eax, -800032(%rbp)
	addl	$1, -800040(%rbp)
.L15:
	movl	-800040(%rbp), %eax
	cmpl	-800020(%rbp), %eax
	jl	.L16
	movl	-800024(%rbp), %eax
	movl	%eax, -800040(%rbp)
	jmp	.L17
.L18:
	movl	-800040(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	subl	-800032(%rbp), %eax
	movl	%eax, %edx
	movl	-800040(%rbp), %eax
	cltq
	movl	%edx, -800016(%rbp,%rax,4)
	addl	$1, -800040(%rbp)
.L17:
	movl	-800040(%rbp), %eax
	cmpl	-800020(%rbp), %eax
	jl	.L18
	movl	-800032(%rbp), %eax
	addl	%eax, -800028(%rbp)
	addl	$1, -800036(%rbp)
.L6:
	movl	-800044(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L19
	movl	-800028(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	leave
	.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	MIN
	.type	MIN, @function
MIN:
.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, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	MIN, .-MIN
	.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
	leaq	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1328, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -800028(%rbp)
	leaq	-800044(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -800040(%rbp)
	jmp	.L4
.L5:
	leaq	-800016(%rbp), %rdx
	movl	-800040(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -800040(%rbp)
.L4:
	movl	-800044(%rbp), %eax
	cmpl	%eax, -800040(%rbp)
	jl	.L5
	movl	$0, -800036(%rbp)
	jmp	.L6
.L19:
	movl	$0, -800040(%rbp)
	jmp	.L7
.L10:
	movl	-800040(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L22
	addl	$1, -800040(%rbp)
.L7:
	movl	-800044(%rbp), %eax
	cmpl	%eax, -800040(%rbp)
	jl	.L10
	jmp	.L9
.L22:
	nop
.L9:
	movl	-800040(%rbp), %eax
	movl	%eax, -800024(%rbp)
	movl	-800024(%rbp), %eax
	movl	%eax, -800040(%rbp)
	jmp	.L11
.L14:
	movl	-800040(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	testl	%eax, %eax
	je	.L23
	addl	$1, -800040(%rbp)
.L11:
	movl	-800044(%rbp), %eax
	cmpl	%eax, -800040(%rbp)
	jl	.L14
	jmp	.L13
.L23:
	nop
.L13:
	movl	-800040(%rbp), %eax
	movl	%eax, -800020(%rbp)
	movl	-800024(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	movl	%eax, -800032(%rbp)
	movl	-800024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -800040(%rbp)
	jmp	.L15
.L16:
	movl	-800040(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %edx
	movl	-800032(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	MIN
	movl	%eax, -800032(%rbp)
	addl	$1, -800040(%rbp)
.L15:
	movl	-800040(%rbp), %eax
	cmpl	-800020(%rbp), %eax
	jl	.L16
	movl	-800024(%rbp), %eax
	movl	%eax, -800040(%rbp)
	jmp	.L17
.L18:
	movl	-800040(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	subl	-800032(%rbp), %eax
	movl	%eax, %edx
	movl	-800040(%rbp), %eax
	cltq
	movl	%edx, -800016(%rbp,%rax,4)
	addl	$1, -800040(%rbp)
.L17:
	movl	-800040(%rbp), %eax
	cmpl	-800020(%rbp), %eax
	jl	.L18
	movl	-800032(%rbp), %eax
	addl	%eax, -800028(%rbp)
	addl	$1, -800036(%rbp)
.L6:
	movl	-800044(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L19
	movl	-800028(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	leave
	.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:
