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>
int n, m, q;
int a[55], b[55], c[55], d[55];
int A[10] = {};
int dfs(int *A, int j)
{
    if (j == n)
    {
        int ans = 0;
        for (int i = 0; i < q; i++)
        {
            if (A[b[i]] - A[a[i]] == c[i])
            {
                ans += d[i];
            }
        }
        return ans;
    }
    int max = 0;
    for (int i = A[j - 1]; i <= m; i++)
    {
        A[j] = i;
        int t = dfs(A, j + 1);
        max = (max > t) ? max : t;
    }
    return max;
}
int main()
{
    scanf("%d %d %d", &n, &m, &q);
    for (int i = 0; i < q; i++)
    {
        scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
        a[i]--;
        b[i]--;
    }
    A[0] = 1;
    printf("%d", dfs(A, 1));
    return 0;
}```

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, 220
a:
	.zero	220
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 220
b:
	.zero	220
	.globl	c
	.align 32
	.type	c, @object
	.size	c, 220
c:
	.zero	220
	.globl	d
	.align 32
	.type	d, @object
	.size	d, 220
d:
	.zero	220
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 40
A:
	.zero	40
	.text
	.globl	dfs
	.type	dfs, @function
dfs:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movq	%rdi, -40(%rbp)
	movl	%esi, -44(%rbp)
	movl	n(%rip), %eax
	cmpl	%eax, -44(%rbp)
	jne	.L2
	movl	$0, -20(%rbp)
	movl	$0, -16(%rbp)
	jmp	.L3
.L5:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-16(%rbp), %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
	movq	-40(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	c(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, %ecx
	jne	.L4
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -20(%rbp)
.L4:
	addl	$1, -16(%rbp)
.L3:
	movl	q(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jl	.L5
	movl	-20(%rbp), %eax
	jmp	.L6
.L2:
	movl	$0, -12(%rbp)
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -8(%rbp)
	jmp	.L7
.L8:
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rax, %rdx
	movl	-8(%rbp), %eax
	movl	%eax, (%rdx)
	movl	-44(%rbp), %eax
	leal	1(%rax), %edx
	movq	-40(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	dfs
	movl	%eax, -4(%rbp)
	movl	-12(%rbp), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, -12(%rbp)
	addl	$1, -8(%rbp)
.L7:
	movl	m(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jle	.L8
	movl	-12(%rbp), %eax
.L6:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	dfs, .-dfs
	.section	.rodata
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%d %d %d %d"
.LC2:
	.string	"%d"
	.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	$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	$0, -4(%rbp)
	jmp	.L10
.L11:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	leaq	(%rdx,%rax), %rsi
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	c(%rip), %rax
	leaq	(%rdx,%rax), %rcx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %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	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -4(%rbp)
.L10:
	movl	q(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L11
	movl	$1, A(%rip)
	movl	$1, %esi
	leaq	A(%rip), %rax
	movq	%rax, %rdi
	call	dfs
	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
.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	dfs
	.type	dfs, @function
dfs:
.LFB39:
	.cfi_startproc
	endbr64
	cmpl	%esi, n(%rip)
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	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
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	je	.L13
	movslq	%esi, %r14
	xorl	%r12d, %r12d
	salq	$2, %r14
	movl	-4(%rdi,%r14), %ebx
	cmpl	m(%rip), %ebx
	jg	.L1
	addq	%rdi, %r14
	leal	1(%rsi), %r13d
.L6:
	movl	%ebx, (%r14)
	movl	%r13d, %esi
	movq	%rbp, %rdi
	call	dfs
	cmpl	%eax, %r12d
	cmovl	%eax, %r12d
	addl	$1, %ebx
	cmpl	%ebx, m(%rip)
	jge	.L6
.L1:
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	movl	%r12d, %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
.L13:
	.cfi_restore_state
	movslq	q(%rip), %rsi
	testl	%esi, %esi
	jle	.L7
	xorl	%eax, %eax
	xorl	%r12d, %r12d
	leaq	c(%rip), %r9
	leaq	b(%rip), %r8
	leaq	a(%rip), %rdi
	leaq	d(%rip), %r10
	.p2align 4,,10
	.p2align 3
.L5:
	movslq	(%r8,%rax,4), %rdx
	movslq	(%rdi,%rax,4), %rcx
	movl	0(%rbp,%rdx,4), %edx
	subl	0(%rbp,%rcx,4), %edx
	cmpl	%edx, (%r9,%rax,4)
	jne	.L4
	addl	(%r10,%rax,4), %r12d
.L4:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L5
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	movl	%r12d, %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
.L7:
	.cfi_restore_state
	xorl	%r12d, %r12d
	jmp	.L1
	.cfi_endproc
.LFE39:
	.size	dfs, .-dfs
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d %d %d %d"
	.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	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	$8, %rsp
	.cfi_def_cfa_offset 64
	call	__isoc99_scanf@PLT
	movl	q(%rip), %eax
	testl	%eax, %eax
	jle	.L17
	leaq	a(%rip), %rbp
	leaq	b(%rip), %rbx
	xorl	%r12d, %r12d
	leaq	c(%rip), %r14
	leaq	d(%rip), %r13
	leaq	.LC2(%rip), %r15
	.p2align 4,,10
	.p2align 3
.L16:
	movq	%r13, %r8
	movq	%r14, %rcx
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	xorl	%eax, %eax
	movq	%r15, %rdi
	addl	$1, %r12d
	addq	$4, %r14
	call	__isoc99_scanf@PLT
	addq	$4, %r13
	subl	$1, 0(%rbp)
	addq	$4, %rbp
	subl	$1, (%rbx)
	addq	$4, %rbx
	cmpl	%r12d, q(%rip)
	jg	.L16
.L17:
	movl	$1, %esi
	leaq	A(%rip), %rdi
	movl	$1, A(%rip)
	call	dfs
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addq	$8, %rsp
	.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
	.cfi_endproc
.LFE40:
	.size	main, .-main
	.globl	A
	.bss
	.align 32
	.type	A, @object
	.size	A, 40
A:
	.zero	40
	.globl	d
	.align 32
	.type	d, @object
	.size	d, 220
d:
	.zero	220
	.globl	c
	.align 32
	.type	c, @object
	.size	c, 220
c:
	.zero	220
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 220
b:
	.zero	220
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 220
a:
	.zero	220
	.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
	.p2align 4
	.globl	dfs
	.type	dfs, @function
dfs:
.LFB39:
	.cfi_startproc
	endbr64
	cmpl	%esi, n(%rip)
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	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
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	je	.L13
	movslq	%esi, %r14
	xorl	%r12d, %r12d
	salq	$2, %r14
	movl	-4(%rdi,%r14), %ebx
	cmpl	m(%rip), %ebx
	jg	.L1
	addq	%rdi, %r14
	leal	1(%rsi), %r13d
.L6:
	movl	%ebx, (%r14)
	movl	%r13d, %esi
	movq	%rbp, %rdi
	call	dfs
	cmpl	%eax, %r12d
	cmovl	%eax, %r12d
	addl	$1, %ebx
	cmpl	%ebx, m(%rip)
	jge	.L6
.L1:
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	movl	%r12d, %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
.L13:
	.cfi_restore_state
	movslq	q(%rip), %rsi
	testl	%esi, %esi
	jle	.L7
	xorl	%eax, %eax
	xorl	%r12d, %r12d
	leaq	c(%rip), %r9
	leaq	b(%rip), %r8
	leaq	a(%rip), %rdi
	leaq	d(%rip), %r10
	.p2align 4,,10
	.p2align 3
.L5:
	movslq	(%r8,%rax,4), %rdx
	movslq	(%rdi,%rax,4), %rcx
	movl	0(%rbp,%rdx,4), %edx
	subl	0(%rbp,%rcx,4), %edx
	cmpl	%edx, (%r9,%rax,4)
	jne	.L4
	addl	(%r10,%rax,4), %r12d
.L4:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L5
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	movl	%r12d, %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
.L7:
	.cfi_restore_state
	xorl	%r12d, %r12d
	jmp	.L1
	.cfi_endproc
.LFE39:
	.size	dfs, .-dfs
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d %d %d %d"
	.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	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	$8, %rsp
	.cfi_def_cfa_offset 64
	call	__isoc99_scanf@PLT
	movl	q(%rip), %eax
	testl	%eax, %eax
	jle	.L17
	leaq	a(%rip), %rbp
	leaq	b(%rip), %rbx
	xorl	%r12d, %r12d
	leaq	c(%rip), %r14
	leaq	d(%rip), %r13
	leaq	.LC2(%rip), %r15
	.p2align 4,,10
	.p2align 3
.L16:
	movq	%r13, %r8
	movq	%r14, %rcx
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	xorl	%eax, %eax
	movq	%r15, %rdi
	addl	$1, %r12d
	addq	$4, %r14
	call	__isoc99_scanf@PLT
	addq	$4, %r13
	subl	$1, 0(%rbp)
	addq	$4, %rbp
	subl	$1, (%rbx)
	addq	$4, %rbx
	cmpl	%r12d, q(%rip)
	jg	.L16
.L17:
	movl	$1, %esi
	leaq	A(%rip), %rdi
	movl	$1, A(%rip)
	call	dfs
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addq	$8, %rsp
	.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
	.cfi_endproc
.LFE40:
	.size	main, .-main
	.globl	A
	.bss
	.align 32
	.type	A, @object
	.size	A, 40
A:
	.zero	40
	.globl	d
	.align 32
	.type	d, @object
	.size	d, 220
d:
	.zero	220
	.globl	c
	.align 32
	.type	c, @object
	.size	c, 220
c:
	.zero	220
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 220
b:
	.zero	220
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 220
a:
	.zero	220
	.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>
#include <stdlib.h>
int n, m, q;
int a[55], b[55], c[55], d[55];
int A[10] = {};
int dfs(int *A, int j)
{
    if (j == n)
    {
        int ans = 0;
        for (int i = 0; i < q; i++)
        {
            if (A[b[i]] - A[a[i]] == c[i])
            {
                ans += d[i];
            }
        }
        return ans;
    }
    int max = 0;
    for (int i = A[j - 1]; i <= m; i++)
    {
        A[j] = i;
        int t = dfs(A, j + 1);
        max = (max > t) ? max : t;
    }
    return max;
}
int main()
{
    scanf("%d %d %d", &n, &m, &q);
    for (int i = 0; i < q; i++)
    {
        scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
        a[i]--;
        b[i]--;
    }
    A[0] = 1;
    printf("%d", dfs(A, 1));
    return 0;
}
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>
#include <stdlib.h>
int n, m, q;
int a[55], b[55], c[55], d[55];
int A[10] = {};
int dfs(int *A, int j)
{
    if (j == n)
    {
        int ans = 0;
        for (int i = 0; i < q; i++)
        {
            if (A[b[i]] - A[a[i]] == c[i])
            {
                ans += d[i];
            }
        }
        return ans;
    }
    int max = 0;
    for (int i = A[j - 1]; i <= m; i++)
    {
        A[j] = i;
        int t = dfs(A, j + 1);
        max = (max > t) ? max : t;
    }
    return max;
}
int main()
{
    scanf("%d %d %d", &n, &m, &q);
    for (int i = 0; i < q; i++)
    {
        scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
        a[i]--;
        b[i]--;
    }
    A[0] = 1;
    printf("%d", dfs(A, 1));
    return 0;
}```

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, 220
a:
	.zero	220
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 220
b:
	.zero	220
	.globl	c
	.align 32
	.type	c, @object
	.size	c, 220
c:
	.zero	220
	.globl	d
	.align 32
	.type	d, @object
	.size	d, 220
d:
	.zero	220
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 40
A:
	.zero	40
	.text
	.globl	dfs
	.type	dfs, @function
dfs:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movq	%rdi, -40(%rbp)
	movl	%esi, -44(%rbp)
	movl	n(%rip), %eax
	cmpl	%eax, -44(%rbp)
	jne	.L2
	movl	$0, -20(%rbp)
	movl	$0, -16(%rbp)
	jmp	.L3
.L5:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-16(%rbp), %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
	movq	-40(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	c(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, %ecx
	jne	.L4
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -20(%rbp)
.L4:
	addl	$1, -16(%rbp)
.L3:
	movl	q(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jl	.L5
	movl	-20(%rbp), %eax
	jmp	.L6
.L2:
	movl	$0, -12(%rbp)
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -8(%rbp)
	jmp	.L7
.L8:
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rax, %rdx
	movl	-8(%rbp), %eax
	movl	%eax, (%rdx)
	movl	-44(%rbp), %eax
	leal	1(%rax), %edx
	movq	-40(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	dfs
	movl	%eax, -4(%rbp)
	movl	-12(%rbp), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, -12(%rbp)
	addl	$1, -8(%rbp)
.L7:
	movl	m(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jle	.L8
	movl	-12(%rbp), %eax
.L6:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	dfs, .-dfs
	.section	.rodata
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%d %d %d %d"
.LC2:
	.string	"%d"
	.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	$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	$0, -4(%rbp)
	jmp	.L10
.L11:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	leaq	(%rdx,%rax), %rsi
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	c(%rip), %rax
	leaq	(%rdx,%rax), %rcx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %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	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -4(%rbp)
.L10:
	movl	q(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L11
	movl	$1, A(%rip)
	movl	$1, %esi
	leaq	A(%rip), %rax
	movq	%rax, %rdi
	call	dfs
	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
.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
	.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, 220
a:
	.zero	220
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 220
b:
	.zero	220
	.globl	c
	.align 32
	.type	c, @object
	.size	c, 220
c:
	.zero	220
	.globl	d
	.align 32
	.type	d, @object
	.size	d, 220
d:
	.zero	220
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 40
A:
	.zero	40
	.text
	.globl	dfs
	.type	dfs, @function
dfs:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movq	%rdi, -40(%rbp)
	movl	%esi, -44(%rbp)
	movl	n(%rip), %eax
	cmpl	%eax, -44(%rbp)
	jne	.L2
	movl	$0, -20(%rbp)
	movl	$0, -16(%rbp)
	jmp	.L3
.L5:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-16(%rbp), %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
	movq	-40(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	c(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, %ecx
	jne	.L4
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -20(%rbp)
.L4:
	addl	$1, -16(%rbp)
.L3:
	movl	q(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jl	.L5
	movl	-20(%rbp), %eax
	jmp	.L6
.L2:
	movl	$0, -12(%rbp)
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -8(%rbp)
	jmp	.L7
.L8:
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rax, %rdx
	movl	-8(%rbp), %eax
	movl	%eax, (%rdx)
	movl	-44(%rbp), %eax
	leal	1(%rax), %edx
	movq	-40(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	dfs
	movl	%eax, -4(%rbp)
	movl	-12(%rbp), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, -12(%rbp)
	addl	$1, -8(%rbp)
.L7:
	movl	m(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jle	.L8
	movl	-12(%rbp), %eax
.L6:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	dfs, .-dfs
	.section	.rodata
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%d %d %d %d"
.LC2:
	.string	"%d"
	.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	$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	$0, -4(%rbp)
	jmp	.L10
.L11:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	leaq	(%rdx,%rax), %rsi
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	c(%rip), %rax
	leaq	(%rdx,%rax), %rcx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %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	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -4(%rbp)
.L10:
	movl	q(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L11
	movl	$1, A(%rip)
	movl	$1, %esi
	leaq	A(%rip), %rax
	movq	%rax, %rdi
	call	dfs
	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
.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:
