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

typedef int32_t i32;
typedef int64_t i64;

void update (i64 *bit, i32 x, i64 v) {
  i32 n = bit[0];
  for (i32 i = x; i <= n; i += i & -i) {
    if (bit[i] < v) {
      bit[i] = v;
    }
  }
}

i64 find (i64 *bit, i32 x) {
  i64 max = 0;
  for (i32 i = x; i > 0; i ^= i & -i) {
    if (max < bit[i]) {
      max = bit[i];
    }
  }
  return max;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *h = (i32 *) calloc (n, sizeof (i32));
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, h + i);
  }
  i64 *bit = (i64 *) calloc (n + 1, sizeof (i64));
  bit[0] = n;
  for (i32 i = 0; i < n; ++i) {
    i32 a;
    scanf ("%" SCNi32, &a);
    i64 v = a + find (bit, h[i]);
    update (bit, h[i], v);
  }
  printf ("%" PRIi64 "\n", find (bit, n));
}

int main (void) {
  run();
  return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	update
	.type	update, @function
update:
.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)
	movl	%esi, -28(%rbp)
	movq	%rdx, -40(%rbp)
	movq	-24(%rbp), %rax
	movq	(%rax), %rax
	movl	%eax, -4(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -8(%rbp)
	jmp	.L2
.L4:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	cmpq	%rax, -40(%rbp)
	jle	.L3
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movq	-40(%rbp), %rax
	movq	%rax, (%rdx)
.L3:
	movl	-8(%rbp), %eax
	negl	%eax
	andl	-8(%rbp), %eax
	addl	%eax, -8(%rbp)
.L2:
	movl	-8(%rbp), %eax
	cmpl	-4(%rbp), %eax
	jle	.L4
	nop
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	update, .-update
	.globl	find
	.type	find, @function
find:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movq	$0, -8(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L6
.L8:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	cmpq	%rax, -8(%rbp)
	jge	.L7
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	%rax, -8(%rbp)
.L7:
	movl	-12(%rbp), %eax
	subl	$1, %eax
	andl	%eax, -12(%rbp)
.L6:
	cmpl	$0, -12(%rbp)
	jg	.L8
	movq	-8(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	find, .-find
	.section	.rodata
.LC0:
	.string	"%i"
.LC1:
	.string	"%li\n"
	.text
	.globl	run
	.type	run, @function
run:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	leaq	-64(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-64(%rbp), %eax
	cltq
	movl	$4, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -48(%rbp)
	movl	$0, -56(%rbp)
	jmp	.L11
.L12:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -56(%rbp)
.L11:
	movl	-64(%rbp), %eax
	cmpl	%eax, -56(%rbp)
	jl	.L12
	movl	-64(%rbp), %eax
	addl	$1, %eax
	cltq
	movl	$8, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -40(%rbp)
	movl	-64(%rbp), %eax
	movslq	%eax, %rdx
	movq	-40(%rbp), %rax
	movq	%rdx, (%rax)
	movl	$0, -52(%rbp)
	jmp	.L13
.L14:
	leaq	-60(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-60(%rbp), %eax
	movslq	%eax, %rbx
	movl	-52(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movq	-40(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	find
	addq	%rbx, %rax
	movq	%rax, -32(%rbp)
	movl	-52(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %ecx
	movq	-32(%rbp), %rdx
	movq	-40(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	update
	addl	$1, -52(%rbp)
.L13:
	movl	-64(%rbp), %eax
	cmpl	%eax, -52(%rbp)
	jl	.L14
	movl	-64(%rbp), %edx
	movq	-40(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	find
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	nop
	movq	-24(%rbp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	run, .-run
	.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
	call	run
	movl	$0, %eax
	popq	%rbp
	.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	update
	.type	update, @function
update:
.LFB39:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	movl	%eax, %ecx
	cmpl	%esi, %eax
	jl	.L1
	.p2align 4,,10
	.p2align 3
.L4:
	movslq	%esi, %rax
	leaq	(%rdi,%rax,8), %rax
	cmpq	%rdx, (%rax)
	jge	.L3
	movq	%rdx, (%rax)
.L3:
	movl	%esi, %eax
	negl	%eax
	andl	%esi, %eax
	addl	%eax, %esi
	cmpl	%esi, %ecx
	jge	.L4
.L1:
	ret
	.cfi_endproc
.LFE39:
	.size	update, .-update
	.p2align 4
	.globl	find
	.type	find, @function
find:
.LFB40:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	testl	%esi, %esi
	jle	.L10
	.p2align 4,,10
	.p2align 3
.L9:
	movslq	%esi, %rdx
	movq	(%rdi,%rdx,8), %rdx
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	leal	-1(%rsi), %edx
	andl	%edx, %esi
	jne	.L9
	ret
	.p2align 4,,10
	.p2align 3
.L10:
	ret
	.cfi_endproc
.LFE40:
	.size	find, .-find
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%i"
.LC1:
	.string	"%li\n"
	.text
	.p2align 4
	.globl	run
	.type	run, @function
run:
.LFB41:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	.LC0(%rip), %rbx
	movq	%rbx, %rdi
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	movslq	(%rsp), %rdi
	movl	$4, %esi
	movq	%rdi, %r12
	call	calloc@PLT
	testl	%r12d, %r12d
	jle	.L13
	movq	%rax, %rbp
	movq	%rax, %r13
	xorl	%r12d, %r12d
	.p2align 4,,10
	.p2align 3
.L14:
	movq	%r13, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r12d
	call	__isoc99_scanf@PLT
	movl	(%rsp), %r14d
	addq	$4, %r13
	cmpl	%r12d, %r14d
	jg	.L14
	leal	1(%r14), %edi
	movl	$8, %esi
	movslq	%edi, %rdi
	call	calloc@PLT
	movq	%rax, %r13
	movslq	%r14d, %rax
	movq	%rax, 0(%r13)
	testl	%r14d, %r14d
	jle	.L13
	xorl	%r14d, %r14d
	leaq	4(%rsp), %r12
	.p2align 4,,10
	.p2align 3
.L15:
	movq	%rbx, %rdi
	movq	%r12, %rsi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	0(%rbp,%r14,4), %eax
	movslq	4(%rsp), %rdi
	testl	%eax, %eax
	jle	.L17
	movl	%eax, %edx
	xorl	%ecx, %ecx
	.p2align 4,,10
	.p2align 3
.L18:
	movslq	%edx, %rsi
	movq	0(%r13,%rsi,8), %rsi
	cmpq	%rsi, %rcx
	cmovl	%rsi, %rcx
	leal	-1(%rdx), %esi
	andl	%esi, %edx
	jne	.L18
	addq	%rcx, %rdi
.L17:
	movq	0(%r13), %rdx
	movl	%edx, %ecx
	cmpl	%edx, %eax
	jg	.L22
	.p2align 4,,10
	.p2align 3
.L19:
	movslq	%eax, %rdx
	leaq	0(%r13,%rdx,8), %rdx
	cmpq	%rdi, (%rdx)
	jge	.L21
	movq	%rdi, (%rdx)
.L21:
	movl	%eax, %edx
	negl	%edx
	andl	%eax, %edx
	addl	%edx, %eax
	cmpl	%eax, %ecx
	jge	.L19
.L22:
	movl	(%rsp), %eax
	addq	$1, %r14
	cmpl	%r14d, %eax
	jg	.L15
	testl	%eax, %eax
	jle	.L13
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L23:
	movslq	%eax, %rcx
	movq	0(%r13,%rcx,8), %rcx
	cmpq	%rcx, %rdx
	cmovl	%rcx, %rdx
	leal	-1(%rax), %ecx
	andl	%ecx, %eax
	jne	.L23
.L16:
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L34
	addq	$16, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L13:
	.cfi_restore_state
	xorl	%edx, %edx
	jmp	.L16
.L34:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE41:
	.size	run, .-run
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB42:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	call	run
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE42:
	.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	update
	.type	update, @function
update:
.LFB39:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	movl	%eax, %ecx
	cmpl	%esi, %eax
	jl	.L1
	.p2align 4,,10
	.p2align 3
.L4:
	movslq	%esi, %rax
	leaq	(%rdi,%rax,8), %rax
	cmpq	%rdx, (%rax)
	jge	.L3
	movq	%rdx, (%rax)
.L3:
	movl	%esi, %eax
	negl	%eax
	andl	%esi, %eax
	addl	%eax, %esi
	cmpl	%esi, %ecx
	jge	.L4
.L1:
	ret
	.cfi_endproc
.LFE39:
	.size	update, .-update
	.p2align 4
	.globl	find
	.type	find, @function
find:
.LFB40:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	testl	%esi, %esi
	jle	.L10
	.p2align 4,,10
	.p2align 3
.L9:
	movslq	%esi, %rdx
	movq	(%rdi,%rdx,8), %rdx
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	leal	-1(%rsi), %edx
	andl	%edx, %esi
	jne	.L9
	ret
	.p2align 4,,10
	.p2align 3
.L10:
	ret
	.cfi_endproc
.LFE40:
	.size	find, .-find
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%i"
.LC1:
	.string	"%li\n"
	.text
	.p2align 4
	.globl	run
	.type	run, @function
run:
.LFB41:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	.LC0(%rip), %rbx
	movq	%rbx, %rdi
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	movslq	(%rsp), %rdi
	movl	$4, %esi
	movq	%rdi, %r12
	call	calloc@PLT
	testl	%r12d, %r12d
	jle	.L13
	movq	%rax, %rbp
	movq	%rax, %r13
	xorl	%r12d, %r12d
	.p2align 4,,10
	.p2align 3
.L14:
	movq	%r13, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r12d
	call	__isoc99_scanf@PLT
	movl	(%rsp), %r14d
	addq	$4, %r13
	cmpl	%r12d, %r14d
	jg	.L14
	leal	1(%r14), %edi
	movl	$8, %esi
	movslq	%edi, %rdi
	call	calloc@PLT
	movq	%rax, %r13
	movslq	%r14d, %rax
	movq	%rax, 0(%r13)
	testl	%r14d, %r14d
	jle	.L13
	xorl	%r14d, %r14d
	leaq	4(%rsp), %r12
	.p2align 4,,10
	.p2align 3
.L15:
	movq	%rbx, %rdi
	movq	%r12, %rsi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	0(%rbp,%r14,4), %eax
	movslq	4(%rsp), %rdi
	testl	%eax, %eax
	jle	.L17
	movl	%eax, %edx
	xorl	%ecx, %ecx
	.p2align 4,,10
	.p2align 3
.L18:
	movslq	%edx, %rsi
	movq	0(%r13,%rsi,8), %rsi
	cmpq	%rsi, %rcx
	cmovl	%rsi, %rcx
	leal	-1(%rdx), %esi
	andl	%esi, %edx
	jne	.L18
	addq	%rcx, %rdi
.L17:
	movq	0(%r13), %rdx
	movl	%edx, %ecx
	cmpl	%edx, %eax
	jg	.L22
	.p2align 4,,10
	.p2align 3
.L19:
	movslq	%eax, %rdx
	leaq	0(%r13,%rdx,8), %rdx
	cmpq	%rdi, (%rdx)
	jge	.L21
	movq	%rdi, (%rdx)
.L21:
	movl	%eax, %edx
	negl	%edx
	andl	%eax, %edx
	addl	%edx, %eax
	cmpl	%eax, %ecx
	jge	.L19
.L22:
	movl	(%rsp), %eax
	addq	$1, %r14
	cmpl	%r14d, %eax
	jg	.L15
	testl	%eax, %eax
	jle	.L13
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L23:
	movslq	%eax, %rcx
	movq	0(%r13,%rcx,8), %rcx
	cmpq	%rcx, %rdx
	cmovl	%rcx, %rdx
	leal	-1(%rax), %ecx
	andl	%ecx, %eax
	jne	.L23
.L16:
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L34
	addq	$16, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L13:
	.cfi_restore_state
	xorl	%edx, %edx
	jmp	.L16
.L34:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE41:
	.size	run, .-run
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB42:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	call	run
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE42:
	.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<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

void update (i64 *bit, i32 x, i64 v) {
  i32 n = bit[0];
  for (i32 i = x; i <= n; i += i & -i) {
    if (bit[i] < v) {
      bit[i] = v;
    }
  }
}

i64 find (i64 *bit, i32 x) {
  i64 max = 0;
  for (i32 i = x; i > 0; i ^= i & -i) {
    if (max < bit[i]) {
      max = bit[i];
    }
  }
  return max;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *h = (i32 *) calloc (n, sizeof (i32));
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, h + i);
  }
  i64 *bit = (i64 *) calloc (n + 1, sizeof (i64));
  bit[0] = n;
  for (i32 i = 0; i < n; ++i) {
    i32 a;
    scanf ("%" SCNi32, &a);
    i64 v = a + find (bit, h[i]);
    update (bit, h[i], v);
  }
  printf ("%" PRIi64 "\n", find (bit, n));
}

int main (void) {
  run();
  return 0;
}

5
1 2 3 4 5
1000000000 1000000010 1000000000 1000000000 1000000000
 4
3 1 4 2
10 20 2 40
 9
4 2 5 8 3 6 1 7 9
6 8 8 4 6 5 5 7 5
 5
1 2 3 4 5
1000000000 1000000010 1000000000 1010000000 1000000000
 9
4 2 5 8 3 6 1 7 9
6 8 8 4 6 4 5 7 5
 5
1 2 3 4 5
1000000000 1000000010 1000100000 1010000000 1000000000
 4
3 1 4 2
20 20 2 26
 4
3 1 4 2
15 25 2 40
 5
1 2 3 4 5
1010000000 1000000010 1000100000 1010000000 1000000000
 5
1 2 3 4 5
1010000000 0000000010 1000100000 1010000000 1000000000

5000000010
 60
 33
 5010000010
 32
 5010100010
 46
 65
 5020100010
 4020100008

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

typedef int32_t i32;
typedef int64_t i64;

void update (i64 *bit, i32 x, i64 v) {
  i32 n = bit[0];
  for (i32 i = x; i <= n; i += i & -i) {
    if (bit[i] < v) {
      bit[i] = v;
    }
  }
}

i64 find (i64 *bit, i32 x) {
  i64 max = 0;
  for (i32 i = x; i > 0; i ^= i & -i) {
    if (max < bit[i]) {
      max = bit[i];
    }
  }
  return max;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *h = (i32 *) calloc (n, sizeof (i32));
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, h + i);
  }
  i64 *bit = (i64 *) calloc (n + 1, sizeof (i64));
  bit[0] = n;
  for (i32 i = 0; i < n; ++i) {
    i32 a;
    scanf ("%" SCNi32, &a);
    i64 v = a + find (bit, h[i]);
    update (bit, h[i], v);
  }
  printf ("%" PRIi64 "\n", find (bit, n));
}

int main (void) {
  run();
  return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	update
	.type	update, @function
update:
.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)
	movl	%esi, -28(%rbp)
	movq	%rdx, -40(%rbp)
	movq	-24(%rbp), %rax
	movq	(%rax), %rax
	movl	%eax, -4(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -8(%rbp)
	jmp	.L2
.L4:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	cmpq	%rax, -40(%rbp)
	jle	.L3
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movq	-40(%rbp), %rax
	movq	%rax, (%rdx)
.L3:
	movl	-8(%rbp), %eax
	negl	%eax
	andl	-8(%rbp), %eax
	addl	%eax, -8(%rbp)
.L2:
	movl	-8(%rbp), %eax
	cmpl	-4(%rbp), %eax
	jle	.L4
	nop
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	update, .-update
	.globl	find
	.type	find, @function
find:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movq	$0, -8(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L6
.L8:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	cmpq	%rax, -8(%rbp)
	jge	.L7
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	%rax, -8(%rbp)
.L7:
	movl	-12(%rbp), %eax
	subl	$1, %eax
	andl	%eax, -12(%rbp)
.L6:
	cmpl	$0, -12(%rbp)
	jg	.L8
	movq	-8(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	find, .-find
	.section	.rodata
.LC0:
	.string	"%i"
.LC1:
	.string	"%li\n"
	.text
	.globl	run
	.type	run, @function
run:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	leaq	-64(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-64(%rbp), %eax
	cltq
	movl	$4, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -48(%rbp)
	movl	$0, -56(%rbp)
	jmp	.L11
.L12:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -56(%rbp)
.L11:
	movl	-64(%rbp), %eax
	cmpl	%eax, -56(%rbp)
	jl	.L12
	movl	-64(%rbp), %eax
	addl	$1, %eax
	cltq
	movl	$8, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -40(%rbp)
	movl	-64(%rbp), %eax
	movslq	%eax, %rdx
	movq	-40(%rbp), %rax
	movq	%rdx, (%rax)
	movl	$0, -52(%rbp)
	jmp	.L13
.L14:
	leaq	-60(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-60(%rbp), %eax
	movslq	%eax, %rbx
	movl	-52(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movq	-40(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	find
	addq	%rbx, %rax
	movq	%rax, -32(%rbp)
	movl	-52(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %ecx
	movq	-32(%rbp), %rdx
	movq	-40(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	update
	addl	$1, -52(%rbp)
.L13:
	movl	-64(%rbp), %eax
	cmpl	%eax, -52(%rbp)
	jl	.L14
	movl	-64(%rbp), %edx
	movq	-40(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	find
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	nop
	movq	-24(%rbp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	run, .-run
	.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
	call	run
	movl	$0, %eax
	popq	%rbp
	.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	update
	.type	update, @function
update:
.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)
	movl	%esi, -28(%rbp)
	movq	%rdx, -40(%rbp)
	movq	-24(%rbp), %rax
	movq	(%rax), %rax
	movl	%eax, -4(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -8(%rbp)
	jmp	.L2
.L4:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	cmpq	%rax, -40(%rbp)
	jle	.L3
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movq	-40(%rbp), %rax
	movq	%rax, (%rdx)
.L3:
	movl	-8(%rbp), %eax
	negl	%eax
	andl	-8(%rbp), %eax
	addl	%eax, -8(%rbp)
.L2:
	movl	-8(%rbp), %eax
	cmpl	-4(%rbp), %eax
	jle	.L4
	nop
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	update, .-update
	.globl	find
	.type	find, @function
find:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movq	$0, -8(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L6
.L8:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	cmpq	%rax, -8(%rbp)
	jge	.L7
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	%rax, -8(%rbp)
.L7:
	movl	-12(%rbp), %eax
	subl	$1, %eax
	andl	%eax, -12(%rbp)
.L6:
	cmpl	$0, -12(%rbp)
	jg	.L8
	movq	-8(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	find, .-find
	.section	.rodata
.LC0:
	.string	"%i"
.LC1:
	.string	"%li\n"
	.text
	.globl	run
	.type	run, @function
run:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	leaq	-64(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-64(%rbp), %eax
	cltq
	movl	$4, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -48(%rbp)
	movl	$0, -56(%rbp)
	jmp	.L11
.L12:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -56(%rbp)
.L11:
	movl	-64(%rbp), %eax
	cmpl	%eax, -56(%rbp)
	jl	.L12
	movl	-64(%rbp), %eax
	addl	$1, %eax
	cltq
	movl	$8, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -40(%rbp)
	movl	-64(%rbp), %eax
	movslq	%eax, %rdx
	movq	-40(%rbp), %rax
	movq	%rdx, (%rax)
	movl	$0, -52(%rbp)
	jmp	.L13
.L14:
	leaq	-60(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-60(%rbp), %eax
	movslq	%eax, %rbx
	movl	-52(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movq	-40(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	find
	addq	%rbx, %rax
	movq	%rax, -32(%rbp)
	movl	-52(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %ecx
	movq	-32(%rbp), %rdx
	movq	-40(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	update
	addl	$1, -52(%rbp)
.L13:
	movl	-64(%rbp), %eax
	cmpl	%eax, -52(%rbp)
	jl	.L14
	movl	-64(%rbp), %edx
	movq	-40(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	find
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	nop
	movq	-24(%rbp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	run, .-run
	.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
	call	run
	movl	$0, %eax
	popq	%rbp
	.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:
