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>          // printf(), scanf()
#include <stdlib.h>         // qsort()
#include <stdbool.h>

#define MAX_N 200
#define max(a, b) ((a) > (b) ? (a) : (b))

typedef struct doll_tbl
{
	int h;
	int r;
} doll_t;

int
cmp_func(const void *l_, const void *r_)
{
	const doll_t *l = (const doll_t*) l_;
	const doll_t *r = (const doll_t*) r_;

	if (l->h < r->h)
		return -1;

	if (l->h > r->h)
		return 1;

	return 0;
}

int
solve(doll_t doll[MAX_N], int N)
{
	int dp[MAX_N];

	qsort(doll, N, sizeof(doll_t), cmp_func);

	int count = 0;
	for (int i = 0; i < N; ++i)
	{
		dp[i] = 1;
		for (int j = 0; j < i; ++j)
		{
			if (doll[j].h < doll[i].h && doll[j].r < doll[i].r)
				dp[i] = max(dp[i], dp[j] + 1);
		}

		count = max(count, dp[i]);
	}

	return count;
}

int
main(int argc, char **argv)
{
	doll_t doll[MAX_N];

	while (true)
	{
		int n, m;
		scanf("%d", &n);
		if (n == 0)
			break;

		for (int i = 0; i < n; ++i)
			scanf("%d%d", &doll[i].h, &doll[i].r);

		scanf("%d", &m);
		for (int i = 0; i < m; ++i)
			scanf("%d%d", &doll[n + i].h, &doll[n + i].r);

		printf("%d\n", solve(doll, n + m));
	}

	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	cmp_func
	.type	cmp_func, @function
cmp_func:
.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, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movq	-24(%rbp), %rax
	movq	%rax, -16(%rbp)
	movq	-32(%rbp), %rax
	movq	%rax, -8(%rbp)
	movq	-16(%rbp), %rax
	movl	(%rax), %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jge	.L2
	movl	$-1, %eax
	jmp	.L3
.L2:
	movq	-16(%rbp), %rax
	movl	(%rax), %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jle	.L4
	movl	$1, %eax
	jmp	.L3
.L4:
	movl	$0, %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	cmp_func, .-cmp_func
	.globl	solve
	.type	solve, @function
solve:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$848, %rsp
	movq	%rdi, -840(%rbp)
	movl	%esi, -844(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	-844(%rbp), %eax
	movslq	%eax, %rsi
	movq	-840(%rbp), %rax
	leaq	cmp_func(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -828(%rbp)
	movl	$0, -824(%rbp)
	jmp	.L6
.L10:
	movl	-824(%rbp), %eax
	cltq
	movl	$1, -816(%rbp,%rax,4)
	movl	$0, -820(%rbp)
	jmp	.L7
.L9:
	movl	-820(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-840(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-824(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rcx
	movq	-840(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jge	.L8
	movl	-820(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-840(%rbp), %rax
	addq	%rdx, %rax
	movl	4(%rax), %edx
	movl	-824(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rcx
	movq	-840(%rbp), %rax
	addq	%rcx, %rax
	movl	4(%rax), %eax
	cmpl	%eax, %edx
	jge	.L8
	movl	-820(%rbp), %eax
	cltq
	movl	-816(%rbp,%rax,4), %eax
	leal	1(%rax), %edx
	movl	-824(%rbp), %eax
	cltq
	movl	-816(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	cmovl	%eax, %edx
	movl	-824(%rbp), %eax
	cltq
	movl	%edx, -816(%rbp,%rax,4)
.L8:
	addl	$1, -820(%rbp)
.L7:
	movl	-820(%rbp), %eax
	cmpl	-824(%rbp), %eax
	jl	.L9
	movl	-824(%rbp), %eax
	cltq
	movl	-816(%rbp,%rax,4), %eax
	movl	-828(%rbp), %edx
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, -828(%rbp)
	addl	$1, -824(%rbp)
.L6:
	movl	-824(%rbp), %eax
	cmpl	-844(%rbp), %eax
	jl	.L10
	movl	-828(%rbp), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$1648, %rsp
	movl	%edi, -1636(%rbp)
	movq	%rsi, -1648(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L20:
	leaq	-1632(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-1632(%rbp), %eax
	testl	%eax, %eax
	jne	.L14
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L21
	jmp	.L22
.L14:
	movl	$0, -1624(%rbp)
	jmp	.L16
.L17:
	leaq	-1616(%rbp), %rdx
	movl	-1624(%rbp), %eax
	cltq
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	4(%rax), %rdx
	leaq	-1616(%rbp), %rcx
	movl	-1624(%rbp), %eax
	cltq
	salq	$3, %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -1624(%rbp)
.L16:
	movl	-1632(%rbp), %eax
	cmpl	%eax, -1624(%rbp)
	jl	.L17
	leaq	-1628(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -1620(%rbp)
	jmp	.L18
.L19:
	movl	-1632(%rbp), %edx
	movl	-1620(%rbp), %eax
	addl	%edx, %eax
	leaq	-1616(%rbp), %rdx
	cltq
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	4(%rax), %rdx
	movl	-1632(%rbp), %ecx
	movl	-1620(%rbp), %eax
	addl	%ecx, %eax
	leaq	-1616(%rbp), %rcx
	cltq
	salq	$3, %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -1620(%rbp)
.L18:
	movl	-1628(%rbp), %eax
	cmpl	%eax, -1620(%rbp)
	jl	.L19
	movl	-1632(%rbp), %edx
	movl	-1628(%rbp), %eax
	addl	%eax, %edx
	leaq	-1616(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	solve
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L20
.L22:
	call	__stack_chk_fail@PLT
.L21:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.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	cmp_func
	.type	cmp_func, @function
cmp_func:
.LFB39:
	.cfi_startproc
	endbr64
	movl	(%rsi), %eax
	cmpl	%eax, (%rdi)
	movl	$-1, %edx
	setg	%al
	movzbl	%al, %eax
	cmovl	%edx, %eax
	ret
	.cfi_endproc
.LFE39:
	.size	cmp_func, .-cmp_func
	.p2align 4
	.globl	solve
	.type	solve, @function
solve:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	cmp_func(%rip), %rcx
	movl	$8, %edx
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movslq	%esi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rbp, %rsi
	movq	%rdi, %rbx
	subq	$816, %rsp
	.cfi_def_cfa_offset 848
	movq	%fs:40, %rax
	movq	%rax, 808(%rsp)
	xorl	%eax, %eax
	call	qsort@PLT
	xorl	%r9d, %r9d
	testl	%ebp, %ebp
	jle	.L5
	leaq	4(%rsp), %r8
	movl	$1, (%rsp)
	movl	$1, %edx
	movl	$1, %r9d
	cmpl	$1, %ebp
	je	.L5
	.p2align 4,,10
	.p2align 3
.L9:
	movl	$1, (%r8)
	movl	(%rbx,%rdx,8), %esi
	xorl	%eax, %eax
	movl	$1, %edi
	.p2align 4,,10
	.p2align 3
.L8:
	cmpl	%esi, (%rbx,%rax,8)
	jge	.L11
	movl	4(%rbx,%rdx,8), %ecx
	cmpl	%ecx, 4(%rbx,%rax,8)
	jge	.L11
	movl	(%rsp,%rax,4), %ecx
	addl	$1, %ecx
	cmpl	%ecx, %edi
	cmovl	%ecx, %edi
	movl	%edi, (%r8)
.L11:
	addq	$1, %rax
	cmpq	%rax, %rdx
	jne	.L8
	movl	(%r8), %eax
	cmpl	%eax, %r9d
	cmovl	%eax, %r9d
	addq	$1, %rdx
	addq	$4, %r8
	cmpq	%rbp, %rdx
	jne	.L9
.L5:
	movq	808(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L20
	addq	$816, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	movl	%r9d, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L20:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE40:
	.size	solve, .-solve
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB41:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	.LC0(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	.LC1(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$1656, %rsp
	.cfi_def_cfa_offset 1712
	movq	%fs:40, %rax
	movq	%rax, 1640(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	leaq	24(%rsp), %r13
	movq	%rax, 8(%rsp)
	leaq	32(%rsp), %rbx
	.p2align 4,,10
	.p2align 3
.L28:
	movq	%r13, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	24(%rsp), %eax
	testl	%eax, %eax
	je	.L22
	movq	%rbx, %r15
	movl	$0, %r14d
	jle	.L27
	.p2align 4,,10
	.p2align 3
.L26:
	leaq	4(%r15), %rdx
	movq	%r15, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	addl	$1, %r14d
	addq	$8, %r15
	cmpl	%r14d, 24(%rsp)
	jg	.L26
.L27:
	movq	8(%rsp), %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	xorl	%r14d, %r14d
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %esi
	testl	%esi, %esi
	jle	.L25
	.p2align 4,,10
	.p2align 3
.L24:
	movl	24(%rsp), %esi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	addl	%r14d, %esi
	addl	$1, %r14d
	movslq	%esi, %rsi
	salq	$3, %rsi
	leaq	4(%rbx,%rsi), %rdx
	addq	%rbx, %rsi
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %esi
	cmpl	%r14d, %esi
	jg	.L24
.L25:
	addl	24(%rsp), %esi
	movq	%rbx, %rdi
	call	solve
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L22:
	movq	1640(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L35
	addq	$1656, %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
.L35:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE41:
	.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:

rule
	.file	"temp.c"
	.text
	.p2align 4
	.globl	cmp_func
	.type	cmp_func, @function
cmp_func:
.LFB39:
	.cfi_startproc
	endbr64
	movl	(%rsi), %eax
	cmpl	%eax, (%rdi)
	movl	$-1, %edx
	setg	%al
	movzbl	%al, %eax
	cmovl	%edx, %eax
	ret
	.cfi_endproc
.LFE39:
	.size	cmp_func, .-cmp_func
	.p2align 4
	.globl	solve
	.type	solve, @function
solve:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	cmp_func(%rip), %rcx
	movl	$8, %edx
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movslq	%esi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rbp, %rsi
	movq	%rdi, %rbx
	subq	$816, %rsp
	.cfi_def_cfa_offset 848
	movq	%fs:40, %rax
	movq	%rax, 808(%rsp)
	xorl	%eax, %eax
	call	qsort@PLT
	xorl	%r9d, %r9d
	testl	%ebp, %ebp
	jle	.L5
	leaq	4(%rsp), %r8
	movl	$1, (%rsp)
	movl	$1, %edx
	movl	$1, %r9d
	cmpl	$1, %ebp
	je	.L5
	.p2align 4,,10
	.p2align 3
.L9:
	movl	$1, (%r8)
	movl	(%rbx,%rdx,8), %esi
	xorl	%eax, %eax
	movl	$1, %edi
	.p2align 4,,10
	.p2align 3
.L8:
	cmpl	%esi, (%rbx,%rax,8)
	jge	.L11
	movl	4(%rbx,%rdx,8), %ecx
	cmpl	%ecx, 4(%rbx,%rax,8)
	jge	.L11
	movl	(%rsp,%rax,4), %ecx
	addl	$1, %ecx
	cmpl	%ecx, %edi
	cmovl	%ecx, %edi
	movl	%edi, (%r8)
.L11:
	addq	$1, %rax
	cmpq	%rax, %rdx
	jne	.L8
	movl	(%r8), %eax
	cmpl	%eax, %r9d
	cmovl	%eax, %r9d
	addq	$1, %rdx
	addq	$4, %r8
	cmpq	%rbp, %rdx
	jne	.L9
.L5:
	movq	808(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L20
	addq	$816, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	movl	%r9d, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L20:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE40:
	.size	solve, .-solve
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB41:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	.LC0(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	.LC1(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$1656, %rsp
	.cfi_def_cfa_offset 1712
	movq	%fs:40, %rax
	movq	%rax, 1640(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	leaq	24(%rsp), %r13
	movq	%rax, 8(%rsp)
	leaq	32(%rsp), %rbx
	.p2align 4,,10
	.p2align 3
.L28:
	movq	%r13, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	24(%rsp), %eax
	testl	%eax, %eax
	je	.L22
	movq	%rbx, %r15
	movl	$0, %r14d
	jle	.L27
	.p2align 4,,10
	.p2align 3
.L26:
	leaq	4(%r15), %rdx
	movq	%r15, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	addl	$1, %r14d
	addq	$8, %r15
	cmpl	%r14d, 24(%rsp)
	jg	.L26
.L27:
	movq	8(%rsp), %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	xorl	%r14d, %r14d
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %esi
	testl	%esi, %esi
	jle	.L25
	.p2align 4,,10
	.p2align 3
.L24:
	movl	24(%rsp), %esi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	addl	%r14d, %esi
	addl	$1, %r14d
	movslq	%esi, %rsi
	salq	$3, %rsi
	leaq	4(%rbx,%rsi), %rdx
	addq	%rbx, %rsi
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %esi
	cmpl	%r14d, %esi
	jg	.L24
.L25:
	addl	24(%rsp), %esi
	movq	%rbx, %rdi
	call	solve
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L22:
	movq	1640(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L35
	addq	$1656, %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
.L35:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE41:
	.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:

#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // qsort()
#include <stdbool.h>

#define MAX_N 200
#define max(a, b) ((a) > (b) ? (a) : (b))

typedef struct doll_tbl
{
	int h;
	int r;
} doll_t;

int
cmp_func(const void *l_, const void *r_)
{
	const doll_t *l = (const doll_t*) l_;
	const doll_t *r = (const doll_t*) r_;

	if (l->h < r->h)
		return -1;

	if (l->h > r->h)
		return 1;

	return 0;
}

int
solve(doll_t doll[MAX_N], int N)
{
	int dp[MAX_N];

	qsort(doll, N, sizeof(doll_t), cmp_func);

	int count = 0;
	for (int i = 0; i < N; ++i)
	{
		dp[i] = 1;
		for (int j = 0; j < i; ++j)
		{
			if (doll[j].h < doll[i].h && doll[j].r < doll[i].r)
				dp[i] = max(dp[i], dp[j] + 1);
		}

		count = max(count, dp[i]);
	}

	return count;
}

int
main(int argc, char **argv)
{
	doll_t doll[MAX_N];

	while (true)
	{
		int n, m;
		scanf("%d", &n);
		if (n == 0)
			break;

		for (int i = 0; i < n; ++i)
			scanf("%d%d", &doll[i].h, &doll[i].r);

		scanf("%d", &m);
		for (int i = 0; i < m; ++i)
			scanf("%d%d", &doll[n + i].h, &doll[n + i].r);

		printf("%d\n", solve(doll, n + m));
	}

	return 0;
}

6
1 1
4 3
6 5
8 6
10 10
14 14
5
2 1
5 4
6 6
9 8
15 10
4
1 1
4 3
6 5
8 6
3
2 2
5 4
6 6
4
1 1
4 3
6 5
8 6
4
10 10
12 11
18 15
24 20
0
 6
1 1
4 3
6 5
8 6
10 10
14 14
5
2 2
5 4
6 6
9 8
15 10
4
1 1
4 3
6 5
8 6
3
2 2
5 4
6 6
4
1 2
4 3
6 5
8 6
4
10 10
12 11
18 15
24 20
0
 6
1 1
4 3
6 5
8 6
10 10
14 14
5
2 2
5 4
6 6
9 8
15 10
4
1 1
4 3
6 5
8 6
3
4 2
5 4
6 6
4
1 1
4 3
6 5
8 6
4
10 10
12 11
18 15
24 20
0
 6
1 1
4 3
6 0
8 6
10 10
14 14
5
2 2
5 4
6 6
9 8
15 10
4
1 1
4 3
6 5
8 6
3
2 2
9 4
6 6
4
1 2
4 3
6 5
8 6
4
10 10
12 11
18 15
24 20
0
 6
1 1
4 3
6 0
8 6
10 10
14 14
5
2 2
5 4
6 6
9 10
15 10
4
1 1
4 3
6 5
12 6
3
2 2
9 4
9 6
4
1 2
4 3
6 5
8 6
4
10 10
12 11
18 15
24 20
0
 6
1 1
4 3
6 0
8 6
10 10
14 14
5
2 2
5 4
6 6
9 8
15 10
4
2 1
4 3
6 5
8 6
3
2 2
9 4
6 6
4
1 2
4 3
6 5
8 6
4
10 10
12 11
18 15
24 20
0
 6
1 1
4 3
6 0
8 6
10 10
14 14
5
2 2
5 4
6 6
9 10
15 10
4
1 1
4 3
6 5
12 6
3
1 2
9 4
9 6
4
1 2
4 3
6 5
8 6
4
10 10
12 11
18 15
24 20
0
 6
1 1
4 3
6 5
8 6
10 10
14 14
5
2 2
5 4
6 6
9 15
15 20
4
1 1
4 3
6 3
8 6
3
4 2
5 4
6 6
4
1 1
4 3
6 5
8 6
4
10 10
12 11
18 15
24 20
0
 6
0 1
4 3
6 5
8 6
10 10
14 14
5
2 1
5 5
6 6
9 8
15 10
4
1 1
4 3
6 5
8 6
3
2 2
5 4
6 6
4
1 1
4 3
6 5
8 6
4
10 10
12 11
18 15
24 20
0
 6
1 1
4 3
6 5
8 6
10 10
14 14
5
2 2
5 4
6 6
9 15
15 10
4
1 1
4 3
6 5
8 11
3
4 2
5 4
6 7
4
1 1
4 3
6 5
8 6
4
10 2
12 11
18 15
24 20
0

8
6
8
 9
6
8
 9
5
8
 8
5
8
 7
5
8
 8
4
8
 7
4
8
 9
4
8
 7
6
8
 8
5
7

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>          // printf(), scanf()
#include <stdlib.h>         // qsort()
#include <stdbool.h>

#define MAX_N 200
#define max(a, b) ((a) > (b) ? (a) : (b))

typedef struct doll_tbl
{
	int h;
	int r;
} doll_t;

int
cmp_func(const void *l_, const void *r_)
{
	const doll_t *l = (const doll_t*) l_;
	const doll_t *r = (const doll_t*) r_;

	if (l->h < r->h)
		return -1;

	if (l->h > r->h)
		return 1;

	return 0;
}

int
solve(doll_t doll[MAX_N], int N)
{
	int dp[MAX_N];

	qsort(doll, N, sizeof(doll_t), cmp_func);

	int count = 0;
	for (int i = 0; i < N; ++i)
	{
		dp[i] = 1;
		for (int j = 0; j < i; ++j)
		{
			if (doll[j].h < doll[i].h && doll[j].r < doll[i].r)
				dp[i] = max(dp[i], dp[j] + 1);
		}

		count = max(count, dp[i]);
	}

	return count;
}

int
main(int argc, char **argv)
{
	doll_t doll[MAX_N];

	while (true)
	{
		int n, m;
		scanf("%d", &n);
		if (n == 0)
			break;

		for (int i = 0; i < n; ++i)
			scanf("%d%d", &doll[i].h, &doll[i].r);

		scanf("%d", &m);
		for (int i = 0; i < m; ++i)
			scanf("%d%d", &doll[n + i].h, &doll[n + i].r);

		printf("%d\n", solve(doll, n + m));
	}

	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	cmp_func
	.type	cmp_func, @function
cmp_func:
.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, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movq	-24(%rbp), %rax
	movq	%rax, -16(%rbp)
	movq	-32(%rbp), %rax
	movq	%rax, -8(%rbp)
	movq	-16(%rbp), %rax
	movl	(%rax), %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jge	.L2
	movl	$-1, %eax
	jmp	.L3
.L2:
	movq	-16(%rbp), %rax
	movl	(%rax), %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jle	.L4
	movl	$1, %eax
	jmp	.L3
.L4:
	movl	$0, %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	cmp_func, .-cmp_func
	.globl	solve
	.type	solve, @function
solve:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$848, %rsp
	movq	%rdi, -840(%rbp)
	movl	%esi, -844(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	-844(%rbp), %eax
	movslq	%eax, %rsi
	movq	-840(%rbp), %rax
	leaq	cmp_func(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -828(%rbp)
	movl	$0, -824(%rbp)
	jmp	.L6
.L10:
	movl	-824(%rbp), %eax
	cltq
	movl	$1, -816(%rbp,%rax,4)
	movl	$0, -820(%rbp)
	jmp	.L7
.L9:
	movl	-820(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-840(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-824(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rcx
	movq	-840(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jge	.L8
	movl	-820(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-840(%rbp), %rax
	addq	%rdx, %rax
	movl	4(%rax), %edx
	movl	-824(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rcx
	movq	-840(%rbp), %rax
	addq	%rcx, %rax
	movl	4(%rax), %eax
	cmpl	%eax, %edx
	jge	.L8
	movl	-820(%rbp), %eax
	cltq
	movl	-816(%rbp,%rax,4), %eax
	leal	1(%rax), %edx
	movl	-824(%rbp), %eax
	cltq
	movl	-816(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	cmovl	%eax, %edx
	movl	-824(%rbp), %eax
	cltq
	movl	%edx, -816(%rbp,%rax,4)
.L8:
	addl	$1, -820(%rbp)
.L7:
	movl	-820(%rbp), %eax
	cmpl	-824(%rbp), %eax
	jl	.L9
	movl	-824(%rbp), %eax
	cltq
	movl	-816(%rbp,%rax,4), %eax
	movl	-828(%rbp), %edx
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, -828(%rbp)
	addl	$1, -824(%rbp)
.L6:
	movl	-824(%rbp), %eax
	cmpl	-844(%rbp), %eax
	jl	.L10
	movl	-828(%rbp), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$1648, %rsp
	movl	%edi, -1636(%rbp)
	movq	%rsi, -1648(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L20:
	leaq	-1632(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-1632(%rbp), %eax
	testl	%eax, %eax
	jne	.L14
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L21
	jmp	.L22
.L14:
	movl	$0, -1624(%rbp)
	jmp	.L16
.L17:
	leaq	-1616(%rbp), %rdx
	movl	-1624(%rbp), %eax
	cltq
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	4(%rax), %rdx
	leaq	-1616(%rbp), %rcx
	movl	-1624(%rbp), %eax
	cltq
	salq	$3, %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -1624(%rbp)
.L16:
	movl	-1632(%rbp), %eax
	cmpl	%eax, -1624(%rbp)
	jl	.L17
	leaq	-1628(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -1620(%rbp)
	jmp	.L18
.L19:
	movl	-1632(%rbp), %edx
	movl	-1620(%rbp), %eax
	addl	%edx, %eax
	leaq	-1616(%rbp), %rdx
	cltq
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	4(%rax), %rdx
	movl	-1632(%rbp), %ecx
	movl	-1620(%rbp), %eax
	addl	%ecx, %eax
	leaq	-1616(%rbp), %rcx
	cltq
	salq	$3, %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -1620(%rbp)
.L18:
	movl	-1628(%rbp), %eax
	cmpl	%eax, -1620(%rbp)
	jl	.L19
	movl	-1632(%rbp), %edx
	movl	-1628(%rbp), %eax
	addl	%eax, %edx
	leaq	-1616(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	solve
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L20
.L22:
	call	__stack_chk_fail@PLT
.L21:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.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	cmp_func
	.type	cmp_func, @function
cmp_func:
.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, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movq	-24(%rbp), %rax
	movq	%rax, -16(%rbp)
	movq	-32(%rbp), %rax
	movq	%rax, -8(%rbp)
	movq	-16(%rbp), %rax
	movl	(%rax), %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jge	.L2
	movl	$-1, %eax
	jmp	.L3
.L2:
	movq	-16(%rbp), %rax
	movl	(%rax), %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jle	.L4
	movl	$1, %eax
	jmp	.L3
.L4:
	movl	$0, %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	cmp_func, .-cmp_func
	.globl	solve
	.type	solve, @function
solve:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$848, %rsp
	movq	%rdi, -840(%rbp)
	movl	%esi, -844(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	-844(%rbp), %eax
	movslq	%eax, %rsi
	movq	-840(%rbp), %rax
	leaq	cmp_func(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -828(%rbp)
	movl	$0, -824(%rbp)
	jmp	.L6
.L10:
	movl	-824(%rbp), %eax
	cltq
	movl	$1, -816(%rbp,%rax,4)
	movl	$0, -820(%rbp)
	jmp	.L7
.L9:
	movl	-820(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-840(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-824(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rcx
	movq	-840(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jge	.L8
	movl	-820(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-840(%rbp), %rax
	addq	%rdx, %rax
	movl	4(%rax), %edx
	movl	-824(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rcx
	movq	-840(%rbp), %rax
	addq	%rcx, %rax
	movl	4(%rax), %eax
	cmpl	%eax, %edx
	jge	.L8
	movl	-820(%rbp), %eax
	cltq
	movl	-816(%rbp,%rax,4), %eax
	leal	1(%rax), %edx
	movl	-824(%rbp), %eax
	cltq
	movl	-816(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	cmovl	%eax, %edx
	movl	-824(%rbp), %eax
	cltq
	movl	%edx, -816(%rbp,%rax,4)
.L8:
	addl	$1, -820(%rbp)
.L7:
	movl	-820(%rbp), %eax
	cmpl	-824(%rbp), %eax
	jl	.L9
	movl	-824(%rbp), %eax
	cltq
	movl	-816(%rbp,%rax,4), %eax
	movl	-828(%rbp), %edx
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, -828(%rbp)
	addl	$1, -824(%rbp)
.L6:
	movl	-824(%rbp), %eax
	cmpl	-844(%rbp), %eax
	jl	.L10
	movl	-828(%rbp), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$1648, %rsp
	movl	%edi, -1636(%rbp)
	movq	%rsi, -1648(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L20:
	leaq	-1632(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-1632(%rbp), %eax
	testl	%eax, %eax
	jne	.L14
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L21
	jmp	.L22
.L14:
	movl	$0, -1624(%rbp)
	jmp	.L16
.L17:
	leaq	-1616(%rbp), %rdx
	movl	-1624(%rbp), %eax
	cltq
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	4(%rax), %rdx
	leaq	-1616(%rbp), %rcx
	movl	-1624(%rbp), %eax
	cltq
	salq	$3, %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -1624(%rbp)
.L16:
	movl	-1632(%rbp), %eax
	cmpl	%eax, -1624(%rbp)
	jl	.L17
	leaq	-1628(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -1620(%rbp)
	jmp	.L18
.L19:
	movl	-1632(%rbp), %edx
	movl	-1620(%rbp), %eax
	addl	%edx, %eax
	leaq	-1616(%rbp), %rdx
	cltq
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	4(%rax), %rdx
	movl	-1632(%rbp), %ecx
	movl	-1620(%rbp), %eax
	addl	%ecx, %eax
	leaq	-1616(%rbp), %rcx
	cltq
	salq	$3, %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -1620(%rbp)
.L18:
	movl	-1628(%rbp), %eax
	cmpl	%eax, -1620(%rbp)
	jl	.L19
	movl	-1632(%rbp), %edx
	movl	-1628(%rbp), %eax
	addl	%eax, %edx
	leaq	-1616(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	solve
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L20
.L22:
	call	__stack_chk_fail@PLT
.L21:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.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:
