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 asc(const void* a, const void* b)
{
	if (*(long long int*)a > * (long long int*)b)return 1;
	if (*(long long int*)a < *(long long int*)b)return -1;
	return 0;
}
int main()
{
	long long int w, h;
	scanf("%lld %lld", &w, &h);
	long long int i, j;
	long long int p[100005], q[100005];
	for (i = 0; i < w; i++)
		scanf("%lld", &p[i]);
	for (j = 0; j < h; j++)
		scanf("%lld", &q[j]);
	qsort(p, w, sizeof(long long int), asc);
	qsort(q, h, sizeof(long long int), asc);
	long long int ans = 0;
	i = j = 0;
	for (;;)
	{
		if (i == w)
		{
			ans += q[j];
			j++;
		}
		else if (j == h)
		{
			ans += p[i];
			i++;
		}
		else
		{
			if (q[j] < p[i])
			{
				ans += q[j] * (w - i + 1);
				j++;
			}
			else
			{
				ans += p[i] * (h - j + 1);
				i++;
			}
		}
		if (i == w && j == h)
			break;
	}
	printf("%lld\n", ans);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	asc
	.type	asc, @function
asc:
.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
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jle	.L2
	movl	$1, %eax
	jmp	.L3
.L2:
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jge	.L4
	movl	$-1, %eax
	jmp	.L3
.L4:
	movl	$0, %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	asc, .-asc
	.section	.rodata
.LC0:
	.string	"%lld %lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld\n"
	.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
	leaq	-1597440(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2704, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-1600128(%rbp), %rdx
	leaq	-1600136(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -1600120(%rbp)
	jmp	.L6
.L7:
	leaq	-1600096(%rbp), %rdx
	movq	-1600120(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -1600120(%rbp)
.L6:
	movq	-1600136(%rbp), %rax
	cmpq	%rax, -1600120(%rbp)
	jl	.L7
	movq	$0, -1600112(%rbp)
	jmp	.L8
.L9:
	leaq	-800048(%rbp), %rdx
	movq	-1600112(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -1600112(%rbp)
.L8:
	movq	-1600128(%rbp), %rax
	cmpq	%rax, -1600112(%rbp)
	jl	.L9
	movq	-1600136(%rbp), %rax
	movq	%rax, %rsi
	leaq	-1600096(%rbp), %rax
	leaq	asc(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	-1600128(%rbp), %rax
	movq	%rax, %rsi
	leaq	-800048(%rbp), %rax
	leaq	asc(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	$0, -1600104(%rbp)
	movq	$0, -1600112(%rbp)
	movq	-1600112(%rbp), %rax
	movq	%rax, -1600120(%rbp)
.L16:
	movq	-1600136(%rbp), %rax
	cmpq	%rax, -1600120(%rbp)
	jne	.L10
	movq	-1600112(%rbp), %rax
	movq	-800048(%rbp,%rax,8), %rax
	addq	%rax, -1600104(%rbp)
	addq	$1, -1600112(%rbp)
	jmp	.L11
.L10:
	movq	-1600128(%rbp), %rax
	cmpq	%rax, -1600112(%rbp)
	jne	.L12
	movq	-1600120(%rbp), %rax
	movq	-1600096(%rbp,%rax,8), %rax
	addq	%rax, -1600104(%rbp)
	addq	$1, -1600120(%rbp)
	jmp	.L11
.L12:
	movq	-1600112(%rbp), %rax
	movq	-800048(%rbp,%rax,8), %rdx
	movq	-1600120(%rbp), %rax
	movq	-1600096(%rbp,%rax,8), %rax
	cmpq	%rax, %rdx
	jge	.L13
	movq	-1600112(%rbp), %rax
	movq	-800048(%rbp,%rax,8), %rdx
	movq	-1600136(%rbp), %rax
	subq	-1600120(%rbp), %rax
	addq	$1, %rax
	imulq	%rdx, %rax
	addq	%rax, -1600104(%rbp)
	addq	$1, -1600112(%rbp)
	jmp	.L11
.L13:
	movq	-1600120(%rbp), %rax
	movq	-1600096(%rbp,%rax,8), %rdx
	movq	-1600128(%rbp), %rax
	subq	-1600112(%rbp), %rax
	addq	$1, %rax
	imulq	%rdx, %rax
	addq	%rax, -1600104(%rbp)
	addq	$1, -1600120(%rbp)
.L11:
	movq	-1600136(%rbp), %rax
	cmpq	%rax, -1600120(%rbp)
	jne	.L16
	movq	-1600128(%rbp), %rax
	cmpq	%rax, -1600112(%rbp)
	je	.L20
	jmp	.L16
.L20:
	nop
	movq	-1600104(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	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	asc
	.type	asc, @function
asc:
.LFB39:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rdx
	movl	$1, %eax
	cmpq	%rdx, (%rdi)
	jg	.L1
	setl	%al
	movzbl	%al, %eax
	negl	%eax
.L1:
	ret
	.cfi_endproc
.LFE39:
	.size	asc, .-asc
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%lld %lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld\n"
	.section	.text.unlikely,"ax",@progbits
.LCOLDB3:
	.section	.text.startup,"ax",@progbits
.LHOTB3:
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.cfi_startproc
	endbr64
	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
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	-1597440(%rsp), %r11
	.cfi_def_cfa 11, 1597488
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2672, %rsp
	.cfi_def_cfa_offset 1600160
	leaq	.LC0(%rip), %rdi
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %r13
	movq	%fs:40, %rax
	movq	%rax, 1600104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdx
	movq	%rsp, %rsi
	leaq	16(%rsp), %r14
	movq	%r14, %rbp
	call	__isoc99_scanf@PLT
	cmpq	$0, (%rsp)
	jle	.L10
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%rbp, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addq	$1, %rbx
	call	__isoc99_scanf@PLT
	addq	$8, %rbp
	cmpq	%rbx, (%rsp)
	jg	.L9
.L10:
	leaq	800064(%rsp), %rbx
	xorl	%ebp, %ebp
	cmpq	$0, 8(%rsp)
	movq	%rbx, %r12
	leaq	.LC1(%rip), %r13
	jle	.L8
	.p2align 4,,10
	.p2align 3
.L12:
	movq	%r12, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addq	$1, %rbp
	call	__isoc99_scanf@PLT
	addq	$8, %r12
	cmpq	%rbp, 8(%rsp)
	jg	.L12
.L8:
	movq	(%rsp), %rsi
	leaq	asc(%rip), %r12
	movl	$8, %edx
	movq	%r14, %rdi
	movq	%r12, %rcx
	call	qsort@PLT
	movq	8(%rsp), %rsi
	movq	%rbx, %rdi
	movq	%r12, %rcx
	movl	$8, %edx
	call	qsort@PLT
	movq	(%rsp), %r9
	movq	8(%rsp), %rdi
	xorl	%eax, %eax
	xorl	%r8d, %r8d
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L11:
	cmpq	%rdx, %r9
	jne	.L17
	movq	800064(%rsp,%rax,8), %rdx
	addq	$1, %rax
	addq	%r8, %rdx
	movq	%rdx, %r8
	cmpq	%rax, %rdi
	jne	.L32
.L20:
	xorl	%eax, %eax
	movq	%r8, %rdx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	1600104(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L36
	addq	$1600112, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	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
.L37:
	.cfi_restore_state
	addq	$1, %rdx
	addq	%rcx, %r8
	cmpq	%rdx, %r9
	je	.L20
.L17:
	movq	16(%rsp,%rdx,8), %rcx
	cmpq	%rax, %rdi
	je	.L37
	movq	800064(%rsp,%rax,8), %rsi
	cmpq	%rcx, %rsi
	jge	.L22
	movq	%r9, %rcx
	addq	$1, %rax
	subq	%rdx, %rcx
	addq	$1, %rcx
	imulq	%rsi, %rcx
	addq	%rcx, %r8
	jmp	.L11
	.p2align 4,,10
	.p2align 3
.L22:
	movq	%rdi, %rsi
	addq	$1, %rdx
	subq	%rax, %rsi
	addq	$1, %rsi
	imulq	%rsi, %rcx
	addq	%rcx, %r8
	jmp	.L11
.L36:
	call	__stack_chk_fail@PLT
	.cfi_endproc
	.section	.text.unlikely
	.cfi_startproc
	.type	main.cold, @function
main.cold:
.LFSB40:
.L32:
	.cfi_def_cfa_offset 1600160
	.cfi_offset 3, -48
	.cfi_offset 6, -40
	.cfi_offset 12, -32
	.cfi_offset 13, -24
	.cfi_offset 14, -16
	subq	%rax, %rdi
	cmpq	$1, %rdi
	je	.L24
	movq	%rdi, %r8
	leaq	(%rbx,%rax,8), %rsi
	pxor	%xmm0, %xmm0
	xorl	%ecx, %ecx
	shrq	%r8
.L14:
	movq	%rcx, %r9
	addq	$1, %rcx
	salq	$4, %r9
	movdqu	(%rsi,%r9), %xmm1
	paddq	%xmm1, %xmm0
	cmpq	%rcx, %r8
	jne	.L14
	movdqa	%xmm0, %xmm1
	psrldq	$8, %xmm1
	paddq	%xmm1, %xmm0
	movq	%xmm0, %r8
	addq	%rdx, %r8
	movq	%rdi, %rdx
	andq	$-2, %rdx
	addq	%rdx, %rax
	cmpq	%rdi, %rdx
	je	.L20
.L24:
	addq	800064(%rsp,%rax,8), %r8
	jmp	.L20
	.cfi_endproc
.LFE40:
	.section	.text.startup
	.size	main, .-main
	.section	.text.unlikely
	.size	main.cold, .-main.cold
.LCOLDE3:
	.section	.text.startup
.LHOTE3:
	.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	asc
	.type	asc, @function
asc:
.LFB39:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rdx
	movl	$1, %eax
	cmpq	%rdx, (%rdi)
	jg	.L1
	setl	%al
	movzbl	%al, %eax
	negl	%eax
.L1:
	ret
	.cfi_endproc
.LFE39:
	.size	asc, .-asc
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%lld %lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld\n"
	.section	.text.unlikely,"ax",@progbits
.LCOLDB3:
	.section	.text.startup,"ax",@progbits
.LHOTB3:
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.cfi_startproc
	endbr64
	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
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	-1597440(%rsp), %r11
	.cfi_def_cfa 11, 1597488
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2672, %rsp
	.cfi_def_cfa_offset 1600160
	leaq	.LC0(%rip), %rdi
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %r13
	movq	%fs:40, %rax
	movq	%rax, 1600104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdx
	movq	%rsp, %rsi
	leaq	16(%rsp), %r14
	movq	%r14, %rbp
	call	__isoc99_scanf@PLT
	cmpq	$0, (%rsp)
	jle	.L10
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%rbp, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addq	$1, %rbx
	call	__isoc99_scanf@PLT
	addq	$8, %rbp
	cmpq	%rbx, (%rsp)
	jg	.L9
.L10:
	leaq	800064(%rsp), %rbx
	xorl	%ebp, %ebp
	cmpq	$0, 8(%rsp)
	movq	%rbx, %r12
	leaq	.LC1(%rip), %r13
	jle	.L8
	.p2align 4,,10
	.p2align 3
.L12:
	movq	%r12, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addq	$1, %rbp
	call	__isoc99_scanf@PLT
	addq	$8, %r12
	cmpq	%rbp, 8(%rsp)
	jg	.L12
.L8:
	movq	(%rsp), %rsi
	leaq	asc(%rip), %r12
	movl	$8, %edx
	movq	%r14, %rdi
	movq	%r12, %rcx
	call	qsort@PLT
	movq	8(%rsp), %rsi
	movq	%rbx, %rdi
	movq	%r12, %rcx
	movl	$8, %edx
	call	qsort@PLT
	movq	(%rsp), %r9
	movq	8(%rsp), %rdi
	xorl	%eax, %eax
	xorl	%r8d, %r8d
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L11:
	cmpq	%rdx, %r9
	jne	.L17
	movq	800064(%rsp,%rax,8), %rdx
	addq	$1, %rax
	addq	%r8, %rdx
	movq	%rdx, %r8
	cmpq	%rax, %rdi
	jne	.L32
.L20:
	xorl	%eax, %eax
	movq	%r8, %rdx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	1600104(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L36
	addq	$1600112, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	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
.L37:
	.cfi_restore_state
	addq	$1, %rdx
	addq	%rcx, %r8
	cmpq	%rdx, %r9
	je	.L20
.L17:
	movq	16(%rsp,%rdx,8), %rcx
	cmpq	%rax, %rdi
	je	.L37
	movq	800064(%rsp,%rax,8), %rsi
	cmpq	%rcx, %rsi
	jge	.L22
	movq	%r9, %rcx
	addq	$1, %rax
	subq	%rdx, %rcx
	addq	$1, %rcx
	imulq	%rsi, %rcx
	addq	%rcx, %r8
	jmp	.L11
	.p2align 4,,10
	.p2align 3
.L22:
	movq	%rdi, %rsi
	addq	$1, %rdx
	subq	%rax, %rsi
	addq	$1, %rsi
	imulq	%rsi, %rcx
	addq	%rcx, %r8
	jmp	.L11
.L36:
	call	__stack_chk_fail@PLT
	.cfi_endproc
	.section	.text.unlikely
	.cfi_startproc
	.type	main.cold, @function
main.cold:
.LFSB40:
.L32:
	.cfi_def_cfa_offset 1600160
	.cfi_offset 3, -48
	.cfi_offset 6, -40
	.cfi_offset 12, -32
	.cfi_offset 13, -24
	.cfi_offset 14, -16
	subq	%rax, %rdi
	cmpq	$1, %rdi
	je	.L24
	movq	%rdi, %r8
	leaq	(%rbx,%rax,8), %rsi
	pxor	%xmm0, %xmm0
	xorl	%ecx, %ecx
	shrq	%r8
.L14:
	movq	%rcx, %r9
	addq	$1, %rcx
	salq	$4, %r9
	movdqu	(%rsi,%r9), %xmm1
	paddq	%xmm1, %xmm0
	cmpq	%rcx, %r8
	jne	.L14
	movdqa	%xmm0, %xmm1
	psrldq	$8, %xmm1
	paddq	%xmm1, %xmm0
	movq	%xmm0, %r8
	addq	%rdx, %r8
	movq	%rdi, %rdx
	andq	$-2, %rdx
	addq	%rdx, %rax
	cmpq	%rdi, %rdx
	je	.L20
.L24:
	addq	800064(%rsp,%rax,8), %r8
	jmp	.L20
	.cfi_endproc
.LFE40:
	.section	.text.startup
	.size	main, .-main
	.section	.text.unlikely
	.size	main.cold, .-main.cold
.LCOLDE3:
	.section	.text.startup
.LHOTE3:
	.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 asc(const void* a, const void* b)
{
	if (*(long long int*)a > * (long long int*)b)return 1;
	if (*(long long int*)a < *(long long int*)b)return -1;
	return 0;
}
int main()
{
	long long int w, h;
	scanf("%lld %lld", &w, &h);
	long long int i, j;
	long long int p[100005], q[100005];
	for (i = 0; i < w; i++)
		scanf("%lld", &p[i]);
	for (j = 0; j < h; j++)
		scanf("%lld", &q[j]);
	qsort(p, w, sizeof(long long int), asc);
	qsort(q, h, sizeof(long long int), asc);
	long long int ans = 0;
	i = j = 0;
	for (;;)
	{
		if (i == w)
		{
			ans += q[j];
			j++;
		}
		else if (j == h)
		{
			ans += p[i];
			i++;
		}
		else
		{
			if (q[j] < p[i])
			{
				ans += q[j] * (w - i + 1);
				j++;
			}
			else
			{
				ans += p[i] * (h - j + 1);
				i++;
			}
		}
		if (i == w && j == h)
			break;
	}
	printf("%lld\n", ans);
	return 0;
}
4 3
2
6
8
1
2
9
3
 2 2
3
6
2
7
 0 3
2
6
8
1
2
9
3
 2 2
3
9
2
7
 0 3
2
6
13
1
2
9
3
 2 2
3
16
2
7
 2 2
3
32
2
7
 2 2
0
32
2
7
 0 3
1
6
8
1
2
9
0
 2 2
-1
32
2
7

64
 31
 16
 35
 21
 42
 58
 50
 15
 47

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 asc(const void* a, const void* b)
{
	if (*(long long int*)a > * (long long int*)b)return 1;
	if (*(long long int*)a < *(long long int*)b)return -1;
	return 0;
}
int main()
{
	long long int w, h;
	scanf("%lld %lld", &w, &h);
	long long int i, j;
	long long int p[100005], q[100005];
	for (i = 0; i < w; i++)
		scanf("%lld", &p[i]);
	for (j = 0; j < h; j++)
		scanf("%lld", &q[j]);
	qsort(p, w, sizeof(long long int), asc);
	qsort(q, h, sizeof(long long int), asc);
	long long int ans = 0;
	i = j = 0;
	for (;;)
	{
		if (i == w)
		{
			ans += q[j];
			j++;
		}
		else if (j == h)
		{
			ans += p[i];
			i++;
		}
		else
		{
			if (q[j] < p[i])
			{
				ans += q[j] * (w - i + 1);
				j++;
			}
			else
			{
				ans += p[i] * (h - j + 1);
				i++;
			}
		}
		if (i == w && j == h)
			break;
	}
	printf("%lld\n", ans);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	asc
	.type	asc, @function
asc:
.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
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jle	.L2
	movl	$1, %eax
	jmp	.L3
.L2:
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jge	.L4
	movl	$-1, %eax
	jmp	.L3
.L4:
	movl	$0, %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	asc, .-asc
	.section	.rodata
.LC0:
	.string	"%lld %lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld\n"
	.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
	leaq	-1597440(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2704, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-1600128(%rbp), %rdx
	leaq	-1600136(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -1600120(%rbp)
	jmp	.L6
.L7:
	leaq	-1600096(%rbp), %rdx
	movq	-1600120(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -1600120(%rbp)
.L6:
	movq	-1600136(%rbp), %rax
	cmpq	%rax, -1600120(%rbp)
	jl	.L7
	movq	$0, -1600112(%rbp)
	jmp	.L8
.L9:
	leaq	-800048(%rbp), %rdx
	movq	-1600112(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -1600112(%rbp)
.L8:
	movq	-1600128(%rbp), %rax
	cmpq	%rax, -1600112(%rbp)
	jl	.L9
	movq	-1600136(%rbp), %rax
	movq	%rax, %rsi
	leaq	-1600096(%rbp), %rax
	leaq	asc(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	-1600128(%rbp), %rax
	movq	%rax, %rsi
	leaq	-800048(%rbp), %rax
	leaq	asc(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	$0, -1600104(%rbp)
	movq	$0, -1600112(%rbp)
	movq	-1600112(%rbp), %rax
	movq	%rax, -1600120(%rbp)
.L16:
	movq	-1600136(%rbp), %rax
	cmpq	%rax, -1600120(%rbp)
	jne	.L10
	movq	-1600112(%rbp), %rax
	movq	-800048(%rbp,%rax,8), %rax
	addq	%rax, -1600104(%rbp)
	addq	$1, -1600112(%rbp)
	jmp	.L11
.L10:
	movq	-1600128(%rbp), %rax
	cmpq	%rax, -1600112(%rbp)
	jne	.L12
	movq	-1600120(%rbp), %rax
	movq	-1600096(%rbp,%rax,8), %rax
	addq	%rax, -1600104(%rbp)
	addq	$1, -1600120(%rbp)
	jmp	.L11
.L12:
	movq	-1600112(%rbp), %rax
	movq	-800048(%rbp,%rax,8), %rdx
	movq	-1600120(%rbp), %rax
	movq	-1600096(%rbp,%rax,8), %rax
	cmpq	%rax, %rdx
	jge	.L13
	movq	-1600112(%rbp), %rax
	movq	-800048(%rbp,%rax,8), %rdx
	movq	-1600136(%rbp), %rax
	subq	-1600120(%rbp), %rax
	addq	$1, %rax
	imulq	%rdx, %rax
	addq	%rax, -1600104(%rbp)
	addq	$1, -1600112(%rbp)
	jmp	.L11
.L13:
	movq	-1600120(%rbp), %rax
	movq	-1600096(%rbp,%rax,8), %rdx
	movq	-1600128(%rbp), %rax
	subq	-1600112(%rbp), %rax
	addq	$1, %rax
	imulq	%rdx, %rax
	addq	%rax, -1600104(%rbp)
	addq	$1, -1600120(%rbp)
.L11:
	movq	-1600136(%rbp), %rax
	cmpq	%rax, -1600120(%rbp)
	jne	.L16
	movq	-1600128(%rbp), %rax
	cmpq	%rax, -1600112(%rbp)
	je	.L20
	jmp	.L16
.L20:
	nop
	movq	-1600104(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	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	asc
	.type	asc, @function
asc:
.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
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jle	.L2
	movl	$1, %eax
	jmp	.L3
.L2:
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jge	.L4
	movl	$-1, %eax
	jmp	.L3
.L4:
	movl	$0, %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	asc, .-asc
	.section	.rodata
.LC0:
	.string	"%lld %lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld\n"
	.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
	leaq	-1597440(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2704, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-1600128(%rbp), %rdx
	leaq	-1600136(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -1600120(%rbp)
	jmp	.L6
.L7:
	leaq	-1600096(%rbp), %rdx
	movq	-1600120(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -1600120(%rbp)
.L6:
	movq	-1600136(%rbp), %rax
	cmpq	%rax, -1600120(%rbp)
	jl	.L7
	movq	$0, -1600112(%rbp)
	jmp	.L8
.L9:
	leaq	-800048(%rbp), %rdx
	movq	-1600112(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -1600112(%rbp)
.L8:
	movq	-1600128(%rbp), %rax
	cmpq	%rax, -1600112(%rbp)
	jl	.L9
	movq	-1600136(%rbp), %rax
	movq	%rax, %rsi
	leaq	-1600096(%rbp), %rax
	leaq	asc(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	-1600128(%rbp), %rax
	movq	%rax, %rsi
	leaq	-800048(%rbp), %rax
	leaq	asc(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	$0, -1600104(%rbp)
	movq	$0, -1600112(%rbp)
	movq	-1600112(%rbp), %rax
	movq	%rax, -1600120(%rbp)
.L16:
	movq	-1600136(%rbp), %rax
	cmpq	%rax, -1600120(%rbp)
	jne	.L10
	movq	-1600112(%rbp), %rax
	movq	-800048(%rbp,%rax,8), %rax
	addq	%rax, -1600104(%rbp)
	addq	$1, -1600112(%rbp)
	jmp	.L11
.L10:
	movq	-1600128(%rbp), %rax
	cmpq	%rax, -1600112(%rbp)
	jne	.L12
	movq	-1600120(%rbp), %rax
	movq	-1600096(%rbp,%rax,8), %rax
	addq	%rax, -1600104(%rbp)
	addq	$1, -1600120(%rbp)
	jmp	.L11
.L12:
	movq	-1600112(%rbp), %rax
	movq	-800048(%rbp,%rax,8), %rdx
	movq	-1600120(%rbp), %rax
	movq	-1600096(%rbp,%rax,8), %rax
	cmpq	%rax, %rdx
	jge	.L13
	movq	-1600112(%rbp), %rax
	movq	-800048(%rbp,%rax,8), %rdx
	movq	-1600136(%rbp), %rax
	subq	-1600120(%rbp), %rax
	addq	$1, %rax
	imulq	%rdx, %rax
	addq	%rax, -1600104(%rbp)
	addq	$1, -1600112(%rbp)
	jmp	.L11
.L13:
	movq	-1600120(%rbp), %rax
	movq	-1600096(%rbp,%rax,8), %rdx
	movq	-1600128(%rbp), %rax
	subq	-1600112(%rbp), %rax
	addq	$1, %rax
	imulq	%rdx, %rax
	addq	%rax, -1600104(%rbp)
	addq	$1, -1600120(%rbp)
.L11:
	movq	-1600136(%rbp), %rax
	cmpq	%rax, -1600120(%rbp)
	jne	.L16
	movq	-1600128(%rbp), %rax
	cmpq	%rax, -1600112(%rbp)
	je	.L20
	jmp	.L16
.L20:
	nop
	movq	-1600104(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	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:
