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

```c
// AOJ ALDS1_6_D Minimum Cost Sort
// 2018.5.4 bal4u

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

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int cmp(int *a, int *b) { return *a - *b; }
int min_cost_sort(int n, int *w, int min, int max)
{
	int i, s, t, t1, t2, m, an, cur, ans;
	int *a, *v;
	char *f;

	a = malloc(n<<2), f = malloc(n), v = malloc((max+1)<<2);
	memcpy(a, w, n<<2), memset(f, 0, n);

	qsort(a, n, sizeof(int), cmp);
	for (i = 0; i < n; i++) v[a[i]] = i;

	ans = 0;
	for (i = 0; i < n; i++) {
		if (f[i]) continue;
		cur = i, s = 0, m = max, an = 0;
		while (1) {
			f[cur] = 1, an++, t = w[cur];
			if (t < m) m = t;
			s += t, cur = v[t];
			if (f[cur]) break;
		}
		t1 = s+(an-2)*m, t2 = m+s+(an+1)*min;
		ans += (t1 < t2)? t1: t2;
	}
	free(a), free(f), free(v);
	return ans;
}

int w[1002];

int main()
{
	int n, i, _w, min, max;

	n = in();
	min =  0x10101010;
	max = -0x10101010;
	for (i = 0; i < n; i++) {
		w[i] = _w = in();
		if (_w < min) min = _w;
		if (_w > max) max = _w;
	}
	printf("%d\n", min_cost_sort(n, w, min, max));
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	in
	.type	in, @function
in:
.LFB6:
	.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	$0, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
.L2:
	movl	-8(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %edx
	movl	-4(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
	cmpl	$47, -4(%rbp)
	jg	.L2
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	in, .-in
	.globl	cmp
	.type	cmp, @function
cmp:
.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, -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
.LFE7:
	.size	cmp, .-cmp
	.globl	min_cost_sort
	.type	min_cost_sort, @function
min_cost_sort:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$96, %rsp
	movl	%edi, -68(%rbp)
	movq	%rsi, -80(%rbp)
	movl	%edx, -72(%rbp)
	movl	%ecx, -84(%rbp)
	movl	-68(%rbp), %eax
	sall	$2, %eax
	cltq
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	-68(%rbp), %eax
	cltq
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	-84(%rbp), %eax
	addl	$1, %eax
	sall	$2, %eax
	cltq
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -8(%rbp)
	movl	-68(%rbp), %eax
	sall	$2, %eax
	movslq	%eax, %rdx
	movq	-80(%rbp), %rcx
	movq	-24(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	memcpy@PLT
	movl	-68(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	movl	-68(%rbp), %eax
	movslq	%eax, %rsi
	movq	-24(%rbp), %rax
	leaq	cmp(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -60(%rbp)
	jmp	.L7
.L8:
	movl	-60(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rax, %rdx
	movl	-60(%rbp), %eax
	movl	%eax, (%rdx)
	addl	$1, -60(%rbp)
.L7:
	movl	-60(%rbp), %eax
	cmpl	-68(%rbp), %eax
	jl	.L8
	movl	$0, -40(%rbp)
	movl	$0, -60(%rbp)
	jmp	.L9
.L16:
	movl	-60(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	jne	.L19
	movl	-60(%rbp), %eax
	movl	%eax, -44(%rbp)
	movl	$0, -56(%rbp)
	movl	-84(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	$0, -48(%rbp)
.L15:
	movl	-44(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movb	$1, (%rax)
	addl	$1, -48(%rbp)
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-80(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -36(%rbp)
	movl	-36(%rbp), %eax
	cmpl	-52(%rbp), %eax
	jge	.L12
	movl	-36(%rbp), %eax
	movl	%eax, -52(%rbp)
.L12:
	movl	-36(%rbp), %eax
	addl	%eax, -56(%rbp)
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -44(%rbp)
	movl	-44(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	jne	.L20
	jmp	.L15
.L20:
	nop
	movl	-48(%rbp), %eax
	subl	$2, %eax
	imull	-52(%rbp), %eax
	movl	%eax, %edx
	movl	-56(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -32(%rbp)
	movl	-52(%rbp), %edx
	movl	-56(%rbp), %eax
	addl	%eax, %edx
	movl	-48(%rbp), %eax
	addl	$1, %eax
	imull	-72(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -28(%rbp)
	movl	-28(%rbp), %edx
	movl	-32(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	addl	%eax, -40(%rbp)
	jmp	.L11
.L19:
	nop
.L11:
	addl	$1, -60(%rbp)
.L9:
	movl	-60(%rbp), %eax
	cmpl	-68(%rbp), %eax
	jl	.L16
	movq	-24(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movq	-16(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movq	-8(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	-40(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	min_cost_sort, .-min_cost_sort
	.globl	w
	.bss
	.align 32
	.type	w, @object
	.size	w, 4008
w:
	.zero	4008
	.section	.rodata
.LC0:
	.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
	movl	$0, %eax
	call	in
	movl	%eax, -8(%rbp)
	movl	$269488144, -16(%rbp)
	movl	$-269488144, -12(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L22
.L25:
	movl	$0, %eax
	call	in
	movl	%eax, -4(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	w(%rip), %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	cmpl	-16(%rbp), %eax
	jge	.L23
	movl	-4(%rbp), %eax
	movl	%eax, -16(%rbp)
.L23:
	movl	-4(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jle	.L24
	movl	-4(%rbp), %eax
	movl	%eax, -12(%rbp)
.L24:
	addl	$1, -20(%rbp)
.L22:
	movl	-20(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jl	.L25
	movl	-12(%rbp), %ecx
	movl	-16(%rbp), %edx
	movl	-8(%rbp), %eax
	leaq	w(%rip), %rsi
	movl	%eax, %edi
	call	min_cost_sort
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	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:
.LFB52:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE52:
	.size	cmp, .-cmp
	.p2align 4
	.globl	in
	.type	in, @function
in:
.LFB51:
	.cfi_startproc
	endbr64
	movq	stdin(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	8(%rdi), %rax
	movq	16(%rdi), %rcx
	cmpq	%rcx, %rax
	jnb	.L12
	leaq	1(%rax), %rdx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
.L5:
	xorl	%r12d, %r12d
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L6:
	leaq	1(%rdx), %rax
	movq	%rax, 8(%rdi)
	movzbl	(%rdx), %eax
	cmpl	$47, %eax
	jle	.L3
.L7:
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
.L9:
	leal	(%r12,%r12,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r12d
	cmpq	%rcx, %rdx
	jb	.L6
	call	__uflow@PLT
	cmpl	$47, %eax
	jle	.L3
	movq	stdin(%rip), %rdi
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L3:
	movl	%r12d, %eax
	popq	%r12
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L12:
	.cfi_restore_state
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
	jmp	.L5
	.cfi_endproc
.LFE51:
	.size	in, .-in
	.p2align 4
	.globl	min_cost_sort
	.type	min_cost_sort, @function
min_cost_sort:
.LFB53:
	.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
	movslq	%edi, %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
	movq	%rsi, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	%edx, 12(%rsp)
	leal	0(,%r13,4), %edx
	movslq	%edx, %rdx
	movl	%ecx, 8(%rsp)
	movq	%rdx, %rdi
	movq	%rdx, (%rsp)
	call	malloc@PLT
	movl	$1, %esi
	movq	%r13, %rdi
	movq	%rax, %r14
	call	calloc@PLT
	movl	8(%rsp), %r8d
	movq	%rax, %rbp
	leal	4(,%r8,4), %edi
	movslq	%edi, %rdi
	call	malloc@PLT
	movq	(%rsp), %rdx
	movq	%rbx, %rsi
	movq	%r14, %rdi
	movq	%rax, %r12
	call	memcpy@PLT
	movl	$4, %edx
	movq	%r13, %rsi
	movq	%r14, %rdi
	leaq	cmp(%rip), %rcx
	call	qsort@PLT
	testl	%r13d, %r13d
	jle	.L19
	movl	12(%rsp), %r9d
	movl	8(%rsp), %r8d
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L15:
	movslq	(%r14,%rax,4), %rdx
	movl	%eax, (%r12,%rdx,4)
	addq	$1, %rax
	cmpq	%rax, %r13
	jne	.L15
	xorl	%r10d, %r10d
	xorl	%r15d, %r15d
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L16:
	addq	$1, %r10
	cmpq	%r10, %r13
	je	.L14
.L18:
	cmpb	$0, 0(%rbp,%r10)
	movslq	%r10d, %rax
	jne	.L16
	movl	%r8d, %edx
	xorl	%ecx, %ecx
	xorl	%esi, %esi
	.p2align 4,,10
	.p2align 3
.L17:
	movb	$1, 0(%rbp,%rax)
	movslq	(%rbx,%rax,4), %rax
	movl	%ecx, %edi
	addl	$1, %ecx
	cmpl	%eax, %edx
	cmovg	%eax, %edx
	addl	%eax, %esi
	movslq	(%r12,%rax,4), %rax
	cmpb	$0, 0(%rbp,%rax)
	je	.L17
	leal	2(%rdi), %eax
	subl	$1, %edi
	leal	(%rsi,%rdx), %ecx
	imull	%r9d, %eax
	imull	%edx, %edi
	addl	%ecx, %eax
	addl	%esi, %edi
	cmpl	%edi, %eax
	cmovg	%edi, %eax
	addq	$1, %r10
	addl	%eax, %r15d
	cmpq	%r10, %r13
	jne	.L18
.L14:
	movq	%r14, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%r15d, %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
.L19:
	.cfi_restore_state
	xorl	%r15d, %r15d
	jmp	.L14
	.cfi_endproc
.LFE53:
	.size	min_cost_sort, .-min_cost_sort
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB54:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%eax, %eax
	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	$24, %rsp
	.cfi_def_cfa_offset 80
	call	in
	movl	%eax, %ebp
	testl	%eax, %eax
	jle	.L33
	leaq	w(%rip), %rax
	movl	$-269488144, %r12d
	movl	$269488144, %r15d
	movq	%rax, %r14
	movq	%rax, 8(%rsp)
	leal	-1(%rbp), %eax
	leaq	4(%r14), %rdx
	leaq	(%rdx,%rax,4), %rbx
	.p2align 4,,10
	.p2align 3
.L32:
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rax
	movq	16(%rdi), %rsi
	cmpq	%rsi, %rax
	jnb	.L37
	leaq	1(%rax), %rdx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
.L27:
	xorl	%r13d, %r13d
	jmp	.L31
	.p2align 4,,10
	.p2align 3
.L28:
	leaq	1(%rdx), %rax
	movq	%rax, 8(%rdi)
	movzbl	(%rdx), %eax
	cmpl	$47, %eax
	jle	.L30
.L29:
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rsi
.L31:
	leal	0(%r13,%r13,4), %r8d
	andl	$15, %eax
	leal	(%rax,%r8,2), %r13d
	cmpq	%rsi, %rdx
	jb	.L28
	call	__uflow@PLT
	cmpl	$47, %eax
	jle	.L30
	movq	stdin(%rip), %rdi
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L30:
	cmpl	%r13d, %r15d
	movl	%r13d, (%r14)
	cmovg	%r13d, %r15d
	cmpl	%r13d, %r12d
	cmovl	%r13d, %r12d
	addq	$4, %r14
	cmpq	%rbx, %r14
	jne	.L32
.L25:
	movq	8(%rsp), %rsi
	movl	%r12d, %ecx
	movl	%r15d, %edx
	movl	%ebp, %edi
	call	min_cost_sort
	leaq	.LC0(%rip), %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addq	$24, %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
.L37:
	.cfi_restore_state
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rsi
	jmp	.L27
.L33:
	leaq	w(%rip), %rax
	movl	$-269488144, %r12d
	movl	$269488144, %r15d
	movq	%rax, 8(%rsp)
	jmp	.L25
	.cfi_endproc
.LFE54:
	.size	main, .-main
	.globl	w
	.bss
	.align 32
	.type	w, @object
	.size	w, 4008
w:
	.zero	4008
	.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:
.LFB52:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE52:
	.size	cmp, .-cmp
	.p2align 4
	.globl	in
	.type	in, @function
in:
.LFB51:
	.cfi_startproc
	endbr64
	movq	stdin(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	8(%rdi), %rax
	movq	16(%rdi), %rcx
	cmpq	%rcx, %rax
	jnb	.L12
	leaq	1(%rax), %rdx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
.L5:
	xorl	%r12d, %r12d
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L6:
	leaq	1(%rdx), %rax
	movq	%rax, 8(%rdi)
	movzbl	(%rdx), %eax
	cmpl	$47, %eax
	jle	.L3
.L7:
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
.L9:
	leal	(%r12,%r12,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r12d
	cmpq	%rcx, %rdx
	jb	.L6
	call	__uflow@PLT
	cmpl	$47, %eax
	jle	.L3
	movq	stdin(%rip), %rdi
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L3:
	movl	%r12d, %eax
	popq	%r12
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L12:
	.cfi_restore_state
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
	jmp	.L5
	.cfi_endproc
.LFE51:
	.size	in, .-in
	.p2align 4
	.globl	min_cost_sort
	.type	min_cost_sort, @function
min_cost_sort:
.LFB53:
	.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
	movslq	%edi, %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
	movq	%rsi, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	%edx, 12(%rsp)
	leal	0(,%r13,4), %edx
	movslq	%edx, %rdx
	movl	%ecx, 8(%rsp)
	movq	%rdx, %rdi
	movq	%rdx, (%rsp)
	call	malloc@PLT
	movl	$1, %esi
	movq	%r13, %rdi
	movq	%rax, %r14
	call	calloc@PLT
	movl	8(%rsp), %r8d
	movq	%rax, %rbp
	leal	4(,%r8,4), %edi
	movslq	%edi, %rdi
	call	malloc@PLT
	movq	(%rsp), %rdx
	movq	%rbx, %rsi
	movq	%r14, %rdi
	movq	%rax, %r12
	call	memcpy@PLT
	movl	$4, %edx
	movq	%r13, %rsi
	movq	%r14, %rdi
	leaq	cmp(%rip), %rcx
	call	qsort@PLT
	testl	%r13d, %r13d
	jle	.L19
	movl	12(%rsp), %r9d
	movl	8(%rsp), %r8d
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L15:
	movslq	(%r14,%rax,4), %rdx
	movl	%eax, (%r12,%rdx,4)
	addq	$1, %rax
	cmpq	%rax, %r13
	jne	.L15
	xorl	%r10d, %r10d
	xorl	%r15d, %r15d
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L16:
	addq	$1, %r10
	cmpq	%r10, %r13
	je	.L14
.L18:
	cmpb	$0, 0(%rbp,%r10)
	movslq	%r10d, %rax
	jne	.L16
	movl	%r8d, %edx
	xorl	%ecx, %ecx
	xorl	%esi, %esi
	.p2align 4,,10
	.p2align 3
.L17:
	movb	$1, 0(%rbp,%rax)
	movslq	(%rbx,%rax,4), %rax
	movl	%ecx, %edi
	addl	$1, %ecx
	cmpl	%eax, %edx
	cmovg	%eax, %edx
	addl	%eax, %esi
	movslq	(%r12,%rax,4), %rax
	cmpb	$0, 0(%rbp,%rax)
	je	.L17
	leal	2(%rdi), %eax
	subl	$1, %edi
	leal	(%rsi,%rdx), %ecx
	imull	%r9d, %eax
	imull	%edx, %edi
	addl	%ecx, %eax
	addl	%esi, %edi
	cmpl	%edi, %eax
	cmovg	%edi, %eax
	addq	$1, %r10
	addl	%eax, %r15d
	cmpq	%r10, %r13
	jne	.L18
.L14:
	movq	%r14, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%r15d, %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
.L19:
	.cfi_restore_state
	xorl	%r15d, %r15d
	jmp	.L14
	.cfi_endproc
.LFE53:
	.size	min_cost_sort, .-min_cost_sort
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB54:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%eax, %eax
	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	$24, %rsp
	.cfi_def_cfa_offset 80
	call	in
	movl	%eax, %ebp
	testl	%eax, %eax
	jle	.L33
	leaq	w(%rip), %rax
	movl	$-269488144, %r12d
	movl	$269488144, %r15d
	movq	%rax, %r14
	movq	%rax, 8(%rsp)
	leal	-1(%rbp), %eax
	leaq	4(%r14), %rdx
	leaq	(%rdx,%rax,4), %rbx
	.p2align 4,,10
	.p2align 3
.L32:
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rax
	movq	16(%rdi), %rsi
	cmpq	%rsi, %rax
	jnb	.L37
	leaq	1(%rax), %rdx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
.L27:
	xorl	%r13d, %r13d
	jmp	.L31
	.p2align 4,,10
	.p2align 3
.L28:
	leaq	1(%rdx), %rax
	movq	%rax, 8(%rdi)
	movzbl	(%rdx), %eax
	cmpl	$47, %eax
	jle	.L30
.L29:
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rsi
.L31:
	leal	0(%r13,%r13,4), %r8d
	andl	$15, %eax
	leal	(%rax,%r8,2), %r13d
	cmpq	%rsi, %rdx
	jb	.L28
	call	__uflow@PLT
	cmpl	$47, %eax
	jle	.L30
	movq	stdin(%rip), %rdi
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L30:
	cmpl	%r13d, %r15d
	movl	%r13d, (%r14)
	cmovg	%r13d, %r15d
	cmpl	%r13d, %r12d
	cmovl	%r13d, %r12d
	addq	$4, %r14
	cmpq	%rbx, %r14
	jne	.L32
.L25:
	movq	8(%rsp), %rsi
	movl	%r12d, %ecx
	movl	%r15d, %edx
	movl	%ebp, %edi
	call	min_cost_sort
	leaq	.LC0(%rip), %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addq	$24, %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
.L37:
	.cfi_restore_state
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rsi
	jmp	.L27
.L33:
	leaq	w(%rip), %rax
	movl	$-269488144, %r12d
	movl	$269488144, %r15d
	movq	%rax, 8(%rsp)
	jmp	.L25
	.cfi_endproc
.LFE54:
	.size	main, .-main
	.globl	w
	.bss
	.align 32
	.type	w, @object
	.size	w, 4008
w:
	.zero	4008
	.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:

// AOJ ALDS1_6_D Minimum Cost Sort
// 2018.5.4 bal4u

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

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int cmp(int *a, int *b) { return *a - *b; }
int min_cost_sort(int n, int *w, int min, int max)
{
	int i, s, t, t1, t2, m, an, cur, ans;
	int *a, *v;
	char *f;

	a = malloc(n<<2), f = malloc(n), v = malloc((max+1)<<2);
	memcpy(a, w, n<<2), memset(f, 0, n);

	qsort(a, n, sizeof(int), cmp);
	for (i = 0; i < n; i++) v[a[i]] = i;

	ans = 0;
	for (i = 0; i < n; i++) {
		if (f[i]) continue;
		cur = i, s = 0, m = max, an = 0;
		while (1) {
			f[cur] = 1, an++, t = w[cur];
			if (t < m) m = t;
			s += t, cur = v[t];
			if (f[cur]) break;
		}
		t1 = s+(an-2)*m, t2 = m+s+(an+1)*min;
		ans += (t1 < t2)? t1: t2;
	}
	free(a), free(f), free(v);
	return ans;
}

int w[1002];

int main()
{
	int n, i, _w, min, max;

	n = in();
	min =  0x10101010;
	max = -0x10101010;
	for (i = 0; i < n; i++) {
		w[i] = _w = in();
		if (_w < min) min = _w;
		if (_w > max) max = _w;
	}
	printf("%d\n", min_cost_sort(n, w, min, max));
	return 0;
}

4
8 3 2 1
 5
0 5 3 4 2
 5
0 5 3 1 2
 5
1 8 3 4 2
 5
0 9 3 1 2
 5
1 8 3 4 0
 5
0 15 3 1 2
 5
1 5 3 8 2
 5
0 5 6 4 2
 5
0 5 3 1 4

14
 7
 12
 10
 16
 9
 22
 17
 19
 11

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

```c
// AOJ ALDS1_6_D Minimum Cost Sort
// 2018.5.4 bal4u

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

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int cmp(int *a, int *b) { return *a - *b; }
int min_cost_sort(int n, int *w, int min, int max)
{
	int i, s, t, t1, t2, m, an, cur, ans;
	int *a, *v;
	char *f;

	a = malloc(n<<2), f = malloc(n), v = malloc((max+1)<<2);
	memcpy(a, w, n<<2), memset(f, 0, n);

	qsort(a, n, sizeof(int), cmp);
	for (i = 0; i < n; i++) v[a[i]] = i;

	ans = 0;
	for (i = 0; i < n; i++) {
		if (f[i]) continue;
		cur = i, s = 0, m = max, an = 0;
		while (1) {
			f[cur] = 1, an++, t = w[cur];
			if (t < m) m = t;
			s += t, cur = v[t];
			if (f[cur]) break;
		}
		t1 = s+(an-2)*m, t2 = m+s+(an+1)*min;
		ans += (t1 < t2)? t1: t2;
	}
	free(a), free(f), free(v);
	return ans;
}

int w[1002];

int main()
{
	int n, i, _w, min, max;

	n = in();
	min =  0x10101010;
	max = -0x10101010;
	for (i = 0; i < n; i++) {
		w[i] = _w = in();
		if (_w < min) min = _w;
		if (_w > max) max = _w;
	}
	printf("%d\n", min_cost_sort(n, w, min, max));
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	in
	.type	in, @function
in:
.LFB6:
	.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	$0, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
.L2:
	movl	-8(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %edx
	movl	-4(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
	cmpl	$47, -4(%rbp)
	jg	.L2
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	in, .-in
	.globl	cmp
	.type	cmp, @function
cmp:
.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, -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
.LFE7:
	.size	cmp, .-cmp
	.globl	min_cost_sort
	.type	min_cost_sort, @function
min_cost_sort:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$96, %rsp
	movl	%edi, -68(%rbp)
	movq	%rsi, -80(%rbp)
	movl	%edx, -72(%rbp)
	movl	%ecx, -84(%rbp)
	movl	-68(%rbp), %eax
	sall	$2, %eax
	cltq
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	-68(%rbp), %eax
	cltq
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	-84(%rbp), %eax
	addl	$1, %eax
	sall	$2, %eax
	cltq
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -8(%rbp)
	movl	-68(%rbp), %eax
	sall	$2, %eax
	movslq	%eax, %rdx
	movq	-80(%rbp), %rcx
	movq	-24(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	memcpy@PLT
	movl	-68(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	movl	-68(%rbp), %eax
	movslq	%eax, %rsi
	movq	-24(%rbp), %rax
	leaq	cmp(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -60(%rbp)
	jmp	.L7
.L8:
	movl	-60(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rax, %rdx
	movl	-60(%rbp), %eax
	movl	%eax, (%rdx)
	addl	$1, -60(%rbp)
.L7:
	movl	-60(%rbp), %eax
	cmpl	-68(%rbp), %eax
	jl	.L8
	movl	$0, -40(%rbp)
	movl	$0, -60(%rbp)
	jmp	.L9
.L16:
	movl	-60(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	jne	.L19
	movl	-60(%rbp), %eax
	movl	%eax, -44(%rbp)
	movl	$0, -56(%rbp)
	movl	-84(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	$0, -48(%rbp)
.L15:
	movl	-44(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movb	$1, (%rax)
	addl	$1, -48(%rbp)
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-80(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -36(%rbp)
	movl	-36(%rbp), %eax
	cmpl	-52(%rbp), %eax
	jge	.L12
	movl	-36(%rbp), %eax
	movl	%eax, -52(%rbp)
.L12:
	movl	-36(%rbp), %eax
	addl	%eax, -56(%rbp)
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -44(%rbp)
	movl	-44(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	jne	.L20
	jmp	.L15
.L20:
	nop
	movl	-48(%rbp), %eax
	subl	$2, %eax
	imull	-52(%rbp), %eax
	movl	%eax, %edx
	movl	-56(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -32(%rbp)
	movl	-52(%rbp), %edx
	movl	-56(%rbp), %eax
	addl	%eax, %edx
	movl	-48(%rbp), %eax
	addl	$1, %eax
	imull	-72(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -28(%rbp)
	movl	-28(%rbp), %edx
	movl	-32(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	addl	%eax, -40(%rbp)
	jmp	.L11
.L19:
	nop
.L11:
	addl	$1, -60(%rbp)
.L9:
	movl	-60(%rbp), %eax
	cmpl	-68(%rbp), %eax
	jl	.L16
	movq	-24(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movq	-16(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movq	-8(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	-40(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	min_cost_sort, .-min_cost_sort
	.globl	w
	.bss
	.align 32
	.type	w, @object
	.size	w, 4008
w:
	.zero	4008
	.section	.rodata
.LC0:
	.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
	movl	$0, %eax
	call	in
	movl	%eax, -8(%rbp)
	movl	$269488144, -16(%rbp)
	movl	$-269488144, -12(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L22
.L25:
	movl	$0, %eax
	call	in
	movl	%eax, -4(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	w(%rip), %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	cmpl	-16(%rbp), %eax
	jge	.L23
	movl	-4(%rbp), %eax
	movl	%eax, -16(%rbp)
.L23:
	movl	-4(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jle	.L24
	movl	-4(%rbp), %eax
	movl	%eax, -12(%rbp)
.L24:
	addl	$1, -20(%rbp)
.L22:
	movl	-20(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jl	.L25
	movl	-12(%rbp), %ecx
	movl	-16(%rbp), %edx
	movl	-8(%rbp), %eax
	leaq	w(%rip), %rsi
	movl	%eax, %edi
	call	min_cost_sort
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	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	in
	.type	in, @function
in:
.LFB6:
	.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	$0, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
.L2:
	movl	-8(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %edx
	movl	-4(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
	cmpl	$47, -4(%rbp)
	jg	.L2
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	in, .-in
	.globl	cmp
	.type	cmp, @function
cmp:
.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, -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
.LFE7:
	.size	cmp, .-cmp
	.globl	min_cost_sort
	.type	min_cost_sort, @function
min_cost_sort:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$96, %rsp
	movl	%edi, -68(%rbp)
	movq	%rsi, -80(%rbp)
	movl	%edx, -72(%rbp)
	movl	%ecx, -84(%rbp)
	movl	-68(%rbp), %eax
	sall	$2, %eax
	cltq
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	-68(%rbp), %eax
	cltq
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	-84(%rbp), %eax
	addl	$1, %eax
	sall	$2, %eax
	cltq
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -8(%rbp)
	movl	-68(%rbp), %eax
	sall	$2, %eax
	movslq	%eax, %rdx
	movq	-80(%rbp), %rcx
	movq	-24(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	memcpy@PLT
	movl	-68(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	movl	-68(%rbp), %eax
	movslq	%eax, %rsi
	movq	-24(%rbp), %rax
	leaq	cmp(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -60(%rbp)
	jmp	.L7
.L8:
	movl	-60(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rax, %rdx
	movl	-60(%rbp), %eax
	movl	%eax, (%rdx)
	addl	$1, -60(%rbp)
.L7:
	movl	-60(%rbp), %eax
	cmpl	-68(%rbp), %eax
	jl	.L8
	movl	$0, -40(%rbp)
	movl	$0, -60(%rbp)
	jmp	.L9
.L16:
	movl	-60(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	jne	.L19
	movl	-60(%rbp), %eax
	movl	%eax, -44(%rbp)
	movl	$0, -56(%rbp)
	movl	-84(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	$0, -48(%rbp)
.L15:
	movl	-44(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movb	$1, (%rax)
	addl	$1, -48(%rbp)
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-80(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -36(%rbp)
	movl	-36(%rbp), %eax
	cmpl	-52(%rbp), %eax
	jge	.L12
	movl	-36(%rbp), %eax
	movl	%eax, -52(%rbp)
.L12:
	movl	-36(%rbp), %eax
	addl	%eax, -56(%rbp)
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -44(%rbp)
	movl	-44(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	jne	.L20
	jmp	.L15
.L20:
	nop
	movl	-48(%rbp), %eax
	subl	$2, %eax
	imull	-52(%rbp), %eax
	movl	%eax, %edx
	movl	-56(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -32(%rbp)
	movl	-52(%rbp), %edx
	movl	-56(%rbp), %eax
	addl	%eax, %edx
	movl	-48(%rbp), %eax
	addl	$1, %eax
	imull	-72(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -28(%rbp)
	movl	-28(%rbp), %edx
	movl	-32(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	addl	%eax, -40(%rbp)
	jmp	.L11
.L19:
	nop
.L11:
	addl	$1, -60(%rbp)
.L9:
	movl	-60(%rbp), %eax
	cmpl	-68(%rbp), %eax
	jl	.L16
	movq	-24(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movq	-16(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movq	-8(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	-40(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	min_cost_sort, .-min_cost_sort
	.globl	w
	.bss
	.align 32
	.type	w, @object
	.size	w, 4008
w:
	.zero	4008
	.section	.rodata
.LC0:
	.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
	movl	$0, %eax
	call	in
	movl	%eax, -8(%rbp)
	movl	$269488144, -16(%rbp)
	movl	$-269488144, -12(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L22
.L25:
	movl	$0, %eax
	call	in
	movl	%eax, -4(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	w(%rip), %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	cmpl	-16(%rbp), %eax
	jge	.L23
	movl	-4(%rbp), %eax
	movl	%eax, -16(%rbp)
.L23:
	movl	-4(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jle	.L24
	movl	-4(%rbp), %eax
	movl	%eax, -12(%rbp)
.L24:
	addl	$1, -20(%rbp)
.L22:
	movl	-20(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jl	.L25
	movl	-12(%rbp), %ecx
	movl	-16(%rbp), %edx
	movl	-8(%rbp), %eax
	leaq	w(%rip), %rsi
	movl	%eax, %edi
	call	min_cost_sort
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	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:
