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

```c
/* Coached by rainboy */
#include <stdio.h>
#include <stdlib.h>

#define N 100000
#define L 30

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

int length(int n) {
	return n == 0 ? 0 : length(n / 2) + 1;
}

int main() {
	static int aa[L + 1][N], kk[L + 1];
	int n, m, h, i;
	long long ans;

	scanf("%d%d", &n, &m);
	while (n--) {
		int a;

		scanf("%d", &a);
		h = length(a);
		aa[h][kk[h]++] = a;
	}
	for (h = L; h > 0 && m > 0; h--)
		if (m >= kk[h]) {
			for (i = 0; i < kk[h]; i++) {
				int a = aa[h][i];

				aa[h - 1][kk[h - 1]++] = a / 2;
			}
			m -= kk[h];
			kk[h] = 0;
		} else {
			qsort(aa[h], kk[h], sizeof *aa[h], compare);
			while (m--) {
				int a = aa[h][--kk[h]];

				aa[h - 1][kk[h - 1]++] = a / 2;
			}
		}
	ans = 0;
	for (h = 1; h <= L; h++)
		for (i = 0; i < kk[h]; i++)
			ans += aa[h][i];
	printf("%lld\n", ans);
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	compare
	.type	compare, @function
compare:
.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
	movl	(%rax), %eax
	movl	%eax, -8(%rbp)
	movq	-32(%rbp), %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	subl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	compare, .-compare
	.globl	length
	.type	length, @function
length:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	cmpl	$0, -4(%rbp)
	je	.L4
	movl	-4(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %edi
	call	length
	addl	$1, %eax
	jmp	.L6
.L4:
	movl	$0, %eax
.L6:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	length, .-length
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%lld\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	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-40(%rbp), %rdx
	leaq	-44(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L8
.L9:
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	movl	%eax, %edi
	call	length
	movl	%eax, -32(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	1(%rax), %edx
	movl	-32(%rbp), %ecx
	movslq	%ecx, %rcx
	leaq	0(,%rcx,4), %rsi
	leaq	kk.1(%rip), %rcx
	movl	%edx, (%rsi,%rcx)
	movl	-36(%rbp), %edx
	movslq	%eax, %rcx
	movl	-32(%rbp), %eax
	cltq
	imulq	$100000, %rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	aa.0(%rip), %rax
	movl	%edx, (%rcx,%rax)
.L8:
	movl	-44(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -44(%rbp)
	testl	%eax, %eax
	jne	.L9
	movl	$30, -32(%rbp)
	jmp	.L10
.L18:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-40(%rbp), %eax
	cmpl	%eax, %edx
	jg	.L11
	movl	$0, -28(%rbp)
	jmp	.L12
.L13:
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -20(%rbp)
	movl	-32(%rbp), %eax
	leal	-1(%rax), %edi
	movl	-32(%rbp), %eax
	leal	-1(%rax), %edx
	movslq	%edx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	kk.1(%rip), %rax
	movl	(%rcx,%rax), %eax
	leal	1(%rax), %ecx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	kk.1(%rip), %rdx
	movl	%ecx, (%rsi,%rdx)
	movl	-20(%rbp), %edx
	movl	%edx, %ecx
	shrl	$31, %ecx
	addl	%ecx, %edx
	sarl	%edx
	movl	%edx, %ecx
	movslq	%eax, %rdx
	movslq	%edi, %rax
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -28(%rbp)
.L12:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L13
	movl	-40(%rbp), %eax
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	kk.1(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	movl	%eax, -40(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	$0, (%rdx,%rax)
	jmp	.L14
.L11:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$400000, %rdx, %rdx
	leaq	aa.0(%rip), %rcx
	leaq	(%rdx,%rcx), %rdi
	leaq	compare(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rsi
	call	qsort@PLT
	jmp	.L15
.L16:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -24(%rbp)
	movl	-32(%rbp), %eax
	leal	-1(%rax), %edi
	movl	-32(%rbp), %eax
	leal	-1(%rax), %edx
	movslq	%edx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	kk.1(%rip), %rax
	movl	(%rcx,%rax), %eax
	leal	1(%rax), %ecx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	kk.1(%rip), %rdx
	movl	%ecx, (%rsi,%rdx)
	movl	-24(%rbp), %edx
	movl	%edx, %ecx
	shrl	$31, %ecx
	addl	%ecx, %edx
	sarl	%edx
	movl	%edx, %ecx
	movslq	%eax, %rdx
	movslq	%edi, %rax
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L15:
	movl	-40(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -40(%rbp)
	testl	%eax, %eax
	jne	.L16
.L14:
	subl	$1, -32(%rbp)
.L10:
	cmpl	$0, -32(%rbp)
	jle	.L17
	movl	-40(%rbp), %eax
	testl	%eax, %eax
	jg	.L18
.L17:
	movq	$0, -16(%rbp)
	movl	$1, -32(%rbp)
	jmp	.L19
.L22:
	movl	$0, -28(%rbp)
	jmp	.L20
.L21:
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	addq	%rax, -16(%rbp)
	addl	$1, -28(%rbp)
.L20:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L21
	addl	$1, -32(%rbp)
.L19:
	cmpl	$30, -32(%rbp)
	jle	.L22
	movq	-16(%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	.L24
	call	__stack_chk_fail@PLT
.L24:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	main, .-main
	.local	kk.1
	.comm	kk.1,124,32
	.local	aa.0
	.comm	aa.0,12400000,32
	.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	compare
	.type	compare, @function
compare:
.LFB39:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE39:
	.size	compare, .-compare
	.p2align 4
	.globl	length
	.type	length, @function
length:
.LFB40:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L6
	movl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L5:
	movl	%edi, %edx
	movl	%eax, %r8d
	addl	$1, %eax
	shrl	$31, %edx
	addl	%edx, %edi
	sarl	%edi
	jne	.L5
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L6:
	xorl	%r8d, %r8d
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE40:
	.size	length, .-length
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%lld\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
	leaq	.LC0(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	kk.1(%rip), %r14
	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
	leaq	.LC1(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	aa.0(%rip), %rbx
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	48(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	52(%rsp), %r12
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 44(%rsp)
	testl	%eax, %eax
	je	.L13
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%r12, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	52(%rsp), %esi
	testl	%esi, %esi
	je	.L37
	movl	%esi, %eax
	movl	$1, %edx
	.p2align 4,,10
	.p2align 3
.L12:
	movl	%eax, %ecx
	shrl	$31, %ecx
	addl	%ecx, %eax
	movslq	%edx, %rcx
	addl	$1, %edx
	sarl	%eax
	jne	.L12
.L11:
	movslq	(%r14,%rcx,4), %rax
	leal	1(%rax), %edx
	movl	%edx, (%r14,%rcx,4)
	imulq	$100000, %rcx, %rcx
	addq	%rax, %rcx
	movl	44(%rsp), %eax
	movl	%esi, (%rbx,%rcx,4)
	leal	-1(%rax), %edx
	movl	%edx, 44(%rsp)
	testl	%eax, %eax
	jne	.L9
.L13:
	movl	48(%rsp), %ecx
	movl	$3000000, %ebp
	leaq	12000000+aa.0(%rip), %rbx
	leaq	116+kk.1(%rip), %r15
	movl	$30, %r12d
	leaq	-12000000(%rbx), %r13
	testl	%ecx, %ecx
	jle	.L29
	.p2align 4,,10
	.p2align 3
.L28:
	movl	4(%r15), %eax
	leal	-1(%r12), %esi
	movl	%esi, 12(%rsp)
	cmpl	%ecx, %eax
	jg	.L14
	testl	%eax, %eax
	jle	.L75
	movslq	(%r15), %rdx
	leaq	-400004(,%rdx,4), %rdi
	movq	%rdx, %rsi
	cmpq	$8, %rdi
	jbe	.L16
	leal	-1(%rax), %edi
	cmpl	$2, %edi
	jbe	.L16
	movl	%eax, %edi
	addq	%rbp, %rdx
	pxor	%xmm2, %xmm2
	shrl	$2, %edi
	leaq	-400000(%r13,%rdx,4), %r8
	xorl	%edx, %edx
	salq	$4, %rdi
	.p2align 4,,10
	.p2align 3
.L17:
	movdqa	%xmm2, %xmm1
	movdqa	(%rbx,%rdx), %xmm0
	pcmpgtd	(%rbx,%rdx), %xmm1
	psubd	%xmm1, %xmm0
	psrad	$1, %xmm0
	movups	%xmm0, (%r8,%rdx)
	addq	$16, %rdx
	cmpq	%rdx, %rdi
	jne	.L17
	movl	%eax, %edx
	subq	$100000, %rbp
	andl	$-4, %edx
	leal	(%rsi,%rdx), %edi
	cmpl	%edx, %eax
	je	.L20
	movslq	%r12d, %r8
	movslq	%edx, %r10
	leal	1(%rdi), %r11d
	movslq	%edi, %r9
	imulq	$100000, %r8, %r8
	movl	%r11d, 16(%rsp)
	movslq	12(%rsp), %r11
	imulq	$100000, %r11, %r11
	addq	%r8, %r10
	movl	0(%r13,%r10,4), %r12d
	addq	%r11, %r9
	movl	%r12d, %r10d
	shrl	$31, %r10d
	addl	%r12d, %r10d
	sarl	%r10d
	movl	%r10d, 0(%r13,%r9,4)
	leal	1(%rdx), %r9d
	cmpl	%r9d, %eax
	jle	.L20
	movslq	%r9d, %r9
	movslq	16(%rsp), %r10
	addl	$2, %edx
	addl	$2, %edi
	addq	%r8, %r9
	movl	0(%r13,%r9,4), %r12d
	addq	%r11, %r10
	movl	%r12d, %r9d
	shrl	$31, %r9d
	addl	%r12d, %r9d
	sarl	%r9d
	movl	%r9d, 0(%r13,%r10,4)
	cmpl	%edx, %eax
	jle	.L20
	movslq	%edx, %rdx
	movslq	%edi, %rdi
	addq	%rdx, %r8
	addq	%r11, %rdi
	movl	0(%r13,%r8,4), %r8d
	movl	%r8d, %edx
	shrl	$31, %edx
	addl	%r8d, %edx
	sarl	%edx
	movl	%edx, 0(%r13,%rdi,4)
.L20:
	addl	%eax, %esi
	movl	%esi, (%r15)
.L15:
	subl	%eax, %ecx
	movl	$0, 4(%r15)
	movl	%ecx, 48(%rsp)
.L21:
	leaq	-4(%r15), %rax
	subq	$400000, %rbx
	cmpq	%r15, %r14
	je	.L29
	movl	12(%rsp), %r12d
	movq	%rax, %r15
	testl	%ecx, %ecx
	jg	.L28
.L29:
	leaq	400000+aa.0(%rip), %r9
	movl	$1, %esi
	pxor	%xmm4, %xmm4
	xorl	%r8d, %r8d
	leaq	-400000(%r9), %r10
	.p2align 4,,10
	.p2align 3
.L27:
	movl	(%r14,%rsi,4), %edx
	movl	%esi, %r11d
	testl	%edx, %edx
	jle	.L35
	leal	-1(%rdx), %eax
	cmpl	$2, %eax
	jbe	.L40
	movl	%edx, %eax
	pxor	%xmm1, %xmm1
	shrl	$2, %eax
	leal	-1(%rax), %ecx
	movq	%r9, %rax
	salq	$4, %rcx
	leaq	16(%r9,%rcx), %rcx
	.p2align 4,,10
	.p2align 3
.L31:
	movdqa	(%rax), %xmm0
	movdqa	%xmm4, %xmm2
	addq	$16, %rax
	pcmpgtd	%xmm0, %xmm2
	movdqa	%xmm0, %xmm3
	punpckldq	%xmm2, %xmm3
	punpckhdq	%xmm2, %xmm0
	paddq	%xmm3, %xmm1
	paddq	%xmm0, %xmm1
	cmpq	%rax, %rcx
	jne	.L31
	movdqa	%xmm1, %xmm0
	psrldq	$8, %xmm0
	paddq	%xmm0, %xmm1
	movq	%xmm1, %rcx
	addq	%rcx, %r8
	movl	%edx, %ecx
	andl	$-4, %ecx
	testb	$3, %dl
	je	.L35
.L30:
	movslq	%r11d, %rax
	movslq	%ecx, %rdi
	imulq	$100000, %rax, %rax
	addq	%rax, %rdi
	movslq	(%r10,%rdi,4), %rdi
	addq	%rdi, %r8
	leal	1(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L35
	movslq	%edi, %rdi
	addl	$2, %ecx
	addq	%rax, %rdi
	movslq	(%r10,%rdi,4), %rdi
	addq	%rdi, %r8
	cmpl	%ecx, %edx
	jle	.L35
	movslq	%ecx, %rcx
	addq	%rcx, %rax
	movslq	(%r10,%rax,4), %rax
	addq	%rax, %r8
.L35:
	addq	$1, %rsi
	addq	$400000, %r9
	cmpq	$31, %rsi
	jne	.L27
	xorl	%eax, %eax
	movq	%r8, %rdx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L76
	addq	$72, %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
	.p2align 4,,10
	.p2align 3
.L14:
	.cfi_restore_state
	movslq	%eax, %rsi
	leaq	compare(%rip), %rcx
	movl	$4, %edx
	movq	%rbx, %rdi
	call	qsort@PLT
	movl	48(%rsp), %ecx
	leal	-1(%rcx), %esi
	movl	%esi, 48(%rsp)
	testl	%ecx, %ecx
	je	.L38
	movslq	(%r15), %r9
	movslq	4(%r15), %rdx
	movl	%ecx, %edi
	leaq	(%r9,%rbp), %r8
	movl	%edx, 16(%rsp)
	addq	%rbp, %rdx
	movq	%r9, %r11
	leaq	-400000(,%r8,4), %rax
	addq	%rdi, %r8
	salq	$2, %rdx
	leaq	-400000(,%r8,4), %r10
	movq	%rdi, %r8
	negq	%r8
	leaq	(%rdx,%r8,4), %r8
	cmpq	%r8, %r10
	setle	%r10b
	cmpq	%rax, %rdx
	setle	%r8b
	orb	%r10b, %r8b
	je	.L22
	cmpl	$2, %esi
	jbe	.L22
	movl	%ecx, %edi
	leaq	-16(%r13,%rdx), %rdx
	pxor	%xmm2, %xmm2
	addq	%r13, %rax
	shrl	$2, %edi
	leal	-1(%rdi), %r8d
	movq	$-16, %rdi
	salq	$4, %r8
	subq	%r8, %rdi
	addq	%rdx, %rdi
	.p2align 4,,10
	.p2align 3
.L23:
	movdqu	(%rdx), %xmm5
	movdqa	%xmm2, %xmm1
	subq	$16, %rdx
	addq	$16, %rax
	pshufd	$27, %xmm5, %xmm0
	pcmpgtd	%xmm0, %xmm1
	psubd	%xmm1, %xmm0
	psrad	$1, %xmm0
	movups	%xmm0, -16(%rax)
	cmpq	%rdx, %rdi
	jne	.L23
	movl	%ecx, %eax
	movl	16(%rsp), %edi
	movl	%esi, %edx
	subq	$100000, %rbp
	andl	$-4, %eax
	subl	%eax, %edx
	subl	%eax, %edi
	leal	(%r11,%rax), %r8d
	movl	%edx, 20(%rsp)
	cmpl	%eax, %ecx
	je	.L26
	leal	1(%r8), %eax
	movl	%edi, 28(%rsp)
	subl	$1, %edi
	movslq	12(%rsp), %r9
	movl	%eax, 24(%rsp)
	movslq	%r12d, %rax
	movslq	%edi, %rdi
	movslq	%r8d, %rdx
	imulq	$100000, %rax, %rax
	imulq	$100000, %r9, %r9
	addq	%rax, %rdi
	movl	0(%r13,%rdi,4), %r10d
	addq	%r9, %rdx
	movl	%r10d, %edi
	shrl	$31, %edi
	addl	%r10d, %edi
	sarl	%edi
	movl	%edi, 0(%r13,%rdx,4)
	movl	20(%rsp), %edx
	testl	%edx, %edx
	je	.L26
	movl	28(%rsp), %r12d
	leal	2(%r8), %r10d
	movslq	24(%rsp), %rdx
	leal	-2(%r12), %edi
	addq	%r9, %rdx
	movslq	%edi, %rdi
	addq	%rax, %rdi
	movl	0(%r13,%rdi,4), %r8d
	movl	%r8d, %edi
	shrl	$31, %edi
	addl	%r8d, %edi
	sarl	%edi
	cmpl	$1, 20(%rsp)
	movl	%edi, 0(%r13,%rdx,4)
	je	.L26
	movl	%r12d, %edx
	movslq	%r10d, %rdi
	subl	$3, %edx
	addq	%r9, %rdi
	movslq	%edx, %rdx
	addq	%rdx, %rax
	movl	0(%r13,%rax,4), %edx
	movl	%edx, %eax
	shrl	$31, %eax
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, 0(%r13,%rdi,4)
.L26:
	movl	16(%rsp), %eax
	movl	$-1, 48(%rsp)
	subl	%ecx, %eax
	movl	$-1, %ecx
	movl	%eax, 4(%r15)
	leal	1(%rsi,%r11), %eax
	movl	%eax, (%r15)
	jmp	.L21
.L16:
	subq	$100000, %rbp
	movl	%eax, %r8d
	xorl	%edi, %edi
	addq	%rbp, %rdx
	leaq	0(%r13,%rdx,4), %r9
	.p2align 4,,10
	.p2align 3
.L19:
	movl	(%rbx,%rdi,4), %r10d
	movl	%r10d, %edx
	shrl	$31, %edx
	addl	%r10d, %edx
	sarl	%edx
	movl	%edx, (%r9,%rdi,4)
	addq	$1, %rdi
	cmpq	%rdi, %r8
	jne	.L19
	jmp	.L20
.L40:
	xorl	%ecx, %ecx
	jmp	.L30
.L37:
	xorl	%ecx, %ecx
	jmp	.L11
.L75:
	subq	$100000, %rbp
	jmp	.L15
.L22:
	subq	$100000, %rbp
	addq	%r13, %rdx
	xorl	%r8d, %r8d
	addq	%rbp, %r9
	leaq	0(%r13,%r9,4), %r10
	.p2align 4,,10
	.p2align 3
.L25:
	movl	-4(%rdx), %r9d
	subq	$4, %rdx
	movl	%r9d, %eax
	shrl	$31, %eax
	addl	%r9d, %eax
	sarl	%eax
	movl	%eax, (%r10,%r8,4)
	addq	$1, %r8
	cmpq	%r8, %rdi
	jne	.L25
	jmp	.L26
.L38:
	orl	$-1, %ecx
	subq	$100000, %rbp
	jmp	.L21
.L76:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE41:
	.size	main, .-main
	.local	aa.0
	.comm	aa.0,12400000,32
	.local	kk.1
	.comm	kk.1,124,32
	.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	compare
	.type	compare, @function
compare:
.LFB39:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE39:
	.size	compare, .-compare
	.p2align 4
	.globl	length
	.type	length, @function
length:
.LFB40:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L6
	movl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L5:
	movl	%edi, %edx
	movl	%eax, %r8d
	addl	$1, %eax
	shrl	$31, %edx
	addl	%edx, %edi
	sarl	%edi
	jne	.L5
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L6:
	xorl	%r8d, %r8d
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE40:
	.size	length, .-length
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%lld\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
	leaq	.LC0(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	kk.1(%rip), %r14
	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
	leaq	.LC1(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	aa.0(%rip), %rbx
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	48(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	52(%rsp), %r12
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 44(%rsp)
	testl	%eax, %eax
	je	.L13
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%r12, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	52(%rsp), %esi
	testl	%esi, %esi
	je	.L37
	movl	%esi, %eax
	movl	$1, %edx
	.p2align 4,,10
	.p2align 3
.L12:
	movl	%eax, %ecx
	shrl	$31, %ecx
	addl	%ecx, %eax
	movslq	%edx, %rcx
	addl	$1, %edx
	sarl	%eax
	jne	.L12
.L11:
	movslq	(%r14,%rcx,4), %rax
	leal	1(%rax), %edx
	movl	%edx, (%r14,%rcx,4)
	imulq	$100000, %rcx, %rcx
	addq	%rax, %rcx
	movl	44(%rsp), %eax
	movl	%esi, (%rbx,%rcx,4)
	leal	-1(%rax), %edx
	movl	%edx, 44(%rsp)
	testl	%eax, %eax
	jne	.L9
.L13:
	movl	48(%rsp), %ecx
	movl	$3000000, %ebp
	leaq	12000000+aa.0(%rip), %rbx
	leaq	116+kk.1(%rip), %r15
	movl	$30, %r12d
	leaq	-12000000(%rbx), %r13
	testl	%ecx, %ecx
	jle	.L29
	.p2align 4,,10
	.p2align 3
.L28:
	movl	4(%r15), %eax
	leal	-1(%r12), %esi
	movl	%esi, 12(%rsp)
	cmpl	%ecx, %eax
	jg	.L14
	testl	%eax, %eax
	jle	.L75
	movslq	(%r15), %rdx
	leaq	-400004(,%rdx,4), %rdi
	movq	%rdx, %rsi
	cmpq	$8, %rdi
	jbe	.L16
	leal	-1(%rax), %edi
	cmpl	$2, %edi
	jbe	.L16
	movl	%eax, %edi
	addq	%rbp, %rdx
	pxor	%xmm2, %xmm2
	shrl	$2, %edi
	leaq	-400000(%r13,%rdx,4), %r8
	xorl	%edx, %edx
	salq	$4, %rdi
	.p2align 4,,10
	.p2align 3
.L17:
	movdqa	%xmm2, %xmm1
	movdqa	(%rbx,%rdx), %xmm0
	pcmpgtd	(%rbx,%rdx), %xmm1
	psubd	%xmm1, %xmm0
	psrad	$1, %xmm0
	movups	%xmm0, (%r8,%rdx)
	addq	$16, %rdx
	cmpq	%rdx, %rdi
	jne	.L17
	movl	%eax, %edx
	subq	$100000, %rbp
	andl	$-4, %edx
	leal	(%rsi,%rdx), %edi
	cmpl	%edx, %eax
	je	.L20
	movslq	%r12d, %r8
	movslq	%edx, %r10
	leal	1(%rdi), %r11d
	movslq	%edi, %r9
	imulq	$100000, %r8, %r8
	movl	%r11d, 16(%rsp)
	movslq	12(%rsp), %r11
	imulq	$100000, %r11, %r11
	addq	%r8, %r10
	movl	0(%r13,%r10,4), %r12d
	addq	%r11, %r9
	movl	%r12d, %r10d
	shrl	$31, %r10d
	addl	%r12d, %r10d
	sarl	%r10d
	movl	%r10d, 0(%r13,%r9,4)
	leal	1(%rdx), %r9d
	cmpl	%r9d, %eax
	jle	.L20
	movslq	%r9d, %r9
	movslq	16(%rsp), %r10
	addl	$2, %edx
	addl	$2, %edi
	addq	%r8, %r9
	movl	0(%r13,%r9,4), %r12d
	addq	%r11, %r10
	movl	%r12d, %r9d
	shrl	$31, %r9d
	addl	%r12d, %r9d
	sarl	%r9d
	movl	%r9d, 0(%r13,%r10,4)
	cmpl	%edx, %eax
	jle	.L20
	movslq	%edx, %rdx
	movslq	%edi, %rdi
	addq	%rdx, %r8
	addq	%r11, %rdi
	movl	0(%r13,%r8,4), %r8d
	movl	%r8d, %edx
	shrl	$31, %edx
	addl	%r8d, %edx
	sarl	%edx
	movl	%edx, 0(%r13,%rdi,4)
.L20:
	addl	%eax, %esi
	movl	%esi, (%r15)
.L15:
	subl	%eax, %ecx
	movl	$0, 4(%r15)
	movl	%ecx, 48(%rsp)
.L21:
	leaq	-4(%r15), %rax
	subq	$400000, %rbx
	cmpq	%r15, %r14
	je	.L29
	movl	12(%rsp), %r12d
	movq	%rax, %r15
	testl	%ecx, %ecx
	jg	.L28
.L29:
	leaq	400000+aa.0(%rip), %r9
	movl	$1, %esi
	pxor	%xmm4, %xmm4
	xorl	%r8d, %r8d
	leaq	-400000(%r9), %r10
	.p2align 4,,10
	.p2align 3
.L27:
	movl	(%r14,%rsi,4), %edx
	movl	%esi, %r11d
	testl	%edx, %edx
	jle	.L35
	leal	-1(%rdx), %eax
	cmpl	$2, %eax
	jbe	.L40
	movl	%edx, %eax
	pxor	%xmm1, %xmm1
	shrl	$2, %eax
	leal	-1(%rax), %ecx
	movq	%r9, %rax
	salq	$4, %rcx
	leaq	16(%r9,%rcx), %rcx
	.p2align 4,,10
	.p2align 3
.L31:
	movdqa	(%rax), %xmm0
	movdqa	%xmm4, %xmm2
	addq	$16, %rax
	pcmpgtd	%xmm0, %xmm2
	movdqa	%xmm0, %xmm3
	punpckldq	%xmm2, %xmm3
	punpckhdq	%xmm2, %xmm0
	paddq	%xmm3, %xmm1
	paddq	%xmm0, %xmm1
	cmpq	%rax, %rcx
	jne	.L31
	movdqa	%xmm1, %xmm0
	psrldq	$8, %xmm0
	paddq	%xmm0, %xmm1
	movq	%xmm1, %rcx
	addq	%rcx, %r8
	movl	%edx, %ecx
	andl	$-4, %ecx
	testb	$3, %dl
	je	.L35
.L30:
	movslq	%r11d, %rax
	movslq	%ecx, %rdi
	imulq	$100000, %rax, %rax
	addq	%rax, %rdi
	movslq	(%r10,%rdi,4), %rdi
	addq	%rdi, %r8
	leal	1(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L35
	movslq	%edi, %rdi
	addl	$2, %ecx
	addq	%rax, %rdi
	movslq	(%r10,%rdi,4), %rdi
	addq	%rdi, %r8
	cmpl	%ecx, %edx
	jle	.L35
	movslq	%ecx, %rcx
	addq	%rcx, %rax
	movslq	(%r10,%rax,4), %rax
	addq	%rax, %r8
.L35:
	addq	$1, %rsi
	addq	$400000, %r9
	cmpq	$31, %rsi
	jne	.L27
	xorl	%eax, %eax
	movq	%r8, %rdx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L76
	addq	$72, %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
	.p2align 4,,10
	.p2align 3
.L14:
	.cfi_restore_state
	movslq	%eax, %rsi
	leaq	compare(%rip), %rcx
	movl	$4, %edx
	movq	%rbx, %rdi
	call	qsort@PLT
	movl	48(%rsp), %ecx
	leal	-1(%rcx), %esi
	movl	%esi, 48(%rsp)
	testl	%ecx, %ecx
	je	.L38
	movslq	(%r15), %r9
	movslq	4(%r15), %rdx
	movl	%ecx, %edi
	leaq	(%r9,%rbp), %r8
	movl	%edx, 16(%rsp)
	addq	%rbp, %rdx
	movq	%r9, %r11
	leaq	-400000(,%r8,4), %rax
	addq	%rdi, %r8
	salq	$2, %rdx
	leaq	-400000(,%r8,4), %r10
	movq	%rdi, %r8
	negq	%r8
	leaq	(%rdx,%r8,4), %r8
	cmpq	%r8, %r10
	setle	%r10b
	cmpq	%rax, %rdx
	setle	%r8b
	orb	%r10b, %r8b
	je	.L22
	cmpl	$2, %esi
	jbe	.L22
	movl	%ecx, %edi
	leaq	-16(%r13,%rdx), %rdx
	pxor	%xmm2, %xmm2
	addq	%r13, %rax
	shrl	$2, %edi
	leal	-1(%rdi), %r8d
	movq	$-16, %rdi
	salq	$4, %r8
	subq	%r8, %rdi
	addq	%rdx, %rdi
	.p2align 4,,10
	.p2align 3
.L23:
	movdqu	(%rdx), %xmm5
	movdqa	%xmm2, %xmm1
	subq	$16, %rdx
	addq	$16, %rax
	pshufd	$27, %xmm5, %xmm0
	pcmpgtd	%xmm0, %xmm1
	psubd	%xmm1, %xmm0
	psrad	$1, %xmm0
	movups	%xmm0, -16(%rax)
	cmpq	%rdx, %rdi
	jne	.L23
	movl	%ecx, %eax
	movl	16(%rsp), %edi
	movl	%esi, %edx
	subq	$100000, %rbp
	andl	$-4, %eax
	subl	%eax, %edx
	subl	%eax, %edi
	leal	(%r11,%rax), %r8d
	movl	%edx, 20(%rsp)
	cmpl	%eax, %ecx
	je	.L26
	leal	1(%r8), %eax
	movl	%edi, 28(%rsp)
	subl	$1, %edi
	movslq	12(%rsp), %r9
	movl	%eax, 24(%rsp)
	movslq	%r12d, %rax
	movslq	%edi, %rdi
	movslq	%r8d, %rdx
	imulq	$100000, %rax, %rax
	imulq	$100000, %r9, %r9
	addq	%rax, %rdi
	movl	0(%r13,%rdi,4), %r10d
	addq	%r9, %rdx
	movl	%r10d, %edi
	shrl	$31, %edi
	addl	%r10d, %edi
	sarl	%edi
	movl	%edi, 0(%r13,%rdx,4)
	movl	20(%rsp), %edx
	testl	%edx, %edx
	je	.L26
	movl	28(%rsp), %r12d
	leal	2(%r8), %r10d
	movslq	24(%rsp), %rdx
	leal	-2(%r12), %edi
	addq	%r9, %rdx
	movslq	%edi, %rdi
	addq	%rax, %rdi
	movl	0(%r13,%rdi,4), %r8d
	movl	%r8d, %edi
	shrl	$31, %edi
	addl	%r8d, %edi
	sarl	%edi
	cmpl	$1, 20(%rsp)
	movl	%edi, 0(%r13,%rdx,4)
	je	.L26
	movl	%r12d, %edx
	movslq	%r10d, %rdi
	subl	$3, %edx
	addq	%r9, %rdi
	movslq	%edx, %rdx
	addq	%rdx, %rax
	movl	0(%r13,%rax,4), %edx
	movl	%edx, %eax
	shrl	$31, %eax
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, 0(%r13,%rdi,4)
.L26:
	movl	16(%rsp), %eax
	movl	$-1, 48(%rsp)
	subl	%ecx, %eax
	movl	$-1, %ecx
	movl	%eax, 4(%r15)
	leal	1(%rsi,%r11), %eax
	movl	%eax, (%r15)
	jmp	.L21
.L16:
	subq	$100000, %rbp
	movl	%eax, %r8d
	xorl	%edi, %edi
	addq	%rbp, %rdx
	leaq	0(%r13,%rdx,4), %r9
	.p2align 4,,10
	.p2align 3
.L19:
	movl	(%rbx,%rdi,4), %r10d
	movl	%r10d, %edx
	shrl	$31, %edx
	addl	%r10d, %edx
	sarl	%edx
	movl	%edx, (%r9,%rdi,4)
	addq	$1, %rdi
	cmpq	%rdi, %r8
	jne	.L19
	jmp	.L20
.L40:
	xorl	%ecx, %ecx
	jmp	.L30
.L37:
	xorl	%ecx, %ecx
	jmp	.L11
.L75:
	subq	$100000, %rbp
	jmp	.L15
.L22:
	subq	$100000, %rbp
	addq	%r13, %rdx
	xorl	%r8d, %r8d
	addq	%rbp, %r9
	leaq	0(%r13,%r9,4), %r10
	.p2align 4,,10
	.p2align 3
.L25:
	movl	-4(%rdx), %r9d
	subq	$4, %rdx
	movl	%r9d, %eax
	shrl	$31, %eax
	addl	%r9d, %eax
	sarl	%eax
	movl	%eax, (%r10,%r8,4)
	addq	$1, %r8
	cmpq	%r8, %rdi
	jne	.L25
	jmp	.L26
.L38:
	orl	$-1, %ecx
	subq	$100000, %rbp
	jmp	.L21
.L76:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE41:
	.size	main, .-main
	.local	aa.0
	.comm	aa.0,12400000,32
	.local	kk.1
	.comm	kk.1,124,32
	.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:

/* Coached by rainboy */
#include <stdio.h>
#include <stdlib.h>

#define N 100000
#define L 30

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

int length(int n) {
	return n == 0 ? 0 : length(n / 2) + 1;
}

int main() {
	static int aa[L + 1][N], kk[L + 1];
	int n, m, h, i;
	long long ans;

	scanf("%d%d", &n, &m);
	while (n--) {
		int a;

		scanf("%d", &a);
		h = length(a);
		aa[h][kk[h]++] = a;
	}
	for (h = L; h > 0 && m > 0; h--)
		if (m >= kk[h]) {
			for (i = 0; i < kk[h]; i++) {
				int a = aa[h][i];

				aa[h - 1][kk[h - 1]++] = a / 2;
			}
			m -= kk[h];
			kk[h] = 0;
		} else {
			qsort(aa[h], kk[h], sizeof *aa[h], compare);
			while (m--) {
				int a = aa[h][--kk[h]];

				aa[h - 1][kk[h - 1]++] = a / 2;
			}
		}
	ans = 0;
	for (h = 1; h <= L; h++)
		for (i = 0; i < kk[h]; i++)
			ans += aa[h][i];
	printf("%lld\n", ans);
	return 0;
}

1 101000
1000000000
 10 1
1000000000 1001000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
 3 3
2 13 3
 10 1
1000000000 1001000000 1000000000 1000000000 1000000000 1000000000 1000000000 1010000000 1000000000 1000000000
 3 2
2 13 3
 10 1
1000000000 1001000000 1000000000 1000000000 1000000000 1000000000 1000000000 1010010000 1000000000 1000000000
 3 2
2 13 2
 10 1
1000000000 1001000000 1010000000 1000000000 1000000000 1000000000 1000000000 1010010000 1000000000 1000000000
 10 1
1000000000 1001000000 1010000000 1000000000 1000000000 1000000000 1000000000 1010010000 1000000000 1100000000
 10 1
1000000000 1001000000 1010000000 1100000000 1000000000 1000000000 1000000000 1010010000 1000000000 1100000000

0
 9500500000
 6
 9506000000
 8
 9506005000
 7
 9516005000
 8516005000
 7516005000

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

```c
/* Coached by rainboy */
#include <stdio.h>
#include <stdlib.h>

#define N 100000
#define L 30

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

int length(int n) {
	return n == 0 ? 0 : length(n / 2) + 1;
}

int main() {
	static int aa[L + 1][N], kk[L + 1];
	int n, m, h, i;
	long long ans;

	scanf("%d%d", &n, &m);
	while (n--) {
		int a;

		scanf("%d", &a);
		h = length(a);
		aa[h][kk[h]++] = a;
	}
	for (h = L; h > 0 && m > 0; h--)
		if (m >= kk[h]) {
			for (i = 0; i < kk[h]; i++) {
				int a = aa[h][i];

				aa[h - 1][kk[h - 1]++] = a / 2;
			}
			m -= kk[h];
			kk[h] = 0;
		} else {
			qsort(aa[h], kk[h], sizeof *aa[h], compare);
			while (m--) {
				int a = aa[h][--kk[h]];

				aa[h - 1][kk[h - 1]++] = a / 2;
			}
		}
	ans = 0;
	for (h = 1; h <= L; h++)
		for (i = 0; i < kk[h]; i++)
			ans += aa[h][i];
	printf("%lld\n", ans);
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	compare
	.type	compare, @function
compare:
.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
	movl	(%rax), %eax
	movl	%eax, -8(%rbp)
	movq	-32(%rbp), %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	subl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	compare, .-compare
	.globl	length
	.type	length, @function
length:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	cmpl	$0, -4(%rbp)
	je	.L4
	movl	-4(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %edi
	call	length
	addl	$1, %eax
	jmp	.L6
.L4:
	movl	$0, %eax
.L6:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	length, .-length
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%lld\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	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-40(%rbp), %rdx
	leaq	-44(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L8
.L9:
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	movl	%eax, %edi
	call	length
	movl	%eax, -32(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	1(%rax), %edx
	movl	-32(%rbp), %ecx
	movslq	%ecx, %rcx
	leaq	0(,%rcx,4), %rsi
	leaq	kk.1(%rip), %rcx
	movl	%edx, (%rsi,%rcx)
	movl	-36(%rbp), %edx
	movslq	%eax, %rcx
	movl	-32(%rbp), %eax
	cltq
	imulq	$100000, %rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	aa.0(%rip), %rax
	movl	%edx, (%rcx,%rax)
.L8:
	movl	-44(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -44(%rbp)
	testl	%eax, %eax
	jne	.L9
	movl	$30, -32(%rbp)
	jmp	.L10
.L18:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-40(%rbp), %eax
	cmpl	%eax, %edx
	jg	.L11
	movl	$0, -28(%rbp)
	jmp	.L12
.L13:
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -20(%rbp)
	movl	-32(%rbp), %eax
	leal	-1(%rax), %edi
	movl	-32(%rbp), %eax
	leal	-1(%rax), %edx
	movslq	%edx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	kk.1(%rip), %rax
	movl	(%rcx,%rax), %eax
	leal	1(%rax), %ecx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	kk.1(%rip), %rdx
	movl	%ecx, (%rsi,%rdx)
	movl	-20(%rbp), %edx
	movl	%edx, %ecx
	shrl	$31, %ecx
	addl	%ecx, %edx
	sarl	%edx
	movl	%edx, %ecx
	movslq	%eax, %rdx
	movslq	%edi, %rax
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -28(%rbp)
.L12:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L13
	movl	-40(%rbp), %eax
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	kk.1(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	movl	%eax, -40(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	$0, (%rdx,%rax)
	jmp	.L14
.L11:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$400000, %rdx, %rdx
	leaq	aa.0(%rip), %rcx
	leaq	(%rdx,%rcx), %rdi
	leaq	compare(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rsi
	call	qsort@PLT
	jmp	.L15
.L16:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -24(%rbp)
	movl	-32(%rbp), %eax
	leal	-1(%rax), %edi
	movl	-32(%rbp), %eax
	leal	-1(%rax), %edx
	movslq	%edx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	kk.1(%rip), %rax
	movl	(%rcx,%rax), %eax
	leal	1(%rax), %ecx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	kk.1(%rip), %rdx
	movl	%ecx, (%rsi,%rdx)
	movl	-24(%rbp), %edx
	movl	%edx, %ecx
	shrl	$31, %ecx
	addl	%ecx, %edx
	sarl	%edx
	movl	%edx, %ecx
	movslq	%eax, %rdx
	movslq	%edi, %rax
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L15:
	movl	-40(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -40(%rbp)
	testl	%eax, %eax
	jne	.L16
.L14:
	subl	$1, -32(%rbp)
.L10:
	cmpl	$0, -32(%rbp)
	jle	.L17
	movl	-40(%rbp), %eax
	testl	%eax, %eax
	jg	.L18
.L17:
	movq	$0, -16(%rbp)
	movl	$1, -32(%rbp)
	jmp	.L19
.L22:
	movl	$0, -28(%rbp)
	jmp	.L20
.L21:
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	addq	%rax, -16(%rbp)
	addl	$1, -28(%rbp)
.L20:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L21
	addl	$1, -32(%rbp)
.L19:
	cmpl	$30, -32(%rbp)
	jle	.L22
	movq	-16(%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	.L24
	call	__stack_chk_fail@PLT
.L24:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	main, .-main
	.local	kk.1
	.comm	kk.1,124,32
	.local	aa.0
	.comm	aa.0,12400000,32
	.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	compare
	.type	compare, @function
compare:
.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
	movl	(%rax), %eax
	movl	%eax, -8(%rbp)
	movq	-32(%rbp), %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	subl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	compare, .-compare
	.globl	length
	.type	length, @function
length:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	cmpl	$0, -4(%rbp)
	je	.L4
	movl	-4(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %edi
	call	length
	addl	$1, %eax
	jmp	.L6
.L4:
	movl	$0, %eax
.L6:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	length, .-length
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%lld\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	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-40(%rbp), %rdx
	leaq	-44(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L8
.L9:
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	movl	%eax, %edi
	call	length
	movl	%eax, -32(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	1(%rax), %edx
	movl	-32(%rbp), %ecx
	movslq	%ecx, %rcx
	leaq	0(,%rcx,4), %rsi
	leaq	kk.1(%rip), %rcx
	movl	%edx, (%rsi,%rcx)
	movl	-36(%rbp), %edx
	movslq	%eax, %rcx
	movl	-32(%rbp), %eax
	cltq
	imulq	$100000, %rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	aa.0(%rip), %rax
	movl	%edx, (%rcx,%rax)
.L8:
	movl	-44(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -44(%rbp)
	testl	%eax, %eax
	jne	.L9
	movl	$30, -32(%rbp)
	jmp	.L10
.L18:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-40(%rbp), %eax
	cmpl	%eax, %edx
	jg	.L11
	movl	$0, -28(%rbp)
	jmp	.L12
.L13:
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -20(%rbp)
	movl	-32(%rbp), %eax
	leal	-1(%rax), %edi
	movl	-32(%rbp), %eax
	leal	-1(%rax), %edx
	movslq	%edx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	kk.1(%rip), %rax
	movl	(%rcx,%rax), %eax
	leal	1(%rax), %ecx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	kk.1(%rip), %rdx
	movl	%ecx, (%rsi,%rdx)
	movl	-20(%rbp), %edx
	movl	%edx, %ecx
	shrl	$31, %ecx
	addl	%ecx, %edx
	sarl	%edx
	movl	%edx, %ecx
	movslq	%eax, %rdx
	movslq	%edi, %rax
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -28(%rbp)
.L12:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L13
	movl	-40(%rbp), %eax
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	kk.1(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	movl	%eax, -40(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	$0, (%rdx,%rax)
	jmp	.L14
.L11:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$400000, %rdx, %rdx
	leaq	aa.0(%rip), %rcx
	leaq	(%rdx,%rcx), %rdi
	leaq	compare(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rsi
	call	qsort@PLT
	jmp	.L15
.L16:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -24(%rbp)
	movl	-32(%rbp), %eax
	leal	-1(%rax), %edi
	movl	-32(%rbp), %eax
	leal	-1(%rax), %edx
	movslq	%edx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	kk.1(%rip), %rax
	movl	(%rcx,%rax), %eax
	leal	1(%rax), %ecx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	kk.1(%rip), %rdx
	movl	%ecx, (%rsi,%rdx)
	movl	-24(%rbp), %edx
	movl	%edx, %ecx
	shrl	$31, %ecx
	addl	%ecx, %edx
	sarl	%edx
	movl	%edx, %ecx
	movslq	%eax, %rdx
	movslq	%edi, %rax
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L15:
	movl	-40(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -40(%rbp)
	testl	%eax, %eax
	jne	.L16
.L14:
	subl	$1, -32(%rbp)
.L10:
	cmpl	$0, -32(%rbp)
	jle	.L17
	movl	-40(%rbp), %eax
	testl	%eax, %eax
	jg	.L18
.L17:
	movq	$0, -16(%rbp)
	movl	$1, -32(%rbp)
	jmp	.L19
.L22:
	movl	$0, -28(%rbp)
	jmp	.L20
.L21:
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$100000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	aa.0(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	addq	%rax, -16(%rbp)
	addl	$1, -28(%rbp)
.L20:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	kk.1(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L21
	addl	$1, -32(%rbp)
.L19:
	cmpl	$30, -32(%rbp)
	jle	.L22
	movq	-16(%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	.L24
	call	__stack_chk_fail@PLT
.L24:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	main, .-main
	.local	kk.1
	.comm	kk.1,124,32
	.local	aa.0
	.comm	aa.0,12400000,32
	.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:
