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

```c
// AOJ 0270: Modular Query
// 2017.8.24 bal4u@uu
// 2017.11.5 retry

#include <stdio.h>

char tbl[300005];

char buf[2100010], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int N, Q, i, k, q, max;

	fgets(p=buf, 20, stdin), N = getint(), p++, Q = getint();
	tbl[0] = 1, max = 0;
	fgets(p=buf, sizeof(buf), stdin);
	while (N--) {
		tbl[k=getint()] = 1, p++;
		if (k > max) max = k;
		tbl[k & 1] = 1, tbl[k & 3] = 1, tbl[k & 7] = 1;
	}
	while (Q--) {
		fgets(p=buf, 10, stdin), q = getint();
		if (q > max) printf("%d\n", max);
		else {
			for (k = q-1; ; k--) {
				for (i = k; i <= max; i += q)
					if (tbl[i]) { printf("%d\n", k); goto Done; }
			}
			Done:;
		}
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	tbl
	.bss
	.align 32
	.type	tbl, @object
	.size	tbl, 300005
tbl:
	.zero	300005
	.globl	buf
	.align 32
	.type	buf, @object
	.size	buf, 2100010
buf:
	.zero	2100010
	.globl	p
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.zero	8
	.text
	.globl	getint
	.type	getint, @function
getint:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	$0, -4(%rbp)
	jmp	.L2
.L3:
	movl	-4(%rbp), %eax
	leal	0(,%rax,8), %edx
	movl	-4(%rbp), %eax
	addl	%eax, %eax
	leal	(%rdx,%rax), %ecx
	movq	p(%rip), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, p(%rip)
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	andl	$15, %eax
	addl	%ecx, %eax
	movl	%eax, -4(%rbp)
.L2:
	movq	p(%rip), %rax
	movzbl	(%rax), %eax
	cmpb	$47, %al
	jg	.L3
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	getint, .-getint
	.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
	movq	stdin(%rip), %rdx
	leaq	buf(%rip), %rax
	movq	%rax, p(%rip)
	movq	p(%rip), %rax
	movl	$20, %esi
	movq	%rax, %rdi
	call	fgets@PLT
	movl	$0, %eax
	call	getint
	movl	%eax, -24(%rbp)
	movq	p(%rip), %rax
	addq	$1, %rax
	movq	%rax, p(%rip)
	movl	$0, %eax
	call	getint
	movl	%eax, -20(%rbp)
	movb	$1, tbl(%rip)
	movl	$0, -8(%rbp)
	movq	stdin(%rip), %rdx
	leaq	buf(%rip), %rax
	movq	%rax, p(%rip)
	movq	p(%rip), %rax
	movl	$2100010, %esi
	movq	%rax, %rdi
	call	fgets@PLT
	jmp	.L6
.L8:
	movl	$0, %eax
	call	getint
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	cltq
	leaq	tbl(%rip), %rdx
	movb	$1, (%rax,%rdx)
	movq	p(%rip), %rax
	addq	$1, %rax
	movq	%rax, p(%rip)
	movl	-12(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jle	.L7
	movl	-12(%rbp), %eax
	movl	%eax, -8(%rbp)
.L7:
	movl	-12(%rbp), %eax
	andl	$1, %eax
	cltq
	leaq	tbl(%rip), %rdx
	movb	$1, (%rax,%rdx)
	movl	-12(%rbp), %eax
	andl	$3, %eax
	cltq
	leaq	tbl(%rip), %rdx
	movb	$1, (%rax,%rdx)
	movl	-12(%rbp), %eax
	andl	$7, %eax
	cltq
	leaq	tbl(%rip), %rdx
	movb	$1, (%rax,%rdx)
.L6:
	movl	-24(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -24(%rbp)
	testl	%eax, %eax
	jne	.L8
	jmp	.L9
.L16:
	movq	stdin(%rip), %rdx
	leaq	buf(%rip), %rax
	movq	%rax, p(%rip)
	movq	p(%rip), %rax
	movl	$10, %esi
	movq	%rax, %rdi
	call	fgets@PLT
	movl	$0, %eax
	call	getint
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jle	.L10
	movl	-8(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L9
.L10:
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -12(%rbp)
.L15:
	movl	-12(%rbp), %eax
	movl	%eax, -16(%rbp)
	jmp	.L11
.L14:
	movl	-16(%rbp), %eax
	cltq
	leaq	tbl(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	testb	%al, %al
	je	.L12
	movl	-12(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	nop
.L13:
	jmp	.L9
.L12:
	movl	-4(%rbp), %eax
	addl	%eax, -16(%rbp)
.L11:
	movl	-16(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jle	.L14
	subl	$1, -12(%rbp)
	jmp	.L15
.L9:
	movl	-20(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -20(%rbp)
	testl	%eax, %eax
	jne	.L16
	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	getint
	.type	getint, @function
getint:
.LFB23:
	.cfi_startproc
	endbr64
	movq	p(%rip), %rax
	cmpb	$47, (%rax)
	jle	.L4
	addq	$1, %rax
	xorl	%r8d, %r8d
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rax, p(%rip)
	movzbl	-1(%rax), %edx
	addq	$1, %rax
	leal	(%r8,%r8,4), %ecx
	andl	$15, %edx
	cmpb	$47, -1(%rax)
	leal	(%rdx,%rcx,2), %r8d
	jg	.L3
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L4:
	xorl	%r8d, %r8d
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	getint, .-getint
	.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	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movq	stdin(%rip), %rdx
	movl	$20, %esi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	leaq	buf(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rbp, %rdi
	movq	%rbp, p(%rip)
	call	fgets@PLT
	movq	p(%rip), %rax
	cmpb	$47, (%rax)
	leaq	1(%rax), %rdx
	jle	.L8
	xorl	%r13d, %r13d
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%rdx, p(%rip)
	movzbl	-1(%rdx), %ecx
	movq	%rdx, %rax
	addq	$1, %rdx
	leal	0(%r13,%r13,4), %esi
	andl	$15, %ecx
	cmpb	$47, -1(%rdx)
	leal	(%rcx,%rsi,2), %r13d
	jg	.L9
	movq	%rdx, p(%rip)
	cmpb	$47, 1(%rax)
	leal	-1(%r13), %r12d
	movq	stdin(%rip), %r8
	jle	.L10
.L29:
	addq	$2, %rax
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L11:
	movq	%rax, p(%rip)
	movzbl	-1(%rax), %edx
	addq	$1, %rax
	leal	(%rbx,%rbx,4), %ecx
	andl	$15, %edx
	cmpb	$47, -1(%rax)
	leal	(%rdx,%rcx,2), %ebx
	jg	.L11
	movq	%r8, %rdx
	movl	$2100010, %esi
	movq	%rbp, %rdi
	movb	$1, tbl(%rip)
	movq	%rbp, p(%rip)
	call	fgets@PLT
	testl	%r13d, %r13d
	je	.L12
.L28:
	movq	p(%rip), %rax
	xorl	%r13d, %r13d
	leaq	tbl(%rip), %rdi
	.p2align 4,,10
	.p2align 3
.L13:
	xorl	%edx, %edx
	cmpb	$47, (%rax)
	leaq	1(%rax), %rcx
	jle	.L51
	.p2align 4,,10
	.p2align 3
.L14:
	movq	%rcx, p(%rip)
	leal	(%rdx,%rdx,4), %esi
	movzbl	-1(%rcx), %edx
	movq	%rcx, %rax
	leaq	1(%rcx), %rcx
	andl	$15, %edx
	cmpb	$47, (%rax)
	leal	(%rdx,%rsi,2), %edx
	jg	.L14
	movl	%edx, %ecx
	movl	%edx, %esi
	movl	%edx, %r8d
	andl	$1, %ecx
	andl	$3, %esi
	andl	$7, %r8d
.L16:
	addq	$1, %rax
	cmpl	%edx, %r13d
	movslq	%edx, %r9
	cmovl	%edx, %r13d
	movslq	%ecx, %rdx
	movb	$1, (%rdi,%r9)
	movb	$1, (%rdi,%rdx)
	movslq	%esi, %rdx
	movb	$1, (%rdi,%rdx)
	movslq	%r8d, %rdx
	movq	%rax, p(%rip)
	movb	$1, (%rdi,%rdx)
	subl	$1, %r12d
	jnb	.L13
.L12:
	leaq	.LC0(%rip), %r12
	leaq	tbl(%rip), %r14
	testl	%ebx, %ebx
	je	.L48
	.p2align 4,,10
	.p2align 3
.L26:
	movq	stdin(%rip), %rdx
	movl	$10, %esi
	movq	%rbp, %rdi
	movq	%rbp, p(%rip)
	call	fgets@PLT
	movq	p(%rip), %rax
	cmpb	$47, (%rax)
	jle	.L31
	addq	$1, %rax
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L19:
	movq	%rax, p(%rip)
	leal	(%rdx,%rdx,4), %ecx
	movzbl	-1(%rax), %edx
	addq	$1, %rax
	andl	$15, %edx
	cmpb	$47, -1(%rax)
	leal	(%rdx,%rcx,2), %edx
	jg	.L19
	leal	-1(%rdx), %r8d
	cmpl	%r13d, %edx
	jle	.L18
	movl	%r13d, %edx
	movq	%r12, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L21:
	subl	$1, %ebx
	jne	.L26
.L48:
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L31:
	.cfi_restore_state
	movl	$-1, %r8d
	xorl	%edx, %edx
.L18:
	movslq	%r8d, %rcx
	movslq	%edx, %rdx
.L25:
	cmpl	%r13d, %r8d
	jg	.L22
	movq	%rcx, %rax
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L23:
	addq	%rdx, %rax
	cmpl	%eax, %r13d
	jl	.L22
.L24:
	cmpb	$0, (%r14,%rax)
	je	.L23
	movl	%r8d, %edx
	movq	%r12, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L22:
	subl	$1, %r8d
	subq	$1, %rcx
	jmp	.L25
	.p2align 4,,10
	.p2align 3
.L51:
	xorl	%r8d, %r8d
	xorl	%esi, %esi
	xorl	%ecx, %ecx
	jmp	.L16
.L8:
	movq	%rdx, p(%rip)
	orl	$-1, %r12d
	xorl	%r13d, %r13d
	cmpb	$47, 1(%rax)
	movq	stdin(%rip), %r8
	jg	.L29
	movq	%r8, %rdx
	movl	$2100010, %esi
	movq	%rbp, %rdi
	movq	%rbp, p(%rip)
	movb	$1, tbl(%rip)
	call	fgets@PLT
	jmp	.L48
.L10:
	movq	%r8, %rdx
	movl	$2100010, %esi
	movq	%rbp, %rdi
	xorl	%ebx, %ebx
	movb	$1, tbl(%rip)
	movq	%rbp, p(%rip)
	call	fgets@PLT
	testl	%r13d, %r13d
	jne	.L28
	jmp	.L48
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	p
	.bss
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.zero	8
	.globl	buf
	.align 32
	.type	buf, @object
	.size	buf, 2100010
buf:
	.zero	2100010
	.globl	tbl
	.align 32
	.type	tbl, @object
	.size	tbl, 300005
tbl:
	.zero	300005
	.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	getint
	.type	getint, @function
getint:
.LFB23:
	.cfi_startproc
	endbr64
	movq	p(%rip), %rax
	cmpb	$47, (%rax)
	jle	.L4
	addq	$1, %rax
	xorl	%r8d, %r8d
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rax, p(%rip)
	movzbl	-1(%rax), %edx
	addq	$1, %rax
	leal	(%r8,%r8,4), %ecx
	andl	$15, %edx
	cmpb	$47, -1(%rax)
	leal	(%rdx,%rcx,2), %r8d
	jg	.L3
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L4:
	xorl	%r8d, %r8d
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	getint, .-getint
	.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	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movq	stdin(%rip), %rdx
	movl	$20, %esi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	leaq	buf(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rbp, %rdi
	movq	%rbp, p(%rip)
	call	fgets@PLT
	movq	p(%rip), %rax
	cmpb	$47, (%rax)
	leaq	1(%rax), %rdx
	jle	.L8
	xorl	%r13d, %r13d
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%rdx, p(%rip)
	movzbl	-1(%rdx), %ecx
	movq	%rdx, %rax
	addq	$1, %rdx
	leal	0(%r13,%r13,4), %esi
	andl	$15, %ecx
	cmpb	$47, -1(%rdx)
	leal	(%rcx,%rsi,2), %r13d
	jg	.L9
	movq	%rdx, p(%rip)
	cmpb	$47, 1(%rax)
	leal	-1(%r13), %r12d
	movq	stdin(%rip), %r8
	jle	.L10
.L29:
	addq	$2, %rax
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L11:
	movq	%rax, p(%rip)
	movzbl	-1(%rax), %edx
	addq	$1, %rax
	leal	(%rbx,%rbx,4), %ecx
	andl	$15, %edx
	cmpb	$47, -1(%rax)
	leal	(%rdx,%rcx,2), %ebx
	jg	.L11
	movq	%r8, %rdx
	movl	$2100010, %esi
	movq	%rbp, %rdi
	movb	$1, tbl(%rip)
	movq	%rbp, p(%rip)
	call	fgets@PLT
	testl	%r13d, %r13d
	je	.L12
.L28:
	movq	p(%rip), %rax
	xorl	%r13d, %r13d
	leaq	tbl(%rip), %rdi
	.p2align 4,,10
	.p2align 3
.L13:
	xorl	%edx, %edx
	cmpb	$47, (%rax)
	leaq	1(%rax), %rcx
	jle	.L51
	.p2align 4,,10
	.p2align 3
.L14:
	movq	%rcx, p(%rip)
	leal	(%rdx,%rdx,4), %esi
	movzbl	-1(%rcx), %edx
	movq	%rcx, %rax
	leaq	1(%rcx), %rcx
	andl	$15, %edx
	cmpb	$47, (%rax)
	leal	(%rdx,%rsi,2), %edx
	jg	.L14
	movl	%edx, %ecx
	movl	%edx, %esi
	movl	%edx, %r8d
	andl	$1, %ecx
	andl	$3, %esi
	andl	$7, %r8d
.L16:
	addq	$1, %rax
	cmpl	%edx, %r13d
	movslq	%edx, %r9
	cmovl	%edx, %r13d
	movslq	%ecx, %rdx
	movb	$1, (%rdi,%r9)
	movb	$1, (%rdi,%rdx)
	movslq	%esi, %rdx
	movb	$1, (%rdi,%rdx)
	movslq	%r8d, %rdx
	movq	%rax, p(%rip)
	movb	$1, (%rdi,%rdx)
	subl	$1, %r12d
	jnb	.L13
.L12:
	leaq	.LC0(%rip), %r12
	leaq	tbl(%rip), %r14
	testl	%ebx, %ebx
	je	.L48
	.p2align 4,,10
	.p2align 3
.L26:
	movq	stdin(%rip), %rdx
	movl	$10, %esi
	movq	%rbp, %rdi
	movq	%rbp, p(%rip)
	call	fgets@PLT
	movq	p(%rip), %rax
	cmpb	$47, (%rax)
	jle	.L31
	addq	$1, %rax
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L19:
	movq	%rax, p(%rip)
	leal	(%rdx,%rdx,4), %ecx
	movzbl	-1(%rax), %edx
	addq	$1, %rax
	andl	$15, %edx
	cmpb	$47, -1(%rax)
	leal	(%rdx,%rcx,2), %edx
	jg	.L19
	leal	-1(%rdx), %r8d
	cmpl	%r13d, %edx
	jle	.L18
	movl	%r13d, %edx
	movq	%r12, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L21:
	subl	$1, %ebx
	jne	.L26
.L48:
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L31:
	.cfi_restore_state
	movl	$-1, %r8d
	xorl	%edx, %edx
.L18:
	movslq	%r8d, %rcx
	movslq	%edx, %rdx
.L25:
	cmpl	%r13d, %r8d
	jg	.L22
	movq	%rcx, %rax
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L23:
	addq	%rdx, %rax
	cmpl	%eax, %r13d
	jl	.L22
.L24:
	cmpb	$0, (%r14,%rax)
	je	.L23
	movl	%r8d, %edx
	movq	%r12, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L22:
	subl	$1, %r8d
	subq	$1, %rcx
	jmp	.L25
	.p2align 4,,10
	.p2align 3
.L51:
	xorl	%r8d, %r8d
	xorl	%esi, %esi
	xorl	%ecx, %ecx
	jmp	.L16
.L8:
	movq	%rdx, p(%rip)
	orl	$-1, %r12d
	xorl	%r13d, %r13d
	cmpb	$47, 1(%rax)
	movq	stdin(%rip), %r8
	jg	.L29
	movq	%r8, %rdx
	movl	$2100010, %esi
	movq	%rbp, %rdi
	movq	%rbp, p(%rip)
	movb	$1, tbl(%rip)
	call	fgets@PLT
	jmp	.L48
.L10:
	movq	%r8, %rdx
	movl	$2100010, %esi
	movq	%rbp, %rdi
	xorl	%ebx, %ebx
	movb	$1, tbl(%rip)
	movq	%rbp, p(%rip)
	call	fgets@PLT
	testl	%r13d, %r13d
	jne	.L28
	jmp	.L48
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	p
	.bss
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.zero	8
	.globl	buf
	.align 32
	.type	buf, @object
	.size	buf, 2100010
buf:
	.zero	2100010
	.globl	tbl
	.align 32
	.type	tbl, @object
	.size	tbl, 300005
tbl:
	.zero	300005
	.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 0270: Modular Query
// 2017.8.24 bal4u@uu
// 2017.11.5 retry

#include <stdio.h>

char tbl[300005];

char buf[2100010], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int N, Q, i, k, q, max;

	fgets(p=buf, 20, stdin), N = getint(), p++, Q = getint();
	tbl[0] = 1, max = 0;
	fgets(p=buf, sizeof(buf), stdin);
	while (N--) {
		tbl[k=getint()] = 1, p++;
		if (k > max) max = k;
		tbl[k & 1] = 1, tbl[k & 3] = 1, tbl[k & 7] = 1;
	}
	while (Q--) {
		fgets(p=buf, 10, stdin), q = getint();
		if (q > max) printf("%d\n", max);
		else {
			for (k = q-1; ; k--) {
				for (i = k; i <= max; i += q)
					if (tbl[i]) { printf("%d\n", k); goto Done; }
			}
			Done:;
		}
	}
	return 0;
}
3 3
9 3 8
6
6
5
 3 3
9 3 10
6
6
5
 3 3
9 3 8
4
6
3
 3 3
9 3 8
6
6
2
 3 2
1 3 8
4
6
3
 3 3
9 2 8
4
6
5
 3 3
12 3 8
6
6
5
 3 3
9 3 8
4
6
1
 3 3
9 3 8
12
6
2
 3 2
1 3 11
4
6
3

3
3
4
 4
4
4
 3
3
2
 3
3
1
 3
3
 2
3
4
 4
4
4
 3
3
0
 9
3
1
 3
5

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

```c
// AOJ 0270: Modular Query
// 2017.8.24 bal4u@uu
// 2017.11.5 retry

#include <stdio.h>

char tbl[300005];

char buf[2100010], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int N, Q, i, k, q, max;

	fgets(p=buf, 20, stdin), N = getint(), p++, Q = getint();
	tbl[0] = 1, max = 0;
	fgets(p=buf, sizeof(buf), stdin);
	while (N--) {
		tbl[k=getint()] = 1, p++;
		if (k > max) max = k;
		tbl[k & 1] = 1, tbl[k & 3] = 1, tbl[k & 7] = 1;
	}
	while (Q--) {
		fgets(p=buf, 10, stdin), q = getint();
		if (q > max) printf("%d\n", max);
		else {
			for (k = q-1; ; k--) {
				for (i = k; i <= max; i += q)
					if (tbl[i]) { printf("%d\n", k); goto Done; }
			}
			Done:;
		}
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	tbl
	.bss
	.align 32
	.type	tbl, @object
	.size	tbl, 300005
tbl:
	.zero	300005
	.globl	buf
	.align 32
	.type	buf, @object
	.size	buf, 2100010
buf:
	.zero	2100010
	.globl	p
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.zero	8
	.text
	.globl	getint
	.type	getint, @function
getint:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	$0, -4(%rbp)
	jmp	.L2
.L3:
	movl	-4(%rbp), %eax
	leal	0(,%rax,8), %edx
	movl	-4(%rbp), %eax
	addl	%eax, %eax
	leal	(%rdx,%rax), %ecx
	movq	p(%rip), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, p(%rip)
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	andl	$15, %eax
	addl	%ecx, %eax
	movl	%eax, -4(%rbp)
.L2:
	movq	p(%rip), %rax
	movzbl	(%rax), %eax
	cmpb	$47, %al
	jg	.L3
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	getint, .-getint
	.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
	movq	stdin(%rip), %rdx
	leaq	buf(%rip), %rax
	movq	%rax, p(%rip)
	movq	p(%rip), %rax
	movl	$20, %esi
	movq	%rax, %rdi
	call	fgets@PLT
	movl	$0, %eax
	call	getint
	movl	%eax, -24(%rbp)
	movq	p(%rip), %rax
	addq	$1, %rax
	movq	%rax, p(%rip)
	movl	$0, %eax
	call	getint
	movl	%eax, -20(%rbp)
	movb	$1, tbl(%rip)
	movl	$0, -8(%rbp)
	movq	stdin(%rip), %rdx
	leaq	buf(%rip), %rax
	movq	%rax, p(%rip)
	movq	p(%rip), %rax
	movl	$2100010, %esi
	movq	%rax, %rdi
	call	fgets@PLT
	jmp	.L6
.L8:
	movl	$0, %eax
	call	getint
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	cltq
	leaq	tbl(%rip), %rdx
	movb	$1, (%rax,%rdx)
	movq	p(%rip), %rax
	addq	$1, %rax
	movq	%rax, p(%rip)
	movl	-12(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jle	.L7
	movl	-12(%rbp), %eax
	movl	%eax, -8(%rbp)
.L7:
	movl	-12(%rbp), %eax
	andl	$1, %eax
	cltq
	leaq	tbl(%rip), %rdx
	movb	$1, (%rax,%rdx)
	movl	-12(%rbp), %eax
	andl	$3, %eax
	cltq
	leaq	tbl(%rip), %rdx
	movb	$1, (%rax,%rdx)
	movl	-12(%rbp), %eax
	andl	$7, %eax
	cltq
	leaq	tbl(%rip), %rdx
	movb	$1, (%rax,%rdx)
.L6:
	movl	-24(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -24(%rbp)
	testl	%eax, %eax
	jne	.L8
	jmp	.L9
.L16:
	movq	stdin(%rip), %rdx
	leaq	buf(%rip), %rax
	movq	%rax, p(%rip)
	movq	p(%rip), %rax
	movl	$10, %esi
	movq	%rax, %rdi
	call	fgets@PLT
	movl	$0, %eax
	call	getint
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jle	.L10
	movl	-8(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L9
.L10:
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -12(%rbp)
.L15:
	movl	-12(%rbp), %eax
	movl	%eax, -16(%rbp)
	jmp	.L11
.L14:
	movl	-16(%rbp), %eax
	cltq
	leaq	tbl(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	testb	%al, %al
	je	.L12
	movl	-12(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	nop
.L13:
	jmp	.L9
.L12:
	movl	-4(%rbp), %eax
	addl	%eax, -16(%rbp)
.L11:
	movl	-16(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jle	.L14
	subl	$1, -12(%rbp)
	jmp	.L15
.L9:
	movl	-20(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -20(%rbp)
	testl	%eax, %eax
	jne	.L16
	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	tbl
	.bss
	.align 32
	.type	tbl, @object
	.size	tbl, 300005
tbl:
	.zero	300005
	.globl	buf
	.align 32
	.type	buf, @object
	.size	buf, 2100010
buf:
	.zero	2100010
	.globl	p
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.zero	8
	.text
	.globl	getint
	.type	getint, @function
getint:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	$0, -4(%rbp)
	jmp	.L2
.L3:
	movl	-4(%rbp), %eax
	leal	0(,%rax,8), %edx
	movl	-4(%rbp), %eax
	addl	%eax, %eax
	leal	(%rdx,%rax), %ecx
	movq	p(%rip), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, p(%rip)
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	andl	$15, %eax
	addl	%ecx, %eax
	movl	%eax, -4(%rbp)
.L2:
	movq	p(%rip), %rax
	movzbl	(%rax), %eax
	cmpb	$47, %al
	jg	.L3
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	getint, .-getint
	.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
	movq	stdin(%rip), %rdx
	leaq	buf(%rip), %rax
	movq	%rax, p(%rip)
	movq	p(%rip), %rax
	movl	$20, %esi
	movq	%rax, %rdi
	call	fgets@PLT
	movl	$0, %eax
	call	getint
	movl	%eax, -24(%rbp)
	movq	p(%rip), %rax
	addq	$1, %rax
	movq	%rax, p(%rip)
	movl	$0, %eax
	call	getint
	movl	%eax, -20(%rbp)
	movb	$1, tbl(%rip)
	movl	$0, -8(%rbp)
	movq	stdin(%rip), %rdx
	leaq	buf(%rip), %rax
	movq	%rax, p(%rip)
	movq	p(%rip), %rax
	movl	$2100010, %esi
	movq	%rax, %rdi
	call	fgets@PLT
	jmp	.L6
.L8:
	movl	$0, %eax
	call	getint
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	cltq
	leaq	tbl(%rip), %rdx
	movb	$1, (%rax,%rdx)
	movq	p(%rip), %rax
	addq	$1, %rax
	movq	%rax, p(%rip)
	movl	-12(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jle	.L7
	movl	-12(%rbp), %eax
	movl	%eax, -8(%rbp)
.L7:
	movl	-12(%rbp), %eax
	andl	$1, %eax
	cltq
	leaq	tbl(%rip), %rdx
	movb	$1, (%rax,%rdx)
	movl	-12(%rbp), %eax
	andl	$3, %eax
	cltq
	leaq	tbl(%rip), %rdx
	movb	$1, (%rax,%rdx)
	movl	-12(%rbp), %eax
	andl	$7, %eax
	cltq
	leaq	tbl(%rip), %rdx
	movb	$1, (%rax,%rdx)
.L6:
	movl	-24(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -24(%rbp)
	testl	%eax, %eax
	jne	.L8
	jmp	.L9
.L16:
	movq	stdin(%rip), %rdx
	leaq	buf(%rip), %rax
	movq	%rax, p(%rip)
	movq	p(%rip), %rax
	movl	$10, %esi
	movq	%rax, %rdi
	call	fgets@PLT
	movl	$0, %eax
	call	getint
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jle	.L10
	movl	-8(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L9
.L10:
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -12(%rbp)
.L15:
	movl	-12(%rbp), %eax
	movl	%eax, -16(%rbp)
	jmp	.L11
.L14:
	movl	-16(%rbp), %eax
	cltq
	leaq	tbl(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	testb	%al, %al
	je	.L12
	movl	-12(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	nop
.L13:
	jmp	.L9
.L12:
	movl	-4(%rbp), %eax
	addl	%eax, -16(%rbp)
.L11:
	movl	-16(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jle	.L14
	subl	$1, -12(%rbp)
	jmp	.L15
.L9:
	movl	-20(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -20(%rbp)
	testl	%eax, %eax
	jne	.L16
	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:
