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 w[11], s[11], i, j, n, wmax, res, sum;
  char f[11][21];

  while(scanf("%d", &n) && n){
    sum = 0;
    for(i = 0; i < n; ++i){
      scanf("%s %d %d", f[i], &w[i], &s[i]);
      sum += w[i];
    }

    for(j = 0; j < n; ++j){
      wmax = 0;
      for(i = 0; i < n; ++i)
	if(sum - w[i] <= s[i] && wmax <= w[i])
	  res = i, wmax = w[i];
      
      puts(f[res]);
      s[res] = -999999;
      sum -= w[res];
    }
  }
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%s %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	$368, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	jmp	.L2
.L11:
	movl	$0, -340(%rbp)
	movl	$0, -356(%rbp)
	jmp	.L3
.L4:
	leaq	-288(%rbp), %rdx
	movl	-356(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	(%rdx,%rax), %rcx
	leaq	-336(%rbp), %rdx
	movl	-356(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	(%rdx,%rax), %rsi
	leaq	-240(%rbp), %rdi
	movl	-356(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rdi, %rax
	movq	%rsi, %rdx
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-356(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %eax
	addl	%eax, -340(%rbp)
	addl	$1, -356(%rbp)
.L3:
	movl	-360(%rbp), %eax
	cmpl	%eax, -356(%rbp)
	jl	.L4
	movl	$0, -352(%rbp)
	jmp	.L5
.L9:
	movl	$0, -348(%rbp)
	movl	$0, -356(%rbp)
	jmp	.L6
.L8:
	movl	-356(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %ecx
	movl	-340(%rbp), %eax
	subl	%ecx, %eax
	movl	%eax, %edx
	movl	-356(%rbp), %eax
	cltq
	movl	-288(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jg	.L7
	movl	-356(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %eax
	cmpl	%eax, -348(%rbp)
	jg	.L7
	movl	-356(%rbp), %eax
	movl	%eax, -344(%rbp)
	movl	-356(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %eax
	movl	%eax, -348(%rbp)
.L7:
	addl	$1, -356(%rbp)
.L6:
	movl	-360(%rbp), %eax
	cmpl	%eax, -356(%rbp)
	jl	.L8
	leaq	-240(%rbp), %rcx
	movl	-344(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	movq	%rax, %rdi
	call	puts@PLT
	movl	-344(%rbp), %eax
	cltq
	movl	$-999999, -288(%rbp,%rax,4)
	movl	-344(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %eax
	subl	%eax, -340(%rbp)
	addl	$1, -352(%rbp)
.L5:
	movl	-360(%rbp), %eax
	cmpl	%eax, -352(%rbp)
	jl	.L9
.L2:
	leaq	-360(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	testl	%eax, %eax
	je	.L10
	movl	-360(%rbp), %eax
	testl	%eax, %eax
	jne	.L11
.L10:
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	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	"%s %d %d"
.LC1:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$376, %rsp
	.cfi_def_cfa_offset 432
	movq	%fs:40, %rax
	movq	%rax, 360(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movq	%rax, 8(%rsp)
	leaq	128(%rsp), %rax
	movq	%rax, (%rsp)
	.p2align 4,,10
	.p2align 3
.L2:
	movq	8(%rsp), %rsi
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rdi
	call	__isoc99_scanf@PLT
	testl	%eax, %eax
	je	.L29
	movl	28(%rsp), %eax
	testl	%eax, %eax
	je	.L29
	jle	.L2
	movq	(%rsp), %r12
	leaq	32(%rsp), %r15
	leaq	80(%rsp), %rbp
	xorl	%ebx, %ebx
	xorl	%r14d, %r14d
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rcx
	movq	%r15, %rdx
	movq	%r12, %rsi
	xorl	%eax, %eax
	addl	$1, %r14d
	addq	$21, %r12
	addq	$4, %r15
	addq	$4, %rbp
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	addl	-4(%r15), %ebx
	cmpl	%r14d, %eax
	jg	.L3
	testl	%eax, %eax
	jle	.L2
	xorl	%r14d, %r14d
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L126:
	testl	%edx, %edx
	js	.L43
	xorl	%r13d, %r13d
.L5:
	cmpl	$1, %eax
	je	.L7
	movl	36(%rsp), %ecx
	movl	%ebx, %edi
	subl	%ecx, %edi
	cmpl	%edi, 84(%rsp)
	jl	.L44
	cmpl	%ecx, %edx
	jg	.L44
	movl	$1, %r13d
.L8:
	cmpl	$2, %eax
	je	.L7
	movl	40(%rsp), %edx
	movl	%ebx, %edi
	subl	%edx, %edi
	cmpl	88(%rsp), %edi
	jg	.L45
	cmpl	%edx, %ecx
	jg	.L45
	movl	$2, %r13d
.L10:
	cmpl	$3, %eax
	je	.L7
	movl	44(%rsp), %ecx
	movl	%ebx, %edi
	subl	%ecx, %edi
	cmpl	%edi, 92(%rsp)
	jl	.L46
	cmpl	%edx, %ecx
	jl	.L46
	movl	$3, %r13d
.L12:
	cmpl	$4, %eax
	je	.L7
	movl	48(%rsp), %edx
	movl	%ebx, %edi
	subl	%edx, %edi
	cmpl	96(%rsp), %edi
	jg	.L47
	cmpl	%edx, %ecx
	jg	.L47
	movl	$4, %r13d
.L14:
	cmpl	$5, %eax
	je	.L7
	movl	52(%rsp), %ecx
	movl	%ebx, %edi
	subl	%ecx, %edi
	cmpl	100(%rsp), %edi
	jg	.L48
	cmpl	%ecx, %edx
	jg	.L48
	movl	$5, %r13d
.L16:
	cmpl	$6, %eax
	je	.L7
	movl	56(%rsp), %edx
	movl	%ebx, %edi
	subl	%edx, %edi
	cmpl	104(%rsp), %edi
	jg	.L49
	cmpl	%edx, %ecx
	jg	.L49
	movl	$6, %r13d
.L18:
	cmpl	$7, %eax
	je	.L7
	movl	60(%rsp), %ecx
	movl	%ebx, %edi
	subl	%ecx, %edi
	cmpl	108(%rsp), %edi
	jg	.L50
	cmpl	%ecx, %edx
	jg	.L50
	movl	$7, %r13d
.L20:
	cmpl	$8, %eax
	je	.L7
	movl	64(%rsp), %edx
	movl	%ebx, %edi
	subl	%edx, %edi
	cmpl	112(%rsp), %edi
	jg	.L51
	cmpl	%edx, %ecx
	jg	.L51
	movl	$8, %r13d
.L22:
	cmpl	$9, %eax
	je	.L7
	movl	68(%rsp), %ecx
	movl	%ebx, %edi
	subl	%ecx, %edi
	cmpl	116(%rsp), %edi
	jg	.L52
	cmpl	%ecx, %edx
	jg	.L52
	movl	$9, %r13d
.L24:
	cmpl	$10, %eax
	je	.L7
	movl	72(%rsp), %eax
	movl	%ebx, %edx
	subl	%eax, %edx
	cmpl	%edx, 120(%rsp)
	jl	.L7
	cmpl	%ecx, %eax
	movl	$10, %eax
	cmovge	%eax, %r13d
.L7:
	movslq	%r13d, %r15
	addl	$1, %r14d
	leaq	(%r15,%r15,4), %rax
	leaq	(%r15,%rax,4), %rdi
	addq	(%rsp), %rdi
	call	puts@PLT
	movl	28(%rsp), %eax
	subl	32(%rsp,%r15,4), %ebx
	movl	$-999999, 80(%rsp,%r15,4)
	cmpl	%r14d, %eax
	jle	.L2
.L28:
	movl	32(%rsp), %edx
	movl	%ebx, %ecx
	subl	%edx, %ecx
	cmpl	80(%rsp), %ecx
	jle	.L126
.L43:
	xorl	%edx, %edx
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L44:
	movl	%edx, %ecx
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L45:
	movl	%ecx, %edx
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L46:
	movl	%edx, %ecx
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L47:
	movl	%ecx, %edx
	jmp	.L14
	.p2align 4,,10
	.p2align 3
.L48:
	movl	%edx, %ecx
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L49:
	movl	%ecx, %edx
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L50:
	movl	%edx, %ecx
	jmp	.L20
.L51:
	movl	%ecx, %edx
	jmp	.L22
.L52:
	movl	%edx, %ecx
	jmp	.L24
.L29:
	movq	360(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L127
	addq	$376, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L127:
	.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	"%s %d %d"
.LC1:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$376, %rsp
	.cfi_def_cfa_offset 432
	movq	%fs:40, %rax
	movq	%rax, 360(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movq	%rax, 8(%rsp)
	leaq	128(%rsp), %rax
	movq	%rax, (%rsp)
	.p2align 4,,10
	.p2align 3
.L2:
	movq	8(%rsp), %rsi
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rdi
	call	__isoc99_scanf@PLT
	testl	%eax, %eax
	je	.L29
	movl	28(%rsp), %eax
	testl	%eax, %eax
	je	.L29
	jle	.L2
	movq	(%rsp), %r12
	leaq	32(%rsp), %r15
	leaq	80(%rsp), %rbp
	xorl	%ebx, %ebx
	xorl	%r14d, %r14d
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rcx
	movq	%r15, %rdx
	movq	%r12, %rsi
	xorl	%eax, %eax
	addl	$1, %r14d
	addq	$21, %r12
	addq	$4, %r15
	addq	$4, %rbp
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	addl	-4(%r15), %ebx
	cmpl	%r14d, %eax
	jg	.L3
	testl	%eax, %eax
	jle	.L2
	xorl	%r14d, %r14d
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L126:
	testl	%edx, %edx
	js	.L43
	xorl	%r13d, %r13d
.L5:
	cmpl	$1, %eax
	je	.L7
	movl	36(%rsp), %ecx
	movl	%ebx, %edi
	subl	%ecx, %edi
	cmpl	%edi, 84(%rsp)
	jl	.L44
	cmpl	%ecx, %edx
	jg	.L44
	movl	$1, %r13d
.L8:
	cmpl	$2, %eax
	je	.L7
	movl	40(%rsp), %edx
	movl	%ebx, %edi
	subl	%edx, %edi
	cmpl	88(%rsp), %edi
	jg	.L45
	cmpl	%edx, %ecx
	jg	.L45
	movl	$2, %r13d
.L10:
	cmpl	$3, %eax
	je	.L7
	movl	44(%rsp), %ecx
	movl	%ebx, %edi
	subl	%ecx, %edi
	cmpl	%edi, 92(%rsp)
	jl	.L46
	cmpl	%edx, %ecx
	jl	.L46
	movl	$3, %r13d
.L12:
	cmpl	$4, %eax
	je	.L7
	movl	48(%rsp), %edx
	movl	%ebx, %edi
	subl	%edx, %edi
	cmpl	96(%rsp), %edi
	jg	.L47
	cmpl	%edx, %ecx
	jg	.L47
	movl	$4, %r13d
.L14:
	cmpl	$5, %eax
	je	.L7
	movl	52(%rsp), %ecx
	movl	%ebx, %edi
	subl	%ecx, %edi
	cmpl	100(%rsp), %edi
	jg	.L48
	cmpl	%ecx, %edx
	jg	.L48
	movl	$5, %r13d
.L16:
	cmpl	$6, %eax
	je	.L7
	movl	56(%rsp), %edx
	movl	%ebx, %edi
	subl	%edx, %edi
	cmpl	104(%rsp), %edi
	jg	.L49
	cmpl	%edx, %ecx
	jg	.L49
	movl	$6, %r13d
.L18:
	cmpl	$7, %eax
	je	.L7
	movl	60(%rsp), %ecx
	movl	%ebx, %edi
	subl	%ecx, %edi
	cmpl	108(%rsp), %edi
	jg	.L50
	cmpl	%ecx, %edx
	jg	.L50
	movl	$7, %r13d
.L20:
	cmpl	$8, %eax
	je	.L7
	movl	64(%rsp), %edx
	movl	%ebx, %edi
	subl	%edx, %edi
	cmpl	112(%rsp), %edi
	jg	.L51
	cmpl	%edx, %ecx
	jg	.L51
	movl	$8, %r13d
.L22:
	cmpl	$9, %eax
	je	.L7
	movl	68(%rsp), %ecx
	movl	%ebx, %edi
	subl	%ecx, %edi
	cmpl	116(%rsp), %edi
	jg	.L52
	cmpl	%ecx, %edx
	jg	.L52
	movl	$9, %r13d
.L24:
	cmpl	$10, %eax
	je	.L7
	movl	72(%rsp), %eax
	movl	%ebx, %edx
	subl	%eax, %edx
	cmpl	%edx, 120(%rsp)
	jl	.L7
	cmpl	%ecx, %eax
	movl	$10, %eax
	cmovge	%eax, %r13d
.L7:
	movslq	%r13d, %r15
	addl	$1, %r14d
	leaq	(%r15,%r15,4), %rax
	leaq	(%r15,%rax,4), %rdi
	addq	(%rsp), %rdi
	call	puts@PLT
	movl	28(%rsp), %eax
	subl	32(%rsp,%r15,4), %ebx
	movl	$-999999, 80(%rsp,%r15,4)
	cmpl	%r14d, %eax
	jle	.L2
.L28:
	movl	32(%rsp), %edx
	movl	%ebx, %ecx
	subl	%edx, %ecx
	cmpl	80(%rsp), %ecx
	jle	.L126
.L43:
	xorl	%edx, %edx
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L44:
	movl	%edx, %ecx
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L45:
	movl	%ecx, %edx
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L46:
	movl	%edx, %ecx
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L47:
	movl	%ecx, %edx
	jmp	.L14
	.p2align 4,,10
	.p2align 3
.L48:
	movl	%edx, %ecx
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L49:
	movl	%ecx, %edx
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L50:
	movl	%edx, %ecx
	jmp	.L20
.L51:
	movl	%ecx, %edx
	jmp	.L22
.L52:
	movl	%edx, %ecx
	jmp	.L24
.L29:
	movq	360(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L127
	addq	$376, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L127:
	.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(){
  int w[11], s[11], i, j, n, wmax, res, sum;
  char f[11][21];

  while(scanf("%d", &n) && n){
    sum = 0;
    for(i = 0; i < n; ++i){
      scanf("%s %d %d", f[i], &w[i], &s[i]);
      sum += w[i];
    }

    for(j = 0; j < n; ++j){
      wmax = 0;
      for(i = 0; i < n; ++i)
	if(sum - w[i] <= s[i] && wmax <= w[i])
	  res = i, wmax = w[i];
      
      puts(f[res]);
      s[res] = -999999;
      sum -= w[res];
    }
  }
  return 0;
}
4
sandwich 80 120
apple 50 200
cheese 20 40
cake 100 100
9
onigiri 80 300
onigiri 80 300
anpan 70 280
mikan 50 80
kanzume 100 500
chocolaue 50 350
cookie 30 80
purin 40 400
cracker 40 160
0
 4
sandwich 80 120
apple 50 200
cheese 20 40
cake 100 100
9
onigiri 80 300
onigiri 80 300
anpan 70 280
mikan 50 80
kanzume 100 500
chocolate 50 350
cookie 30 80
purin 40 400
cracker 40 154
0
 4
sandwich 80 120
apple 50 200
cheese 20 40
cake 100 100
9
onigiri 80 300
onigiri 80 300
anpan 70 280
mikan 50 80
kanyume 100 500
chocolaue 50 350
cookie 30 80
purin 40 400
cracker 40 160
0
 4
sandwich 30 120
apple 50 200
cheese 20 40
cake 100 100
9
onigiri 80 300
onigiri 80 300
anpan 70 280
mikan 50 80
kanzume 100 500
chocolate 50 350
cookie 30 80
purin 40 400
cracker 40 154
0
 4
sandwich 80 120
apple 50 200
cheese 20 40
cake 100 100
9
onigiri 80 300
onigiri 80 300
anpan 70 280
mikan 50 80
kanyume 100 500
chocolaud 50 350
cookie 30 80
purin 40 400
cracker 40 160
0
 4
sandwich 80 120
apple 50 200
cheese 20 40
cake 100 100
9
onigiri 66 300
onigiri 80 300
anpan 70 280
mikan 50 80
kanyume 100 500
chocolaud 50 350
cookie 30 80
purin 40 400
cracker 40 160
0
 4
sandwich 80 120
apple 50 200
cheese 20 40
cake 100 100
9
onigiri 80 300
onigiri 80 300
anpan 70 280
mikan 50 80
kanzume 100 500
etalocohc 50 350
cookie 30 80
purin 40 400
cracker 40 160
0
 4
sandwidh 80 120
apple 50 200
cheese 20 40
cake 100 100
9
onigiri 80 300
onigiri 80 300
anpan 70 280
mikan 50 80
kanzume 100 500
chocolate 50 350
cookie 30 80
purin 40 400
cracker 40 154
0
 4
sandwich 80 120
apple 50 200
cheese 20 40
cake 100 100
9
onigiri 80 300
onigiri 80 300
anpan 70 280
mikan 50 80
emuynak 100 500
chocolaue 50 350
cookie 30 80
purin 40 400
cracker 40 160
0
 4
sandwich 80 120
apple 50 200
cheese 20 40
cake 100 100
9
onigiri 66 300
onigiri 80 300
anpan 70 280
mikan 50 80
kanyume 100 500
chocolaud 50 350
cookie 30 80
purni 40 400
cracker 40 160
0

apple
cake
sandwich
cheese
kanzume
purin
chocolaue
onigiri
onigiri
anpan
mikan
cracker
cookie
 apple
cake
sandwich
cheese
kanzume
purin
chocolate
onigiri
onigiri
anpan
mikan
cracker
cookie
 apple
cake
sandwich
cheese
kanyume
purin
chocolaue
onigiri
onigiri
anpan
mikan
cracker
cookie
 cake
apple
sandwich
cheese
kanzume
purin
chocolate
onigiri
onigiri
anpan
mikan
cracker
cookie
 apple
cake
sandwich
cheese
kanyume
purin
chocolaud
onigiri
onigiri
anpan
mikan
cracker
cookie
 apple
cake
sandwich
cheese
kanyume
purin
chocolaud
onigiri
anpan
onigiri
mikan
cracker
cookie
 apple
cake
sandwich
cheese
kanzume
purin
etalocohc
onigiri
onigiri
anpan
mikan
cracker
cookie
 apple
cake
sandwidh
cheese
kanzume
purin
chocolate
onigiri
onigiri
anpan
mikan
cracker
cookie
 apple
cake
sandwich
cheese
emuynak
purin
chocolaue
onigiri
onigiri
anpan
mikan
cracker
cookie
 apple
cake
sandwich
cheese
kanyume
purni
chocolaud
onigiri
anpan
onigiri
mikan
cracker
cookie

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 w[11], s[11], i, j, n, wmax, res, sum;
  char f[11][21];

  while(scanf("%d", &n) && n){
    sum = 0;
    for(i = 0; i < n; ++i){
      scanf("%s %d %d", f[i], &w[i], &s[i]);
      sum += w[i];
    }

    for(j = 0; j < n; ++j){
      wmax = 0;
      for(i = 0; i < n; ++i)
	if(sum - w[i] <= s[i] && wmax <= w[i])
	  res = i, wmax = w[i];
      
      puts(f[res]);
      s[res] = -999999;
      sum -= w[res];
    }
  }
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%s %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	$368, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	jmp	.L2
.L11:
	movl	$0, -340(%rbp)
	movl	$0, -356(%rbp)
	jmp	.L3
.L4:
	leaq	-288(%rbp), %rdx
	movl	-356(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	(%rdx,%rax), %rcx
	leaq	-336(%rbp), %rdx
	movl	-356(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	(%rdx,%rax), %rsi
	leaq	-240(%rbp), %rdi
	movl	-356(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rdi, %rax
	movq	%rsi, %rdx
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-356(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %eax
	addl	%eax, -340(%rbp)
	addl	$1, -356(%rbp)
.L3:
	movl	-360(%rbp), %eax
	cmpl	%eax, -356(%rbp)
	jl	.L4
	movl	$0, -352(%rbp)
	jmp	.L5
.L9:
	movl	$0, -348(%rbp)
	movl	$0, -356(%rbp)
	jmp	.L6
.L8:
	movl	-356(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %ecx
	movl	-340(%rbp), %eax
	subl	%ecx, %eax
	movl	%eax, %edx
	movl	-356(%rbp), %eax
	cltq
	movl	-288(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jg	.L7
	movl	-356(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %eax
	cmpl	%eax, -348(%rbp)
	jg	.L7
	movl	-356(%rbp), %eax
	movl	%eax, -344(%rbp)
	movl	-356(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %eax
	movl	%eax, -348(%rbp)
.L7:
	addl	$1, -356(%rbp)
.L6:
	movl	-360(%rbp), %eax
	cmpl	%eax, -356(%rbp)
	jl	.L8
	leaq	-240(%rbp), %rcx
	movl	-344(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	movq	%rax, %rdi
	call	puts@PLT
	movl	-344(%rbp), %eax
	cltq
	movl	$-999999, -288(%rbp,%rax,4)
	movl	-344(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %eax
	subl	%eax, -340(%rbp)
	addl	$1, -352(%rbp)
.L5:
	movl	-360(%rbp), %eax
	cmpl	%eax, -352(%rbp)
	jl	.L9
.L2:
	leaq	-360(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	testl	%eax, %eax
	je	.L10
	movl	-360(%rbp), %eax
	testl	%eax, %eax
	jne	.L11
.L10:
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	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	"%s %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	$368, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	jmp	.L2
.L11:
	movl	$0, -340(%rbp)
	movl	$0, -356(%rbp)
	jmp	.L3
.L4:
	leaq	-288(%rbp), %rdx
	movl	-356(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	(%rdx,%rax), %rcx
	leaq	-336(%rbp), %rdx
	movl	-356(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	(%rdx,%rax), %rsi
	leaq	-240(%rbp), %rdi
	movl	-356(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rdi, %rax
	movq	%rsi, %rdx
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-356(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %eax
	addl	%eax, -340(%rbp)
	addl	$1, -356(%rbp)
.L3:
	movl	-360(%rbp), %eax
	cmpl	%eax, -356(%rbp)
	jl	.L4
	movl	$0, -352(%rbp)
	jmp	.L5
.L9:
	movl	$0, -348(%rbp)
	movl	$0, -356(%rbp)
	jmp	.L6
.L8:
	movl	-356(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %ecx
	movl	-340(%rbp), %eax
	subl	%ecx, %eax
	movl	%eax, %edx
	movl	-356(%rbp), %eax
	cltq
	movl	-288(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jg	.L7
	movl	-356(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %eax
	cmpl	%eax, -348(%rbp)
	jg	.L7
	movl	-356(%rbp), %eax
	movl	%eax, -344(%rbp)
	movl	-356(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %eax
	movl	%eax, -348(%rbp)
.L7:
	addl	$1, -356(%rbp)
.L6:
	movl	-360(%rbp), %eax
	cmpl	%eax, -356(%rbp)
	jl	.L8
	leaq	-240(%rbp), %rcx
	movl	-344(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	movq	%rax, %rdi
	call	puts@PLT
	movl	-344(%rbp), %eax
	cltq
	movl	$-999999, -288(%rbp,%rax,4)
	movl	-344(%rbp), %eax
	cltq
	movl	-336(%rbp,%rax,4), %eax
	subl	%eax, -340(%rbp)
	addl	$1, -352(%rbp)
.L5:
	movl	-360(%rbp), %eax
	cmpl	%eax, -352(%rbp)
	jl	.L9
.L2:
	leaq	-360(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	testl	%eax, %eax
	je	.L10
	movl	-360(%rbp), %eax
	testl	%eax, %eax
	jne	.L11
.L10:
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	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:
