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

```c
#include <stdio.h>
int N, M, Q;
int a[50], b[50], c[50], d[50];
int A[10];
int i, j;
int ans;
int main () {
    scanf("%d%d%d", &N, &M, &Q);
    N--, M--;
    for (i = 0; i < Q; i++) {
        scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
        a[i]--, b[i]--;
    }
    while (1) {
        int res = 0;
        for (i = 0; i < Q; i++) {
            if (A[b[i]]-A[a[i]] == c[i]) res += d[i];
        }
        if (ans < res) ans = res;
        if (A[0] == M) break;
        for (i = N;; i--) {
            if (A[i] < M) {
                A[i]++;
                for (j = N; j > i; j--) {
                    A[j] = A[i];
                }
                break;
            }
        }
    }
    printf("%d", ans);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	N
	.bss
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	Q
	.align 4
	.type	Q, @object
	.size	Q, 4
Q:
	.zero	4
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 200
a:
	.zero	200
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 200
b:
	.zero	200
	.globl	c
	.align 32
	.type	c, @object
	.size	c, 200
c:
	.zero	200
	.globl	d
	.align 32
	.type	d, @object
	.size	d, 200
d:
	.zero	200
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 40
A:
	.zero	40
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	j
	.align 4
	.type	j, @object
	.size	j, 4
j:
	.zero	4
	.globl	ans
	.align 4
	.type	ans, @object
	.size	ans, 4
ans:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.string	"%d%d%d%d"
.LC2:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	leaq	Q(%rip), %rax
	movq	%rax, %rcx
	leaq	M(%rip), %rax
	movq	%rax, %rdx
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	N(%rip), %eax
	subl	$1, %eax
	movl	%eax, N(%rip)
	movl	M(%rip), %eax
	subl	$1, %eax
	movl	%eax, M(%rip)
	movl	$0, i(%rip)
	jmp	.L2
.L3:
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	leaq	(%rdx,%rax), %rsi
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	c(%rip), %rax
	leaq	(%rdx,%rax), %rcx
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	addq	%rax, %rdx
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdi
	leaq	a(%rip), %rax
	addq	%rdi, %rax
	movq	%rsi, %r8
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	i(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	-1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	i(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	b(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	-1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
.L2:
	movl	i(%rip), %edx
	movl	Q(%rip), %eax
	cmpl	%eax, %edx
	jl	.L3
.L15:
	movl	$0, -4(%rbp)
	movl	$0, i(%rip)
	jmp	.L4
.L6:
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	i(%rip), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	c(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, %ecx
	jne	.L5
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -4(%rbp)
.L5:
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
.L4:
	movl	i(%rip), %edx
	movl	Q(%rip), %eax
	cmpl	%eax, %edx
	jl	.L6
	movl	ans(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jle	.L7
	movl	-4(%rbp), %eax
	movl	%eax, ans(%rip)
.L7:
	movl	A(%rip), %edx
	movl	M(%rip), %eax
	cmpl	%eax, %edx
	je	.L19
	movl	N(%rip), %eax
	movl	%eax, i(%rip)
.L14:
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	M(%rip), %eax
	cmpl	%eax, %edx
	jge	.L10
	movl	i(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	N(%rip), %eax
	movl	%eax, j(%rip)
	jmp	.L11
.L12:
	movl	i(%rip), %eax
	movl	j(%rip), %edx
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	A(%rip), %rax
	movl	(%rcx,%rax), %eax
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	j(%rip), %eax
	subl	$1, %eax
	movl	%eax, j(%rip)
.L11:
	movl	j(%rip), %edx
	movl	i(%rip), %eax
	cmpl	%eax, %edx
	jg	.L12
	jmp	.L18
.L10:
	movl	i(%rip), %eax
	subl	$1, %eax
	movl	%eax, i(%rip)
	jmp	.L14
.L18:
	jmp	.L15
.L19:
	nop
	movl	ans(%rip), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
user
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%d%d"
.LC1:
	.string	"%d%d%d%d"
.LC2:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	Q(%rip), %rcx
	xorl	%eax, %eax
	leaq	M(%rip), %rdx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	N(%rip), %rsi
	leaq	.LC0(%rip), %rdi
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	call	__isoc99_scanf@PLT
	movl	Q(%rip), %r13d
	subl	$1, N(%rip)
	subl	$1, M(%rip)
	movl	$0, i(%rip)
	testl	%r13d, %r13d
	jle	.L2
	xorl	%eax, %eax
	leaq	d(%rip), %r14
	leaq	c(%rip), %r12
	leaq	b(%rip), %rbx
	leaq	a(%rip), %r15
	leaq	.LC1(%rip), %rbp
	.p2align 4,,10
	.p2align 3
.L3:
	cltq
	movq	%rbp, %rdi
	salq	$2, %rax
	leaq	(%rbx,%rax), %rdx
	leaq	(%r12,%rax), %rcx
	leaq	(%r15,%rax), %rsi
	leaq	(%r14,%rax), %r8
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	i(%rip), %rdx
	movl	Q(%rip), %r13d
	movq	%rdx, %rax
	subl	$1, (%r15,%rdx,4)
	addl	$1, %eax
	subl	$1, (%rbx,%rdx,4)
	movl	%eax, i(%rip)
	cmpl	%r13d, %eax
	jl	.L3
.L2:
	movslq	N(%rip), %r15
	movl	ans(%rip), %eax
	leaq	A(%rip), %rcx
	movb	$0, 43(%rsp)
	movl	M(%rip), %r12d
	leaq	c(%rip), %r11
	leal	-7(%r15), %edi
	leal	-9(%r15), %esi
	movl	%eax, 60(%rsp)
	movq	%r15, %r10
	leaq	0(,%r15,4), %rbx
	movl	%eax, 24(%rsp)
	leal	-5(%r15), %eax
	movq	%rbx, 16(%rsp)
	leaq	-16(%rcx,%rbx), %rbx
	movl	%eax, 28(%rsp)
	cltq
	movl	%edi, 44(%rsp)
	movslq	%edi, %rdi
	movl	%esi, 56(%rsp)
	movslq	%esi, %rsi
	movq	%rbx, 32(%rsp)
	xorl	%ebx, %ebx
	movq	%rsi, 72(%rsp)
	movq	%rdi, 64(%rsp)
	movq	%rax, 48(%rsp)
	testl	%r13d, %r13d
	jle	.L24
	.p2align 4,,10
	.p2align 3
.L50:
	movslq	%r13d, %r9
	xorl	%eax, %eax
	leaq	b(%rip), %r8
	xorl	%ebp, %ebp
	leaq	a(%rip), %rdi
	leaq	d(%rip), %r14
	.p2align 4,,10
	.p2align 3
.L6:
	movslq	(%r8,%rax,4), %rdx
	movslq	(%rdi,%rax,4), %rsi
	movl	(%rcx,%rdx,4), %edx
	subl	(%rcx,%rsi,4), %edx
	cmpl	(%r11,%rax,4), %edx
	jne	.L5
	addl	(%r14,%rax,4), %ebp
.L5:
	addq	$1, %rax
	cmpq	%r9, %rax
	jne	.L6
	movl	%r13d, %eax
.L4:
	cmpl	%ebp, 24(%rsp)
	jge	.L7
	movl	%ebp, 24(%rsp)
	movb	$1, 43(%rsp)
.L7:
	cmpl	%r12d, (%rcx)
	je	.L8
	movl	(%rcx,%r15,4), %eax
	cmpl	%eax, %r12d
	jg	.L49
	leal	-1(%r10), %r9d
	movslq	%r9d, %rax
	movq	%rax, 8(%rsp)
	movl	(%rcx,%rax,4), %eax
	cmpl	%eax, %r12d
	jg	.L20
	leal	-2(%r10), %ebx
	movslq	%ebx, %rdi
	movl	%ebx, %edx
	movl	(%rcx,%rdi,4), %eax
	cmpl	%eax, %r12d
	jg	.L27
	leal	-3(%r10), %esi
	movslq	%esi, %rax
	movl	(%rcx,%rax,4), %eax
	cmpl	%eax, %r12d
	jg	.L28
	leal	-4(%r10), %edx
	movslq	%edx, %rdi
	movl	(%rcx,%rdi,4), %eax
	cmpl	%eax, %r12d
	jg	.L21
	movslq	28(%rsp), %rax
	movl	%eax, %esi
	movl	(%rcx,%rax,4), %eax
	cmpl	%eax, %r12d
	jg	.L29
	leal	-6(%r10), %edx
	movslq	%edx, %rdi
	movl	(%rcx,%rdi,4), %eax
	cmpl	%eax, %r12d
	jg	.L21
	movslq	44(%rsp), %rax
	movl	%eax, %esi
	movl	(%rcx,%rax,4), %eax
	cmpl	%eax, %r12d
	jg	.L30
	leal	-8(%r10), %edx
	movslq	%edx, %rdi
	movl	(%rcx,%rdi,4), %eax
	cmpl	%eax, %r12d
	jg	.L21
	movslq	56(%rsp), %rax
	movl	%eax, %esi
	movl	(%rcx,%rax,4), %eax
	cmpl	%eax, %r12d
	jg	.L31
	leal	-10(%r10), %edx
	movslq	%edx, %rdi
	movl	(%rcx,%rdi,4), %eax
.L21:
	addl	$1, %eax
	movl	%eax, (%rcx,%rdi,4)
	cmpl	%edx, %r10d
	jle	.L26
	movl	%eax, (%rcx,%r15,4)
	cmpl	%esi, %r10d
	jle	.L12
	movl	%r10d, %r8d
	movq	16(%rsp), %rbp
	addl	$1, %edx
	subl	%esi, %r8d
	movslq	%edx, %rdx
	movl	%r8d, %r14d
	salq	$2, %rdx
	negq	%r14
	leaq	0(%rbp,%r14,4), %r14
	cmpq	%rdx, %r14
	setge	%r14b
	subq	$4, %rdx
	cmpq	%rbp, %rdx
	setge	%dl
	orb	%r14b, %dl
	je	.L15
	leal	-1(%r8), %edx
	cmpl	$2, %edx
	jbe	.L15
	movd	%eax, %xmm1
	movq	32(%rsp), %rbx
	movl	%r8d, %eax
	pshufd	$0, %xmm1, %xmm0
	shrl	$2, %eax
	movups	%xmm0, (%rbx)
	cmpl	$1, %eax
	je	.L18
	movups	%xmm0, -16(%rbx)
.L18:
	movl	%r8d, %edx
	movl	%r9d, %eax
	andl	$-4, %edx
	subl	%edx, %eax
	cmpl	%edx, %r8d
	je	.L12
	movl	(%rcx,%rdi,4), %edx
	movslq	%eax, %r8
	movl	%edx, (%rcx,%r8,4)
	leal	-1(%rax), %r8d
	cmpl	%eax, %esi
	jge	.L12
	movslq	%r8d, %rbx
	subl	$2, %eax
	movl	%edx, (%rcx,%rbx,4)
	cmpl	%r8d, %esi
	jge	.L12
.L47:
	movl	(%rcx,%rdi,4), %edx
	cltq
	movl	%edx, (%rcx,%rax,4)
.L12:
	movl	%esi, %eax
	xorl	%edx, %edx
	subl	%r10d, %eax
	cmpl	%esi, %r10d
	cmovl	%edx, %eax
	addl	%r9d, %eax
	movl	%eax, 8(%rsp)
.L11:
	movl	$1, %ebx
	testl	%r13d, %r13d
	jg	.L50
.L24:
	xorl	%eax, %eax
	xorl	%ebp, %ebp
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L15:
	movq	8(%rsp), %rdx
	movl	%eax, (%rcx,%rdx,4)
	cmpl	%r9d, %esi
	jge	.L12
	movl	(%rcx,%rdi,4), %eax
	movslq	%ebx, %rdx
	movl	%eax, (%rcx,%rdx,4)
	leal	-3(%r10), %edx
	cmpl	%ebx, %esi
	jge	.L12
	movslq	%edx, %r8
	movl	%eax, (%rcx,%r8,4)
	leal	-4(%r10), %eax
	cmpl	%esi, %edx
	jle	.L12
	movl	(%rcx,%rdi,4), %edx
	movslq	%eax, %r8
	movl	%edx, (%rcx,%r8,4)
	cmpl	%esi, %eax
	jle	.L12
	movslq	28(%rsp), %rax
	movq	%rax, %rbx
	movl	%edx, (%rcx,%rax,4)
	leal	-6(%r10), %eax
	cmpl	%esi, %ebx
	jle	.L12
	movl	(%rcx,%rdi,4), %edx
	movslq	%eax, %r8
	movl	%edx, (%rcx,%r8,4)
	cmpl	%eax, %esi
	jge	.L12
	movslq	44(%rsp), %rax
	movq	%rax, %rbx
	movl	%edx, (%rcx,%rax,4)
	leal	-8(%r10), %eax
	cmpl	%ebx, %esi
	jge	.L12
	movl	(%rcx,%rdi,4), %edx
	movslq	%eax, %r8
	movl	%edx, (%rcx,%r8,4)
	cmpl	%eax, %esi
	jge	.L12
	movslq	56(%rsp), %rax
	movq	%rax, %rbx
	movl	%edx, (%rcx,%rax,4)
	leal	-10(%r10), %eax
	cmpl	%ebx, %esi
	jl	.L47
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L8:
	cmpb	$0, 43(%rsp)
	movl	%eax, i(%rip)
	je	.L32
	movl	24(%rsp), %eax
	movl	%eax, ans(%rip)
.L22:
	testb	%bl, %bl
	je	.L23
	movl	8(%rsp), %eax
	movl	%eax, j(%rip)
.L23:
	movl	24(%rsp), %edx
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addq	$88, %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
.L49:
	.cfi_restore_state
	addl	$1, %eax
	movl	%r10d, 8(%rsp)
	movl	%eax, (%rcx,%r15,4)
	jmp	.L11
.L20:
	movq	8(%rsp), %rbx
	addl	$1, %eax
	movl	%r10d, %esi
	movl	%eax, (%rcx,%rbx,4)
	movl	%eax, (%rcx,%r15,4)
	jmp	.L12
.L27:
	movl	%r9d, %esi
	jmp	.L21
.L28:
	movslq	%esi, %rdi
	movl	%ebx, %esi
	movq	%rdi, %rdx
	jmp	.L21
.L29:
	movl	%edx, %esi
	movq	48(%rsp), %rdi
	movl	28(%rsp), %edx
	jmp	.L21
.L30:
	movl	%edx, %esi
	movq	64(%rsp), %rdi
	movl	44(%rsp), %edx
	jmp	.L21
.L32:
	movl	60(%rsp), %eax
	movl	%eax, 24(%rsp)
	jmp	.L22
.L31:
	movl	%edx, %esi
	movq	72(%rsp), %rdi
	movl	56(%rsp), %edx
	jmp	.L21
.L26:
	movl	%r10d, 8(%rsp)
	jmp	.L11
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	ans
	.bss
	.align 4
	.type	ans, @object
	.size	ans, 4
ans:
	.zero	4
	.globl	j
	.align 4
	.type	j, @object
	.size	j, 4
j:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 40
A:
	.zero	40
	.globl	d
	.align 32
	.type	d, @object
	.size	d, 200
d:
	.zero	200
	.globl	c
	.align 32
	.type	c, @object
	.size	c, 200
c:
	.zero	200
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 200
b:
	.zero	200
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 200
a:
	.zero	200
	.globl	Q
	.align 4
	.type	Q, @object
	.size	Q, 4
Q:
	.zero	4
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	N
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.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%d"
.LC1:
	.string	"%d%d%d%d"
.LC2:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	Q(%rip), %rcx
	xorl	%eax, %eax
	leaq	M(%rip), %rdx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	N(%rip), %rsi
	leaq	.LC0(%rip), %rdi
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	call	__isoc99_scanf@PLT
	movl	Q(%rip), %r13d
	subl	$1, N(%rip)
	subl	$1, M(%rip)
	movl	$0, i(%rip)
	testl	%r13d, %r13d
	jle	.L2
	xorl	%eax, %eax
	leaq	d(%rip), %r14
	leaq	c(%rip), %r12
	leaq	b(%rip), %rbx
	leaq	a(%rip), %r15
	leaq	.LC1(%rip), %rbp
	.p2align 4,,10
	.p2align 3
.L3:
	cltq
	movq	%rbp, %rdi
	salq	$2, %rax
	leaq	(%rbx,%rax), %rdx
	leaq	(%r12,%rax), %rcx
	leaq	(%r15,%rax), %rsi
	leaq	(%r14,%rax), %r8
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	i(%rip), %rdx
	movl	Q(%rip), %r13d
	movq	%rdx, %rax
	subl	$1, (%r15,%rdx,4)
	addl	$1, %eax
	subl	$1, (%rbx,%rdx,4)
	movl	%eax, i(%rip)
	cmpl	%r13d, %eax
	jl	.L3
.L2:
	movslq	N(%rip), %r15
	movl	ans(%rip), %eax
	leaq	A(%rip), %rcx
	movb	$0, 43(%rsp)
	movl	M(%rip), %r12d
	leaq	c(%rip), %r11
	leal	-7(%r15), %edi
	leal	-9(%r15), %esi
	movl	%eax, 60(%rsp)
	movq	%r15, %r10
	leaq	0(,%r15,4), %rbx
	movl	%eax, 24(%rsp)
	leal	-5(%r15), %eax
	movq	%rbx, 16(%rsp)
	leaq	-16(%rcx,%rbx), %rbx
	movl	%eax, 28(%rsp)
	cltq
	movl	%edi, 44(%rsp)
	movslq	%edi, %rdi
	movl	%esi, 56(%rsp)
	movslq	%esi, %rsi
	movq	%rbx, 32(%rsp)
	xorl	%ebx, %ebx
	movq	%rsi, 72(%rsp)
	movq	%rdi, 64(%rsp)
	movq	%rax, 48(%rsp)
	testl	%r13d, %r13d
	jle	.L24
	.p2align 4,,10
	.p2align 3
.L50:
	movslq	%r13d, %r9
	xorl	%eax, %eax
	leaq	b(%rip), %r8
	xorl	%ebp, %ebp
	leaq	a(%rip), %rdi
	leaq	d(%rip), %r14
	.p2align 4,,10
	.p2align 3
.L6:
	movslq	(%r8,%rax,4), %rdx
	movslq	(%rdi,%rax,4), %rsi
	movl	(%rcx,%rdx,4), %edx
	subl	(%rcx,%rsi,4), %edx
	cmpl	(%r11,%rax,4), %edx
	jne	.L5
	addl	(%r14,%rax,4), %ebp
.L5:
	addq	$1, %rax
	cmpq	%r9, %rax
	jne	.L6
	movl	%r13d, %eax
.L4:
	cmpl	%ebp, 24(%rsp)
	jge	.L7
	movl	%ebp, 24(%rsp)
	movb	$1, 43(%rsp)
.L7:
	cmpl	%r12d, (%rcx)
	je	.L8
	movl	(%rcx,%r15,4), %eax
	cmpl	%eax, %r12d
	jg	.L49
	leal	-1(%r10), %r9d
	movslq	%r9d, %rax
	movq	%rax, 8(%rsp)
	movl	(%rcx,%rax,4), %eax
	cmpl	%eax, %r12d
	jg	.L20
	leal	-2(%r10), %ebx
	movslq	%ebx, %rdi
	movl	%ebx, %edx
	movl	(%rcx,%rdi,4), %eax
	cmpl	%eax, %r12d
	jg	.L27
	leal	-3(%r10), %esi
	movslq	%esi, %rax
	movl	(%rcx,%rax,4), %eax
	cmpl	%eax, %r12d
	jg	.L28
	leal	-4(%r10), %edx
	movslq	%edx, %rdi
	movl	(%rcx,%rdi,4), %eax
	cmpl	%eax, %r12d
	jg	.L21
	movslq	28(%rsp), %rax
	movl	%eax, %esi
	movl	(%rcx,%rax,4), %eax
	cmpl	%eax, %r12d
	jg	.L29
	leal	-6(%r10), %edx
	movslq	%edx, %rdi
	movl	(%rcx,%rdi,4), %eax
	cmpl	%eax, %r12d
	jg	.L21
	movslq	44(%rsp), %rax
	movl	%eax, %esi
	movl	(%rcx,%rax,4), %eax
	cmpl	%eax, %r12d
	jg	.L30
	leal	-8(%r10), %edx
	movslq	%edx, %rdi
	movl	(%rcx,%rdi,4), %eax
	cmpl	%eax, %r12d
	jg	.L21
	movslq	56(%rsp), %rax
	movl	%eax, %esi
	movl	(%rcx,%rax,4), %eax
	cmpl	%eax, %r12d
	jg	.L31
	leal	-10(%r10), %edx
	movslq	%edx, %rdi
	movl	(%rcx,%rdi,4), %eax
.L21:
	addl	$1, %eax
	movl	%eax, (%rcx,%rdi,4)
	cmpl	%edx, %r10d
	jle	.L26
	movl	%eax, (%rcx,%r15,4)
	cmpl	%esi, %r10d
	jle	.L12
	movl	%r10d, %r8d
	movq	16(%rsp), %rbp
	addl	$1, %edx
	subl	%esi, %r8d
	movslq	%edx, %rdx
	movl	%r8d, %r14d
	salq	$2, %rdx
	negq	%r14
	leaq	0(%rbp,%r14,4), %r14
	cmpq	%rdx, %r14
	setge	%r14b
	subq	$4, %rdx
	cmpq	%rbp, %rdx
	setge	%dl
	orb	%r14b, %dl
	je	.L15
	leal	-1(%r8), %edx
	cmpl	$2, %edx
	jbe	.L15
	movd	%eax, %xmm1
	movq	32(%rsp), %rbx
	movl	%r8d, %eax
	pshufd	$0, %xmm1, %xmm0
	shrl	$2, %eax
	movups	%xmm0, (%rbx)
	cmpl	$1, %eax
	je	.L18
	movups	%xmm0, -16(%rbx)
.L18:
	movl	%r8d, %edx
	movl	%r9d, %eax
	andl	$-4, %edx
	subl	%edx, %eax
	cmpl	%edx, %r8d
	je	.L12
	movl	(%rcx,%rdi,4), %edx
	movslq	%eax, %r8
	movl	%edx, (%rcx,%r8,4)
	leal	-1(%rax), %r8d
	cmpl	%eax, %esi
	jge	.L12
	movslq	%r8d, %rbx
	subl	$2, %eax
	movl	%edx, (%rcx,%rbx,4)
	cmpl	%r8d, %esi
	jge	.L12
.L47:
	movl	(%rcx,%rdi,4), %edx
	cltq
	movl	%edx, (%rcx,%rax,4)
.L12:
	movl	%esi, %eax
	xorl	%edx, %edx
	subl	%r10d, %eax
	cmpl	%esi, %r10d
	cmovl	%edx, %eax
	addl	%r9d, %eax
	movl	%eax, 8(%rsp)
.L11:
	movl	$1, %ebx
	testl	%r13d, %r13d
	jg	.L50
.L24:
	xorl	%eax, %eax
	xorl	%ebp, %ebp
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L15:
	movq	8(%rsp), %rdx
	movl	%eax, (%rcx,%rdx,4)
	cmpl	%r9d, %esi
	jge	.L12
	movl	(%rcx,%rdi,4), %eax
	movslq	%ebx, %rdx
	movl	%eax, (%rcx,%rdx,4)
	leal	-3(%r10), %edx
	cmpl	%ebx, %esi
	jge	.L12
	movslq	%edx, %r8
	movl	%eax, (%rcx,%r8,4)
	leal	-4(%r10), %eax
	cmpl	%esi, %edx
	jle	.L12
	movl	(%rcx,%rdi,4), %edx
	movslq	%eax, %r8
	movl	%edx, (%rcx,%r8,4)
	cmpl	%esi, %eax
	jle	.L12
	movslq	28(%rsp), %rax
	movq	%rax, %rbx
	movl	%edx, (%rcx,%rax,4)
	leal	-6(%r10), %eax
	cmpl	%esi, %ebx
	jle	.L12
	movl	(%rcx,%rdi,4), %edx
	movslq	%eax, %r8
	movl	%edx, (%rcx,%r8,4)
	cmpl	%eax, %esi
	jge	.L12
	movslq	44(%rsp), %rax
	movq	%rax, %rbx
	movl	%edx, (%rcx,%rax,4)
	leal	-8(%r10), %eax
	cmpl	%ebx, %esi
	jge	.L12
	movl	(%rcx,%rdi,4), %edx
	movslq	%eax, %r8
	movl	%edx, (%rcx,%r8,4)
	cmpl	%eax, %esi
	jge	.L12
	movslq	56(%rsp), %rax
	movq	%rax, %rbx
	movl	%edx, (%rcx,%rax,4)
	leal	-10(%r10), %eax
	cmpl	%ebx, %esi
	jl	.L47
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L8:
	cmpb	$0, 43(%rsp)
	movl	%eax, i(%rip)
	je	.L32
	movl	24(%rsp), %eax
	movl	%eax, ans(%rip)
.L22:
	testb	%bl, %bl
	je	.L23
	movl	8(%rsp), %eax
	movl	%eax, j(%rip)
.L23:
	movl	24(%rsp), %edx
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addq	$88, %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
.L49:
	.cfi_restore_state
	addl	$1, %eax
	movl	%r10d, 8(%rsp)
	movl	%eax, (%rcx,%r15,4)
	jmp	.L11
.L20:
	movq	8(%rsp), %rbx
	addl	$1, %eax
	movl	%r10d, %esi
	movl	%eax, (%rcx,%rbx,4)
	movl	%eax, (%rcx,%r15,4)
	jmp	.L12
.L27:
	movl	%r9d, %esi
	jmp	.L21
.L28:
	movslq	%esi, %rdi
	movl	%ebx, %esi
	movq	%rdi, %rdx
	jmp	.L21
.L29:
	movl	%edx, %esi
	movq	48(%rsp), %rdi
	movl	28(%rsp), %edx
	jmp	.L21
.L30:
	movl	%edx, %esi
	movq	64(%rsp), %rdi
	movl	44(%rsp), %edx
	jmp	.L21
.L32:
	movl	60(%rsp), %eax
	movl	%eax, 24(%rsp)
	jmp	.L22
.L31:
	movl	%edx, %esi
	movq	72(%rsp), %rdi
	movl	56(%rsp), %edx
	jmp	.L21
.L26:
	movl	%r10d, 8(%rsp)
	jmp	.L11
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	ans
	.bss
	.align 4
	.type	ans, @object
	.size	ans, 4
ans:
	.zero	4
	.globl	j
	.align 4
	.type	j, @object
	.size	j, 4
j:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 40
A:
	.zero	40
	.globl	d
	.align 32
	.type	d, @object
	.size	d, 200
d:
	.zero	200
	.globl	c
	.align 32
	.type	c, @object
	.size	c, 200
c:
	.zero	200
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 200
b:
	.zero	200
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 200
a:
	.zero	200
	.globl	Q
	.align 4
	.type	Q, @object
	.size	Q, 4
Q:
	.zero	4
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	N
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.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>
int N, M, Q;
int a[50], b[50], c[50], d[50];
int A[10];
int i, j;
int ans;
int main () {
    scanf("%d%d%d", &N, &M, &Q);
    N--, M--;
    for (i = 0; i < Q; i++) {
        scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
        a[i]--, b[i]--;
    }
    while (1) {
        int res = 0;
        for (i = 0; i < Q; i++) {
            if (A[b[i]]-A[a[i]] == c[i]) res += d[i];
        }
        if (ans < res) ans = res;
        if (A[0] == M) break;
        for (i = N;; i--) {
            if (A[i] < M) {
                A[i]++;
                for (j = N; j > i; j--) {
                    A[j] = A[i];
                }
                break;
            }
        }
    }
    printf("%d", ans);
}
10 10 1
1 10 12 1
 4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 1 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
 4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 1 114896
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 3 0 94325
1 4 3 94328
 4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 1 114896
3 4 2 8580
1 2 0 96263
1 4 2 2156
1 3 0 28081
1 4 3 94328
 4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 1368
3 4 1 114896
3 4 2 8580
1 2 0 96263
1 4 2 2156
1 3 0 28081
1 4 3 94328
 4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 1368
3 4 1 114896
3 4 2 8580
1 2 0 38547
1 4 2 2156
1 3 0 28081
1 4 3 94328
 4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 29125
3 4 1 1368
3 4 1 114896
1 4 2 8580
1 2 1 38547
1 4 2 2156
1 3 0 28081
1 4 3 94328
 4 6 10
2 4 2 86568
1 4 0 90629
2 3 0 29125
3 4 1 1368
3 4 1 114896
1 4 2 8580
1 2 1 38547
1 4 2 2156
0 3 0 24162
1 4 3 94328
 3 4 3
2 3 3 100
1 2 2 10
2 3 2 10
 4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 1 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
2 2 0 94325
1 4 3 94328

0 383045 419404 445329 417486 387470 326285 335707 100 477370
Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include <stdio.h>
int N, M, Q;
int a[50], b[50], c[50], d[50];
int A[10];
int i, j;
int ans;
int main () {
    scanf("%d%d%d", &N, &M, &Q);
    N--, M--;
    for (i = 0; i < Q; i++) {
        scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
        a[i]--, b[i]--;
    }
    while (1) {
        int res = 0;
        for (i = 0; i < Q; i++) {
            if (A[b[i]]-A[a[i]] == c[i]) res += d[i];
        }
        if (ans < res) ans = res;
        if (A[0] == M) break;
        for (i = N;; i--) {
            if (A[i] < M) {
                A[i]++;
                for (j = N; j > i; j--) {
                    A[j] = A[i];
                }
                break;
            }
        }
    }
    printf("%d", ans);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	N
	.bss
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	Q
	.align 4
	.type	Q, @object
	.size	Q, 4
Q:
	.zero	4
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 200
a:
	.zero	200
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 200
b:
	.zero	200
	.globl	c
	.align 32
	.type	c, @object
	.size	c, 200
c:
	.zero	200
	.globl	d
	.align 32
	.type	d, @object
	.size	d, 200
d:
	.zero	200
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 40
A:
	.zero	40
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	j
	.align 4
	.type	j, @object
	.size	j, 4
j:
	.zero	4
	.globl	ans
	.align 4
	.type	ans, @object
	.size	ans, 4
ans:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.string	"%d%d%d%d"
.LC2:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	leaq	Q(%rip), %rax
	movq	%rax, %rcx
	leaq	M(%rip), %rax
	movq	%rax, %rdx
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	N(%rip), %eax
	subl	$1, %eax
	movl	%eax, N(%rip)
	movl	M(%rip), %eax
	subl	$1, %eax
	movl	%eax, M(%rip)
	movl	$0, i(%rip)
	jmp	.L2
.L3:
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	leaq	(%rdx,%rax), %rsi
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	c(%rip), %rax
	leaq	(%rdx,%rax), %rcx
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	addq	%rax, %rdx
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdi
	leaq	a(%rip), %rax
	addq	%rdi, %rax
	movq	%rsi, %r8
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	i(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	-1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	i(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	b(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	-1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
.L2:
	movl	i(%rip), %edx
	movl	Q(%rip), %eax
	cmpl	%eax, %edx
	jl	.L3
.L15:
	movl	$0, -4(%rbp)
	movl	$0, i(%rip)
	jmp	.L4
.L6:
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	i(%rip), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	c(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, %ecx
	jne	.L5
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -4(%rbp)
.L5:
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
.L4:
	movl	i(%rip), %edx
	movl	Q(%rip), %eax
	cmpl	%eax, %edx
	jl	.L6
	movl	ans(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jle	.L7
	movl	-4(%rbp), %eax
	movl	%eax, ans(%rip)
.L7:
	movl	A(%rip), %edx
	movl	M(%rip), %eax
	cmpl	%eax, %edx
	je	.L19
	movl	N(%rip), %eax
	movl	%eax, i(%rip)
.L14:
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	M(%rip), %eax
	cmpl	%eax, %edx
	jge	.L10
	movl	i(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	N(%rip), %eax
	movl	%eax, j(%rip)
	jmp	.L11
.L12:
	movl	i(%rip), %eax
	movl	j(%rip), %edx
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	A(%rip), %rax
	movl	(%rcx,%rax), %eax
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	j(%rip), %eax
	subl	$1, %eax
	movl	%eax, j(%rip)
.L11:
	movl	j(%rip), %edx
	movl	i(%rip), %eax
	cmpl	%eax, %edx
	jg	.L12
	jmp	.L18
.L10:
	movl	i(%rip), %eax
	subl	$1, %eax
	movl	%eax, i(%rip)
	jmp	.L14
.L18:
	jmp	.L15
.L19:
	nop
	movl	ans(%rip), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
train
	.file	"temp.c"
	.text
	.globl	N
	.bss
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	Q
	.align 4
	.type	Q, @object
	.size	Q, 4
Q:
	.zero	4
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 200
a:
	.zero	200
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 200
b:
	.zero	200
	.globl	c
	.align 32
	.type	c, @object
	.size	c, 200
c:
	.zero	200
	.globl	d
	.align 32
	.type	d, @object
	.size	d, 200
d:
	.zero	200
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 40
A:
	.zero	40
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	j
	.align 4
	.type	j, @object
	.size	j, 4
j:
	.zero	4
	.globl	ans
	.align 4
	.type	ans, @object
	.size	ans, 4
ans:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.string	"%d%d%d%d"
.LC2:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	leaq	Q(%rip), %rax
	movq	%rax, %rcx
	leaq	M(%rip), %rax
	movq	%rax, %rdx
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	N(%rip), %eax
	subl	$1, %eax
	movl	%eax, N(%rip)
	movl	M(%rip), %eax
	subl	$1, %eax
	movl	%eax, M(%rip)
	movl	$0, i(%rip)
	jmp	.L2
.L3:
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	leaq	(%rdx,%rax), %rsi
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	c(%rip), %rax
	leaq	(%rdx,%rax), %rcx
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	addq	%rax, %rdx
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdi
	leaq	a(%rip), %rax
	addq	%rdi, %rax
	movq	%rsi, %r8
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	i(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	-1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	i(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	b(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	-1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
.L2:
	movl	i(%rip), %edx
	movl	Q(%rip), %eax
	cmpl	%eax, %edx
	jl	.L3
.L15:
	movl	$0, -4(%rbp)
	movl	$0, i(%rip)
	jmp	.L4
.L6:
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	i(%rip), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	c(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, %ecx
	jne	.L5
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -4(%rbp)
.L5:
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
.L4:
	movl	i(%rip), %edx
	movl	Q(%rip), %eax
	cmpl	%eax, %edx
	jl	.L6
	movl	ans(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jle	.L7
	movl	-4(%rbp), %eax
	movl	%eax, ans(%rip)
.L7:
	movl	A(%rip), %edx
	movl	M(%rip), %eax
	cmpl	%eax, %edx
	je	.L19
	movl	N(%rip), %eax
	movl	%eax, i(%rip)
.L14:
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	M(%rip), %eax
	cmpl	%eax, %edx
	jge	.L10
	movl	i(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	N(%rip), %eax
	movl	%eax, j(%rip)
	jmp	.L11
.L12:
	movl	i(%rip), %eax
	movl	j(%rip), %edx
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	A(%rip), %rax
	movl	(%rcx,%rax), %eax
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	j(%rip), %eax
	subl	$1, %eax
	movl	%eax, j(%rip)
.L11:
	movl	j(%rip), %edx
	movl	i(%rip), %eax
	cmpl	%eax, %edx
	jg	.L12
	jmp	.L18
.L10:
	movl	i(%rip), %eax
	subl	$1, %eax
	movl	%eax, i(%rip)
	jmp	.L14
.L18:
	jmp	.L15
.L19:
	nop
	movl	ans(%rip), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
