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>
#define N 1000
#define Z 500000
int a, b, c, d;
int push(void);
int top(void);
int pop(void);
int A[N][Z];
int size[N];
////////////////////////////////////////////////////////////
int main(void){
    scanf("%d%d", &b, &a);
    while (a-- != 0){
        scanf("%d", &b);
        if (b == 0) push();
        if (b == 1) top();
        if (b == 2) pop();
    }
    return 0;
}
int push(void){
    scanf("%d%d", &c, &d);
    A[c][size[c]] = d;
    size[c]++;
    return 0;
}
int top(void){
    scanf("%d", &c);
    if (size[c] == 0) return 0;
    printf("%d\n", A[c][size[c]-1]);
    return 0;
}
int pop(void){
    scanf("%d", &c);
    A[c][size[c]] = 0;
    if (size[c] == 0) return 0;
    size[c]--;
    return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	a
	.bss
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	c
	.align 4
	.type	c, @object
	.size	c, 4
c:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 2000000000
A:
	.zero	2000000000
	.globl	size
	.align 32
	.type	size, @object
	.size	size, 4000
size:
	.zero	4000
	.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
	leaq	a(%rip), %rax
	movq	%rax, %rdx
	leaq	b(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L2
.L5:
	leaq	b(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	b(%rip), %eax
	testl	%eax, %eax
	jne	.L3
	call	push
.L3:
	movl	b(%rip), %eax
	cmpl	$1, %eax
	jne	.L4
	call	top
.L4:
	movl	b(%rip), %eax
	cmpl	$2, %eax
	jne	.L2
	call	pop
.L2:
	movl	a(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, a(%rip)
	testl	%eax, %eax
	jne	.L5
	movl	$0, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	push
	.type	push, @function
push:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	d(%rip), %rax
	movq	%rax, %rdx
	leaq	c(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	c(%rip), %edx
	movl	c(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	size(%rip), %rax
	movl	(%rcx,%rax), %ecx
	movl	d(%rip), %eax
	movslq	%ecx, %rcx
	movslq	%edx, %rdx
	imulq	$500000, %rdx, %rdx
	addq	%rcx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	c(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	size(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	size(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	$0, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	push, .-push
	.section	.rodata
.LC2:
	.string	"%d\n"
	.text
	.globl	top
	.type	top, @function
top:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	c(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	c(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	size(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L10
	movl	$0, %eax
	jmp	.L11
.L10:
	movl	c(%rip), %eax
	movl	c(%rip), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	size(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	$1, %edx
	movslq	%edx, %rdx
	cltq
	imulq	$500000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L11:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	top, .-top
	.globl	pop
	.type	pop, @function
pop:
.LFB3:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	c(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	c(%rip), %eax
	movl	c(%rip), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	size(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	movslq	%edx, %rdx
	cltq
	imulq	$500000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	$0, (%rdx,%rax)
	movl	c(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	size(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L13
	movl	$0, %eax
	jmp	.L14
.L13:
	movl	c(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	size(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	-1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	size(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	$0, %eax
.L14:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3:
	.size	pop, .-pop
	.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"
	.text
	.p2align 4
	.globl	push
	.type	push, @function
push:
.LFB24:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	d(%rip), %rdx
	leaq	c(%rip), %rsi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movslq	c(%rip), %rdx
	leaq	size(%rip), %rsi
	movl	d(%rip), %r8d
	movslq	(%rsi,%rdx,4), %rdi
	imulq	$500000, %rdx, %rcx
	movq	%rdi, %rax
	addq	%rdi, %rcx
	addl	$1, %eax
	leaq	A(%rip), %rdi
	movl	%eax, (%rsi,%rdx,4)
	xorl	%eax, %eax
	movl	%r8d, (%rdi,%rcx,4)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE24:
	.size	push, .-push
	.section	.rodata.str1.1
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.text
	.p2align 4
	.globl	top
	.type	top, @function
top:
.LFB25:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	c(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	c(%rip), %rax
	leaq	size(%rip), %rdx
	movl	(%rdx,%rax,4), %edx
	testl	%edx, %edx
	je	.L5
	imulq	$500000, %rax, %rax
	subl	$1, %edx
	movl	$1, %edi
	movslq	%edx, %rdx
	leaq	.LC2(%rip), %rsi
	addq	%rdx, %rax
	leaq	A(%rip), %rdx
	movl	(%rdx,%rax,4), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L5:
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE25:
	.size	top, .-top
	.p2align 4
	.globl	pop
	.type	pop, @function
pop:
.LFB26:
	.cfi_startproc
	endbr64
	leaq	c(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	c(%rip), %rcx
	leaq	size(%rip), %rsi
	imulq	$500000, %rcx, %rdx
	movslq	(%rsi,%rcx,4), %rdi
	movq	%rdi, %rax
	addq	%rdi, %rdx
	leaq	A(%rip), %rdi
	movl	$0, (%rdi,%rdx,4)
	testl	%eax, %eax
	je	.L11
	subl	$1, %eax
	movl	%eax, (%rsi,%rcx,4)
.L11:
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE26:
	.size	pop, .-pop
	.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
	leaq	a(%rip), %rdx
	xorl	%eax, %eax
	leaq	d(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC0(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%r14, %rdi
	leaq	c(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	b(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rbp, %rsi
	leaq	.LC1(%rip), %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	call	__isoc99_scanf@PLT
.L17:
	leaq	size(%rip), %r12
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L18:
	cmpl	$1, %eax
	je	.L26
.L19:
	cmpl	$2, %eax
	je	.L27
.L21:
	movl	a(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, a(%rip)
	testl	%eax, %eax
	je	.L28
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	b(%rip), %eax
	testl	%eax, %eax
	jne	.L18
	movq	%r15, %rdx
	movq	%r13, %rsi
	movq	%r14, %rdi
	call	__isoc99_scanf@PLT
	movslq	c(%rip), %rdx
	movl	d(%rip), %edi
	movslq	(%r12,%rdx,4), %rsi
	imulq	$500000, %rdx, %rcx
	movq	%rsi, %rax
	addl	$1, %eax
	addq	%rsi, %rcx
	leaq	A(%rip), %rsi
	movl	%eax, (%r12,%rdx,4)
	movl	b(%rip), %eax
	movl	%edi, (%rsi,%rcx,4)
	cmpl	$1, %eax
	jne	.L19
.L26:
	movq	%r13, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	c(%rip), %rax
	movl	(%r12,%rax,4), %edx
	testl	%edx, %edx
	je	.L25
	imulq	$500000, %rax, %rax
	subl	$1, %edx
	movl	$1, %edi
	movslq	%edx, %rdx
	leaq	.LC2(%rip), %rsi
	addq	%rdx, %rax
	leaq	A(%rip), %rdx
	movl	(%rdx,%rax,4), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L25:
	movl	b(%rip), %eax
	cmpl	$2, %eax
	jne	.L21
.L27:
	call	pop
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L28:
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	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
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	size
	.bss
	.align 32
	.type	size, @object
	.size	size, 4000
size:
	.zero	4000
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 2000000000
A:
	.zero	2000000000
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	c
	.align 4
	.type	c, @object
	.size	c, 4
c:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.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"
	.text
	.p2align 4
	.globl	push
	.type	push, @function
push:
.LFB24:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	d(%rip), %rdx
	leaq	c(%rip), %rsi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movslq	c(%rip), %rdx
	leaq	size(%rip), %rsi
	movl	d(%rip), %r8d
	movslq	(%rsi,%rdx,4), %rdi
	imulq	$500000, %rdx, %rcx
	movq	%rdi, %rax
	addq	%rdi, %rcx
	addl	$1, %eax
	leaq	A(%rip), %rdi
	movl	%eax, (%rsi,%rdx,4)
	xorl	%eax, %eax
	movl	%r8d, (%rdi,%rcx,4)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE24:
	.size	push, .-push
	.section	.rodata.str1.1
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.text
	.p2align 4
	.globl	top
	.type	top, @function
top:
.LFB25:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	c(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	c(%rip), %rax
	leaq	size(%rip), %rdx
	movl	(%rdx,%rax,4), %edx
	testl	%edx, %edx
	je	.L5
	imulq	$500000, %rax, %rax
	subl	$1, %edx
	movl	$1, %edi
	movslq	%edx, %rdx
	leaq	.LC2(%rip), %rsi
	addq	%rdx, %rax
	leaq	A(%rip), %rdx
	movl	(%rdx,%rax,4), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L5:
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE25:
	.size	top, .-top
	.p2align 4
	.globl	pop
	.type	pop, @function
pop:
.LFB26:
	.cfi_startproc
	endbr64
	leaq	c(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	c(%rip), %rcx
	leaq	size(%rip), %rsi
	imulq	$500000, %rcx, %rdx
	movslq	(%rsi,%rcx,4), %rdi
	movq	%rdi, %rax
	addq	%rdi, %rdx
	leaq	A(%rip), %rdi
	movl	$0, (%rdi,%rdx,4)
	testl	%eax, %eax
	je	.L11
	subl	$1, %eax
	movl	%eax, (%rsi,%rcx,4)
.L11:
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE26:
	.size	pop, .-pop
	.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
	leaq	a(%rip), %rdx
	xorl	%eax, %eax
	leaq	d(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC0(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%r14, %rdi
	leaq	c(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	b(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rbp, %rsi
	leaq	.LC1(%rip), %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	call	__isoc99_scanf@PLT
.L17:
	leaq	size(%rip), %r12
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L18:
	cmpl	$1, %eax
	je	.L26
.L19:
	cmpl	$2, %eax
	je	.L27
.L21:
	movl	a(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, a(%rip)
	testl	%eax, %eax
	je	.L28
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	b(%rip), %eax
	testl	%eax, %eax
	jne	.L18
	movq	%r15, %rdx
	movq	%r13, %rsi
	movq	%r14, %rdi
	call	__isoc99_scanf@PLT
	movslq	c(%rip), %rdx
	movl	d(%rip), %edi
	movslq	(%r12,%rdx,4), %rsi
	imulq	$500000, %rdx, %rcx
	movq	%rsi, %rax
	addl	$1, %eax
	addq	%rsi, %rcx
	leaq	A(%rip), %rsi
	movl	%eax, (%r12,%rdx,4)
	movl	b(%rip), %eax
	movl	%edi, (%rsi,%rcx,4)
	cmpl	$1, %eax
	jne	.L19
.L26:
	movq	%r13, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	c(%rip), %rax
	movl	(%r12,%rax,4), %edx
	testl	%edx, %edx
	je	.L25
	imulq	$500000, %rax, %rax
	subl	$1, %edx
	movl	$1, %edi
	movslq	%edx, %rdx
	leaq	.LC2(%rip), %rsi
	addq	%rdx, %rax
	leaq	A(%rip), %rdx
	movl	(%rdx,%rax,4), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L25:
	movl	b(%rip), %eax
	cmpl	$2, %eax
	jne	.L21
.L27:
	call	pop
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L28:
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	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
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	size
	.bss
	.align 32
	.type	size, @object
	.size	size, 4000
size:
	.zero	4000
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 2000000000
A:
	.zero	2000000000
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	c
	.align 4
	.type	c, @object
	.size	c, 4
c:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.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>
#define N 1000
#define Z 500000
int a, b, c, d;
int push(void);
int top(void);
int pop(void);
int A[N][Z];
int size[N];
////////////////////////////////////////////////////////////
int main(void){
    scanf("%d%d", &b, &a);
    while (a-- != 0){
        scanf("%d", &b);
        if (b == 0) push();
        if (b == 1) top();
        if (b == 2) pop();
    }
    return 0;
}
int push(void){
    scanf("%d%d", &c, &d);
    A[c][size[c]] = d;
    size[c]++;
    return 0;
}
int top(void){
    scanf("%d", &c);
    if (size[c] == 0) return 0;
    printf("%d\n", A[c][size[c]-1]);
    return 0;
}
int pop(void){
    scanf("%d", &c);
    A[c][size[c]] = 0;
    if (size[c] == 0) return 0;
    size[c]--;
    return 0;
}

3 9
0 0 0
0 0 2
0 0 3
0 2 4
0 2 5
1 0
1 2
2 0
1 0
 3 9
0 0 0
0 0 2
0 0 3
0 2 4
0 0 5
1 0
1 2
2 0
1 0
 3 9
0 0 0
0 0 2
0 0 3
0 2 4
0 2 5
1 1
1 2
2 0
1 0
 6 9
0 0 0
0 0 2
0 0 3
0 2 4
0 0 5
1 1
1 2
2 0
1 0
 3 9
0 0 0
0 0 2
0 0 1
0 2 4
0 2 9
1 1
1 2
2 0
1 0
 3 9
0 0 1
0 0 2
0 0 6
0 2 4
0 2 5
1 0
1 2
2 0
1 0
 6 9
0 0 0
0 0 2
0 0 1
0 2 4
0 0 5
1 0
1 2
2 0
1 0
 3 9
0 0 0
0 0 2
0 0 1
0 2 4
0 2 9
1 1
1 2
1 0
1 0
 3 12
0 0 1
0 0 2
0 0 6
0 2 4
0 2 5
1 0
1 2
2 0
1 0
 3 9
0 0 0
0 0 2
0 0 1
0 0 4
0 2 9
1 1
1 2
1 0
1 0

3
5
2
 5
4
3
 5
2
 4
3
 9
2
 6
5
2
 5
4
1
 9
1
1
 6
5
2
2
2
2
 9
4
4

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>
#define N 1000
#define Z 500000
int a, b, c, d;
int push(void);
int top(void);
int pop(void);
int A[N][Z];
int size[N];
////////////////////////////////////////////////////////////
int main(void){
    scanf("%d%d", &b, &a);
    while (a-- != 0){
        scanf("%d", &b);
        if (b == 0) push();
        if (b == 1) top();
        if (b == 2) pop();
    }
    return 0;
}
int push(void){
    scanf("%d%d", &c, &d);
    A[c][size[c]] = d;
    size[c]++;
    return 0;
}
int top(void){
    scanf("%d", &c);
    if (size[c] == 0) return 0;
    printf("%d\n", A[c][size[c]-1]);
    return 0;
}
int pop(void){
    scanf("%d", &c);
    A[c][size[c]] = 0;
    if (size[c] == 0) return 0;
    size[c]--;
    return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	a
	.bss
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	c
	.align 4
	.type	c, @object
	.size	c, 4
c:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 2000000000
A:
	.zero	2000000000
	.globl	size
	.align 32
	.type	size, @object
	.size	size, 4000
size:
	.zero	4000
	.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
	leaq	a(%rip), %rax
	movq	%rax, %rdx
	leaq	b(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L2
.L5:
	leaq	b(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	b(%rip), %eax
	testl	%eax, %eax
	jne	.L3
	call	push
.L3:
	movl	b(%rip), %eax
	cmpl	$1, %eax
	jne	.L4
	call	top
.L4:
	movl	b(%rip), %eax
	cmpl	$2, %eax
	jne	.L2
	call	pop
.L2:
	movl	a(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, a(%rip)
	testl	%eax, %eax
	jne	.L5
	movl	$0, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	push
	.type	push, @function
push:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	d(%rip), %rax
	movq	%rax, %rdx
	leaq	c(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	c(%rip), %edx
	movl	c(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	size(%rip), %rax
	movl	(%rcx,%rax), %ecx
	movl	d(%rip), %eax
	movslq	%ecx, %rcx
	movslq	%edx, %rdx
	imulq	$500000, %rdx, %rdx
	addq	%rcx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	c(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	size(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	size(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	$0, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	push, .-push
	.section	.rodata
.LC2:
	.string	"%d\n"
	.text
	.globl	top
	.type	top, @function
top:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	c(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	c(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	size(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L10
	movl	$0, %eax
	jmp	.L11
.L10:
	movl	c(%rip), %eax
	movl	c(%rip), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	size(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	$1, %edx
	movslq	%edx, %rdx
	cltq
	imulq	$500000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L11:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	top, .-top
	.globl	pop
	.type	pop, @function
pop:
.LFB3:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	c(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	c(%rip), %eax
	movl	c(%rip), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	size(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	movslq	%edx, %rdx
	cltq
	imulq	$500000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	$0, (%rdx,%rax)
	movl	c(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	size(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L13
	movl	$0, %eax
	jmp	.L14
.L13:
	movl	c(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	size(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	-1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	size(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	$0, %eax
.L14:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3:
	.size	pop, .-pop
	.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	a
	.bss
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	c
	.align 4
	.type	c, @object
	.size	c, 4
c:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 2000000000
A:
	.zero	2000000000
	.globl	size
	.align 32
	.type	size, @object
	.size	size, 4000
size:
	.zero	4000
	.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
	leaq	a(%rip), %rax
	movq	%rax, %rdx
	leaq	b(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L2
.L5:
	leaq	b(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	b(%rip), %eax
	testl	%eax, %eax
	jne	.L3
	call	push
.L3:
	movl	b(%rip), %eax
	cmpl	$1, %eax
	jne	.L4
	call	top
.L4:
	movl	b(%rip), %eax
	cmpl	$2, %eax
	jne	.L2
	call	pop
.L2:
	movl	a(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, a(%rip)
	testl	%eax, %eax
	jne	.L5
	movl	$0, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	push
	.type	push, @function
push:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	d(%rip), %rax
	movq	%rax, %rdx
	leaq	c(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	c(%rip), %edx
	movl	c(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	size(%rip), %rax
	movl	(%rcx,%rax), %ecx
	movl	d(%rip), %eax
	movslq	%ecx, %rcx
	movslq	%edx, %rdx
	imulq	$500000, %rdx, %rdx
	addq	%rcx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	c(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	size(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	size(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	$0, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	push, .-push
	.section	.rodata
.LC2:
	.string	"%d\n"
	.text
	.globl	top
	.type	top, @function
top:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	c(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	c(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	size(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L10
	movl	$0, %eax
	jmp	.L11
.L10:
	movl	c(%rip), %eax
	movl	c(%rip), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	size(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	$1, %edx
	movslq	%edx, %rdx
	cltq
	imulq	$500000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L11:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	top, .-top
	.globl	pop
	.type	pop, @function
pop:
.LFB3:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	c(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	c(%rip), %eax
	movl	c(%rip), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	size(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	movslq	%edx, %rdx
	cltq
	imulq	$500000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	$0, (%rdx,%rax)
	movl	c(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	size(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L13
	movl	$0, %eax
	jmp	.L14
.L13:
	movl	c(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	size(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	-1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	size(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	$0, %eax
.L14:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3:
	.size	pop, .-pop
	.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:
