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

```c
// Aizu 1188: Hierarchical Democracy
// 2017.9.18 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char buf[10003];

int cmp(int *a, int *b) { return *a - *b; }

char *pair(char *p)
{
	int n = 0;
	while (1) {
		if (*p == '[') n++;
		else if (*p == ']') { n--; if (n < 0) break; }
		p++;
	}
	return p;
}

char *calc(char *p, int *v, int *half)
{
	int n, i, s, h;
	char *pp;
	int *t;

	pp = p, n = 0; while (*p == '[') p++, p = pair(p), p++, n++;
	if (n == 0) {
		s = 0; while (isdigit(*p)) s = s * 10 + *p++ - '0';
		*v = s, *half = 1; return p;
	}
	t = calloc(n, sizeof(int));
	p = pp; for (i = 0; i < n; i++) p++, p = calc(p, &s, &h), p++, t[i] = s;
	qsort(t, n, sizeof(int), cmp);
	for (s = 0, n >>= 1, i = 0; i <= n; i++) if (h) s += 1 + (t[i] >> 1); else s += t[i];
	free(t);
	*v = s, *half = 0;
	return p;
}

int main()
{
	int n, ans, t;
	char *p;

	scanf("%d", &n);
	while (n-- > 0) {
		scanf("%s", p = buf); p++;
		calc(p, &ans, &t);
		printf("%d\n", ans);
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	buf
	.bss
	.align 32
	.type	buf, @object
	.size	buf, 10003
buf:
	.zero	10003
	.text
	.globl	cmp
	.type	cmp, @function
cmp:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	cmp, .-cmp
	.globl	pair
	.type	pair, @function
pair:
.LFB7:
	.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)
	movl	$0, -4(%rbp)
.L7:
	movq	-24(%rbp), %rax
	movzbl	(%rax), %eax
	cmpb	$91, %al
	jne	.L4
	addl	$1, -4(%rbp)
	jmp	.L5
.L4:
	movq	-24(%rbp), %rax
	movzbl	(%rax), %eax
	cmpb	$93, %al
	jne	.L5
	subl	$1, -4(%rbp)
	cmpl	$0, -4(%rbp)
	js	.L10
.L5:
	addq	$1, -24(%rbp)
	jmp	.L7
.L10:
	nop
	movq	-24(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	pair, .-pair
	.globl	calc
	.type	calc, @function
calc:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$80, %rsp
	movq	%rdi, -56(%rbp)
	movq	%rsi, -64(%rbp)
	movq	%rdx, -72(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	-56(%rbp), %rax
	movq	%rax, -24(%rbp)
	movl	$0, -32(%rbp)
	jmp	.L12
.L13:
	addq	$1, -56(%rbp)
	movq	-56(%rbp), %rax
	movq	%rax, %rdi
	call	pair
	movq	%rax, -56(%rbp)
	addq	$1, -56(%rbp)
	addl	$1, -32(%rbp)
.L12:
	movq	-56(%rbp), %rax
	movzbl	(%rax), %eax
	cmpb	$91, %al
	je	.L13
	cmpl	$0, -32(%rbp)
	jne	.L14
	movl	$0, -40(%rbp)
	jmp	.L15
.L16:
	movl	-40(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %ecx
	movq	-56(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -56(%rbp)
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	addl	%ecx, %eax
	subl	$48, %eax
	movl	%eax, -40(%rbp)
.L15:
	call	__ctype_b_loc@PLT
	movq	(%rax), %rdx
	movq	-56(%rbp), %rax
	movzbl	(%rax), %eax
	movsbq	%al, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	movzwl	(%rax), %eax
	movzwl	%ax, %eax
	andl	$2048, %eax
	testl	%eax, %eax
	jne	.L16
	movl	-40(%rbp), %edx
	movq	-64(%rbp), %rax
	movl	%edx, (%rax)
	movq	-72(%rbp), %rax
	movl	$1, (%rax)
	movq	-56(%rbp), %rax
	jmp	.L24
.L14:
	movl	-32(%rbp), %eax
	cltq
	movl	$4, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -16(%rbp)
	movq	-24(%rbp), %rax
	movq	%rax, -56(%rbp)
	movl	$0, -28(%rbp)
	jmp	.L18
.L19:
	addq	$1, -56(%rbp)
	leaq	-36(%rbp), %rdx
	leaq	-40(%rbp), %rcx
	movq	-56(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	calc
	movq	%rax, -56(%rbp)
	addq	$1, -56(%rbp)
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movl	-40(%rbp), %eax
	movl	%eax, (%rdx)
	addl	$1, -28(%rbp)
.L18:
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jl	.L19
	movl	-32(%rbp), %eax
	movslq	%eax, %rsi
	movq	-16(%rbp), %rax
	leaq	cmp(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -40(%rbp)
	sarl	-32(%rbp)
	movl	$0, -28(%rbp)
	jmp	.L20
.L23:
	movl	-36(%rbp), %eax
	testl	%eax, %eax
	je	.L21
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	sarl	%eax
	leal	1(%rax), %edx
	movl	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -40(%rbp)
	jmp	.L22
.L21:
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -40(%rbp)
.L22:
	addl	$1, -28(%rbp)
.L20:
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jle	.L23
	movq	-16(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	-40(%rbp), %edx
	movq	-64(%rbp), %rax
	movl	%edx, (%rax)
	movq	-72(%rbp), %rax
	movl	$0, (%rax)
	movq	-56(%rbp), %rax
.L24:
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	calc, .-calc
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-28(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L27
.L28:
	leaq	buf(%rip), %rax
	movq	%rax, -16(%rbp)
	movq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -16(%rbp)
	leaq	-20(%rbp), %rdx
	leaq	-24(%rbp), %rcx
	movq	-16(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	calc
	movl	-24(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L27:
	movl	-28(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -28(%rbp)
	testl	%eax, %eax
	jg	.L28
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.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
	.type	cmp, @function
cmp:
.LFB41:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE41:
	.size	cmp, .-cmp
	.p2align 4
	.globl	pair
	.type	pair, @function
pair:
.LFB42:
	.cfi_startproc
	endbr64
	movq	%rdi, %rax
	xorl	%ecx, %ecx
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L4:
	cmpb	$93, %dl
	je	.L8
.L5:
	addq	$1, %rax
.L7:
	movzbl	(%rax), %edx
	cmpb	$91, %dl
	jne	.L4
	addl	$1, %ecx
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L8:
	subl	$1, %ecx
	jnb	.L5
	ret
	.cfi_endproc
.LFE42:
	.size	pair, .-pair
	.p2align 4
	.globl	calc
	.type	calc, @function
calc:
.LFB43:
	.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
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movsbl	(%rdi), %r14d
	movq	%rsi, 24(%rsp)
	movq	%rdx, 32(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	cmpb	$91, %r14b
	jne	.L10
	movq	%rdi, %rdx
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L15:
	leaq	1(%rdx), %rax
	xorl	%ecx, %ecx
	jmp	.L14
	.p2align 4,,10
	.p2align 3
.L11:
	cmpb	$93, %dl
	je	.L42
.L12:
	addq	$1, %rax
.L14:
	movzbl	(%rax), %edx
	cmpb	$91, %dl
	jne	.L11
	addl	$1, %ecx
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L42:
	subl	$1, %ecx
	jnb	.L12
	addl	$1, %ebx
	cmpb	$91, 1(%rax)
	leaq	1(%rax), %rdx
	je	.L15
	movslq	%ebx, %r15
	movl	$4, %esi
	leaq	52(%rsp), %r14
	movq	%r15, %rdi
	movq	%r15, 40(%rsp)
	call	calloc@PLT
	movq	%rax, %rbp
	movq	%rax, %r12
	leaq	(%rax,%r15,4), %rax
	movq	%rax, 16(%rsp)
	movq	%rbp, %rcx
	leaq	48(%rsp), %r15
.L19:
	leaq	1(%r13), %rdi
	movq	%r14, %rdx
	movq	%r15, %rsi
	movq	%rcx, 8(%rsp)
	call	calc
	movq	8(%rsp), %rcx
	leaq	1(%rax), %r13
	movl	48(%rsp), %eax
	addq	$4, %rcx
	movl	%eax, -4(%rcx)
	cmpq	16(%rsp), %rcx
	jne	.L19
	movq	40(%rsp), %rsi
	movl	$4, %edx
	sarl	%ebx
	movq	%rbp, %rdi
	leaq	cmp(%rip), %rcx
	call	qsort@PLT
	movl	%ebx, %edx
	movl	52(%rsp), %ebx
	leal	1(%rdx), %ecx
	testl	%ebx, %ebx
	jne	.L21
	cmpl	$2, %edx
	jle	.L33
	movl	%ecx, %eax
	pxor	%xmm0, %xmm0
	shrl	$2, %eax
	salq	$4, %rax
	addq	%rbp, %rax
.L23:
	movdqu	(%r12), %xmm3
	addq	$16, %r12
	paddd	%xmm3, %xmm0
	cmpq	%r12, %rax
	jne	.L23
	movdqa	%xmm0, %xmm1
	movl	%ecx, %eax
	psrldq	$8, %xmm1
	andl	$-4, %eax
	andl	$3, %ecx
	paddd	%xmm1, %xmm0
	movdqa	%xmm0, %xmm1
	psrldq	$4, %xmm1
	paddd	%xmm1, %xmm0
	movd	%xmm0, %ebx
	je	.L28
.L22:
	movslq	%eax, %rsi
	leaq	0(,%rsi,4), %rcx
	addl	0(%rbp,%rsi,4), %ebx
	leal	1(%rax), %esi
	cmpl	%edx, %esi
	jg	.L28
	addl	$2, %eax
	addl	4(%rbp,%rcx), %ebx
	cmpl	%eax, %edx
	jl	.L28
	addl	8(%rbp,%rcx), %ebx
.L28:
	movq	%rbp, %rdi
	call	free@PLT
	xorl	%eax, %eax
	jmp	.L20
.L10:
	call	__ctype_b_loc@PLT
	xorl	%ebx, %ebx
	movq	(%rax), %rdx
	movsbq	%r14b, %rax
	testb	$8, 1(%rdx,%rax,2)
	je	.L18
	.p2align 4,,10
	.p2align 3
.L17:
	leal	(%rbx,%rbx,4), %eax
	addq	$1, %r13
	leal	-48(%r14,%rax,2), %ebx
	movsbl	0(%r13), %r14d
	movsbq	%r14b, %rax
	testb	$8, 1(%rdx,%rax,2)
	jne	.L17
.L18:
	movl	$1, %eax
.L20:
	movq	24(%rsp), %rsi
	movq	32(%rsp), %rdi
	movl	%ebx, (%rsi)
	movl	%eax, (%rdi)
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L43
	addq	$72, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movq	%r13, %rax
	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
.L21:
	.cfi_restore_state
	cmpl	$2, %edx
	jle	.L34
	movl	%ecx, %eax
	movdqa	.LC0(%rip), %xmm2
	pxor	%xmm1, %xmm1
	shrl	$2, %eax
	salq	$4, %rax
	addq	%rbp, %rax
.L26:
	movdqu	(%r12), %xmm0
	addq	$16, %r12
	psrad	$1, %xmm0
	paddd	%xmm2, %xmm0
	paddd	%xmm0, %xmm1
	cmpq	%rax, %r12
	jne	.L26
	movdqa	%xmm1, %xmm0
	movl	%ecx, %eax
	psrldq	$8, %xmm0
	andl	$-4, %eax
	andl	$3, %ecx
	paddd	%xmm0, %xmm1
	movdqa	%xmm1, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm1
	movd	%xmm1, %ebx
	je	.L28
.L25:
	movslq	%eax, %rcx
	leaq	0(,%rcx,4), %rsi
	movl	0(%rbp,%rcx,4), %ecx
	sarl	%ecx
	leal	1(%rbx,%rcx), %ebx
	leal	1(%rax), %ecx
	cmpl	%ecx, %edx
	jl	.L28
	movl	4(%rbp,%rsi), %ecx
	addl	$2, %eax
	sarl	%ecx
	leal	1(%rbx,%rcx), %ebx
	cmpl	%eax, %edx
	jl	.L28
	movl	8(%rbp,%rsi), %eax
	movq	%rbp, %rdi
	sarl	%eax
	leal	1(%rbx,%rax), %ebx
	call	free@PLT
	xorl	%eax, %eax
	jmp	.L20
.L34:
	xorl	%ebx, %ebx
	xorl	%eax, %eax
	jmp	.L25
.L33:
	xorl	%eax, %eax
	jmp	.L22
.L43:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE43:
	.size	calc, .-calc
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%d"
.LC2:
	.string	"%s"
.LC3:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB44:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC1(%rip), %rdi
	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
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 12(%rsp)
	testl	%eax, %eax
	jle	.L45
	leaq	buf(%rip), %r15
	leaq	.LC2(%rip), %r14
	leaq	20(%rsp), %r13
	leaq	16(%rsp), %r12
	leaq	1(%r15), %rbp
	leaq	.LC3(%rip), %rbx
	.p2align 4,,10
	.p2align 3
.L46:
	movq	%r15, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	%r13, %rdx
	movq	%r12, %rsi
	movq	%rbp, %rdi
	call	calc
	movl	16(%rsp), %edx
	movq	%rbx, %rsi
	xorl	%eax, %eax
	movl	$1, %edi
	call	__printf_chk@PLT
	movl	12(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 12(%rsp)
	testl	%eax, %eax
	jg	.L46
.L45:
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L50
	addq	$40, %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
.L50:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE44:
	.size	main, .-main
	.globl	buf
	.bss
	.align 32
	.type	buf, @object
	.size	buf, 10003
buf:
	.zero	10003
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	1
	.long	1
	.long	1
	.long	1
	.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
	.type	cmp, @function
cmp:
.LFB41:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE41:
	.size	cmp, .-cmp
	.p2align 4
	.globl	pair
	.type	pair, @function
pair:
.LFB42:
	.cfi_startproc
	endbr64
	movq	%rdi, %rax
	xorl	%ecx, %ecx
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L4:
	cmpb	$93, %dl
	je	.L8
.L5:
	addq	$1, %rax
.L7:
	movzbl	(%rax), %edx
	cmpb	$91, %dl
	jne	.L4
	addl	$1, %ecx
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L8:
	subl	$1, %ecx
	jnb	.L5
	ret
	.cfi_endproc
.LFE42:
	.size	pair, .-pair
	.p2align 4
	.globl	calc
	.type	calc, @function
calc:
.LFB43:
	.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
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movsbl	(%rdi), %r14d
	movq	%rsi, 24(%rsp)
	movq	%rdx, 32(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	cmpb	$91, %r14b
	jne	.L10
	movq	%rdi, %rdx
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L15:
	leaq	1(%rdx), %rax
	xorl	%ecx, %ecx
	jmp	.L14
	.p2align 4,,10
	.p2align 3
.L11:
	cmpb	$93, %dl
	je	.L42
.L12:
	addq	$1, %rax
.L14:
	movzbl	(%rax), %edx
	cmpb	$91, %dl
	jne	.L11
	addl	$1, %ecx
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L42:
	subl	$1, %ecx
	jnb	.L12
	addl	$1, %ebx
	cmpb	$91, 1(%rax)
	leaq	1(%rax), %rdx
	je	.L15
	movslq	%ebx, %r15
	movl	$4, %esi
	leaq	52(%rsp), %r14
	movq	%r15, %rdi
	movq	%r15, 40(%rsp)
	call	calloc@PLT
	movq	%rax, %rbp
	movq	%rax, %r12
	leaq	(%rax,%r15,4), %rax
	movq	%rax, 16(%rsp)
	movq	%rbp, %rcx
	leaq	48(%rsp), %r15
.L19:
	leaq	1(%r13), %rdi
	movq	%r14, %rdx
	movq	%r15, %rsi
	movq	%rcx, 8(%rsp)
	call	calc
	movq	8(%rsp), %rcx
	leaq	1(%rax), %r13
	movl	48(%rsp), %eax
	addq	$4, %rcx
	movl	%eax, -4(%rcx)
	cmpq	16(%rsp), %rcx
	jne	.L19
	movq	40(%rsp), %rsi
	movl	$4, %edx
	sarl	%ebx
	movq	%rbp, %rdi
	leaq	cmp(%rip), %rcx
	call	qsort@PLT
	movl	%ebx, %edx
	movl	52(%rsp), %ebx
	leal	1(%rdx), %ecx
	testl	%ebx, %ebx
	jne	.L21
	cmpl	$2, %edx
	jle	.L33
	movl	%ecx, %eax
	pxor	%xmm0, %xmm0
	shrl	$2, %eax
	salq	$4, %rax
	addq	%rbp, %rax
.L23:
	movdqu	(%r12), %xmm3
	addq	$16, %r12
	paddd	%xmm3, %xmm0
	cmpq	%r12, %rax
	jne	.L23
	movdqa	%xmm0, %xmm1
	movl	%ecx, %eax
	psrldq	$8, %xmm1
	andl	$-4, %eax
	andl	$3, %ecx
	paddd	%xmm1, %xmm0
	movdqa	%xmm0, %xmm1
	psrldq	$4, %xmm1
	paddd	%xmm1, %xmm0
	movd	%xmm0, %ebx
	je	.L28
.L22:
	movslq	%eax, %rsi
	leaq	0(,%rsi,4), %rcx
	addl	0(%rbp,%rsi,4), %ebx
	leal	1(%rax), %esi
	cmpl	%edx, %esi
	jg	.L28
	addl	$2, %eax
	addl	4(%rbp,%rcx), %ebx
	cmpl	%eax, %edx
	jl	.L28
	addl	8(%rbp,%rcx), %ebx
.L28:
	movq	%rbp, %rdi
	call	free@PLT
	xorl	%eax, %eax
	jmp	.L20
.L10:
	call	__ctype_b_loc@PLT
	xorl	%ebx, %ebx
	movq	(%rax), %rdx
	movsbq	%r14b, %rax
	testb	$8, 1(%rdx,%rax,2)
	je	.L18
	.p2align 4,,10
	.p2align 3
.L17:
	leal	(%rbx,%rbx,4), %eax
	addq	$1, %r13
	leal	-48(%r14,%rax,2), %ebx
	movsbl	0(%r13), %r14d
	movsbq	%r14b, %rax
	testb	$8, 1(%rdx,%rax,2)
	jne	.L17
.L18:
	movl	$1, %eax
.L20:
	movq	24(%rsp), %rsi
	movq	32(%rsp), %rdi
	movl	%ebx, (%rsi)
	movl	%eax, (%rdi)
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L43
	addq	$72, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movq	%r13, %rax
	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
.L21:
	.cfi_restore_state
	cmpl	$2, %edx
	jle	.L34
	movl	%ecx, %eax
	movdqa	.LC0(%rip), %xmm2
	pxor	%xmm1, %xmm1
	shrl	$2, %eax
	salq	$4, %rax
	addq	%rbp, %rax
.L26:
	movdqu	(%r12), %xmm0
	addq	$16, %r12
	psrad	$1, %xmm0
	paddd	%xmm2, %xmm0
	paddd	%xmm0, %xmm1
	cmpq	%rax, %r12
	jne	.L26
	movdqa	%xmm1, %xmm0
	movl	%ecx, %eax
	psrldq	$8, %xmm0
	andl	$-4, %eax
	andl	$3, %ecx
	paddd	%xmm0, %xmm1
	movdqa	%xmm1, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm1
	movd	%xmm1, %ebx
	je	.L28
.L25:
	movslq	%eax, %rcx
	leaq	0(,%rcx,4), %rsi
	movl	0(%rbp,%rcx,4), %ecx
	sarl	%ecx
	leal	1(%rbx,%rcx), %ebx
	leal	1(%rax), %ecx
	cmpl	%ecx, %edx
	jl	.L28
	movl	4(%rbp,%rsi), %ecx
	addl	$2, %eax
	sarl	%ecx
	leal	1(%rbx,%rcx), %ebx
	cmpl	%eax, %edx
	jl	.L28
	movl	8(%rbp,%rsi), %eax
	movq	%rbp, %rdi
	sarl	%eax
	leal	1(%rbx,%rax), %ebx
	call	free@PLT
	xorl	%eax, %eax
	jmp	.L20
.L34:
	xorl	%ebx, %ebx
	xorl	%eax, %eax
	jmp	.L25
.L33:
	xorl	%eax, %eax
	jmp	.L22
.L43:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE43:
	.size	calc, .-calc
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%d"
.LC2:
	.string	"%s"
.LC3:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB44:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC1(%rip), %rdi
	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
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 12(%rsp)
	testl	%eax, %eax
	jle	.L45
	leaq	buf(%rip), %r15
	leaq	.LC2(%rip), %r14
	leaq	20(%rsp), %r13
	leaq	16(%rsp), %r12
	leaq	1(%r15), %rbp
	leaq	.LC3(%rip), %rbx
	.p2align 4,,10
	.p2align 3
.L46:
	movq	%r15, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	%r13, %rdx
	movq	%r12, %rsi
	movq	%rbp, %rdi
	call	calc
	movl	16(%rsp), %edx
	movq	%rbx, %rsi
	xorl	%eax, %eax
	movl	$1, %edi
	call	__printf_chk@PLT
	movl	12(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 12(%rsp)
	testl	%eax, %eax
	jg	.L46
.L45:
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L50
	addq	$40, %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
.L50:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE44:
	.size	main, .-main
	.globl	buf
	.bss
	.align 32
	.type	buf, @object
	.size	buf, 10003
buf:
	.zero	10003
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	1
	.long	1
	.long	1
	.long	1
	.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:

// Aizu 1188: Hierarchical Democracy
// 2017.9.18 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char buf[10003];

int cmp(int *a, int *b) { return *a - *b; }

char *pair(char *p)
{
	int n = 0;
	while (1) {
		if (*p == '[') n++;
		else if (*p == ']') { n--; if (n < 0) break; }
		p++;
	}
	return p;
}

char *calc(char *p, int *v, int *half)
{
	int n, i, s, h;
	char *pp;
	int *t;

	pp = p, n = 0; while (*p == '[') p++, p = pair(p), p++, n++;
	if (n == 0) {
		s = 0; while (isdigit(*p)) s = s * 10 + *p++ - '0';
		*v = s, *half = 1; return p;
	}
	t = calloc(n, sizeof(int));
	p = pp; for (i = 0; i < n; i++) p++, p = calc(p, &s, &h), p++, t[i] = s;
	qsort(t, n, sizeof(int), cmp);
	for (s = 0, n >>= 1, i = 0; i <= n; i++) if (h) s += 1 + (t[i] >> 1); else s += t[i];
	free(t);
	*v = s, *half = 0;
	return p;
}

int main()
{
	int n, ans, t;
	char *p;

	scanf("%d", &n);
	while (n-- > 0) {
		scanf("%s", p = buf); p++;
		calc(p, &ans, &t);
		printf("%d\n", ans);
	}
	return 0;
}
6
[[133][4567][89]]
[[5][3][7][3][9]]
[[[99][59][63][85][51]][[1539][7995][467]][[51][57][79][99][3][91][59]]]
[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]]
[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]]
[[8231][3721][203][3271][8843]]
 6
[[133][4567][89]]
[[5][3][7][3][9]]
[[[95][59][63][85][51]][[1539][7995][467]][[51][97][79][99][3][91][59]]]
[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]]
[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]]
[[8231][3721][203][3271][8843]]
 6
[[133][4567][89]]
[[5][3][7][3][9]]
[[[99][59][73][85][51]][[1539][7995][467]][[51][57][79][99][3][91][59]]]
[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]]
[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]]
[[8231][3721][203][3271][8843]]
 6
[[123][4567][89]]
[[5][3][6][3][9]]
[[[99][59][63][85][51]][[1539][7995][467]][[51][57][79][99][3][91][59]]]
[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][94][5][69][31]][[99][59][65][73][31]]]
[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]]
[[8231][3721][203][3271][8853]]
 6
[[123][4567][89]]
[[5][3][7][3][9]]
[[[99][59][73][85][51]][[1539][7995][467]][[51][57][79][99][3][91][59]]]
[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]]
[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]]
[[8231][3721][203][3271][8843]]
 6
[[133][4667][89]]
[[5][3][7][3][9]]
[[[99][59][63][85][51]][[1559][7995][467]][[51][57][79][99][3][91][39]]]
[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]]
[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]]
[[8231][3721][203][3271][8843]]
 6
[[133][4568][89]]
[[5][3][7][3][9]]
[[[99][59][63][85][51]][[1539][7995][467]][[51][57][79][99][3][91][59]]]
[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]]
[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]]
[[8231][3721][203][3371][8852]]
 6
[[133][4567][89]]
[[5][3][7][3][9]]
[[[95][59][63][85][51]][[1539][7995][467]][[51][97][79][99][3][91][59]]]
[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]]
[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]]
[[8241][3731][203][3271][8943]]
 6
[[133][4567][89]]
[[5][3][7][3][9]]
[[[99][59][63][85][51]][[1539][7995][467]][[51][57][79][99][3][91][59]]]
[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][79][29]][[47][95][5][69][31]][[99][59][65][73][31]]]
[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]]
[[8231][3711][203][3271][8853]]
 6
[[133][4667][89]]
[[5][3][7][3][9]]
[[[99][59][63][85][51]][[1559][7995][467]][[51][57][79][99][3][91][39]]]
[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]]
[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]]
[[8221][3731][203][3271][8843]]

112
7
175
95
21
3599
 112
7
186
95
21
3599
 112
7
180
95
21
3599
 107
7
175
95
21
3599
 107
7
180
95
21
3599
 112
7
165
95
21
3599
 112
7
175
95
21
3649
 112
7
186
95
21
3604
 112
7
175
95
21
3594
 112
7
165
95
21
3604

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

```c
// Aizu 1188: Hierarchical Democracy
// 2017.9.18 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char buf[10003];

int cmp(int *a, int *b) { return *a - *b; }

char *pair(char *p)
{
	int n = 0;
	while (1) {
		if (*p == '[') n++;
		else if (*p == ']') { n--; if (n < 0) break; }
		p++;
	}
	return p;
}

char *calc(char *p, int *v, int *half)
{
	int n, i, s, h;
	char *pp;
	int *t;

	pp = p, n = 0; while (*p == '[') p++, p = pair(p), p++, n++;
	if (n == 0) {
		s = 0; while (isdigit(*p)) s = s * 10 + *p++ - '0';
		*v = s, *half = 1; return p;
	}
	t = calloc(n, sizeof(int));
	p = pp; for (i = 0; i < n; i++) p++, p = calc(p, &s, &h), p++, t[i] = s;
	qsort(t, n, sizeof(int), cmp);
	for (s = 0, n >>= 1, i = 0; i <= n; i++) if (h) s += 1 + (t[i] >> 1); else s += t[i];
	free(t);
	*v = s, *half = 0;
	return p;
}

int main()
{
	int n, ans, t;
	char *p;

	scanf("%d", &n);
	while (n-- > 0) {
		scanf("%s", p = buf); p++;
		calc(p, &ans, &t);
		printf("%d\n", ans);
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	buf
	.bss
	.align 32
	.type	buf, @object
	.size	buf, 10003
buf:
	.zero	10003
	.text
	.globl	cmp
	.type	cmp, @function
cmp:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	cmp, .-cmp
	.globl	pair
	.type	pair, @function
pair:
.LFB7:
	.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)
	movl	$0, -4(%rbp)
.L7:
	movq	-24(%rbp), %rax
	movzbl	(%rax), %eax
	cmpb	$91, %al
	jne	.L4
	addl	$1, -4(%rbp)
	jmp	.L5
.L4:
	movq	-24(%rbp), %rax
	movzbl	(%rax), %eax
	cmpb	$93, %al
	jne	.L5
	subl	$1, -4(%rbp)
	cmpl	$0, -4(%rbp)
	js	.L10
.L5:
	addq	$1, -24(%rbp)
	jmp	.L7
.L10:
	nop
	movq	-24(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	pair, .-pair
	.globl	calc
	.type	calc, @function
calc:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$80, %rsp
	movq	%rdi, -56(%rbp)
	movq	%rsi, -64(%rbp)
	movq	%rdx, -72(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	-56(%rbp), %rax
	movq	%rax, -24(%rbp)
	movl	$0, -32(%rbp)
	jmp	.L12
.L13:
	addq	$1, -56(%rbp)
	movq	-56(%rbp), %rax
	movq	%rax, %rdi
	call	pair
	movq	%rax, -56(%rbp)
	addq	$1, -56(%rbp)
	addl	$1, -32(%rbp)
.L12:
	movq	-56(%rbp), %rax
	movzbl	(%rax), %eax
	cmpb	$91, %al
	je	.L13
	cmpl	$0, -32(%rbp)
	jne	.L14
	movl	$0, -40(%rbp)
	jmp	.L15
.L16:
	movl	-40(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %ecx
	movq	-56(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -56(%rbp)
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	addl	%ecx, %eax
	subl	$48, %eax
	movl	%eax, -40(%rbp)
.L15:
	call	__ctype_b_loc@PLT
	movq	(%rax), %rdx
	movq	-56(%rbp), %rax
	movzbl	(%rax), %eax
	movsbq	%al, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	movzwl	(%rax), %eax
	movzwl	%ax, %eax
	andl	$2048, %eax
	testl	%eax, %eax
	jne	.L16
	movl	-40(%rbp), %edx
	movq	-64(%rbp), %rax
	movl	%edx, (%rax)
	movq	-72(%rbp), %rax
	movl	$1, (%rax)
	movq	-56(%rbp), %rax
	jmp	.L24
.L14:
	movl	-32(%rbp), %eax
	cltq
	movl	$4, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -16(%rbp)
	movq	-24(%rbp), %rax
	movq	%rax, -56(%rbp)
	movl	$0, -28(%rbp)
	jmp	.L18
.L19:
	addq	$1, -56(%rbp)
	leaq	-36(%rbp), %rdx
	leaq	-40(%rbp), %rcx
	movq	-56(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	calc
	movq	%rax, -56(%rbp)
	addq	$1, -56(%rbp)
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movl	-40(%rbp), %eax
	movl	%eax, (%rdx)
	addl	$1, -28(%rbp)
.L18:
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jl	.L19
	movl	-32(%rbp), %eax
	movslq	%eax, %rsi
	movq	-16(%rbp), %rax
	leaq	cmp(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -40(%rbp)
	sarl	-32(%rbp)
	movl	$0, -28(%rbp)
	jmp	.L20
.L23:
	movl	-36(%rbp), %eax
	testl	%eax, %eax
	je	.L21
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	sarl	%eax
	leal	1(%rax), %edx
	movl	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -40(%rbp)
	jmp	.L22
.L21:
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -40(%rbp)
.L22:
	addl	$1, -28(%rbp)
.L20:
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jle	.L23
	movq	-16(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	-40(%rbp), %edx
	movq	-64(%rbp), %rax
	movl	%edx, (%rax)
	movq	-72(%rbp), %rax
	movl	$0, (%rax)
	movq	-56(%rbp), %rax
.L24:
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	calc, .-calc
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-28(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L27
.L28:
	leaq	buf(%rip), %rax
	movq	%rax, -16(%rbp)
	movq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -16(%rbp)
	leaq	-20(%rbp), %rdx
	leaq	-24(%rbp), %rcx
	movq	-16(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	calc
	movl	-24(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L27:
	movl	-28(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -28(%rbp)
	testl	%eax, %eax
	jg	.L28
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.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	buf
	.bss
	.align 32
	.type	buf, @object
	.size	buf, 10003
buf:
	.zero	10003
	.text
	.globl	cmp
	.type	cmp, @function
cmp:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	cmp, .-cmp
	.globl	pair
	.type	pair, @function
pair:
.LFB7:
	.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)
	movl	$0, -4(%rbp)
.L7:
	movq	-24(%rbp), %rax
	movzbl	(%rax), %eax
	cmpb	$91, %al
	jne	.L4
	addl	$1, -4(%rbp)
	jmp	.L5
.L4:
	movq	-24(%rbp), %rax
	movzbl	(%rax), %eax
	cmpb	$93, %al
	jne	.L5
	subl	$1, -4(%rbp)
	cmpl	$0, -4(%rbp)
	js	.L10
.L5:
	addq	$1, -24(%rbp)
	jmp	.L7
.L10:
	nop
	movq	-24(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	pair, .-pair
	.globl	calc
	.type	calc, @function
calc:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$80, %rsp
	movq	%rdi, -56(%rbp)
	movq	%rsi, -64(%rbp)
	movq	%rdx, -72(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	-56(%rbp), %rax
	movq	%rax, -24(%rbp)
	movl	$0, -32(%rbp)
	jmp	.L12
.L13:
	addq	$1, -56(%rbp)
	movq	-56(%rbp), %rax
	movq	%rax, %rdi
	call	pair
	movq	%rax, -56(%rbp)
	addq	$1, -56(%rbp)
	addl	$1, -32(%rbp)
.L12:
	movq	-56(%rbp), %rax
	movzbl	(%rax), %eax
	cmpb	$91, %al
	je	.L13
	cmpl	$0, -32(%rbp)
	jne	.L14
	movl	$0, -40(%rbp)
	jmp	.L15
.L16:
	movl	-40(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %ecx
	movq	-56(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -56(%rbp)
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	addl	%ecx, %eax
	subl	$48, %eax
	movl	%eax, -40(%rbp)
.L15:
	call	__ctype_b_loc@PLT
	movq	(%rax), %rdx
	movq	-56(%rbp), %rax
	movzbl	(%rax), %eax
	movsbq	%al, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	movzwl	(%rax), %eax
	movzwl	%ax, %eax
	andl	$2048, %eax
	testl	%eax, %eax
	jne	.L16
	movl	-40(%rbp), %edx
	movq	-64(%rbp), %rax
	movl	%edx, (%rax)
	movq	-72(%rbp), %rax
	movl	$1, (%rax)
	movq	-56(%rbp), %rax
	jmp	.L24
.L14:
	movl	-32(%rbp), %eax
	cltq
	movl	$4, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -16(%rbp)
	movq	-24(%rbp), %rax
	movq	%rax, -56(%rbp)
	movl	$0, -28(%rbp)
	jmp	.L18
.L19:
	addq	$1, -56(%rbp)
	leaq	-36(%rbp), %rdx
	leaq	-40(%rbp), %rcx
	movq	-56(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	calc
	movq	%rax, -56(%rbp)
	addq	$1, -56(%rbp)
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movl	-40(%rbp), %eax
	movl	%eax, (%rdx)
	addl	$1, -28(%rbp)
.L18:
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jl	.L19
	movl	-32(%rbp), %eax
	movslq	%eax, %rsi
	movq	-16(%rbp), %rax
	leaq	cmp(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -40(%rbp)
	sarl	-32(%rbp)
	movl	$0, -28(%rbp)
	jmp	.L20
.L23:
	movl	-36(%rbp), %eax
	testl	%eax, %eax
	je	.L21
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	sarl	%eax
	leal	1(%rax), %edx
	movl	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -40(%rbp)
	jmp	.L22
.L21:
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -40(%rbp)
.L22:
	addl	$1, -28(%rbp)
.L20:
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jle	.L23
	movq	-16(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	-40(%rbp), %edx
	movq	-64(%rbp), %rax
	movl	%edx, (%rax)
	movq	-72(%rbp), %rax
	movl	$0, (%rax)
	movq	-56(%rbp), %rax
.L24:
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	calc, .-calc
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-28(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L27
.L28:
	leaq	buf(%rip), %rax
	movq	%rax, -16(%rbp)
	movq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -16(%rbp)
	leaq	-20(%rbp), %rdx
	leaq	-24(%rbp), %rcx
	movq	-16(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	calc
	movl	-24(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L27:
	movl	-28(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -28(%rbp)
	testl	%eax, %eax
	jg	.L28
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.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:
