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

```c
#define H 10000
n,d,p,q,m[H];
b,h;
main(){
	for(;scanf("%d",&n),n;){
		memset(m,0,sizeof(m));
		for(;n--;){
			scanf("%d%d%d",&d,&p,&q);
			if(d==1)
				b=((1<<p)-1)<<q;
			else
				b=1<<q;
			for(h=H-1;h>=0;h--)
				if(m[h]&b)
					break;
			h++;
			if(d==1)
				p=1;
			for(;p--;){
				m[h]|=b;
				if(m[h]==0x3e)
					memmove(m+h,m+h+1,H-h-1);
				else
					h++;
			}
		}
		p=0;
		for(h=0;h<H;h++){
			for(;q=-m[h]&m[h];m[h]-=q)
				p++;
		}
		printf("%d\n",p);
	}
	exit(0);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	p
	.align 4
	.type	p, @object
	.size	p, 4
p:
	.zero	4
	.globl	q
	.align 4
	.type	q, @object
	.size	q, 4
q:
	.zero	4
	.globl	m
	.align 32
	.type	m, @object
	.size	m, 40000
m:
	.zero	40000
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.string	"%d\n"
.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
	jmp	.L2
.L19:
	movl	$40000, %edx
	movl	$0, %esi
	leaq	m(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	jmp	.L3
.L14:
	leaq	q(%rip), %rax
	movq	%rax, %rcx
	leaq	p(%rip), %rax
	movq	%rax, %rdx
	leaq	d(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	d(%rip), %eax
	cmpl	$1, %eax
	jne	.L4
	movl	p(%rip), %eax
	movl	$1, %edx
	movl	%eax, %ecx
	sall	%cl, %edx
	movl	%edx, %eax
	leal	-1(%rax), %edx
	movl	q(%rip), %eax
	movl	%eax, %ecx
	sall	%cl, %edx
	movl	%edx, %eax
	movl	%eax, b(%rip)
	jmp	.L5
.L4:
	movl	q(%rip), %eax
	movl	$1, %edx
	movl	%eax, %ecx
	sall	%cl, %edx
	movl	%edx, %eax
	movl	%eax, b(%rip)
.L5:
	movl	$9999, h(%rip)
	jmp	.L6
.L9:
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	b(%rip), %eax
	andl	%edx, %eax
	testl	%eax, %eax
	jne	.L20
	movl	h(%rip), %eax
	subl	$1, %eax
	movl	%eax, h(%rip)
.L6:
	movl	h(%rip), %eax
	testl	%eax, %eax
	jns	.L9
	jmp	.L8
.L20:
	nop
.L8:
	movl	h(%rip), %eax
	addl	$1, %eax
	movl	%eax, h(%rip)
	movl	d(%rip), %eax
	cmpl	$1, %eax
	jne	.L11
	movl	$1, p(%rip)
	jmp	.L11
.L13:
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	b(%rip), %edx
	movl	h(%rip), %eax
	orl	%edx, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$62, %eax
	jne	.L12
	movl	h(%rip), %edx
	movl	$9999, %eax
	subl	%edx, %eax
	cltq
	movl	h(%rip), %edx
	movslq	%edx, %rdx
	addq	$1, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	m(%rip), %rdx
	leaq	(%rcx,%rdx), %rsi
	movl	h(%rip), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	m(%rip), %rdx
	addq	%rdx, %rcx
	movq	%rax, %rdx
	movq	%rcx, %rdi
	call	memmove@PLT
	jmp	.L11
.L12:
	movl	h(%rip), %eax
	addl	$1, %eax
	movl	%eax, h(%rip)
.L11:
	movl	p(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, p(%rip)
	testl	%eax, %eax
	jne	.L13
.L3:
	movl	n(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, n(%rip)
	testl	%eax, %eax
	jne	.L14
	movl	$0, p(%rip)
	movl	$0, h(%rip)
	jmp	.L15
.L17:
	movl	p(%rip), %eax
	addl	$1, %eax
	movl	%eax, p(%rip)
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	q(%rip), %esi
	movl	h(%rip), %eax
	movl	%edx, %ecx
	subl	%esi, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L16:
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	negl	%eax
	movl	%eax, %ecx
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	andl	%ecx, %eax
	movl	%eax, q(%rip)
	movl	q(%rip), %eax
	testl	%eax, %eax
	jne	.L17
	movl	h(%rip), %eax
	addl	$1, %eax
	movl	%eax, h(%rip)
.L15:
	movl	h(%rip), %eax
	cmpl	$9999, %eax
	jle	.L16
	movl	p(%rip), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L2:
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	n(%rip), %eax
	testl	%eax, %eax
	jne	.L19
	movl	$0, %edi
	call	exit@PLT
	.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\n"
.LC2:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	m(%rip), %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	.p2align 4,,10
	.p2align 3
.L2:
	leaq	n(%rip), %rsi
	leaq	.LC2(%rip), %rdi
	xorl	%eax, %eax
	call	scanf@PLT
	movl	n(%rip), %ebp
	testl	%ebp, %ebp
	je	.L34
	movl	$40000, %edx
	xorl	%esi, %esi
	movq	%rbx, %rdi
	subl	$1, %ebp
	call	memset@PLT
	movl	%ebp, n(%rip)
	leaq	q(%rip), %r15
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%r15, %rcx
	leaq	d(%rip), %rsi
	leaq	p(%rip), %rdx
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	movl	$1, %r13d
	call	scanf@PLT
	movl	q(%rip), %ecx
	movl	d(%rip), %esi
	sall	%cl, %r13d
	cmpl	$1, %esi
	jne	.L4
	movl	p(%rip), %ecx
	movl	%esi, %r13d
	sall	%cl, %r13d
	movl	q(%rip), %ecx
	subl	$1, %r13d
	sall	%cl, %r13d
.L4:
	movl	%r13d, b(%rip)
	leaq	39996+m(%rip), %rax
	movl	$9999, %edx
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L5:
	subl	$1, %edx
	subq	$4, %rax
	cmpl	$-1, %edx
	je	.L6
.L7:
	movl	%r13d, %ebp
	andl	(%rax), %ebp
	je	.L5
	leal	1(%rdx), %ebp
.L6:
	movl	%ebp, h(%rip)
	cmpl	$1, %esi
	je	.L35
	movl	p(%rip), %eax
	leal	-1(%rax), %r12d
	movl	%r12d, p(%rip)
	testl	%eax, %eax
	jne	.L9
	jmp	.L14
	.p2align 4,,10
	.p2align 3
.L12:
	addl	$1, %ebp
	subl	$1, %r12d
	movl	%ebp, h(%rip)
	movl	%r12d, p(%rip)
	cmpl	$-1, %r12d
	je	.L14
.L9:
	movslq	%ebp, %r14
.L15:
	movl	(%rbx,%r14,4), %eax
	orl	%r13d, %eax
	movl	%eax, (%rbx,%r14,4)
	cmpl	$62, %eax
	jne	.L12
	movl	$9999, %edx
	leaq	4(,%r14,4), %rax
	subl	$1, %r12d
	subl	%ebp, %edx
	leaq	(%rax,%rbx), %rsi
	leaq	-4(%rbx,%rax), %rdi
	movslq	%edx, %rdx
	call	memmove@PLT
	movl	%r12d, p(%rip)
	cmpl	$-1, %r12d
	jne	.L15
	.p2align 4,,10
	.p2align 3
.L14:
	movl	n(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, n(%rip)
	testl	%eax, %eax
	jne	.L10
	movl	$0, p(%rip)
	leaq	m(%rip), %rdi
	xorl	%esi, %esi
	xorl	%r8d, %r8d
	leaq	40000(%rdi), %r9
	.p2align 4,,10
	.p2align 3
.L16:
	movl	(%rdi), %edx
	leal	1(%rsi), %ecx
	movl	%edx, %eax
	negl	%eax
	andl	%edx, %eax
	je	.L20
	.p2align 4,,10
	.p2align 3
.L17:
	movl	%ecx, %esi
	movl	%edx, %ecx
	subl	%eax, %edx
	subl	%ecx, %eax
	leal	1(%rsi), %ecx
	andl	%edx, %eax
	jne	.L17
	movl	%edx, (%rdi)
	movl	$1, %r8d
.L20:
	addq	$4, %rdi
	cmpq	%rdi, %r9
	jne	.L16
	movl	$0, q(%rip)
	movl	$10000, h(%rip)
	testb	%r8b, %r8b
	je	.L23
	movl	%esi, p(%rip)
.L21:
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	printf@PLT
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L35:
	movl	$0, p(%rip)
	xorl	%r12d, %r12d
	jmp	.L9
.L23:
	xorl	%esi, %esi
	jmp	.L21
.L34:
	xorl	%edi, %edi
	call	exit@PLT
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	h
	.bss
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	m
	.align 32
	.type	m, @object
	.size	m, 40000
m:
	.zero	40000
	.globl	q
	.align 4
	.type	q, @object
	.size	q, 4
q:
	.zero	4
	.globl	p
	.align 4
	.type	p, @object
	.size	p, 4
p:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.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\n"
.LC2:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	m(%rip), %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	.p2align 4,,10
	.p2align 3
.L2:
	leaq	n(%rip), %rsi
	leaq	.LC2(%rip), %rdi
	xorl	%eax, %eax
	call	scanf@PLT
	movl	n(%rip), %ebp
	testl	%ebp, %ebp
	je	.L34
	movl	$40000, %edx
	xorl	%esi, %esi
	movq	%rbx, %rdi
	subl	$1, %ebp
	call	memset@PLT
	movl	%ebp, n(%rip)
	leaq	q(%rip), %r15
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%r15, %rcx
	leaq	d(%rip), %rsi
	leaq	p(%rip), %rdx
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	movl	$1, %r13d
	call	scanf@PLT
	movl	q(%rip), %ecx
	movl	d(%rip), %esi
	sall	%cl, %r13d
	cmpl	$1, %esi
	jne	.L4
	movl	p(%rip), %ecx
	movl	%esi, %r13d
	sall	%cl, %r13d
	movl	q(%rip), %ecx
	subl	$1, %r13d
	sall	%cl, %r13d
.L4:
	movl	%r13d, b(%rip)
	leaq	39996+m(%rip), %rax
	movl	$9999, %edx
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L5:
	subl	$1, %edx
	subq	$4, %rax
	cmpl	$-1, %edx
	je	.L6
.L7:
	movl	%r13d, %ebp
	andl	(%rax), %ebp
	je	.L5
	leal	1(%rdx), %ebp
.L6:
	movl	%ebp, h(%rip)
	cmpl	$1, %esi
	je	.L35
	movl	p(%rip), %eax
	leal	-1(%rax), %r12d
	movl	%r12d, p(%rip)
	testl	%eax, %eax
	jne	.L9
	jmp	.L14
	.p2align 4,,10
	.p2align 3
.L12:
	addl	$1, %ebp
	subl	$1, %r12d
	movl	%ebp, h(%rip)
	movl	%r12d, p(%rip)
	cmpl	$-1, %r12d
	je	.L14
.L9:
	movslq	%ebp, %r14
.L15:
	movl	(%rbx,%r14,4), %eax
	orl	%r13d, %eax
	movl	%eax, (%rbx,%r14,4)
	cmpl	$62, %eax
	jne	.L12
	movl	$9999, %edx
	leaq	4(,%r14,4), %rax
	subl	$1, %r12d
	subl	%ebp, %edx
	leaq	(%rax,%rbx), %rsi
	leaq	-4(%rbx,%rax), %rdi
	movslq	%edx, %rdx
	call	memmove@PLT
	movl	%r12d, p(%rip)
	cmpl	$-1, %r12d
	jne	.L15
	.p2align 4,,10
	.p2align 3
.L14:
	movl	n(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, n(%rip)
	testl	%eax, %eax
	jne	.L10
	movl	$0, p(%rip)
	leaq	m(%rip), %rdi
	xorl	%esi, %esi
	xorl	%r8d, %r8d
	leaq	40000(%rdi), %r9
	.p2align 4,,10
	.p2align 3
.L16:
	movl	(%rdi), %edx
	leal	1(%rsi), %ecx
	movl	%edx, %eax
	negl	%eax
	andl	%edx, %eax
	je	.L20
	.p2align 4,,10
	.p2align 3
.L17:
	movl	%ecx, %esi
	movl	%edx, %ecx
	subl	%eax, %edx
	subl	%ecx, %eax
	leal	1(%rsi), %ecx
	andl	%edx, %eax
	jne	.L17
	movl	%edx, (%rdi)
	movl	$1, %r8d
.L20:
	addq	$4, %rdi
	cmpq	%rdi, %r9
	jne	.L16
	movl	$0, q(%rip)
	movl	$10000, h(%rip)
	testb	%r8b, %r8b
	je	.L23
	movl	%esi, p(%rip)
.L21:
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	printf@PLT
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L35:
	movl	$0, p(%rip)
	xorl	%r12d, %r12d
	jmp	.L9
.L23:
	xorl	%esi, %esi
	jmp	.L21
.L34:
	xorl	%edi, %edi
	call	exit@PLT
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	h
	.bss
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	m
	.align 32
	.type	m, @object
	.size	m, 40000
m:
	.zero	40000
	.globl	q
	.align 4
	.type	q, @object
	.size	q, 4
q:
	.zero	4
	.globl	p
	.align 4
	.type	p, @object
	.size	p, 4
p:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.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:

#define H 10000
n,d,p,q,m[H];
b,h;
main(){
	for(;scanf("%d",&n),n;){
		memset(m,0,sizeof(m));
		for(;n--;){
			scanf("%d%d%d",&d,&p,&q);
			if(d==1)
				b=((1<<p)-1)<<q;
			else
				b=1<<q;
			for(h=H-1;h>=0;h--)
				if(m[h]&b)
					break;
			h++;
			if(d==1)
				p=1;
			for(;p--;){
				m[h]|=b;
				if(m[h]==0x3e)
					memmove(m+h,m+h+1,H-h-1);
				else
					h++;
			}
		}
		p=0;
		for(h=0;h<H;h++){
			for(;q=-m[h]&m[h];m[h]-=q)
				p++;
		}
		printf("%d\n",p);
	}
	exit(0);
}
4
1 4 1
1 3 2
2 2 4
2 3 5
1
1 5 1
7
2 2 2
1 4 1
2 1 3
1 4 1
1 1 1
2 5 5
1 4 2
0
 4
1 4 1
1 3 2
1 2 4
2 3 5
1
1 5 1
7
2 2 2
1 4 1
2 1 3
1 4 1
1 1 1
2 5 5
1 4 2
0
 4
1 4 1
1 3 1
2 2 4
2 3 5
1
1 5 1
7
2 2 2
1 1 1
2 1 3
1 4 1
1 1 1
2 5 5
1 4 2
0
 4
2 4 1
1 3 1
2 2 4
2 3 5
1
1 5 1
7
2 2 2
1 1 1
2 1 3
1 4 1
1 1 1
2 5 5
1 4 2
0
 4
1 4 1
1 2 2
2 2 4
2 3 5
1
1 5 1
7
2 2 2
1 4 1
2 1 3
1 4 1
1 1 1
2 5 5
1 4 2
0
 4
1 4 1
1 3 2
2 2 4
2 3 5
1
1 5 1
7
2 2 2
1 3 1
2 1 3
1 4 1
1 1 1
2 5 5
1 4 2
0
 4
1 4 1
1 3 1
2 2 4
2 1 5
1
1 5 1
7
2 2 2
1 1 1
2 1 3
1 4 1
1 1 1
2 5 5
1 4 2
0
 4
2 4 1
1 3 1
2 2 4
2 3 5
1
1 5 1
7
2 2 2
1 1 1
2 0 3
1 4 1
1 1 1
2 5 5
1 4 2
0
 4
1 4 1
1 2 2
1 2 4
2 3 5
1
1 5 1
7
2 2 2
1 4 1
2 1 3
1 4 1
1 1 1
2 5 5
1 4 2
0
 4
1 4 1
1 3 2
2 2 4
2 3 5
1
1 5 1
7
2 2 2
1 3 1
2 1 5
1 4 1
1 1 1
2 5 5
1 4 2
0

7
0
6
 12
0
6
 2
0
13
 12
0
13
 6
0
6
 7
0
10
 5
0
13
 12
0
12
 11
0
6
 7
0
15

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

```c
#define H 10000
n,d,p,q,m[H];
b,h;
main(){
	for(;scanf("%d",&n),n;){
		memset(m,0,sizeof(m));
		for(;n--;){
			scanf("%d%d%d",&d,&p,&q);
			if(d==1)
				b=((1<<p)-1)<<q;
			else
				b=1<<q;
			for(h=H-1;h>=0;h--)
				if(m[h]&b)
					break;
			h++;
			if(d==1)
				p=1;
			for(;p--;){
				m[h]|=b;
				if(m[h]==0x3e)
					memmove(m+h,m+h+1,H-h-1);
				else
					h++;
			}
		}
		p=0;
		for(h=0;h<H;h++){
			for(;q=-m[h]&m[h];m[h]-=q)
				p++;
		}
		printf("%d\n",p);
	}
	exit(0);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	p
	.align 4
	.type	p, @object
	.size	p, 4
p:
	.zero	4
	.globl	q
	.align 4
	.type	q, @object
	.size	q, 4
q:
	.zero	4
	.globl	m
	.align 32
	.type	m, @object
	.size	m, 40000
m:
	.zero	40000
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.string	"%d\n"
.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
	jmp	.L2
.L19:
	movl	$40000, %edx
	movl	$0, %esi
	leaq	m(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	jmp	.L3
.L14:
	leaq	q(%rip), %rax
	movq	%rax, %rcx
	leaq	p(%rip), %rax
	movq	%rax, %rdx
	leaq	d(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	d(%rip), %eax
	cmpl	$1, %eax
	jne	.L4
	movl	p(%rip), %eax
	movl	$1, %edx
	movl	%eax, %ecx
	sall	%cl, %edx
	movl	%edx, %eax
	leal	-1(%rax), %edx
	movl	q(%rip), %eax
	movl	%eax, %ecx
	sall	%cl, %edx
	movl	%edx, %eax
	movl	%eax, b(%rip)
	jmp	.L5
.L4:
	movl	q(%rip), %eax
	movl	$1, %edx
	movl	%eax, %ecx
	sall	%cl, %edx
	movl	%edx, %eax
	movl	%eax, b(%rip)
.L5:
	movl	$9999, h(%rip)
	jmp	.L6
.L9:
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	b(%rip), %eax
	andl	%edx, %eax
	testl	%eax, %eax
	jne	.L20
	movl	h(%rip), %eax
	subl	$1, %eax
	movl	%eax, h(%rip)
.L6:
	movl	h(%rip), %eax
	testl	%eax, %eax
	jns	.L9
	jmp	.L8
.L20:
	nop
.L8:
	movl	h(%rip), %eax
	addl	$1, %eax
	movl	%eax, h(%rip)
	movl	d(%rip), %eax
	cmpl	$1, %eax
	jne	.L11
	movl	$1, p(%rip)
	jmp	.L11
.L13:
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	b(%rip), %edx
	movl	h(%rip), %eax
	orl	%edx, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$62, %eax
	jne	.L12
	movl	h(%rip), %edx
	movl	$9999, %eax
	subl	%edx, %eax
	cltq
	movl	h(%rip), %edx
	movslq	%edx, %rdx
	addq	$1, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	m(%rip), %rdx
	leaq	(%rcx,%rdx), %rsi
	movl	h(%rip), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	m(%rip), %rdx
	addq	%rdx, %rcx
	movq	%rax, %rdx
	movq	%rcx, %rdi
	call	memmove@PLT
	jmp	.L11
.L12:
	movl	h(%rip), %eax
	addl	$1, %eax
	movl	%eax, h(%rip)
.L11:
	movl	p(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, p(%rip)
	testl	%eax, %eax
	jne	.L13
.L3:
	movl	n(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, n(%rip)
	testl	%eax, %eax
	jne	.L14
	movl	$0, p(%rip)
	movl	$0, h(%rip)
	jmp	.L15
.L17:
	movl	p(%rip), %eax
	addl	$1, %eax
	movl	%eax, p(%rip)
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	q(%rip), %esi
	movl	h(%rip), %eax
	movl	%edx, %ecx
	subl	%esi, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L16:
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	negl	%eax
	movl	%eax, %ecx
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	andl	%ecx, %eax
	movl	%eax, q(%rip)
	movl	q(%rip), %eax
	testl	%eax, %eax
	jne	.L17
	movl	h(%rip), %eax
	addl	$1, %eax
	movl	%eax, h(%rip)
.L15:
	movl	h(%rip), %eax
	cmpl	$9999, %eax
	jle	.L16
	movl	p(%rip), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L2:
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	n(%rip), %eax
	testl	%eax, %eax
	jne	.L19
	movl	$0, %edi
	call	exit@PLT
	.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.
val
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	p
	.align 4
	.type	p, @object
	.size	p, 4
p:
	.zero	4
	.globl	q
	.align 4
	.type	q, @object
	.size	q, 4
q:
	.zero	4
	.globl	m
	.align 32
	.type	m, @object
	.size	m, 40000
m:
	.zero	40000
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.string	"%d\n"
.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
	jmp	.L2
.L19:
	movl	$40000, %edx
	movl	$0, %esi
	leaq	m(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	jmp	.L3
.L14:
	leaq	q(%rip), %rax
	movq	%rax, %rcx
	leaq	p(%rip), %rax
	movq	%rax, %rdx
	leaq	d(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	d(%rip), %eax
	cmpl	$1, %eax
	jne	.L4
	movl	p(%rip), %eax
	movl	$1, %edx
	movl	%eax, %ecx
	sall	%cl, %edx
	movl	%edx, %eax
	leal	-1(%rax), %edx
	movl	q(%rip), %eax
	movl	%eax, %ecx
	sall	%cl, %edx
	movl	%edx, %eax
	movl	%eax, b(%rip)
	jmp	.L5
.L4:
	movl	q(%rip), %eax
	movl	$1, %edx
	movl	%eax, %ecx
	sall	%cl, %edx
	movl	%edx, %eax
	movl	%eax, b(%rip)
.L5:
	movl	$9999, h(%rip)
	jmp	.L6
.L9:
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	b(%rip), %eax
	andl	%edx, %eax
	testl	%eax, %eax
	jne	.L20
	movl	h(%rip), %eax
	subl	$1, %eax
	movl	%eax, h(%rip)
.L6:
	movl	h(%rip), %eax
	testl	%eax, %eax
	jns	.L9
	jmp	.L8
.L20:
	nop
.L8:
	movl	h(%rip), %eax
	addl	$1, %eax
	movl	%eax, h(%rip)
	movl	d(%rip), %eax
	cmpl	$1, %eax
	jne	.L11
	movl	$1, p(%rip)
	jmp	.L11
.L13:
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	b(%rip), %edx
	movl	h(%rip), %eax
	orl	%edx, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$62, %eax
	jne	.L12
	movl	h(%rip), %edx
	movl	$9999, %eax
	subl	%edx, %eax
	cltq
	movl	h(%rip), %edx
	movslq	%edx, %rdx
	addq	$1, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	m(%rip), %rdx
	leaq	(%rcx,%rdx), %rsi
	movl	h(%rip), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	m(%rip), %rdx
	addq	%rdx, %rcx
	movq	%rax, %rdx
	movq	%rcx, %rdi
	call	memmove@PLT
	jmp	.L11
.L12:
	movl	h(%rip), %eax
	addl	$1, %eax
	movl	%eax, h(%rip)
.L11:
	movl	p(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, p(%rip)
	testl	%eax, %eax
	jne	.L13
.L3:
	movl	n(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, n(%rip)
	testl	%eax, %eax
	jne	.L14
	movl	$0, p(%rip)
	movl	$0, h(%rip)
	jmp	.L15
.L17:
	movl	p(%rip), %eax
	addl	$1, %eax
	movl	%eax, p(%rip)
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	q(%rip), %esi
	movl	h(%rip), %eax
	movl	%edx, %ecx
	subl	%esi, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L16:
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	negl	%eax
	movl	%eax, %ecx
	movl	h(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	andl	%ecx, %eax
	movl	%eax, q(%rip)
	movl	q(%rip), %eax
	testl	%eax, %eax
	jne	.L17
	movl	h(%rip), %eax
	addl	$1, %eax
	movl	%eax, h(%rip)
.L15:
	movl	h(%rip), %eax
	cmpl	$9999, %eax
	jle	.L16
	movl	p(%rip), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L2:
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	n(%rip), %eax
	testl	%eax, %eax
	jne	.L19
	movl	$0, %edi
	call	exit@PLT
	.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:
