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>
#include <stdlib.h>

/* constant */

#define MAX_N   (300000)
#define MAX_Q   (100000)

/* global variables */

static int cards[MAX_N + 1];
static int cmap[MAX_N * 2 + 1];

/* subroutines */

int comp(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

/* main */

int main(int argc, char **argv) {
  int c0, c1, i, j, max_c, max_qi, max_rem, n, prev, q, qi, qn, rem;

  scanf("%d%d", &n, &qn);

  for (i = 0; i < n; i++)
    scanf("%d", &cards[i]);

  qsort(cards, n, sizeof(int), comp);

  c0 = 0;
  for (i = 0; i < n; i++) {
    c1 = cards[i];
    for (j = c0; j < c1; j++) cmap[j] = c0;
    c0 = c1;
  }
  max_c = cmap[c0] = c0;

  for (i = 0; i < qn; i++) {
    scanf("%d", &q);

    max_qi = (max_c / q + 1) * q;
    for (j = max_c; j <= max_qi; j++)
      cmap[j] = max_c;

    max_rem = 0;

    for (qi = q - 1; qi <= max_qi; qi += q) {
      rem = cmap[qi] % q;
      if (max_rem < rem) {
        max_rem = rem;
        if (max_rem == q - 1) break;
      }
    }

    printf("%d\n", max_rem);
  }

  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.local	cards
	.comm	cards,1200004,32
	.local	cmap
	.comm	cmap,2400004,32
	.globl	comp
	.type	comp, @function
comp:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	comp, .-comp
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$80, %rsp
	movl	%edi, -68(%rbp)
	movq	%rsi, -80(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-48(%rbp), %rdx
	leaq	-56(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -40(%rbp)
	jmp	.L4
.L5:
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cards(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -40(%rbp)
.L4:
	movl	-56(%rbp), %eax
	cmpl	%eax, -40(%rbp)
	jl	.L5
	movl	-56(%rbp), %eax
	cltq
	leaq	comp(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rsi
	leaq	cards(%rip), %rax
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -44(%rbp)
	movl	$0, -40(%rbp)
	jmp	.L6
.L9:
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cards(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -12(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L7
.L8:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	cmap(%rip), %rdx
	movl	-44(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	addl	$1, -36(%rbp)
.L7:
	movl	-36(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jl	.L8
	movl	-12(%rbp), %eax
	movl	%eax, -44(%rbp)
	addl	$1, -40(%rbp)
.L6:
	movl	-56(%rbp), %eax
	cmpl	%eax, -40(%rbp)
	jl	.L9
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	cmap(%rip), %rdx
	movl	-44(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cmap(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -24(%rbp)
	movl	$0, -40(%rbp)
	jmp	.L10
.L17:
	leaq	-52(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-52(%rbp), %esi
	movl	-24(%rbp), %eax
	cltd
	idivl	%esi
	leal	1(%rax), %edx
	movl	-52(%rbp), %eax
	imull	%edx, %eax
	movl	%eax, -20(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L11
.L12:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	cmap(%rip), %rdx
	movl	-24(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	addl	$1, -36(%rbp)
.L11:
	movl	-36(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jle	.L12
	movl	$0, -32(%rbp)
	movl	-52(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -28(%rbp)
	jmp	.L13
.L16:
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cmap(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-52(%rbp), %ecx
	cltd
	idivl	%ecx
	movl	%edx, -16(%rbp)
	movl	-32(%rbp), %eax
	cmpl	-16(%rbp), %eax
	jge	.L14
	movl	-16(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-52(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -32(%rbp)
	je	.L20
.L14:
	movl	-52(%rbp), %eax
	addl	%eax, -28(%rbp)
.L13:
	movl	-28(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jle	.L16
	jmp	.L15
.L20:
	nop
.L15:
	movl	-32(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -40(%rbp)
.L10:
	movl	-48(%rbp), %eax
	cmpl	%eax, -40(%rbp)
	jl	.L17
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.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	comp
	.type	comp, @function
comp:
.LFB39:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE39:
	.size	comp, .-comp
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leaq	cards(%rip), %r13
	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	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	36(%rsp), %rdx
	leaq	28(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	jle	.L4
	movq	%r13, %r12
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %rbp
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%r12, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	addq	$4, %r12
	cmpl	%ebx, %eax
	jg	.L5
.L4:
	movslq	%eax, %rsi
	leaq	comp(%rip), %rcx
	movl	$4, %edx
	movq	%r13, %rdi
	call	qsort@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	jle	.L22
	leaq	cards(%rip), %r9
	leal	-1(%rax), %edx
	xorl	%r15d, %r15d
	leaq	4(%r9), %rax
	leaq	cmap(%rip), %r12
	leaq	(%rax,%rdx,4), %r10
	.p2align 4,,10
	.p2align 3
.L11:
	movl	%r15d, %esi
	movl	(%r9), %r15d
	cmpl	%esi, %r15d
	jle	.L7
	movl	%r15d, %edi
	subl	%esi, %edi
	leal	-1(%rdi), %eax
	cmpl	$2, %eax
	jbe	.L23
	movslq	%esi, %rax
	movd	%esi, %xmm1
	leaq	(%r12,%rax,4), %rdx
	movl	%edi, %eax
	pshufd	$0, %xmm1, %xmm0
	shrl	$2, %eax
	leal	-1(%rax), %ecx
	leaq	16(%rdx), %rax
	salq	$4, %rcx
	addq	%rax, %rcx
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L38:
	addq	$16, %rax
.L9:
	movups	%xmm0, (%rdx)
	movq	%rax, %rdx
	cmpq	%rcx, %rax
	jne	.L38
	movl	%edi, %edx
	andl	$-4, %edx
	leal	(%rdx,%rsi), %eax
	cmpl	%edx, %edi
	je	.L7
.L8:
	movslq	%eax, %rdx
	movl	%esi, (%r12,%rdx,4)
	leal	1(%rax), %edx
	cmpl	%edx, %r15d
	jle	.L7
	movslq	%edx, %rdx
	addl	$2, %eax
	movl	%esi, (%r12,%rdx,4)
	cmpl	%eax, %r15d
	jle	.L7
	cltq
	movl	%esi, (%r12,%rax,4)
.L7:
	addq	$4, %r9
	cmpq	%r10, %r9
	jne	.L11
.L6:
	movl	36(%rsp), %edx
	movslq	%r15d, %rax
	movl	%r15d, (%r12,%rax,4)
	testl	%edx, %edx
	jle	.L12
	leaq	(%r12,%rax,4), %rax
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %rbp
	movq	%rax, 8(%rsp)
	leaq	32(%rsp), %r14
	leaq	.LC2(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L20:
	movq	%r14, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	32(%rsp), %esi
	movl	%r15d, %eax
	cltd
	idivl	%esi
	leal	1(%rax), %ecx
	imull	%esi, %ecx
	cmpl	%r15d, %ecx
	jl	.L13
	movl	%ecx, %eax
	subl	%r15d, %eax
	leal	1(%rax), %edi
	cmpl	$2, %eax
	jbe	.L24
	movl	%edi, %eax
	movq	8(%rsp), %r8
	movd	%r15d, %xmm2
	shrl	$2, %eax
	pshufd	$0, %xmm2, %xmm0
	subl	$1, %eax
	salq	$4, %rax
	leaq	16(%r8,%rax), %rdx
	movq	%r8, %rax
	.p2align 4,,10
	.p2align 3
.L15:
	movups	%xmm0, (%rax)
	addq	$16, %rax
	cmpq	%rdx, %rax
	jne	.L15
	movl	%edi, %edx
	andl	$-4, %edx
	leal	(%rdx,%r15), %eax
	cmpl	%edx, %edi
	je	.L13
.L14:
	movslq	%eax, %rdx
	movl	%r15d, (%r12,%rdx,4)
	leal	1(%rax), %edx
	cmpl	%edx, %ecx
	jl	.L13
	movslq	%edx, %rdx
	addl	$2, %eax
	movl	%r15d, (%r12,%rdx,4)
	cmpl	%eax, %ecx
	jl	.L13
	cltq
	movl	%r15d, (%r12,%rax,4)
.L13:
	leal	-1(%rsi), %r10d
	xorl	%r9d, %r9d
	cmpl	%r10d, %ecx
	jl	.L17
	cmpl	$1, %esi
	jne	.L39
.L17:
	movl	%r9d, %edx
	movq	%r13, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addl	$1, %ebx
	cmpl	%ebx, 36(%rsp)
	jg	.L20
.L12:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L40
	addq	$56, %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
.L39:
	.cfi_restore_state
	movslq	%esi, %r11
	movslq	%r10d, %rdi
	jmp	.L19
	.p2align 4,,10
	.p2align 3
.L41:
	movl	%edx, %r9d
.L18:
	addq	%r11, %rdi
	cmpl	%edi, %ecx
	jl	.L17
.L19:
	movl	(%r12,%rdi,4), %eax
	cltd
	idivl	%esi
	cmpl	%r9d, %edx
	jle	.L18
	cmpl	%edx, %r10d
	jne	.L41
	movl	%r10d, %r9d
	jmp	.L17
.L23:
	movl	%esi, %eax
	jmp	.L8
.L24:
	movl	%r15d, %eax
	jmp	.L14
.L22:
	xorl	%r15d, %r15d
	leaq	cmap(%rip), %r12
	jmp	.L6
.L40:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE40:
	.size	main, .-main
	.local	cmap
	.comm	cmap,2400004,32
	.local	cards
	.comm	cards,1200004,32
	.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	comp
	.type	comp, @function
comp:
.LFB39:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE39:
	.size	comp, .-comp
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leaq	cards(%rip), %r13
	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	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	36(%rsp), %rdx
	leaq	28(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	jle	.L4
	movq	%r13, %r12
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %rbp
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%r12, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	addq	$4, %r12
	cmpl	%ebx, %eax
	jg	.L5
.L4:
	movslq	%eax, %rsi
	leaq	comp(%rip), %rcx
	movl	$4, %edx
	movq	%r13, %rdi
	call	qsort@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	jle	.L22
	leaq	cards(%rip), %r9
	leal	-1(%rax), %edx
	xorl	%r15d, %r15d
	leaq	4(%r9), %rax
	leaq	cmap(%rip), %r12
	leaq	(%rax,%rdx,4), %r10
	.p2align 4,,10
	.p2align 3
.L11:
	movl	%r15d, %esi
	movl	(%r9), %r15d
	cmpl	%esi, %r15d
	jle	.L7
	movl	%r15d, %edi
	subl	%esi, %edi
	leal	-1(%rdi), %eax
	cmpl	$2, %eax
	jbe	.L23
	movslq	%esi, %rax
	movd	%esi, %xmm1
	leaq	(%r12,%rax,4), %rdx
	movl	%edi, %eax
	pshufd	$0, %xmm1, %xmm0
	shrl	$2, %eax
	leal	-1(%rax), %ecx
	leaq	16(%rdx), %rax
	salq	$4, %rcx
	addq	%rax, %rcx
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L38:
	addq	$16, %rax
.L9:
	movups	%xmm0, (%rdx)
	movq	%rax, %rdx
	cmpq	%rcx, %rax
	jne	.L38
	movl	%edi, %edx
	andl	$-4, %edx
	leal	(%rdx,%rsi), %eax
	cmpl	%edx, %edi
	je	.L7
.L8:
	movslq	%eax, %rdx
	movl	%esi, (%r12,%rdx,4)
	leal	1(%rax), %edx
	cmpl	%edx, %r15d
	jle	.L7
	movslq	%edx, %rdx
	addl	$2, %eax
	movl	%esi, (%r12,%rdx,4)
	cmpl	%eax, %r15d
	jle	.L7
	cltq
	movl	%esi, (%r12,%rax,4)
.L7:
	addq	$4, %r9
	cmpq	%r10, %r9
	jne	.L11
.L6:
	movl	36(%rsp), %edx
	movslq	%r15d, %rax
	movl	%r15d, (%r12,%rax,4)
	testl	%edx, %edx
	jle	.L12
	leaq	(%r12,%rax,4), %rax
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %rbp
	movq	%rax, 8(%rsp)
	leaq	32(%rsp), %r14
	leaq	.LC2(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L20:
	movq	%r14, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	32(%rsp), %esi
	movl	%r15d, %eax
	cltd
	idivl	%esi
	leal	1(%rax), %ecx
	imull	%esi, %ecx
	cmpl	%r15d, %ecx
	jl	.L13
	movl	%ecx, %eax
	subl	%r15d, %eax
	leal	1(%rax), %edi
	cmpl	$2, %eax
	jbe	.L24
	movl	%edi, %eax
	movq	8(%rsp), %r8
	movd	%r15d, %xmm2
	shrl	$2, %eax
	pshufd	$0, %xmm2, %xmm0
	subl	$1, %eax
	salq	$4, %rax
	leaq	16(%r8,%rax), %rdx
	movq	%r8, %rax
	.p2align 4,,10
	.p2align 3
.L15:
	movups	%xmm0, (%rax)
	addq	$16, %rax
	cmpq	%rdx, %rax
	jne	.L15
	movl	%edi, %edx
	andl	$-4, %edx
	leal	(%rdx,%r15), %eax
	cmpl	%edx, %edi
	je	.L13
.L14:
	movslq	%eax, %rdx
	movl	%r15d, (%r12,%rdx,4)
	leal	1(%rax), %edx
	cmpl	%edx, %ecx
	jl	.L13
	movslq	%edx, %rdx
	addl	$2, %eax
	movl	%r15d, (%r12,%rdx,4)
	cmpl	%eax, %ecx
	jl	.L13
	cltq
	movl	%r15d, (%r12,%rax,4)
.L13:
	leal	-1(%rsi), %r10d
	xorl	%r9d, %r9d
	cmpl	%r10d, %ecx
	jl	.L17
	cmpl	$1, %esi
	jne	.L39
.L17:
	movl	%r9d, %edx
	movq	%r13, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addl	$1, %ebx
	cmpl	%ebx, 36(%rsp)
	jg	.L20
.L12:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L40
	addq	$56, %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
.L39:
	.cfi_restore_state
	movslq	%esi, %r11
	movslq	%r10d, %rdi
	jmp	.L19
	.p2align 4,,10
	.p2align 3
.L41:
	movl	%edx, %r9d
.L18:
	addq	%r11, %rdi
	cmpl	%edi, %ecx
	jl	.L17
.L19:
	movl	(%r12,%rdi,4), %eax
	cltd
	idivl	%esi
	cmpl	%r9d, %edx
	jle	.L18
	cmpl	%edx, %r10d
	jne	.L41
	movl	%r10d, %r9d
	jmp	.L17
.L23:
	movl	%esi, %eax
	jmp	.L8
.L24:
	movl	%r15d, %eax
	jmp	.L14
.L22:
	xorl	%r15d, %r15d
	leaq	cmap(%rip), %r12
	jmp	.L6
.L40:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE40:
	.size	main, .-main
	.local	cmap
	.comm	cmap,2400004,32
	.local	cards
	.comm	cards,1200004,32
	.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>
#include <stdlib.h>

/* constant */

#define MAX_N   (300000)
#define MAX_Q   (100000)

/* global variables */

static int cards[MAX_N + 1];
static int cmap[MAX_N * 2 + 1];

/* subroutines */

int comp(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

/* main */

int main(int argc, char **argv) {
  int c0, c1, i, j, max_c, max_qi, max_rem, n, prev, q, qi, qn, rem;

  scanf("%d%d", &n, &qn);

  for (i = 0; i < n; i++)
    scanf("%d", &cards[i]);

  qsort(cards, n, sizeof(int), comp);

  c0 = 0;
  for (i = 0; i < n; i++) {
    c1 = cards[i];
    for (j = c0; j < c1; j++) cmap[j] = c0;
    c0 = c1;
  }
  max_c = cmap[c0] = c0;

  for (i = 0; i < qn; i++) {
    scanf("%d", &q);

    max_qi = (max_c / q + 1) * q;
    for (j = max_c; j <= max_qi; j++)
      cmap[j] = max_c;

    max_rem = 0;

    for (qi = q - 1; qi <= max_qi; qi += q) {
      rem = cmap[qi] % q;
      if (max_rem < rem) {
        max_rem = rem;
        if (max_rem == q - 1) break;
      }
    }

    printf("%d\n", max_rem);
  }

  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
 3
3
3
 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
#include <stdio.h>
#include <stdlib.h>

/* constant */

#define MAX_N   (300000)
#define MAX_Q   (100000)

/* global variables */

static int cards[MAX_N + 1];
static int cmap[MAX_N * 2 + 1];

/* subroutines */

int comp(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

/* main */

int main(int argc, char **argv) {
  int c0, c1, i, j, max_c, max_qi, max_rem, n, prev, q, qi, qn, rem;

  scanf("%d%d", &n, &qn);

  for (i = 0; i < n; i++)
    scanf("%d", &cards[i]);

  qsort(cards, n, sizeof(int), comp);

  c0 = 0;
  for (i = 0; i < n; i++) {
    c1 = cards[i];
    for (j = c0; j < c1; j++) cmap[j] = c0;
    c0 = c1;
  }
  max_c = cmap[c0] = c0;

  for (i = 0; i < qn; i++) {
    scanf("%d", &q);

    max_qi = (max_c / q + 1) * q;
    for (j = max_c; j <= max_qi; j++)
      cmap[j] = max_c;

    max_rem = 0;

    for (qi = q - 1; qi <= max_qi; qi += q) {
      rem = cmap[qi] % q;
      if (max_rem < rem) {
        max_rem = rem;
        if (max_rem == q - 1) break;
      }
    }

    printf("%d\n", max_rem);
  }

  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.local	cards
	.comm	cards,1200004,32
	.local	cmap
	.comm	cmap,2400004,32
	.globl	comp
	.type	comp, @function
comp:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	comp, .-comp
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$80, %rsp
	movl	%edi, -68(%rbp)
	movq	%rsi, -80(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-48(%rbp), %rdx
	leaq	-56(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -40(%rbp)
	jmp	.L4
.L5:
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cards(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -40(%rbp)
.L4:
	movl	-56(%rbp), %eax
	cmpl	%eax, -40(%rbp)
	jl	.L5
	movl	-56(%rbp), %eax
	cltq
	leaq	comp(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rsi
	leaq	cards(%rip), %rax
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -44(%rbp)
	movl	$0, -40(%rbp)
	jmp	.L6
.L9:
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cards(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -12(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L7
.L8:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	cmap(%rip), %rdx
	movl	-44(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	addl	$1, -36(%rbp)
.L7:
	movl	-36(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jl	.L8
	movl	-12(%rbp), %eax
	movl	%eax, -44(%rbp)
	addl	$1, -40(%rbp)
.L6:
	movl	-56(%rbp), %eax
	cmpl	%eax, -40(%rbp)
	jl	.L9
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	cmap(%rip), %rdx
	movl	-44(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cmap(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -24(%rbp)
	movl	$0, -40(%rbp)
	jmp	.L10
.L17:
	leaq	-52(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-52(%rbp), %esi
	movl	-24(%rbp), %eax
	cltd
	idivl	%esi
	leal	1(%rax), %edx
	movl	-52(%rbp), %eax
	imull	%edx, %eax
	movl	%eax, -20(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L11
.L12:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	cmap(%rip), %rdx
	movl	-24(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	addl	$1, -36(%rbp)
.L11:
	movl	-36(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jle	.L12
	movl	$0, -32(%rbp)
	movl	-52(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -28(%rbp)
	jmp	.L13
.L16:
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cmap(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-52(%rbp), %ecx
	cltd
	idivl	%ecx
	movl	%edx, -16(%rbp)
	movl	-32(%rbp), %eax
	cmpl	-16(%rbp), %eax
	jge	.L14
	movl	-16(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-52(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -32(%rbp)
	je	.L20
.L14:
	movl	-52(%rbp), %eax
	addl	%eax, -28(%rbp)
.L13:
	movl	-28(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jle	.L16
	jmp	.L15
.L20:
	nop
.L15:
	movl	-32(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -40(%rbp)
.L10:
	movl	-48(%rbp), %eax
	cmpl	%eax, -40(%rbp)
	jl	.L17
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.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
	.local	cards
	.comm	cards,1200004,32
	.local	cmap
	.comm	cmap,2400004,32
	.globl	comp
	.type	comp, @function
comp:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	comp, .-comp
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$80, %rsp
	movl	%edi, -68(%rbp)
	movq	%rsi, -80(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-48(%rbp), %rdx
	leaq	-56(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -40(%rbp)
	jmp	.L4
.L5:
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cards(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -40(%rbp)
.L4:
	movl	-56(%rbp), %eax
	cmpl	%eax, -40(%rbp)
	jl	.L5
	movl	-56(%rbp), %eax
	cltq
	leaq	comp(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rsi
	leaq	cards(%rip), %rax
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -44(%rbp)
	movl	$0, -40(%rbp)
	jmp	.L6
.L9:
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cards(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -12(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L7
.L8:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	cmap(%rip), %rdx
	movl	-44(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	addl	$1, -36(%rbp)
.L7:
	movl	-36(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jl	.L8
	movl	-12(%rbp), %eax
	movl	%eax, -44(%rbp)
	addl	$1, -40(%rbp)
.L6:
	movl	-56(%rbp), %eax
	cmpl	%eax, -40(%rbp)
	jl	.L9
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	cmap(%rip), %rdx
	movl	-44(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cmap(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -24(%rbp)
	movl	$0, -40(%rbp)
	jmp	.L10
.L17:
	leaq	-52(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-52(%rbp), %esi
	movl	-24(%rbp), %eax
	cltd
	idivl	%esi
	leal	1(%rax), %edx
	movl	-52(%rbp), %eax
	imull	%edx, %eax
	movl	%eax, -20(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L11
.L12:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	cmap(%rip), %rdx
	movl	-24(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	addl	$1, -36(%rbp)
.L11:
	movl	-36(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jle	.L12
	movl	$0, -32(%rbp)
	movl	-52(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -28(%rbp)
	jmp	.L13
.L16:
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cmap(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-52(%rbp), %ecx
	cltd
	idivl	%ecx
	movl	%edx, -16(%rbp)
	movl	-32(%rbp), %eax
	cmpl	-16(%rbp), %eax
	jge	.L14
	movl	-16(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-52(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -32(%rbp)
	je	.L20
.L14:
	movl	-52(%rbp), %eax
	addl	%eax, -28(%rbp)
.L13:
	movl	-28(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jle	.L16
	jmp	.L15
.L20:
	nop
.L15:
	movl	-32(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -40(%rbp)
.L10:
	movl	-48(%rbp), %eax
	cmpl	%eax, -40(%rbp)
	jl	.L17
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.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:
