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>
#include <inttypes.h>

uint64_t solve(int32_t n, const int32_t* a) {
	int32_t i;
	uint64_t cost = 0;
	int64_t value = 0;
	int64_t target = 1;
	for (i = 0; i < n; i++) {
		value += a[i];
		if (value == 0 || (value > 0) != (target > 0)) {
			int64_t diff = value - target;
			if (diff < 0) diff = -diff;
			cost += diff;
			value = target;
		}
		target = -target;
	}
	return cost;
}

int main(void) {
	int32_t n;
	int32_t* a;
	int32_t i;
	uint64_t c1, c2;
	if (scanf("%" SCNd32, &n) != 1) return 1;
	a = malloc(sizeof(*a) * n);
	if (a == NULL) return 2;
	for (i = 0; i < n; i++) {
		if (scanf("%" PRId32, &a[i]) != 1) return 1;
	}
	c1 = solve(n, a);
	for (i = 0; i < n; i++) a[i] = -a[i];
	c2 = solve(n, a);
	printf("%" PRIu64 "\n", c1 <= c2 ? c1 : c2);
	free(a);
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	solve
	.type	solve, @function
solve:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -52(%rbp)
	movq	%rsi, -64(%rbp)
	movq	$0, -32(%rbp)
	movq	$0, -24(%rbp)
	movq	$1, -16(%rbp)
	movl	$0, -36(%rbp)
	jmp	.L2
.L6:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-64(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cltq
	addq	%rax, -24(%rbp)
	cmpq	$0, -24(%rbp)
	je	.L3
	cmpq	$0, -24(%rbp)
	setg	%dl
	cmpq	$0, -16(%rbp)
	setg	%al
	xorl	%edx, %eax
	testb	%al, %al
	je	.L4
.L3:
	movq	-24(%rbp), %rax
	subq	-16(%rbp), %rax
	movq	%rax, -8(%rbp)
	cmpq	$0, -8(%rbp)
	jns	.L5
	negq	-8(%rbp)
.L5:
	movq	-8(%rbp), %rax
	addq	%rax, -32(%rbp)
	movq	-16(%rbp), %rax
	movq	%rax, -24(%rbp)
.L4:
	negq	-16(%rbp)
	addl	$1, -36(%rbp)
.L2:
	movl	-36(%rbp), %eax
	cmpl	-52(%rbp), %eax
	jl	.L6
	movq	-32(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%lu\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
	subq	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L9
	movl	$1, %eax
	jmp	.L17
.L9:
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -32(%rbp)
	cmpq	$0, -32(%rbp)
	jne	.L11
	movl	$2, %eax
	jmp	.L17
.L11:
	movl	$0, -36(%rbp)
	jmp	.L12
.L14:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L13
	movl	$1, %eax
	jmp	.L17
.L13:
	addl	$1, -36(%rbp)
.L12:
	movl	-40(%rbp), %eax
	cmpl	%eax, -36(%rbp)
	jl	.L14
	movl	-40(%rbp), %eax
	movq	-32(%rbp), %rdx
	movq	%rdx, %rsi
	movl	%eax, %edi
	call	solve
	movq	%rax, -24(%rbp)
	movl	$0, -36(%rbp)
	jmp	.L15
.L16:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	negl	%edx
	movl	%edx, (%rax)
	addl	$1, -36(%rbp)
.L15:
	movl	-40(%rbp), %eax
	cmpl	%eax, -36(%rbp)
	jl	.L16
	movl	-40(%rbp), %eax
	movq	-32(%rbp), %rdx
	movq	%rdx, %rsi
	movl	%eax, %edi
	call	solve
	movq	%rax, -16(%rbp)
	movq	-24(%rbp), %rdx
	movq	-16(%rbp), %rax
	cmpq	%rax, %rdx
	cmovbe	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-32(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
.L17:
	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	solve
	.type	solve, @function
solve:
.LFB39:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	jle	.L8
	leal	-1(%rdi), %eax
	movl	$1, %edx
	xorl	%r8d, %r8d
	leaq	4(%rsi,%rax,4), %rdi
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L7:
	movslq	(%rsi), %rcx
	addq	%rcx, %rax
	testq	%rax, %rax
	je	.L6
	setg	%r9b
	testq	%rdx, %rdx
	setg	%cl
	cmpb	%cl, %r9b
	je	.L5
.L6:
	movq	%rdx, %rcx
	subq	%rax, %rcx
	subq	%rdx, %rax
	cmovs	%rcx, %rax
	addq	%rax, %r8
	movq	%rdx, %rax
.L5:
	addq	$4, %rsi
	negq	%rdx
	cmpq	%rsi, %rdi
	jne	.L7
	movq	%r8, %rax
	ret
	.p2align 4,,10
	.p2align 3
.L8:
	xorl	%r8d, %r8d
	movq	%r8, %rax
	ret
	.cfi_endproc
.LFE39:
	.size	solve, .-solve
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%lu\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.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
	leaq	.LC0(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%r13, %rdi
	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
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rsi
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L12
.L15:
	movl	$1, %eax
.L11:
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	jne	.L28
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	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
.L12:
	.cfi_restore_state
	movslq	4(%rsp), %rdi
	movq	%rdi, %r12
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %r15
	testq	%rax, %rax
	je	.L23
	testl	%r12d, %r12d
	jle	.L14
	movq	%rax, %r14
	movq	%rax, %rbx
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L16:
	xorl	%eax, %eax
	movq	%rbx, %rsi
	movq	%r13, %rdi
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	jne	.L15
	movl	4(%rsp), %r12d
	addl	$1, %ebp
	addq	$4, %rbx
	cmpl	%ebp, %r12d
	jg	.L16
	movq	%r15, %rsi
	movl	%r12d, %edi
	call	solve
	movq	%rax, %r10
	testl	%r12d, %r12d
	jle	.L17
	leal	-1(%r12), %eax
	cmpl	$2, %eax
	jbe	.L24
	movl	%r12d, %eax
	pxor	%xmm1, %xmm1
	shrl	$2, %eax
	salq	$4, %rax
	addq	%r15, %rax
	.p2align 4,,10
	.p2align 3
.L19:
	movdqu	(%r14), %xmm2
	movdqa	%xmm1, %xmm0
	addq	$16, %r14
	psubd	%xmm2, %xmm0
	movups	%xmm0, -16(%r14)
	cmpq	%rax, %r14
	jne	.L19
	movl	%r12d, %edx
	andl	$-4, %edx
	testb	$3, %r12b
	je	.L17
.L18:
	movslq	%edx, %rax
	leal	1(%rdx), %ecx
	salq	$2, %rax
	negl	(%r15,%rax)
	cmpl	%ecx, %r12d
	jle	.L17
	addl	$2, %edx
	negl	4(%r15,%rax)
	cmpl	%edx, %r12d
	jle	.L17
	negl	8(%r15,%rax)
.L17:
	movq	%r15, %rsi
	movl	%r12d, %edi
	call	solve
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	cmpq	%rax, %r10
	cmovbe	%r10, %rax
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r15, %rdi
	call	free@PLT
	xorl	%eax, %eax
	jmp	.L11
.L14:
	movq	%rax, %rsi
	movl	%r12d, %edi
	call	solve
	movq	%rax, %r10
	jmp	.L17
.L24:
	xorl	%edx, %edx
	jmp	.L18
.L28:
	call	__stack_chk_fail@PLT
.L23:
	movl	$2, %eax
	jmp	.L11
	.cfi_endproc
.LFE40:
	.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:

rule
	.file	"temp.c"
	.text
	.p2align 4
	.globl	solve
	.type	solve, @function
solve:
.LFB39:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	jle	.L8
	leal	-1(%rdi), %eax
	movl	$1, %edx
	xorl	%r8d, %r8d
	leaq	4(%rsi,%rax,4), %rdi
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L7:
	movslq	(%rsi), %rcx
	addq	%rcx, %rax
	testq	%rax, %rax
	je	.L6
	setg	%r9b
	testq	%rdx, %rdx
	setg	%cl
	cmpb	%cl, %r9b
	je	.L5
.L6:
	movq	%rdx, %rcx
	subq	%rax, %rcx
	subq	%rdx, %rax
	cmovs	%rcx, %rax
	addq	%rax, %r8
	movq	%rdx, %rax
.L5:
	addq	$4, %rsi
	negq	%rdx
	cmpq	%rsi, %rdi
	jne	.L7
	movq	%r8, %rax
	ret
	.p2align 4,,10
	.p2align 3
.L8:
	xorl	%r8d, %r8d
	movq	%r8, %rax
	ret
	.cfi_endproc
.LFE39:
	.size	solve, .-solve
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%lu\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.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
	leaq	.LC0(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%r13, %rdi
	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
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rsi
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L12
.L15:
	movl	$1, %eax
.L11:
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	jne	.L28
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	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
.L12:
	.cfi_restore_state
	movslq	4(%rsp), %rdi
	movq	%rdi, %r12
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %r15
	testq	%rax, %rax
	je	.L23
	testl	%r12d, %r12d
	jle	.L14
	movq	%rax, %r14
	movq	%rax, %rbx
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L16:
	xorl	%eax, %eax
	movq	%rbx, %rsi
	movq	%r13, %rdi
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	jne	.L15
	movl	4(%rsp), %r12d
	addl	$1, %ebp
	addq	$4, %rbx
	cmpl	%ebp, %r12d
	jg	.L16
	movq	%r15, %rsi
	movl	%r12d, %edi
	call	solve
	movq	%rax, %r10
	testl	%r12d, %r12d
	jle	.L17
	leal	-1(%r12), %eax
	cmpl	$2, %eax
	jbe	.L24
	movl	%r12d, %eax
	pxor	%xmm1, %xmm1
	shrl	$2, %eax
	salq	$4, %rax
	addq	%r15, %rax
	.p2align 4,,10
	.p2align 3
.L19:
	movdqu	(%r14), %xmm2
	movdqa	%xmm1, %xmm0
	addq	$16, %r14
	psubd	%xmm2, %xmm0
	movups	%xmm0, -16(%r14)
	cmpq	%rax, %r14
	jne	.L19
	movl	%r12d, %edx
	andl	$-4, %edx
	testb	$3, %r12b
	je	.L17
.L18:
	movslq	%edx, %rax
	leal	1(%rdx), %ecx
	salq	$2, %rax
	negl	(%r15,%rax)
	cmpl	%ecx, %r12d
	jle	.L17
	addl	$2, %edx
	negl	4(%r15,%rax)
	cmpl	%edx, %r12d
	jle	.L17
	negl	8(%r15,%rax)
.L17:
	movq	%r15, %rsi
	movl	%r12d, %edi
	call	solve
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	cmpq	%rax, %r10
	cmovbe	%r10, %rax
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r15, %rdi
	call	free@PLT
	xorl	%eax, %eax
	jmp	.L11
.L14:
	movq	%rax, %rsi
	movl	%r12d, %edi
	call	solve
	movq	%rax, %r10
	jmp	.L17
.L24:
	xorl	%edx, %edx
	jmp	.L18
.L28:
	call	__stack_chk_fail@PLT
.L23:
	movl	$2, %eax
	jmp	.L11
	.cfi_endproc
.LFE40:
	.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:

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

uint64_t solve(int32_t n, const int32_t* a) {
	int32_t i;
	uint64_t cost = 0;
	int64_t value = 0;
	int64_t target = 1;
	for (i = 0; i < n; i++) {
		value += a[i];
		if (value == 0 || (value > 0) != (target > 0)) {
			int64_t diff = value - target;
			if (diff < 0) diff = -diff;
			cost += diff;
			value = target;
		}
		target = -target;
	}
	return cost;
}

int main(void) {
	int32_t n;
	int32_t* a;
	int32_t i;
	uint64_t c1, c2;
	if (scanf("%" SCNd32, &n) != 1) return 1;
	a = malloc(sizeof(*a) * n);
	if (a == NULL) return 2;
	for (i = 0; i < n; i++) {
		if (scanf("%" PRId32, &a[i]) != 1) return 1;
	}
	c1 = solve(n, a);
	for (i = 0; i < n; i++) a[i] = -a[i];
	c2 = solve(n, a);
	printf("%" PRIu64 "\n", c1 <= c2 ? c1 : c2);
	free(a);
	return 0;
}

5
3 -6 4 -8 7
 4
1 -3 1 -1
 6
-1 4 3 2 -5 0
 4
1 -5 1 -1
 6
-1 4 2 2 -5 0
 5
3 -8 4 -12 7
 4
1 -5 0 -1
 6
-1 4 1 2 -5 0
 5
3 -5 4 -12 7
 6
-1 8 1 2 -5 0

1
 3
 12
 5
 11
 7
 6
 10
 4
 14

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>
#include <inttypes.h>

uint64_t solve(int32_t n, const int32_t* a) {
	int32_t i;
	uint64_t cost = 0;
	int64_t value = 0;
	int64_t target = 1;
	for (i = 0; i < n; i++) {
		value += a[i];
		if (value == 0 || (value > 0) != (target > 0)) {
			int64_t diff = value - target;
			if (diff < 0) diff = -diff;
			cost += diff;
			value = target;
		}
		target = -target;
	}
	return cost;
}

int main(void) {
	int32_t n;
	int32_t* a;
	int32_t i;
	uint64_t c1, c2;
	if (scanf("%" SCNd32, &n) != 1) return 1;
	a = malloc(sizeof(*a) * n);
	if (a == NULL) return 2;
	for (i = 0; i < n; i++) {
		if (scanf("%" PRId32, &a[i]) != 1) return 1;
	}
	c1 = solve(n, a);
	for (i = 0; i < n; i++) a[i] = -a[i];
	c2 = solve(n, a);
	printf("%" PRIu64 "\n", c1 <= c2 ? c1 : c2);
	free(a);
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	solve
	.type	solve, @function
solve:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -52(%rbp)
	movq	%rsi, -64(%rbp)
	movq	$0, -32(%rbp)
	movq	$0, -24(%rbp)
	movq	$1, -16(%rbp)
	movl	$0, -36(%rbp)
	jmp	.L2
.L6:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-64(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cltq
	addq	%rax, -24(%rbp)
	cmpq	$0, -24(%rbp)
	je	.L3
	cmpq	$0, -24(%rbp)
	setg	%dl
	cmpq	$0, -16(%rbp)
	setg	%al
	xorl	%edx, %eax
	testb	%al, %al
	je	.L4
.L3:
	movq	-24(%rbp), %rax
	subq	-16(%rbp), %rax
	movq	%rax, -8(%rbp)
	cmpq	$0, -8(%rbp)
	jns	.L5
	negq	-8(%rbp)
.L5:
	movq	-8(%rbp), %rax
	addq	%rax, -32(%rbp)
	movq	-16(%rbp), %rax
	movq	%rax, -24(%rbp)
.L4:
	negq	-16(%rbp)
	addl	$1, -36(%rbp)
.L2:
	movl	-36(%rbp), %eax
	cmpl	-52(%rbp), %eax
	jl	.L6
	movq	-32(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%lu\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
	subq	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L9
	movl	$1, %eax
	jmp	.L17
.L9:
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -32(%rbp)
	cmpq	$0, -32(%rbp)
	jne	.L11
	movl	$2, %eax
	jmp	.L17
.L11:
	movl	$0, -36(%rbp)
	jmp	.L12
.L14:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L13
	movl	$1, %eax
	jmp	.L17
.L13:
	addl	$1, -36(%rbp)
.L12:
	movl	-40(%rbp), %eax
	cmpl	%eax, -36(%rbp)
	jl	.L14
	movl	-40(%rbp), %eax
	movq	-32(%rbp), %rdx
	movq	%rdx, %rsi
	movl	%eax, %edi
	call	solve
	movq	%rax, -24(%rbp)
	movl	$0, -36(%rbp)
	jmp	.L15
.L16:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	negl	%edx
	movl	%edx, (%rax)
	addl	$1, -36(%rbp)
.L15:
	movl	-40(%rbp), %eax
	cmpl	%eax, -36(%rbp)
	jl	.L16
	movl	-40(%rbp), %eax
	movq	-32(%rbp), %rdx
	movq	%rdx, %rsi
	movl	%eax, %edi
	call	solve
	movq	%rax, -16(%rbp)
	movq	-24(%rbp), %rdx
	movq	-16(%rbp), %rax
	cmpq	%rax, %rdx
	cmovbe	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-32(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
.L17:
	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	solve
	.type	solve, @function
solve:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -52(%rbp)
	movq	%rsi, -64(%rbp)
	movq	$0, -32(%rbp)
	movq	$0, -24(%rbp)
	movq	$1, -16(%rbp)
	movl	$0, -36(%rbp)
	jmp	.L2
.L6:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-64(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cltq
	addq	%rax, -24(%rbp)
	cmpq	$0, -24(%rbp)
	je	.L3
	cmpq	$0, -24(%rbp)
	setg	%dl
	cmpq	$0, -16(%rbp)
	setg	%al
	xorl	%edx, %eax
	testb	%al, %al
	je	.L4
.L3:
	movq	-24(%rbp), %rax
	subq	-16(%rbp), %rax
	movq	%rax, -8(%rbp)
	cmpq	$0, -8(%rbp)
	jns	.L5
	negq	-8(%rbp)
.L5:
	movq	-8(%rbp), %rax
	addq	%rax, -32(%rbp)
	movq	-16(%rbp), %rax
	movq	%rax, -24(%rbp)
.L4:
	negq	-16(%rbp)
	addl	$1, -36(%rbp)
.L2:
	movl	-36(%rbp), %eax
	cmpl	-52(%rbp), %eax
	jl	.L6
	movq	-32(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%lu\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
	subq	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L9
	movl	$1, %eax
	jmp	.L17
.L9:
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -32(%rbp)
	cmpq	$0, -32(%rbp)
	jne	.L11
	movl	$2, %eax
	jmp	.L17
.L11:
	movl	$0, -36(%rbp)
	jmp	.L12
.L14:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L13
	movl	$1, %eax
	jmp	.L17
.L13:
	addl	$1, -36(%rbp)
.L12:
	movl	-40(%rbp), %eax
	cmpl	%eax, -36(%rbp)
	jl	.L14
	movl	-40(%rbp), %eax
	movq	-32(%rbp), %rdx
	movq	%rdx, %rsi
	movl	%eax, %edi
	call	solve
	movq	%rax, -24(%rbp)
	movl	$0, -36(%rbp)
	jmp	.L15
.L16:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	negl	%edx
	movl	%edx, (%rax)
	addl	$1, -36(%rbp)
.L15:
	movl	-40(%rbp), %eax
	cmpl	%eax, -36(%rbp)
	jl	.L16
	movl	-40(%rbp), %eax
	movq	-32(%rbp), %rdx
	movq	%rdx, %rsi
	movl	%eax, %edi
	call	solve
	movq	%rax, -16(%rbp)
	movq	-24(%rbp), %rdx
	movq	-16(%rbp), %rax
	cmpq	%rax, %rdx
	cmovbe	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-32(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
.L17:
	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:
