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(void){
	int N,K,i,j,k,a[51],max=0,sum=0;
	scanf("%d %d",&N,&K);
	for(i=0;i<N;i++){scanf("%d",&a[i]);}
	for(i=0;i<K;i++){
		for(j=0;j<N;j++){if(max<a[j]){max=a[j];k=j;}}
		sum+=max;
		a[k]=0;
		max=0;
	}
	printf("%d",sum);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
	.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
	subq	$256, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -232(%rbp)
	movl	$0, -228(%rbp)
	leaq	-248(%rbp), %rdx
	leaq	-252(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -244(%rbp)
	jmp	.L2
.L3:
	leaq	-224(%rbp), %rdx
	movl	-244(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -244(%rbp)
.L2:
	movl	-252(%rbp), %eax
	cmpl	%eax, -244(%rbp)
	jl	.L3
	movl	$0, -244(%rbp)
	jmp	.L4
.L8:
	movl	$0, -240(%rbp)
	jmp	.L5
.L7:
	movl	-240(%rbp), %eax
	cltq
	movl	-224(%rbp,%rax,4), %eax
	cmpl	%eax, -232(%rbp)
	jge	.L6
	movl	-240(%rbp), %eax
	cltq
	movl	-224(%rbp,%rax,4), %eax
	movl	%eax, -232(%rbp)
	movl	-240(%rbp), %eax
	movl	%eax, -236(%rbp)
.L6:
	addl	$1, -240(%rbp)
.L5:
	movl	-252(%rbp), %eax
	cmpl	%eax, -240(%rbp)
	jl	.L7
	movl	-232(%rbp), %eax
	addl	%eax, -228(%rbp)
	movl	-236(%rbp), %eax
	cltq
	movl	$0, -224(%rbp,%rax,4)
	movl	$0, -232(%rbp)
	addl	$1, -244(%rbp)
.L4:
	movl	-248(%rbp), %eax
	cmpl	%eax, -244(%rbp)
	jl	.L8
	movl	-228(%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	.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 %d"
.LC1:
	.string	"%d"
	.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	.LC0(%rip), %rdi
	leaq	.LC1(%rip), %r13
	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
	subq	$248, %rsp
	.cfi_def_cfa_offset 288
	movq	%fs:40, %rax
	movq	%rax, 232(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rdx
	leaq	8(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	8(%rsp), %r8d
	testl	%r8d, %r8d
	jle	.L2
	leaq	16(%rsp), %r12
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%r12, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebp
	call	__isoc99_scanf@PLT
	movl	8(%rsp), %r8d
	addq	$4, %r12
	cmpl	%ebp, %r8d
	jg	.L3
.L2:
	movl	12(%rsp), %r11d
	xorl	%r10d, %r10d
	xorl	%r9d, %r9d
	movslq	%r8d, %rdi
	testl	%r11d, %r11d
	jle	.L5
	.p2align 4,,10
	.p2align 3
.L4:
	xorl	%eax, %eax
	xorl	%ecx, %ecx
	leaq	16(%rsp), %rsi
	testl	%r8d, %r8d
	jle	.L9
	.p2align 4,,10
	.p2align 3
.L7:
	movl	(%rsi,%rax,4), %edx
	cmpl	%edx, %ecx
	jge	.L6
	movl	%edx, %ecx
	movl	%eax, %ebx
.L6:
	addq	$1, %rax
	cmpq	%rax, %rdi
	jne	.L7
	addl	%ecx, %r10d
.L9:
	movslq	%ebx, %rax
	addl	$1, %r9d
	movl	$0, 16(%rsp,%rax,4)
	cmpl	%r11d, %r9d
	jne	.L4
.L5:
	xorl	%eax, %eax
	movl	%r10d, %edx
	movq	%r13, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	232(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L18
	addq	$248, %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
.L18:
	.cfi_restore_state
	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 %d"
.LC1:
	.string	"%d"
	.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	.LC0(%rip), %rdi
	leaq	.LC1(%rip), %r13
	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
	subq	$248, %rsp
	.cfi_def_cfa_offset 288
	movq	%fs:40, %rax
	movq	%rax, 232(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rdx
	leaq	8(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	8(%rsp), %r8d
	testl	%r8d, %r8d
	jle	.L2
	leaq	16(%rsp), %r12
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%r12, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebp
	call	__isoc99_scanf@PLT
	movl	8(%rsp), %r8d
	addq	$4, %r12
	cmpl	%ebp, %r8d
	jg	.L3
.L2:
	movl	12(%rsp), %r11d
	xorl	%r10d, %r10d
	xorl	%r9d, %r9d
	movslq	%r8d, %rdi
	testl	%r11d, %r11d
	jle	.L5
	.p2align 4,,10
	.p2align 3
.L4:
	xorl	%eax, %eax
	xorl	%ecx, %ecx
	leaq	16(%rsp), %rsi
	testl	%r8d, %r8d
	jle	.L9
	.p2align 4,,10
	.p2align 3
.L7:
	movl	(%rsi,%rax,4), %edx
	cmpl	%edx, %ecx
	jge	.L6
	movl	%edx, %ecx
	movl	%eax, %ebx
.L6:
	addq	$1, %rax
	cmpq	%rax, %rdi
	jne	.L7
	addl	%ecx, %r10d
.L9:
	movslq	%ebx, %rax
	addl	$1, %r9d
	movl	$0, 16(%rsp,%rax,4)
	cmpl	%r11d, %r9d
	jne	.L4
.L5:
	xorl	%eax, %eax
	movl	%r10d, %edx
	movq	%r13, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	232(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L18
	addq	$248, %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
.L18:
	.cfi_restore_state
	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(void){
	int N,K,i,j,k,a[51],max=0,sum=0;
	scanf("%d %d",&N,&K);
	for(i=0;i<N;i++){scanf("%d",&a[i]);}
	for(i=0;i<K;i++){
		for(j=0;j<N;j++){if(max<a[j]){max=a[j];k=j;}}
		sum+=max;
		a[k]=0;
		max=0;
	}
	printf("%d",sum);
	return 0;
}
15 14
49 26 27 21 41 7 42 35 7 5 5 36 39 1 45
 5 5
1 2 3 4 5
 15 14
49 26 27 21 33 7 42 35 7 5 5 36 39 1 45
 5 5
2 2 3 4 5
 15 14
49 26 27 26 33 7 42 35 7 5 5 36 39 1 45
 5 3
2 2 3 4 5
 15 14
50 26 27 21 41 7 42 35 7 5 5 36 33 1 45
 15 14
49 26 27 21 41 12 42 35 7 5 5 36 39 1 45
 5 5
1 2 2 4 5
 15 14
49 26 27 21 33 7 42 35 7 5 5 31 39 1 45

385 15 377 16 382 12 380 390 14 372
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(void){
	int N,K,i,j,k,a[51],max=0,sum=0;
	scanf("%d %d",&N,&K);
	for(i=0;i<N;i++){scanf("%d",&a[i]);}
	for(i=0;i<K;i++){
		for(j=0;j<N;j++){if(max<a[j]){max=a[j];k=j;}}
		sum+=max;
		a[k]=0;
		max=0;
	}
	printf("%d",sum);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
	.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
	subq	$256, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -232(%rbp)
	movl	$0, -228(%rbp)
	leaq	-248(%rbp), %rdx
	leaq	-252(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -244(%rbp)
	jmp	.L2
.L3:
	leaq	-224(%rbp), %rdx
	movl	-244(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -244(%rbp)
.L2:
	movl	-252(%rbp), %eax
	cmpl	%eax, -244(%rbp)
	jl	.L3
	movl	$0, -244(%rbp)
	jmp	.L4
.L8:
	movl	$0, -240(%rbp)
	jmp	.L5
.L7:
	movl	-240(%rbp), %eax
	cltq
	movl	-224(%rbp,%rax,4), %eax
	cmpl	%eax, -232(%rbp)
	jge	.L6
	movl	-240(%rbp), %eax
	cltq
	movl	-224(%rbp,%rax,4), %eax
	movl	%eax, -232(%rbp)
	movl	-240(%rbp), %eax
	movl	%eax, -236(%rbp)
.L6:
	addl	$1, -240(%rbp)
.L5:
	movl	-252(%rbp), %eax
	cmpl	%eax, -240(%rbp)
	jl	.L7
	movl	-232(%rbp), %eax
	addl	%eax, -228(%rbp)
	movl	-236(%rbp), %eax
	cltq
	movl	$0, -224(%rbp,%rax,4)
	movl	$0, -232(%rbp)
	addl	$1, -244(%rbp)
.L4:
	movl	-248(%rbp), %eax
	cmpl	%eax, -244(%rbp)
	jl	.L8
	movl	-228(%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	.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 %d"
.LC1:
	.string	"%d"
	.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
	subq	$256, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -232(%rbp)
	movl	$0, -228(%rbp)
	leaq	-248(%rbp), %rdx
	leaq	-252(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -244(%rbp)
	jmp	.L2
.L3:
	leaq	-224(%rbp), %rdx
	movl	-244(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -244(%rbp)
.L2:
	movl	-252(%rbp), %eax
	cmpl	%eax, -244(%rbp)
	jl	.L3
	movl	$0, -244(%rbp)
	jmp	.L4
.L8:
	movl	$0, -240(%rbp)
	jmp	.L5
.L7:
	movl	-240(%rbp), %eax
	cltq
	movl	-224(%rbp,%rax,4), %eax
	cmpl	%eax, -232(%rbp)
	jge	.L6
	movl	-240(%rbp), %eax
	cltq
	movl	-224(%rbp,%rax,4), %eax
	movl	%eax, -232(%rbp)
	movl	-240(%rbp), %eax
	movl	%eax, -236(%rbp)
.L6:
	addl	$1, -240(%rbp)
.L5:
	movl	-252(%rbp), %eax
	cmpl	%eax, -240(%rbp)
	jl	.L7
	movl	-232(%rbp), %eax
	addl	%eax, -228(%rbp)
	movl	-236(%rbp), %eax
	cltq
	movl	$0, -224(%rbp,%rax,4)
	movl	$0, -232(%rbp)
	addl	$1, -244(%rbp)
.L4:
	movl	-248(%rbp), %eax
	cmpl	%eax, -244(%rbp)
	jl	.L8
	movl	-228(%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	.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:
