Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
// AOJ 2867 Many Kinds of Apples
// 2018.3.29 bal4u

#include <stdio.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int c[1002];
int a[1002];

int main()
{
	int N, Q, i, t, x, d, ans;

	N = in();
	for (i = 1; i <= N; i++) c[i] = in();
	Q = in();
	ans = 0;
	while (Q--) {
		t = in(), x = in(), d = in();
		if (t == 1) {
			a[x] += d;
			if (a[x] > c[x]) { ans = x; break; }
		} else {
			a[x] -= d;
			if (a[x] < 0) { ans = x; break; }
		}
	}
	printf("%d\n", ans);
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	in
	.type	in, @function
in:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	$0, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
.L2:
	movl	-8(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %edx
	movl	-4(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
	cmpl	$47, -4(%rbp)
	jg	.L2
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	in, .-in
	.globl	c
	.bss
	.align 32
	.type	c, @object
	.size	c, 4008
c:
	.zero	4008
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 4008
a:
	.zero	4008
	.section	.rodata
.LC0:
	.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	$32, %rsp
	movl	$0, %eax
	call	in
	movl	%eax, -16(%rbp)
	movl	$1, -24(%rbp)
	jmp	.L5
.L6:
	movl	$0, %eax
	call	in
	movl	-24(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	c(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -24(%rbp)
.L5:
	movl	-24(%rbp), %eax
	cmpl	-16(%rbp), %eax
	jle	.L6
	movl	$0, %eax
	call	in
	movl	%eax, -28(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L7
.L10:
	movl	$0, %eax
	call	in
	movl	%eax, -12(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -8(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -4(%rbp)
	cmpl	$1, -12(%rbp)
	jne	.L8
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-4(%rbp), %eax
	leal	(%rdx,%rax), %ecx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	c(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jle	.L7
	movl	-8(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L9
.L8:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	-4(%rbp), %eax
	movl	-8(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jns	.L7
	movl	-8(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L9
.L7:
	movl	-28(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -28(%rbp)
	testl	%eax, %eax
	jne	.L10
.L9:
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	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	in
	.type	in, @function
in:
.LFB23:
	.cfi_startproc
	endbr64
	movq	stdin(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	8(%rdi), %rax
	movq	16(%rdi), %rcx
	cmpq	%rcx, %rax
	jnb	.L11
	leaq	1(%rax), %rdx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
.L3:
	xorl	%r12d, %r12d
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L4:
	leaq	1(%rdx), %rax
	movq	%rax, 8(%rdi)
	movzbl	(%rdx), %eax
	cmpl	$47, %eax
	jle	.L1
.L5:
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
.L7:
	leal	(%r12,%r12,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r12d
	cmpq	%rcx, %rdx
	jb	.L4
	call	__uflow@PLT
	cmpl	$47, %eax
	jle	.L1
	movq	stdin(%rip), %rdi
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L1:
	movl	%r12d, %eax
	popq	%r12
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L11:
	.cfi_restore_state
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
	jmp	.L3
	.cfi_endproc
.LFE23:
	.size	in, .-in
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%eax, %eax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	$1, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	c(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	call	in
	movl	%eax, %ebx
	testl	%eax, %eax
	jle	.L22
	.p2align 4,,10
	.p2align 3
.L13:
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rax
	movq	16(%rdi), %rcx
	cmpq	%rcx, %rax
	jnb	.L54
	leaq	1(%rax), %rdx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
.L17:
	xorl	%r12d, %r12d
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L18:
	leaq	1(%rdx), %rax
	movq	%rax, 8(%rdi)
	movzbl	(%rdx), %eax
	cmpl	$47, %eax
	jle	.L20
.L19:
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
.L21:
	leal	(%r12,%r12,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r12d
	cmpq	%rcx, %rdx
	jb	.L18
	call	__uflow@PLT
	cmpl	$47, %eax
	jle	.L20
	movq	stdin(%rip), %rdi
	jmp	.L19
	.p2align 4,,10
	.p2align 3
.L20:
	movl	%r12d, 0(%rbp,%r13,4)
	addq	$1, %r13
	cmpl	%r13d, %ebx
	jge	.L13
.L22:
	xorl	%eax, %eax
	leaq	a(%rip), %rbp
	leaq	c(%rip), %r12
	call	in
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L15
	.p2align 4,,10
	.p2align 3
.L43:
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rax
	movq	16(%rdi), %rdx
	cmpq	%rdx, %rax
	jnb	.L55
	leaq	1(%rax), %rcx
	movq	%rcx, 8(%rdi)
	movzbl	(%rax), %eax
.L25:
	xorl	%r13d, %r13d
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L26:
	leaq	1(%rcx), %rsi
	movq	%rsi, 8(%rdi)
	movzbl	(%rcx), %eax
	cmpl	$47, %eax
	jle	.L28
.L27:
	movq	%rsi, %rcx
.L29:
	leal	0(%r13,%r13,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r13d
	cmpq	%rdx, %rcx
	jb	.L26
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rsi
	movq	16(%rdi), %rdx
	cmpl	$47, %eax
	jg	.L27
	.p2align 4,,10
	.p2align 3
.L28:
	cmpq	%rsi, %rdx
	jbe	.L56
	leaq	1(%rsi), %rcx
	movq	%rcx, 8(%rdi)
	movzbl	(%rsi), %eax
.L31:
	xorl	%r14d, %r14d
	jmp	.L35
	.p2align 4,,10
	.p2align 3
.L32:
	leaq	1(%rcx), %rsi
	movq	%rsi, 8(%rdi)
	movzbl	(%rcx), %eax
	cmpl	$47, %eax
	jle	.L34
.L33:
	movq	%rsi, %rcx
.L35:
	leal	(%r14,%r14,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r14d
	cmpq	%rdx, %rcx
	jb	.L32
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rsi
	movq	16(%rdi), %rdx
	cmpl	$47, %eax
	jg	.L33
	.p2align 4,,10
	.p2align 3
.L34:
	cmpq	%rdx, %rsi
	jnb	.L57
	leaq	1(%rsi), %rcx
	movq	%rcx, 8(%rdi)
	movzbl	(%rsi), %eax
.L37:
	xorl	%r15d, %r15d
	jmp	.L41
	.p2align 4,,10
	.p2align 3
.L38:
	leaq	1(%rcx), %rax
	movq	%rax, 8(%rdi)
	movzbl	(%rcx), %eax
	cmpl	$47, %eax
	jle	.L40
.L39:
	movq	8(%rdi), %rcx
	movq	16(%rdi), %rdx
.L41:
	leal	(%r15,%r15,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r15d
	cmpq	%rdx, %rcx
	jb	.L38
	call	__uflow@PLT
	cmpl	$47, %eax
	jle	.L40
	movq	stdin(%rip), %rdi
	jmp	.L39
	.p2align 4,,10
	.p2align 3
.L40:
	movslq	%r14d, %rdx
	movl	0(%rbp,%rdx,4), %eax
	cmpl	$1, %r13d
	je	.L58
	subl	%r15d, %eax
	movl	%eax, 0(%rbp,%rdx,4)
	js	.L23
.L44:
	subl	$1, %ebx
	jne	.L43
.L15:
	xorl	%r14d, %r14d
.L23:
	movl	%r14d, %edx
	leaq	.LC0(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addq	$8, %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
	.p2align 4,,10
	.p2align 3
.L58:
	.cfi_restore_state
	addl	%r15d, %eax
	movl	%eax, 0(%rbp,%rdx,4)
	cmpl	(%r12,%rdx,4), %eax
	jle	.L44
	jmp	.L23
	.p2align 4,,10
	.p2align 3
.L57:
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rcx
	movq	16(%rdi), %rdx
	jmp	.L37
	.p2align 4,,10
	.p2align 3
.L56:
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rcx
	movq	16(%rdi), %rdx
	jmp	.L31
	.p2align 4,,10
	.p2align 3
.L55:
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rcx
	movq	16(%rdi), %rdx
	jmp	.L25
.L54:
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
	jmp	.L17
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	a
	.bss
	.align 32
	.type	a, @object
	.size	a, 4008
a:
	.zero	4008
	.globl	c
	.align 32
	.type	c, @object
	.size	c, 4008
c:
	.zero	4008
	.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	in
	.type	in, @function
in:
.LFB23:
	.cfi_startproc
	endbr64
	movq	stdin(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	8(%rdi), %rax
	movq	16(%rdi), %rcx
	cmpq	%rcx, %rax
	jnb	.L11
	leaq	1(%rax), %rdx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
.L3:
	xorl	%r12d, %r12d
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L4:
	leaq	1(%rdx), %rax
	movq	%rax, 8(%rdi)
	movzbl	(%rdx), %eax
	cmpl	$47, %eax
	jle	.L1
.L5:
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
.L7:
	leal	(%r12,%r12,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r12d
	cmpq	%rcx, %rdx
	jb	.L4
	call	__uflow@PLT
	cmpl	$47, %eax
	jle	.L1
	movq	stdin(%rip), %rdi
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L1:
	movl	%r12d, %eax
	popq	%r12
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L11:
	.cfi_restore_state
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
	jmp	.L3
	.cfi_endproc
.LFE23:
	.size	in, .-in
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%eax, %eax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	$1, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	c(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	call	in
	movl	%eax, %ebx
	testl	%eax, %eax
	jle	.L22
	.p2align 4,,10
	.p2align 3
.L13:
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rax
	movq	16(%rdi), %rcx
	cmpq	%rcx, %rax
	jnb	.L54
	leaq	1(%rax), %rdx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
.L17:
	xorl	%r12d, %r12d
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L18:
	leaq	1(%rdx), %rax
	movq	%rax, 8(%rdi)
	movzbl	(%rdx), %eax
	cmpl	$47, %eax
	jle	.L20
.L19:
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
.L21:
	leal	(%r12,%r12,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r12d
	cmpq	%rcx, %rdx
	jb	.L18
	call	__uflow@PLT
	cmpl	$47, %eax
	jle	.L20
	movq	stdin(%rip), %rdi
	jmp	.L19
	.p2align 4,,10
	.p2align 3
.L20:
	movl	%r12d, 0(%rbp,%r13,4)
	addq	$1, %r13
	cmpl	%r13d, %ebx
	jge	.L13
.L22:
	xorl	%eax, %eax
	leaq	a(%rip), %rbp
	leaq	c(%rip), %r12
	call	in
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L15
	.p2align 4,,10
	.p2align 3
.L43:
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rax
	movq	16(%rdi), %rdx
	cmpq	%rdx, %rax
	jnb	.L55
	leaq	1(%rax), %rcx
	movq	%rcx, 8(%rdi)
	movzbl	(%rax), %eax
.L25:
	xorl	%r13d, %r13d
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L26:
	leaq	1(%rcx), %rsi
	movq	%rsi, 8(%rdi)
	movzbl	(%rcx), %eax
	cmpl	$47, %eax
	jle	.L28
.L27:
	movq	%rsi, %rcx
.L29:
	leal	0(%r13,%r13,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r13d
	cmpq	%rdx, %rcx
	jb	.L26
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rsi
	movq	16(%rdi), %rdx
	cmpl	$47, %eax
	jg	.L27
	.p2align 4,,10
	.p2align 3
.L28:
	cmpq	%rsi, %rdx
	jbe	.L56
	leaq	1(%rsi), %rcx
	movq	%rcx, 8(%rdi)
	movzbl	(%rsi), %eax
.L31:
	xorl	%r14d, %r14d
	jmp	.L35
	.p2align 4,,10
	.p2align 3
.L32:
	leaq	1(%rcx), %rsi
	movq	%rsi, 8(%rdi)
	movzbl	(%rcx), %eax
	cmpl	$47, %eax
	jle	.L34
.L33:
	movq	%rsi, %rcx
.L35:
	leal	(%r14,%r14,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r14d
	cmpq	%rdx, %rcx
	jb	.L32
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rsi
	movq	16(%rdi), %rdx
	cmpl	$47, %eax
	jg	.L33
	.p2align 4,,10
	.p2align 3
.L34:
	cmpq	%rdx, %rsi
	jnb	.L57
	leaq	1(%rsi), %rcx
	movq	%rcx, 8(%rdi)
	movzbl	(%rsi), %eax
.L37:
	xorl	%r15d, %r15d
	jmp	.L41
	.p2align 4,,10
	.p2align 3
.L38:
	leaq	1(%rcx), %rax
	movq	%rax, 8(%rdi)
	movzbl	(%rcx), %eax
	cmpl	$47, %eax
	jle	.L40
.L39:
	movq	8(%rdi), %rcx
	movq	16(%rdi), %rdx
.L41:
	leal	(%r15,%r15,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r15d
	cmpq	%rdx, %rcx
	jb	.L38
	call	__uflow@PLT
	cmpl	$47, %eax
	jle	.L40
	movq	stdin(%rip), %rdi
	jmp	.L39
	.p2align 4,,10
	.p2align 3
.L40:
	movslq	%r14d, %rdx
	movl	0(%rbp,%rdx,4), %eax
	cmpl	$1, %r13d
	je	.L58
	subl	%r15d, %eax
	movl	%eax, 0(%rbp,%rdx,4)
	js	.L23
.L44:
	subl	$1, %ebx
	jne	.L43
.L15:
	xorl	%r14d, %r14d
.L23:
	movl	%r14d, %edx
	leaq	.LC0(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addq	$8, %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
	.p2align 4,,10
	.p2align 3
.L58:
	.cfi_restore_state
	addl	%r15d, %eax
	movl	%eax, 0(%rbp,%rdx,4)
	cmpl	(%r12,%rdx,4), %eax
	jle	.L44
	jmp	.L23
	.p2align 4,,10
	.p2align 3
.L57:
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rcx
	movq	16(%rdi), %rdx
	jmp	.L37
	.p2align 4,,10
	.p2align 3
.L56:
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rcx
	movq	16(%rdi), %rdx
	jmp	.L31
	.p2align 4,,10
	.p2align 3
.L55:
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rcx
	movq	16(%rdi), %rdx
	jmp	.L25
.L54:
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
	jmp	.L17
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	a
	.bss
	.align 32
	.type	a, @object
	.size	a, 4008
a:
	.zero	4008
	.globl	c
	.align 32
	.type	c, @object
	.size	c, 4008
c:
	.zero	4008
	.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:

// AOJ 2867 Many Kinds of Apples
// 2018.3.29 bal4u

#include <stdio.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int c[1002];
int a[1002];

int main()
{
	int N, Q, i, t, x, d, ans;

	N = in();
	for (i = 1; i <= N; i++) c[i] = in();
	Q = in();
	ans = 0;
	while (Q--) {
		t = in(), x = in(), d = in();
		if (t == 1) {
			a[x] += d;
			if (a[x] > c[x]) { ans = x; break; }
		} else {
			a[x] -= d;
			if (a[x] < 0) { ans = x; break; }
		}
	}
	printf("%d\n", ans);
	return 0;
}

2
3 3
4
1 1 0
1 2 3
2 1 3
2 2 3
 2
3 3
0
1 1 0
1 2 3
2 1 3
2 2 3
 2
3 3
4
1 1 2
1 2 4
2 1 3
2 2 3
 2
3 2
0
1 1 0
1 2 3
2 1 3
2 2 3
 2
3 2
0
1 1 0
1 2 3
2 1 3
2 2 1
 2
3 2
0
1 1 0
1 2 3
2 1 3
0 2 1
 2
3 2
0
1 1 1
1 2 3
2 1 3
0 2 1
 2
3 2
0
1 1 1
1 4 3
2 1 3
0 2 1
 2
3 2
0
1 0 1
1 4 3
2 1 3
0 2 1
 2
3 2
0
1 0 1
1 2 3
2 1 3
0 2 1

1
 0
 2
 0
 0
 0
 0
 0
 0
 0

Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
// AOJ 2867 Many Kinds of Apples
// 2018.3.29 bal4u

#include <stdio.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int c[1002];
int a[1002];

int main()
{
	int N, Q, i, t, x, d, ans;

	N = in();
	for (i = 1; i <= N; i++) c[i] = in();
	Q = in();
	ans = 0;
	while (Q--) {
		t = in(), x = in(), d = in();
		if (t == 1) {
			a[x] += d;
			if (a[x] > c[x]) { ans = x; break; }
		} else {
			a[x] -= d;
			if (a[x] < 0) { ans = x; break; }
		}
	}
	printf("%d\n", ans);
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	in
	.type	in, @function
in:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	$0, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
.L2:
	movl	-8(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %edx
	movl	-4(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
	cmpl	$47, -4(%rbp)
	jg	.L2
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	in, .-in
	.globl	c
	.bss
	.align 32
	.type	c, @object
	.size	c, 4008
c:
	.zero	4008
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 4008
a:
	.zero	4008
	.section	.rodata
.LC0:
	.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	$32, %rsp
	movl	$0, %eax
	call	in
	movl	%eax, -16(%rbp)
	movl	$1, -24(%rbp)
	jmp	.L5
.L6:
	movl	$0, %eax
	call	in
	movl	-24(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	c(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -24(%rbp)
.L5:
	movl	-24(%rbp), %eax
	cmpl	-16(%rbp), %eax
	jle	.L6
	movl	$0, %eax
	call	in
	movl	%eax, -28(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L7
.L10:
	movl	$0, %eax
	call	in
	movl	%eax, -12(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -8(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -4(%rbp)
	cmpl	$1, -12(%rbp)
	jne	.L8
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-4(%rbp), %eax
	leal	(%rdx,%rax), %ecx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	c(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jle	.L7
	movl	-8(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L9
.L8:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	-4(%rbp), %eax
	movl	-8(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jns	.L7
	movl	-8(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L9
.L7:
	movl	-28(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -28(%rbp)
	testl	%eax, %eax
	jne	.L10
.L9:
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	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	in
	.type	in, @function
in:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	$0, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
.L2:
	movl	-8(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %edx
	movl	-4(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
	cmpl	$47, -4(%rbp)
	jg	.L2
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	in, .-in
	.globl	c
	.bss
	.align 32
	.type	c, @object
	.size	c, 4008
c:
	.zero	4008
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 4008
a:
	.zero	4008
	.section	.rodata
.LC0:
	.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	$32, %rsp
	movl	$0, %eax
	call	in
	movl	%eax, -16(%rbp)
	movl	$1, -24(%rbp)
	jmp	.L5
.L6:
	movl	$0, %eax
	call	in
	movl	-24(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	c(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -24(%rbp)
.L5:
	movl	-24(%rbp), %eax
	cmpl	-16(%rbp), %eax
	jle	.L6
	movl	$0, %eax
	call	in
	movl	%eax, -28(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L7
.L10:
	movl	$0, %eax
	call	in
	movl	%eax, -12(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -8(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -4(%rbp)
	cmpl	$1, -12(%rbp)
	jne	.L8
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-4(%rbp), %eax
	leal	(%rdx,%rax), %ecx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	c(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jle	.L7
	movl	-8(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L9
.L8:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	-4(%rbp), %eax
	movl	-8(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jns	.L7
	movl	-8(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L9
.L7:
	movl	-28(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -28(%rbp)
	testl	%eax, %eax
	jne	.L10
.L9:
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	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:
