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 max( int num[ ] , int test)
{
    int m , i , pos = 0 ;
    m= num[0] ;
    for( i =0 ; i < test ; i++)
    {
        if( num[i] > m)
        {
             m = num[i] ;
             pos = i ;
        }
           
    }
    return pos;
}
int main( )
{
    int num[15] , test , i , maximum , result = 0 ;
    scanf("%d" , &test);
    for( i = 0 ; i < test ; i++)
    {
        scanf("%d" , &num[i]);
    }
    
    maximum = max( num , test );
    
    for( i = 0 ; i < test ; i++)
    {
           if( maximum == i)
            result = result + num[i]/2 ;
            else
                result = result + num[i] ;
    }
    printf("%d\n" , result);
    return 0 ;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	max
	.type	max, @function
max:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	$0, -4(%rbp)
	movq	-24(%rbp), %rax
	movl	(%rax), %eax
	movl	%eax, -12(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L2
.L4:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -12(%rbp)
	jge	.L3
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -12(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, -4(%rbp)
.L3:
	addl	$1, -8(%rbp)
.L2:
	movl	-8(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L4
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	max, .-max
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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
	subq	$96, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -88(%rbp)
	leaq	-96(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -92(%rbp)
	jmp	.L7
.L8:
	leaq	-80(%rbp), %rdx
	movl	-92(%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, -92(%rbp)
.L7:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L8
	movl	-96(%rbp), %edx
	leaq	-80(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	max
	movl	%eax, -84(%rbp)
	movl	$0, -92(%rbp)
	jmp	.L9
.L12:
	movl	-84(%rbp), %eax
	cmpl	-92(%rbp), %eax
	jne	.L10
	movl	-92(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	addl	%eax, -88(%rbp)
	jmp	.L11
.L10:
	movl	-92(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	addl	%eax, -88(%rbp)
.L11:
	addl	$1, -92(%rbp)
.L9:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L12
	movl	-88(%rbp), %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	.L14
	call	__stack_chk_fail@PLT
.L14:
	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	max
	.type	max, @function
max:
.LFB23:
	.cfi_startproc
	endbr64
	movl	(%rdi), %ecx
	testl	%esi, %esi
	jle	.L5
	movslq	%esi, %rsi
	xorl	%eax, %eax
	xorl	%r8d, %r8d
	.p2align 4,,10
	.p2align 3
.L4:
	movl	(%rdi,%rax,4), %edx
	cmpl	%edx, %ecx
	jge	.L3
	movl	%eax, %r8d
	movl	%edx, %ecx
.L3:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L4
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L5:
	xorl	%r8d, %r8d
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	max, .-max
	.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:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%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	$104, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L10
	leaq	16(%rsp), %r12
	xorl	%ebx, %ebx
	movq	%r12, %rbp
	.p2align 4,,10
	.p2align 3
.L11:
	movq	%rbp, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %ecx
	addq	$4, %rbp
	cmpl	%ebx, %ecx
	jg	.L11
	movl	16(%rsp), %r8d
	testl	%ecx, %ecx
	jle	.L10
	movslq	%ecx, %r9
	movl	%r8d, %esi
	xorl	%eax, %eax
	xorl	%edi, %edi
	.p2align 4,,10
	.p2align 3
.L13:
	movl	(%r12,%rax,4), %edx
	cmpl	%edx, %esi
	jge	.L12
	movl	%eax, %edi
	movl	%edx, %esi
.L12:
	addq	$1, %rax
	cmpq	%r9, %rax
	jne	.L13
	testl	%edi, %edi
	je	.L66
	cmpl	$1, %ecx
	je	.L57
	cmpl	$1, %edi
	je	.L17
.L15:
	addl	20(%rsp), %r8d
	cmpl	$2, %ecx
	jle	.L57
	cmpl	$2, %edi
	je	.L20
.L19:
	addl	24(%rsp), %r8d
	cmpl	$3, %ecx
	jle	.L57
	cmpl	$3, %edi
	je	.L23
.L22:
	addl	28(%rsp), %r8d
	cmpl	$4, %ecx
	jle	.L57
	cmpl	$4, %edi
	je	.L26
.L25:
	addl	32(%rsp), %r8d
	cmpl	$5, %ecx
	jle	.L57
	cmpl	$5, %edi
	je	.L29
.L28:
	addl	36(%rsp), %r8d
	cmpl	$6, %ecx
	jle	.L57
	cmpl	$6, %edi
	je	.L32
.L31:
	addl	40(%rsp), %r8d
	cmpl	$7, %ecx
	jle	.L57
	cmpl	$7, %edi
	je	.L35
.L34:
	addl	44(%rsp), %r8d
	cmpl	$8, %ecx
	jle	.L57
	cmpl	$8, %edi
	je	.L38
.L37:
	addl	48(%rsp), %r8d
	cmpl	$9, %ecx
	jle	.L57
	cmpl	$9, %edi
	je	.L41
.L40:
	addl	52(%rsp), %r8d
	cmpl	$10, %ecx
	jle	.L57
	cmpl	$10, %edi
	je	.L44
.L43:
	addl	56(%rsp), %r8d
	cmpl	$11, %ecx
	jle	.L57
	cmpl	$11, %edi
	je	.L47
.L46:
	addl	60(%rsp), %r8d
	cmpl	$12, %ecx
	jle	.L57
	cmpl	$12, %edi
	je	.L50
.L49:
	addl	64(%rsp), %r8d
	cmpl	$13, %ecx
	jle	.L57
	cmpl	$13, %edi
	je	.L53
.L52:
	addl	68(%rsp), %r8d
	cmpl	$14, %ecx
	jle	.L57
	cmpl	$14, %edi
	je	.L67
.L55:
	addl	72(%rsp), %r8d
	.p2align 4,,10
	.p2align 3
.L57:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L68
	addq	$104, %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
.L17:
	.cfi_restore_state
	movl	20(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$2, %ecx
	jne	.L19
	jmp	.L57
.L20:
	movl	24(%rsp), %eax
	cltd
	idivl	%edi
	addl	%eax, %r8d
	cmpl	$3, %ecx
	jne	.L22
	jmp	.L57
.L38:
	movl	48(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$9, %ecx
	jne	.L40
	jmp	.L57
.L41:
	movl	52(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$10, %ecx
	jne	.L43
	jmp	.L57
.L44:
	movl	56(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$11, %ecx
	jne	.L46
	jmp	.L57
.L66:
	movl	%r8d, %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	movl	%eax, %r8d
	cmpl	$1, %ecx
	jne	.L15
	jmp	.L57
.L23:
	movl	28(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$4, %ecx
	jne	.L25
	jmp	.L57
.L26:
	movl	32(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$5, %ecx
	jne	.L28
	jmp	.L57
.L29:
	movl	36(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$6, %ecx
	jne	.L31
	jmp	.L57
.L10:
	xorl	%r8d, %r8d
	jmp	.L57
.L32:
	movl	40(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$7, %ecx
	jne	.L34
	jmp	.L57
.L35:
	movl	44(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$8, %ecx
	jne	.L37
	jmp	.L57
.L47:
	movl	60(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$12, %ecx
	jne	.L49
	jmp	.L57
.L50:
	movl	64(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$13, %ecx
	jne	.L52
	jmp	.L57
.L53:
	movl	68(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$14, %ecx
	jne	.L55
	jmp	.L57
.L67:
	movl	72(%rsp), %eax
	movl	$2, %ecx
	cltd
	idivl	%ecx
	addl	%eax, %r8d
	jmp	.L57
.L68:
	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	max
	.type	max, @function
max:
.LFB23:
	.cfi_startproc
	endbr64
	movl	(%rdi), %ecx
	testl	%esi, %esi
	jle	.L5
	movslq	%esi, %rsi
	xorl	%eax, %eax
	xorl	%r8d, %r8d
	.p2align 4,,10
	.p2align 3
.L4:
	movl	(%rdi,%rax,4), %edx
	cmpl	%edx, %ecx
	jge	.L3
	movl	%eax, %r8d
	movl	%edx, %ecx
.L3:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L4
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L5:
	xorl	%r8d, %r8d
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	max, .-max
	.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:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%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	$104, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L10
	leaq	16(%rsp), %r12
	xorl	%ebx, %ebx
	movq	%r12, %rbp
	.p2align 4,,10
	.p2align 3
.L11:
	movq	%rbp, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %ecx
	addq	$4, %rbp
	cmpl	%ebx, %ecx
	jg	.L11
	movl	16(%rsp), %r8d
	testl	%ecx, %ecx
	jle	.L10
	movslq	%ecx, %r9
	movl	%r8d, %esi
	xorl	%eax, %eax
	xorl	%edi, %edi
	.p2align 4,,10
	.p2align 3
.L13:
	movl	(%r12,%rax,4), %edx
	cmpl	%edx, %esi
	jge	.L12
	movl	%eax, %edi
	movl	%edx, %esi
.L12:
	addq	$1, %rax
	cmpq	%r9, %rax
	jne	.L13
	testl	%edi, %edi
	je	.L66
	cmpl	$1, %ecx
	je	.L57
	cmpl	$1, %edi
	je	.L17
.L15:
	addl	20(%rsp), %r8d
	cmpl	$2, %ecx
	jle	.L57
	cmpl	$2, %edi
	je	.L20
.L19:
	addl	24(%rsp), %r8d
	cmpl	$3, %ecx
	jle	.L57
	cmpl	$3, %edi
	je	.L23
.L22:
	addl	28(%rsp), %r8d
	cmpl	$4, %ecx
	jle	.L57
	cmpl	$4, %edi
	je	.L26
.L25:
	addl	32(%rsp), %r8d
	cmpl	$5, %ecx
	jle	.L57
	cmpl	$5, %edi
	je	.L29
.L28:
	addl	36(%rsp), %r8d
	cmpl	$6, %ecx
	jle	.L57
	cmpl	$6, %edi
	je	.L32
.L31:
	addl	40(%rsp), %r8d
	cmpl	$7, %ecx
	jle	.L57
	cmpl	$7, %edi
	je	.L35
.L34:
	addl	44(%rsp), %r8d
	cmpl	$8, %ecx
	jle	.L57
	cmpl	$8, %edi
	je	.L38
.L37:
	addl	48(%rsp), %r8d
	cmpl	$9, %ecx
	jle	.L57
	cmpl	$9, %edi
	je	.L41
.L40:
	addl	52(%rsp), %r8d
	cmpl	$10, %ecx
	jle	.L57
	cmpl	$10, %edi
	je	.L44
.L43:
	addl	56(%rsp), %r8d
	cmpl	$11, %ecx
	jle	.L57
	cmpl	$11, %edi
	je	.L47
.L46:
	addl	60(%rsp), %r8d
	cmpl	$12, %ecx
	jle	.L57
	cmpl	$12, %edi
	je	.L50
.L49:
	addl	64(%rsp), %r8d
	cmpl	$13, %ecx
	jle	.L57
	cmpl	$13, %edi
	je	.L53
.L52:
	addl	68(%rsp), %r8d
	cmpl	$14, %ecx
	jle	.L57
	cmpl	$14, %edi
	je	.L67
.L55:
	addl	72(%rsp), %r8d
	.p2align 4,,10
	.p2align 3
.L57:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L68
	addq	$104, %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
.L17:
	.cfi_restore_state
	movl	20(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$2, %ecx
	jne	.L19
	jmp	.L57
.L20:
	movl	24(%rsp), %eax
	cltd
	idivl	%edi
	addl	%eax, %r8d
	cmpl	$3, %ecx
	jne	.L22
	jmp	.L57
.L38:
	movl	48(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$9, %ecx
	jne	.L40
	jmp	.L57
.L41:
	movl	52(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$10, %ecx
	jne	.L43
	jmp	.L57
.L44:
	movl	56(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$11, %ecx
	jne	.L46
	jmp	.L57
.L66:
	movl	%r8d, %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	movl	%eax, %r8d
	cmpl	$1, %ecx
	jne	.L15
	jmp	.L57
.L23:
	movl	28(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$4, %ecx
	jne	.L25
	jmp	.L57
.L26:
	movl	32(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$5, %ecx
	jne	.L28
	jmp	.L57
.L29:
	movl	36(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$6, %ecx
	jne	.L31
	jmp	.L57
.L10:
	xorl	%r8d, %r8d
	jmp	.L57
.L32:
	movl	40(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$7, %ecx
	jne	.L34
	jmp	.L57
.L35:
	movl	44(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$8, %ecx
	jne	.L37
	jmp	.L57
.L47:
	movl	60(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$12, %ecx
	jne	.L49
	jmp	.L57
.L50:
	movl	64(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$13, %ecx
	jne	.L52
	jmp	.L57
.L53:
	movl	68(%rsp), %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	addl	%eax, %r8d
	cmpl	$14, %ecx
	jne	.L55
	jmp	.L57
.L67:
	movl	72(%rsp), %eax
	movl	$2, %ecx
	cltd
	idivl	%ecx
	addl	%eax, %r8d
	jmp	.L57
.L68:
	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 max( int num[ ] , int test)
{
    int m , i , pos = 0 ;
    m= num[0] ;
    for( i =0 ; i < test ; i++)
    {
        if( num[i] > m)
        {
             m = num[i] ;
             pos = i ;
        }
           
    }
    return pos;
}
int main( )
{
    int num[15] , test , i , maximum , result = 0 ;
    scanf("%d" , &test);
    for( i = 0 ; i < test ; i++)
    {
        scanf("%d" , &num[i]);
    }
    
    maximum = max( num , test );
    
    for( i = 0 ; i < test ; i++)
    {
           if( maximum == i)
            result = result + num[i]/2 ;
            else
                result = result + num[i] ;
    }
    printf("%d\n" , result);
    return 0 ;
}

4
4320
7204
4320
4320
 3
32
7980
6980
 3
32
7980
615
 3
6
7980
615
 3
6
7980
329
 3
6
7980
207
 3
7
7980
207
 3
7
7980
269
 3
7
4428
269
 3
7
4428
505

16562
 11002
 4637
 4611
 4325
 4203
 4204
 4266
 2490
 2726

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 max( int num[ ] , int test)
{
    int m , i , pos = 0 ;
    m= num[0] ;
    for( i =0 ; i < test ; i++)
    {
        if( num[i] > m)
        {
             m = num[i] ;
             pos = i ;
        }
           
    }
    return pos;
}
int main( )
{
    int num[15] , test , i , maximum , result = 0 ;
    scanf("%d" , &test);
    for( i = 0 ; i < test ; i++)
    {
        scanf("%d" , &num[i]);
    }
    
    maximum = max( num , test );
    
    for( i = 0 ; i < test ; i++)
    {
           if( maximum == i)
            result = result + num[i]/2 ;
            else
                result = result + num[i] ;
    }
    printf("%d\n" , result);
    return 0 ;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	max
	.type	max, @function
max:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	$0, -4(%rbp)
	movq	-24(%rbp), %rax
	movl	(%rax), %eax
	movl	%eax, -12(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L2
.L4:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -12(%rbp)
	jge	.L3
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -12(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, -4(%rbp)
.L3:
	addl	$1, -8(%rbp)
.L2:
	movl	-8(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L4
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	max, .-max
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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
	subq	$96, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -88(%rbp)
	leaq	-96(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -92(%rbp)
	jmp	.L7
.L8:
	leaq	-80(%rbp), %rdx
	movl	-92(%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, -92(%rbp)
.L7:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L8
	movl	-96(%rbp), %edx
	leaq	-80(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	max
	movl	%eax, -84(%rbp)
	movl	$0, -92(%rbp)
	jmp	.L9
.L12:
	movl	-84(%rbp), %eax
	cmpl	-92(%rbp), %eax
	jne	.L10
	movl	-92(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	addl	%eax, -88(%rbp)
	jmp	.L11
.L10:
	movl	-92(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	addl	%eax, -88(%rbp)
.L11:
	addl	$1, -92(%rbp)
.L9:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L12
	movl	-88(%rbp), %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	.L14
	call	__stack_chk_fail@PLT
.L14:
	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	max
	.type	max, @function
max:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	$0, -4(%rbp)
	movq	-24(%rbp), %rax
	movl	(%rax), %eax
	movl	%eax, -12(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L2
.L4:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -12(%rbp)
	jge	.L3
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -12(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, -4(%rbp)
.L3:
	addl	$1, -8(%rbp)
.L2:
	movl	-8(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L4
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	max, .-max
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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
	subq	$96, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -88(%rbp)
	leaq	-96(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -92(%rbp)
	jmp	.L7
.L8:
	leaq	-80(%rbp), %rdx
	movl	-92(%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, -92(%rbp)
.L7:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L8
	movl	-96(%rbp), %edx
	leaq	-80(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	max
	movl	%eax, -84(%rbp)
	movl	$0, -92(%rbp)
	jmp	.L9
.L12:
	movl	-84(%rbp), %eax
	cmpl	-92(%rbp), %eax
	jne	.L10
	movl	-92(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	addl	%eax, -88(%rbp)
	jmp	.L11
.L10:
	movl	-92(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	addl	%eax, -88(%rbp)
.L11:
	addl	$1, -92(%rbp)
.L9:
	movl	-96(%rbp), %eax
	cmpl	%eax, -92(%rbp)
	jl	.L12
	movl	-88(%rbp), %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	.L14
	call	__stack_chk_fail@PLT
.L14:
	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:
