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>

typedef struct {
    int flip;
    long long rotate;
} Query;

long long n, k, q;

Query tree[(1 << 20) * 2];

void  build(long long _n);
Query merge(Query a, Query b);
void  update(Query data, long long i);
Query sum(void);

int main()
{
    long long _n;
    long long a;

    scanf("%lld %lld %lld", &k, &_n, &q);

    build(_n);

    for (long long i = 0; i < _n; i++) {
        scanf("%lld", &a);

        Query data = {0, 0};

        if (a == 0) data.flip = 1;
        else data.rotate = -a;

        update(data, i);
    }

    for (long long i = 0; i < q; i++) {
        long long left, right;
        Query l, r;
        scanf("%lld %lld", &left, &right);
        left--;
        right--;

        l = tree[left + n - 1];
        r = tree[right + n - 1];

        update(l, right);
        update(r, left);


        Query total = sum();

        long long num;
        if (total.rotate < 0) total.rotate = k + total.rotate;
        num = 1 + total.rotate;

        if (total.flip) {
            if (num == 1) num *= -1;
            else num = ((k + 2) - num) * -1;
        }

        printf("%lld\n", num);
        //        printf("%d %lld\n", total.flip, total.rotate);
    }
    
    return 0;
}

void  build(long long _n)
{
    n = 1;

    while (n < _n) {
        n *= 2;
    }

    for (long long i = 0; i < 2 * n; i++) {
        tree[i] = (Query){0, 0};
    }

    return;
}

Query merge(Query a, Query b)
{
    Query x;

    x.flip = (a.flip + b.flip) % 2;

    if (b.flip) {
        x.rotate = (b.rotate - a.rotate) % k;
    } else {
        x.rotate = (a.rotate + b.rotate) % k;
    }

    return x;
}

void update(Query data, long long i)
{
    i += n - 1;

    tree[i] = data;

    while (i != 0) {
        i = (i - 1) / 2;
        tree[i] = merge(tree[i * 2 + 1], tree[i * 2 + 2]);
    }

    return;
}

Query sum(void)
{
    return tree[0];
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	k
	.align 8
	.type	k, @object
	.size	k, 8
k:
	.zero	8
	.globl	q
	.align 8
	.type	q, @object
	.size	q, 8
q:
	.zero	8
	.globl	tree
	.align 32
	.type	tree, @object
	.size	tree, 33554432
tree:
	.zero	33554432
	.section	.rodata
.LC0:
	.string	"%lld %lld %lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld %lld"
.LC3:
	.string	"%lld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	addq	$-128, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-120(%rbp), %rax
	leaq	q(%rip), %rdx
	movq	%rdx, %rcx
	movq	%rax, %rdx
	leaq	k(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-120(%rbp), %rax
	movq	%rax, %rdi
	call	build
	movq	$0, -88(%rbp)
	jmp	.L2
.L5:
	leaq	-112(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -32(%rbp)
	movq	$0, -24(%rbp)
	movq	-112(%rbp), %rax
	testq	%rax, %rax
	jne	.L3
	movl	$1, -32(%rbp)
	jmp	.L4
.L3:
	movq	-112(%rbp), %rax
	negq	%rax
	movq	%rax, -24(%rbp)
.L4:
	movq	-88(%rbp), %rdx
	movl	-32(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %edi
	movq	%rax, %rsi
	call	update
	addq	$1, -88(%rbp)
.L2:
	movq	-120(%rbp), %rax
	cmpq	%rax, -88(%rbp)
	jl	.L5
	movq	$0, -80(%rbp)
	jmp	.L6
.L10:
	leaq	-96(%rbp), %rdx
	leaq	-104(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-104(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -104(%rbp)
	movq	-96(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -96(%rbp)
	movq	-104(%rbp), %rdx
	movq	n(%rip), %rax
	addq	%rdx, %rax
	subq	$1, %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	tree(%rip), %rax
	leaq	(%rdx,%rax), %rdx
	movq	(%rdx), %rax
	movq	8(%rdx), %rdx
	movq	%rax, -64(%rbp)
	movq	%rdx, -56(%rbp)
	movq	-96(%rbp), %rdx
	movq	n(%rip), %rax
	addq	%rdx, %rax
	subq	$1, %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	tree(%rip), %rax
	leaq	(%rdx,%rax), %rdx
	movq	(%rdx), %rax
	movq	8(%rdx), %rdx
	movq	%rax, -48(%rbp)
	movq	%rdx, -40(%rbp)
	movq	-96(%rbp), %rdx
	movl	-64(%rbp), %ecx
	movq	-56(%rbp), %rax
	movl	%ecx, %edi
	movq	%rax, %rsi
	call	update
	movq	-104(%rbp), %rdx
	movl	-48(%rbp), %ecx
	movq	-40(%rbp), %rax
	movl	%ecx, %edi
	movq	%rax, %rsi
	call	update
	call	sum
	movl	%eax, %ecx
	movq	%rdx, %rax
	movl	%ecx, -32(%rbp)
	movq	%rax, -24(%rbp)
	movq	-24(%rbp), %rax
	testq	%rax, %rax
	jns	.L7
	movq	-24(%rbp), %rdx
	movq	k(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, -24(%rbp)
.L7:
	movq	-24(%rbp), %rax
	addq	$1, %rax
	movq	%rax, -72(%rbp)
	movl	-32(%rbp), %eax
	testl	%eax, %eax
	je	.L8
	cmpq	$1, -72(%rbp)
	jne	.L9
	negq	-72(%rbp)
	jmp	.L8
.L9:
	movq	k(%rip), %rax
	addq	$2, %rax
	subq	%rax, -72(%rbp)
.L8:
	movq	-72(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addq	$1, -80(%rbp)
.L6:
	movq	q(%rip), %rax
	cmpq	%rax, -80(%rbp)
	jl	.L10
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	build
	.type	build, @function
build:
.LFB1:
	.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	$1, n(%rip)
	jmp	.L14
.L15:
	movq	n(%rip), %rax
	addq	%rax, %rax
	movq	%rax, n(%rip)
.L14:
	movq	n(%rip), %rax
	cmpq	%rax, -24(%rbp)
	jg	.L15
	movq	$0, -8(%rbp)
	jmp	.L16
.L17:
	movq	-8(%rbp), %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	tree(%rip), %rax
	movl	$0, (%rdx,%rax)
	movq	-8(%rbp), %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	8+tree(%rip), %rax
	movq	$0, (%rdx,%rax)
	addq	$1, -8(%rbp)
.L16:
	movq	n(%rip), %rax
	addq	%rax, %rax
	cmpq	%rax, -8(%rbp)
	jl	.L17
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	build, .-build
	.globl	merge
	.type	merge, @function
merge:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	.cfi_offset 3, -24
	movq	%rsi, %rax
	movl	%edi, %r8d
	movq	%r8, %rsi
	movq	%r9, %rdi
	movq	%rax, %rdi
	movq	%rsi, -48(%rbp)
	movq	%rdi, -40(%rbp)
	movl	%edx, %eax
	movq	%rcx, %rdx
	movq	%rax, -64(%rbp)
	movq	%rdx, -56(%rbp)
	movl	-48(%rbp), %edx
	movl	-64(%rbp), %eax
	addl	%edx, %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%eax, -32(%rbp)
	movl	-64(%rbp), %eax
	testl	%eax, %eax
	je	.L20
	movq	-56(%rbp), %rax
	movq	-40(%rbp), %rdx
	subq	%rdx, %rax
	movq	k(%rip), %rcx
	cqto
	idivq	%rcx
	movq	%rdx, %rax
	movq	%rax, -24(%rbp)
	jmp	.L21
.L20:
	movq	-40(%rbp), %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	movq	k(%rip), %rcx
	cqto
	idivq	%rcx
	movq	%rdx, %rax
	movq	%rax, -24(%rbp)
.L21:
	movq	-32(%rbp), %rax
	movq	-24(%rbp), %rdx
	movq	%rax, %rcx
	movq	%rdx, %rbx
	movl	%ecx, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	merge, .-merge
	.globl	update
	.type	update, @function
update:
.LFB3:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r12
	pushq	%rbx
	subq	$32, %rsp
	.cfi_offset 12, -24
	.cfi_offset 3, -32
	movl	%edi, %ecx
	movq	%rsi, %rax
	movq	%rax, %rbx
	movq	%rcx, -32(%rbp)
	movq	%rbx, -24(%rbp)
	movq	%rdx, -40(%rbp)
	movq	n(%rip), %rax
	subq	$1, %rax
	addq	%rax, -40(%rbp)
	movq	-40(%rbp), %rax
	salq	$4, %rax
	movq	%rax, %rsi
	leaq	tree(%rip), %rcx
	movq	-32(%rbp), %rax
	movq	-24(%rbp), %rdx
	movq	%rax, (%rsi,%rcx)
	movq	%rdx, 8(%rsi,%rcx)
	jmp	.L24
.L25:
	movq	-40(%rbp), %rax
	subq	$1, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -40(%rbp)
	movq	-40(%rbp), %rax
	addq	$1, %rax
	leaq	(%rax,%rax), %rdx
	movq	-40(%rbp), %rax
	addq	%rax, %rax
	leaq	1(%rax), %rsi
	movq	-40(%rbp), %rax
	salq	$4, %rax
	movq	%rax, %r12
	leaq	tree(%rip), %rbx
	salq	$4, %rdx
	leaq	tree(%rip), %rax
	movl	(%rdx,%rax), %edi
	movq	8(%rdx,%rax), %rcx
	salq	$4, %rsi
	movq	%rsi, %rdx
	leaq	tree(%rip), %rax
	movl	(%rdx,%rax), %esi
	movq	8(%rdx,%rax), %rax
	movl	%edi, %edx
	movl	%esi, %edi
	movq	%rax, %rsi
	call	merge
	movl	%eax, %ecx
	movq	%rdx, %rax
	movl	%ecx, (%r12,%rbx)
	movq	%rax, 8(%r12,%rbx)
.L24:
	cmpq	$0, -40(%rbp)
	jne	.L25
	nop
	addq	$32, %rsp
	popq	%rbx
	popq	%r12
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3:
	.size	update, .-update
	.globl	sum
	.type	sum, @function
sum:
.LFB4:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	.cfi_offset 3, -24
	movq	tree(%rip), %rax
	movq	8+tree(%rip), %rdx
	movq	%rax, %rcx
	movq	%rdx, %rbx
	movl	%ecx, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE4:
	.size	sum, .-sum
	.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	build
	.type	build, @function
build:
.LFB24:
	.cfi_startproc
	endbr64
	movq	$1, n(%rip)
	cmpq	$1, %rdi
	jle	.L6
	movl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rax, %rcx
	addq	%rax, %rax
	cmpq	%rdi, %rax
	jl	.L3
	movq	%rax, n(%rip)
	salq	$2, %rcx
.L2:
	leaq	tree(%rip), %rax
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L4:
	addq	$1, %rdx
	movl	$0, (%rax)
	addq	$16, %rax
	movq	$0, -8(%rax)
	cmpq	%rdx, %rcx
	jg	.L4
	ret
	.p2align 4,,10
	.p2align 3
.L6:
	movl	$2, %ecx
	jmp	.L2
	.cfi_endproc
.LFE24:
	.size	build, .-build
	.p2align 4
	.globl	merge
	.type	merge, @function
merge:
.LFB25:
	.cfi_startproc
	endbr64
	addl	%edx, %edi
	movq	%rcx, %rax
	movl	%edi, %ecx
	shrl	$31, %ecx
	addl	%ecx, %edi
	andl	$1, %edi
	subl	%ecx, %edi
	movq	k(%rip), %rcx
	testl	%edx, %edx
	je	.L11
	subq	%rsi, %rax
	cqto
	idivq	%rcx
	movl	%edi, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L11:
	addq	%rsi, %rax
	cqto
	idivq	%rcx
	movl	%edi, %eax
	ret
	.cfi_endproc
.LFE25:
	.size	merge, .-merge
	.p2align 4
	.globl	update
	.type	update, @function
update:
.LFB26:
	.cfi_startproc
	endbr64
	movq	n(%rip), %rax
	movl	%edi, %r8d
	leaq	tree(%rip), %rdi
	leaq	-1(%rax,%rdx), %rcx
	movq	%rcx, %rax
	salq	$4, %rax
	addq	%rdi, %rax
	movq	%r8, (%rax)
	movq	k(%rip), %r8
	movq	%rsi, 8(%rax)
	testq	%rcx, %rcx
	je	.L13
	.p2align 4,,10
	.p2align 3
.L18:
	leaq	-1(%rcx), %rax
	movq	%rax, %rcx
	shrq	$63, %rcx
	addq	%rax, %rcx
	sarq	%rcx
	leaq	1(%rcx), %rsi
	leaq	1(%rcx,%rcx), %rdx
	salq	$4, %rdx
	salq	$5, %rsi
	addq	%rdi, %rdx
	addq	%rdi, %rsi
	movl	(%rsi), %r10d
	movq	8(%rsi), %rax
	movl	(%rdx), %esi
	movq	8(%rdx), %r9
	addl	%r10d, %esi
	movl	%esi, %edx
	shrl	$31, %esi
	addl	%esi, %edx
	andl	$1, %edx
	subl	%esi, %edx
	movq	%rcx, %rsi
	salq	$4, %rsi
	addq	%rdi, %rsi
	movl	%edx, (%rsi)
	testl	%r10d, %r10d
	je	.L15
	subq	%r9, %rax
	cqto
	idivq	%r8
	movq	%rdx, 8(%rsi)
	testq	%rcx, %rcx
	jne	.L18
	ret
	.p2align 4,,10
	.p2align 3
.L15:
	addq	%r9, %rax
	cqto
	idivq	%r8
	movq	%rdx, 8(%rsi)
	testq	%rcx, %rcx
	jne	.L18
.L13:
	ret
	.cfi_endproc
.LFE26:
	.size	update, .-update
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%lld %lld %lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld %lld"
.LC3:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	k(%rip), %rsi
	leaq	q(%rip), %rcx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC0(%rip), %rdi
	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	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdx
	call	__isoc99_scanf@PLT
	movq	8(%rsp), %rsi
	movq	$1, n(%rip)
	cmpq	$1, %rsi
	jle	.L37
	movl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L25:
	movq	%rax, %rcx
	addq	%rax, %rax
	cmpq	%rax, %rsi
	jg	.L25
	movq	%rax, n(%rip)
	salq	$2, %rcx
.L24:
	leaq	tree(%rip), %rbx
	xorl	%edx, %edx
	movq	%rbx, %rax
	.p2align 4,,10
	.p2align 3
.L27:
	addq	$1, %rdx
	movl	$0, (%rax)
	addq	$16, %rax
	movq	$0, -8(%rax)
	cmpq	%rcx, %rdx
	jl	.L27
	xorl	%ebp, %ebp
	leaq	16(%rsp), %r12
	leaq	.LC1(%rip), %r13
	testq	%rsi, %rsi
	jle	.L33
	xorl	%r15d, %r15d
	movl	$1, %r14d
	.p2align 4,,10
	.p2align 3
.L28:
	movq	%r12, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	16(%rsp), %rsi
	movl	%r14d, %edi
	testq	%rsi, %rsi
	je	.L52
	negq	%rsi
	movl	%r15d, %edi
.L52:
	movq	%rbp, %rdx
	addq	$1, %rbp
	call	update
	cmpq	%rbp, 8(%rsp)
	jg	.L28
.L33:
	cmpq	$0, q(%rip)
	jle	.L30
	xorl	%ebp, %ebp
	leaq	32(%rsp), %r14
	leaq	24(%rsp), %r13
	leaq	.LC2(%rip), %r12
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L53:
	subq	k(%rip), %rdx
	subq	$2, %rdx
.L35:
	xorl	%eax, %eax
	leaq	.LC3(%rip), %rsi
	movl	$1, %edi
	addq	$1, %rbp
	call	__printf_chk@PLT
	cmpq	%rbp, q(%rip)
	jle	.L30
.L29:
	movq	%r14, %rdx
	movq	%r13, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	32(%rsp), %rcx
	movq	24(%rsp), %rax
	leaq	-1(%rcx), %rdx
	movq	n(%rip), %rcx
	subq	$1, %rax
	movq	%rax, 24(%rsp)
	leaq	-1(%rax,%rcx), %rax
	movq	%rdx, 32(%rsp)
	salq	$4, %rax
	movq	(%rbx,%rax), %rdi
	movq	8(%rbx,%rax), %rsi
	leaq	-1(%rdx,%rcx), %rax
	salq	$4, %rax
	movq	(%rbx,%rax), %r11
	movq	8(%rbx,%rax), %r15
	call	update
	movq	24(%rsp), %rdx
	movq	%r11, %rdi
	movq	%r15, %rsi
	call	update
	movq	8+tree(%rip), %rdx
	movl	(%rbx), %eax
	testq	%rdx, %rdx
	jns	.L34
	addq	k(%rip), %rdx
.L34:
	addq	$1, %rdx
	testl	%eax, %eax
	je	.L35
	cmpq	$1, %rdx
	jne	.L53
	movq	$-1, %rdx
	jmp	.L35
	.p2align 4,,10
	.p2align 3
.L30:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L54
	addq	$56, %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
.L37:
	.cfi_restore_state
	movl	$2, %ecx
	jmp	.L24
.L54:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.text
	.p2align 4
	.globl	sum
	.type	sum, @function
sum:
.LFB27:
	.cfi_startproc
	endbr64
	movq	8+tree(%rip), %rdx
	movq	tree(%rip), %rax
	ret
	.cfi_endproc
.LFE27:
	.size	sum, .-sum
	.globl	tree
	.bss
	.align 32
	.type	tree, @object
	.size	tree, 33554432
tree:
	.zero	33554432
	.globl	q
	.align 8
	.type	q, @object
	.size	q, 8
q:
	.zero	8
	.globl	k
	.align 8
	.type	k, @object
	.size	k, 8
k:
	.zero	8
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.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	build
	.type	build, @function
build:
.LFB24:
	.cfi_startproc
	endbr64
	movq	$1, n(%rip)
	cmpq	$1, %rdi
	jle	.L6
	movl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rax, %rcx
	addq	%rax, %rax
	cmpq	%rdi, %rax
	jl	.L3
	movq	%rax, n(%rip)
	salq	$2, %rcx
.L2:
	leaq	tree(%rip), %rax
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L4:
	addq	$1, %rdx
	movl	$0, (%rax)
	addq	$16, %rax
	movq	$0, -8(%rax)
	cmpq	%rdx, %rcx
	jg	.L4
	ret
	.p2align 4,,10
	.p2align 3
.L6:
	movl	$2, %ecx
	jmp	.L2
	.cfi_endproc
.LFE24:
	.size	build, .-build
	.p2align 4
	.globl	merge
	.type	merge, @function
merge:
.LFB25:
	.cfi_startproc
	endbr64
	addl	%edx, %edi
	movq	%rcx, %rax
	movl	%edi, %ecx
	shrl	$31, %ecx
	addl	%ecx, %edi
	andl	$1, %edi
	subl	%ecx, %edi
	movq	k(%rip), %rcx
	testl	%edx, %edx
	je	.L11
	subq	%rsi, %rax
	cqto
	idivq	%rcx
	movl	%edi, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L11:
	addq	%rsi, %rax
	cqto
	idivq	%rcx
	movl	%edi, %eax
	ret
	.cfi_endproc
.LFE25:
	.size	merge, .-merge
	.p2align 4
	.globl	update
	.type	update, @function
update:
.LFB26:
	.cfi_startproc
	endbr64
	movq	n(%rip), %rax
	movl	%edi, %r8d
	leaq	tree(%rip), %rdi
	leaq	-1(%rax,%rdx), %rcx
	movq	%rcx, %rax
	salq	$4, %rax
	addq	%rdi, %rax
	movq	%r8, (%rax)
	movq	k(%rip), %r8
	movq	%rsi, 8(%rax)
	testq	%rcx, %rcx
	je	.L13
	.p2align 4,,10
	.p2align 3
.L18:
	leaq	-1(%rcx), %rax
	movq	%rax, %rcx
	shrq	$63, %rcx
	addq	%rax, %rcx
	sarq	%rcx
	leaq	1(%rcx), %rsi
	leaq	1(%rcx,%rcx), %rdx
	salq	$4, %rdx
	salq	$5, %rsi
	addq	%rdi, %rdx
	addq	%rdi, %rsi
	movl	(%rsi), %r10d
	movq	8(%rsi), %rax
	movl	(%rdx), %esi
	movq	8(%rdx), %r9
	addl	%r10d, %esi
	movl	%esi, %edx
	shrl	$31, %esi
	addl	%esi, %edx
	andl	$1, %edx
	subl	%esi, %edx
	movq	%rcx, %rsi
	salq	$4, %rsi
	addq	%rdi, %rsi
	movl	%edx, (%rsi)
	testl	%r10d, %r10d
	je	.L15
	subq	%r9, %rax
	cqto
	idivq	%r8
	movq	%rdx, 8(%rsi)
	testq	%rcx, %rcx
	jne	.L18
	ret
	.p2align 4,,10
	.p2align 3
.L15:
	addq	%r9, %rax
	cqto
	idivq	%r8
	movq	%rdx, 8(%rsi)
	testq	%rcx, %rcx
	jne	.L18
.L13:
	ret
	.cfi_endproc
.LFE26:
	.size	update, .-update
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%lld %lld %lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld %lld"
.LC3:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	k(%rip), %rsi
	leaq	q(%rip), %rcx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC0(%rip), %rdi
	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	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdx
	call	__isoc99_scanf@PLT
	movq	8(%rsp), %rsi
	movq	$1, n(%rip)
	cmpq	$1, %rsi
	jle	.L37
	movl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L25:
	movq	%rax, %rcx
	addq	%rax, %rax
	cmpq	%rax, %rsi
	jg	.L25
	movq	%rax, n(%rip)
	salq	$2, %rcx
.L24:
	leaq	tree(%rip), %rbx
	xorl	%edx, %edx
	movq	%rbx, %rax
	.p2align 4,,10
	.p2align 3
.L27:
	addq	$1, %rdx
	movl	$0, (%rax)
	addq	$16, %rax
	movq	$0, -8(%rax)
	cmpq	%rcx, %rdx
	jl	.L27
	xorl	%ebp, %ebp
	leaq	16(%rsp), %r12
	leaq	.LC1(%rip), %r13
	testq	%rsi, %rsi
	jle	.L33
	xorl	%r15d, %r15d
	movl	$1, %r14d
	.p2align 4,,10
	.p2align 3
.L28:
	movq	%r12, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	16(%rsp), %rsi
	movl	%r14d, %edi
	testq	%rsi, %rsi
	je	.L52
	negq	%rsi
	movl	%r15d, %edi
.L52:
	movq	%rbp, %rdx
	addq	$1, %rbp
	call	update
	cmpq	%rbp, 8(%rsp)
	jg	.L28
.L33:
	cmpq	$0, q(%rip)
	jle	.L30
	xorl	%ebp, %ebp
	leaq	32(%rsp), %r14
	leaq	24(%rsp), %r13
	leaq	.LC2(%rip), %r12
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L53:
	subq	k(%rip), %rdx
	subq	$2, %rdx
.L35:
	xorl	%eax, %eax
	leaq	.LC3(%rip), %rsi
	movl	$1, %edi
	addq	$1, %rbp
	call	__printf_chk@PLT
	cmpq	%rbp, q(%rip)
	jle	.L30
.L29:
	movq	%r14, %rdx
	movq	%r13, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	32(%rsp), %rcx
	movq	24(%rsp), %rax
	leaq	-1(%rcx), %rdx
	movq	n(%rip), %rcx
	subq	$1, %rax
	movq	%rax, 24(%rsp)
	leaq	-1(%rax,%rcx), %rax
	movq	%rdx, 32(%rsp)
	salq	$4, %rax
	movq	(%rbx,%rax), %rdi
	movq	8(%rbx,%rax), %rsi
	leaq	-1(%rdx,%rcx), %rax
	salq	$4, %rax
	movq	(%rbx,%rax), %r11
	movq	8(%rbx,%rax), %r15
	call	update
	movq	24(%rsp), %rdx
	movq	%r11, %rdi
	movq	%r15, %rsi
	call	update
	movq	8+tree(%rip), %rdx
	movl	(%rbx), %eax
	testq	%rdx, %rdx
	jns	.L34
	addq	k(%rip), %rdx
.L34:
	addq	$1, %rdx
	testl	%eax, %eax
	je	.L35
	cmpq	$1, %rdx
	jne	.L53
	movq	$-1, %rdx
	jmp	.L35
	.p2align 4,,10
	.p2align 3
.L30:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L54
	addq	$56, %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
.L37:
	.cfi_restore_state
	movl	$2, %ecx
	jmp	.L24
.L54:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.text
	.p2align 4
	.globl	sum
	.type	sum, @function
sum:
.LFB27:
	.cfi_startproc
	endbr64
	movq	8+tree(%rip), %rdx
	movq	tree(%rip), %rax
	ret
	.cfi_endproc
.LFE27:
	.size	sum, .-sum
	.globl	tree
	.bss
	.align 32
	.type	tree, @object
	.size	tree, 33554432
tree:
	.zero	33554432
	.globl	q
	.align 8
	.type	q, @object
	.size	q, 8
q:
	.zero	8
	.globl	k
	.align 8
	.type	k, @object
	.size	k, 8
k:
	.zero	8
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.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>

typedef struct {
    int flip;
    long long rotate;
} Query;

long long n, k, q;

Query tree[(1 << 20) * 2];

void  build(long long _n);
Query merge(Query a, Query b);
void  update(Query data, long long i);
Query sum(void);

int main()
{
    long long _n;
    long long a;

    scanf("%lld %lld %lld", &k, &_n, &q);

    build(_n);

    for (long long i = 0; i < _n; i++) {
        scanf("%lld", &a);

        Query data = {0, 0};

        if (a == 0) data.flip = 1;
        else data.rotate = -a;

        update(data, i);
    }

    for (long long i = 0; i < q; i++) {
        long long left, right;
        Query l, r;
        scanf("%lld %lld", &left, &right);
        left--;
        right--;

        l = tree[left + n - 1];
        r = tree[right + n - 1];

        update(l, right);
        update(r, left);


        Query total = sum();

        long long num;
        if (total.rotate < 0) total.rotate = k + total.rotate;
        num = 1 + total.rotate;

        if (total.flip) {
            if (num == 1) num *= -1;
            else num = ((k + 2) - num) * -1;
        }

        printf("%lld\n", num);
        //        printf("%d %lld\n", total.flip, total.rotate);
    }
    
    return 0;
}

void  build(long long _n)
{
    n = 1;

    while (n < _n) {
        n *= 2;
    }

    for (long long i = 0; i < 2 * n; i++) {
        tree[i] = (Query){0, 0};
    }

    return;
}

Query merge(Query a, Query b)
{
    Query x;

    x.flip = (a.flip + b.flip) % 2;

    if (b.flip) {
        x.rotate = (b.rotate - a.rotate) % k;
    } else {
        x.rotate = (a.rotate + b.rotate) % k;
    }

    return x;
}

void update(Query data, long long i)
{
    i += n - 1;

    tree[i] = data;

    while (i != 0) {
        i = (i - 1) / 2;
        tree[i] = merge(tree[i * 2 + 1], tree[i * 2 + 2]);
    }

    return;
}

Query sum(void)
{
    return tree[0];
}

5 3 1
1 -4 0
2 3
 5 3 1
1 -4 1
2 3
 15 3 1
1 0 1
2 3
 5 7 5
0 0 3 3 3 3 3
1 2
2 3
3 5
4 5
5 6
 2 3 1
1 -4 0
2 3
 10 3 1
0 -4 1
2 3
 5 7 5
0 0 3 3 3 3 3
1 2
1 3
3 5
4 5
5 6
 9 3 1
1 -2 0
2 3
 10 3 1
1 -7 1
2 3
 15 3 1
2 0 1
2 3

-1
 3
 -14
 1
2
4
3
3
 -2
 -8
 1
1
3
2
2
 -7
 6
 -13

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>

typedef struct {
    int flip;
    long long rotate;
} Query;

long long n, k, q;

Query tree[(1 << 20) * 2];

void  build(long long _n);
Query merge(Query a, Query b);
void  update(Query data, long long i);
Query sum(void);

int main()
{
    long long _n;
    long long a;

    scanf("%lld %lld %lld", &k, &_n, &q);

    build(_n);

    for (long long i = 0; i < _n; i++) {
        scanf("%lld", &a);

        Query data = {0, 0};

        if (a == 0) data.flip = 1;
        else data.rotate = -a;

        update(data, i);
    }

    for (long long i = 0; i < q; i++) {
        long long left, right;
        Query l, r;
        scanf("%lld %lld", &left, &right);
        left--;
        right--;

        l = tree[left + n - 1];
        r = tree[right + n - 1];

        update(l, right);
        update(r, left);


        Query total = sum();

        long long num;
        if (total.rotate < 0) total.rotate = k + total.rotate;
        num = 1 + total.rotate;

        if (total.flip) {
            if (num == 1) num *= -1;
            else num = ((k + 2) - num) * -1;
        }

        printf("%lld\n", num);
        //        printf("%d %lld\n", total.flip, total.rotate);
    }
    
    return 0;
}

void  build(long long _n)
{
    n = 1;

    while (n < _n) {
        n *= 2;
    }

    for (long long i = 0; i < 2 * n; i++) {
        tree[i] = (Query){0, 0};
    }

    return;
}

Query merge(Query a, Query b)
{
    Query x;

    x.flip = (a.flip + b.flip) % 2;

    if (b.flip) {
        x.rotate = (b.rotate - a.rotate) % k;
    } else {
        x.rotate = (a.rotate + b.rotate) % k;
    }

    return x;
}

void update(Query data, long long i)
{
    i += n - 1;

    tree[i] = data;

    while (i != 0) {
        i = (i - 1) / 2;
        tree[i] = merge(tree[i * 2 + 1], tree[i * 2 + 2]);
    }

    return;
}

Query sum(void)
{
    return tree[0];
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	k
	.align 8
	.type	k, @object
	.size	k, 8
k:
	.zero	8
	.globl	q
	.align 8
	.type	q, @object
	.size	q, 8
q:
	.zero	8
	.globl	tree
	.align 32
	.type	tree, @object
	.size	tree, 33554432
tree:
	.zero	33554432
	.section	.rodata
.LC0:
	.string	"%lld %lld %lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld %lld"
.LC3:
	.string	"%lld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	addq	$-128, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-120(%rbp), %rax
	leaq	q(%rip), %rdx
	movq	%rdx, %rcx
	movq	%rax, %rdx
	leaq	k(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-120(%rbp), %rax
	movq	%rax, %rdi
	call	build
	movq	$0, -88(%rbp)
	jmp	.L2
.L5:
	leaq	-112(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -32(%rbp)
	movq	$0, -24(%rbp)
	movq	-112(%rbp), %rax
	testq	%rax, %rax
	jne	.L3
	movl	$1, -32(%rbp)
	jmp	.L4
.L3:
	movq	-112(%rbp), %rax
	negq	%rax
	movq	%rax, -24(%rbp)
.L4:
	movq	-88(%rbp), %rdx
	movl	-32(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %edi
	movq	%rax, %rsi
	call	update
	addq	$1, -88(%rbp)
.L2:
	movq	-120(%rbp), %rax
	cmpq	%rax, -88(%rbp)
	jl	.L5
	movq	$0, -80(%rbp)
	jmp	.L6
.L10:
	leaq	-96(%rbp), %rdx
	leaq	-104(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-104(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -104(%rbp)
	movq	-96(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -96(%rbp)
	movq	-104(%rbp), %rdx
	movq	n(%rip), %rax
	addq	%rdx, %rax
	subq	$1, %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	tree(%rip), %rax
	leaq	(%rdx,%rax), %rdx
	movq	(%rdx), %rax
	movq	8(%rdx), %rdx
	movq	%rax, -64(%rbp)
	movq	%rdx, -56(%rbp)
	movq	-96(%rbp), %rdx
	movq	n(%rip), %rax
	addq	%rdx, %rax
	subq	$1, %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	tree(%rip), %rax
	leaq	(%rdx,%rax), %rdx
	movq	(%rdx), %rax
	movq	8(%rdx), %rdx
	movq	%rax, -48(%rbp)
	movq	%rdx, -40(%rbp)
	movq	-96(%rbp), %rdx
	movl	-64(%rbp), %ecx
	movq	-56(%rbp), %rax
	movl	%ecx, %edi
	movq	%rax, %rsi
	call	update
	movq	-104(%rbp), %rdx
	movl	-48(%rbp), %ecx
	movq	-40(%rbp), %rax
	movl	%ecx, %edi
	movq	%rax, %rsi
	call	update
	call	sum
	movl	%eax, %ecx
	movq	%rdx, %rax
	movl	%ecx, -32(%rbp)
	movq	%rax, -24(%rbp)
	movq	-24(%rbp), %rax
	testq	%rax, %rax
	jns	.L7
	movq	-24(%rbp), %rdx
	movq	k(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, -24(%rbp)
.L7:
	movq	-24(%rbp), %rax
	addq	$1, %rax
	movq	%rax, -72(%rbp)
	movl	-32(%rbp), %eax
	testl	%eax, %eax
	je	.L8
	cmpq	$1, -72(%rbp)
	jne	.L9
	negq	-72(%rbp)
	jmp	.L8
.L9:
	movq	k(%rip), %rax
	addq	$2, %rax
	subq	%rax, -72(%rbp)
.L8:
	movq	-72(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addq	$1, -80(%rbp)
.L6:
	movq	q(%rip), %rax
	cmpq	%rax, -80(%rbp)
	jl	.L10
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	build
	.type	build, @function
build:
.LFB1:
	.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	$1, n(%rip)
	jmp	.L14
.L15:
	movq	n(%rip), %rax
	addq	%rax, %rax
	movq	%rax, n(%rip)
.L14:
	movq	n(%rip), %rax
	cmpq	%rax, -24(%rbp)
	jg	.L15
	movq	$0, -8(%rbp)
	jmp	.L16
.L17:
	movq	-8(%rbp), %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	tree(%rip), %rax
	movl	$0, (%rdx,%rax)
	movq	-8(%rbp), %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	8+tree(%rip), %rax
	movq	$0, (%rdx,%rax)
	addq	$1, -8(%rbp)
.L16:
	movq	n(%rip), %rax
	addq	%rax, %rax
	cmpq	%rax, -8(%rbp)
	jl	.L17
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	build, .-build
	.globl	merge
	.type	merge, @function
merge:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	.cfi_offset 3, -24
	movq	%rsi, %rax
	movl	%edi, %r8d
	movq	%r8, %rsi
	movq	%r9, %rdi
	movq	%rax, %rdi
	movq	%rsi, -48(%rbp)
	movq	%rdi, -40(%rbp)
	movl	%edx, %eax
	movq	%rcx, %rdx
	movq	%rax, -64(%rbp)
	movq	%rdx, -56(%rbp)
	movl	-48(%rbp), %edx
	movl	-64(%rbp), %eax
	addl	%edx, %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%eax, -32(%rbp)
	movl	-64(%rbp), %eax
	testl	%eax, %eax
	je	.L20
	movq	-56(%rbp), %rax
	movq	-40(%rbp), %rdx
	subq	%rdx, %rax
	movq	k(%rip), %rcx
	cqto
	idivq	%rcx
	movq	%rdx, %rax
	movq	%rax, -24(%rbp)
	jmp	.L21
.L20:
	movq	-40(%rbp), %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	movq	k(%rip), %rcx
	cqto
	idivq	%rcx
	movq	%rdx, %rax
	movq	%rax, -24(%rbp)
.L21:
	movq	-32(%rbp), %rax
	movq	-24(%rbp), %rdx
	movq	%rax, %rcx
	movq	%rdx, %rbx
	movl	%ecx, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	merge, .-merge
	.globl	update
	.type	update, @function
update:
.LFB3:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r12
	pushq	%rbx
	subq	$32, %rsp
	.cfi_offset 12, -24
	.cfi_offset 3, -32
	movl	%edi, %ecx
	movq	%rsi, %rax
	movq	%rax, %rbx
	movq	%rcx, -32(%rbp)
	movq	%rbx, -24(%rbp)
	movq	%rdx, -40(%rbp)
	movq	n(%rip), %rax
	subq	$1, %rax
	addq	%rax, -40(%rbp)
	movq	-40(%rbp), %rax
	salq	$4, %rax
	movq	%rax, %rsi
	leaq	tree(%rip), %rcx
	movq	-32(%rbp), %rax
	movq	-24(%rbp), %rdx
	movq	%rax, (%rsi,%rcx)
	movq	%rdx, 8(%rsi,%rcx)
	jmp	.L24
.L25:
	movq	-40(%rbp), %rax
	subq	$1, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -40(%rbp)
	movq	-40(%rbp), %rax
	addq	$1, %rax
	leaq	(%rax,%rax), %rdx
	movq	-40(%rbp), %rax
	addq	%rax, %rax
	leaq	1(%rax), %rsi
	movq	-40(%rbp), %rax
	salq	$4, %rax
	movq	%rax, %r12
	leaq	tree(%rip), %rbx
	salq	$4, %rdx
	leaq	tree(%rip), %rax
	movl	(%rdx,%rax), %edi
	movq	8(%rdx,%rax), %rcx
	salq	$4, %rsi
	movq	%rsi, %rdx
	leaq	tree(%rip), %rax
	movl	(%rdx,%rax), %esi
	movq	8(%rdx,%rax), %rax
	movl	%edi, %edx
	movl	%esi, %edi
	movq	%rax, %rsi
	call	merge
	movl	%eax, %ecx
	movq	%rdx, %rax
	movl	%ecx, (%r12,%rbx)
	movq	%rax, 8(%r12,%rbx)
.L24:
	cmpq	$0, -40(%rbp)
	jne	.L25
	nop
	addq	$32, %rsp
	popq	%rbx
	popq	%r12
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3:
	.size	update, .-update
	.globl	sum
	.type	sum, @function
sum:
.LFB4:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	.cfi_offset 3, -24
	movq	tree(%rip), %rax
	movq	8+tree(%rip), %rdx
	movq	%rax, %rcx
	movq	%rdx, %rbx
	movl	%ecx, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE4:
	.size	sum, .-sum
	.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	n
	.bss
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	k
	.align 8
	.type	k, @object
	.size	k, 8
k:
	.zero	8
	.globl	q
	.align 8
	.type	q, @object
	.size	q, 8
q:
	.zero	8
	.globl	tree
	.align 32
	.type	tree, @object
	.size	tree, 33554432
tree:
	.zero	33554432
	.section	.rodata
.LC0:
	.string	"%lld %lld %lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld %lld"
.LC3:
	.string	"%lld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	addq	$-128, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-120(%rbp), %rax
	leaq	q(%rip), %rdx
	movq	%rdx, %rcx
	movq	%rax, %rdx
	leaq	k(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-120(%rbp), %rax
	movq	%rax, %rdi
	call	build
	movq	$0, -88(%rbp)
	jmp	.L2
.L5:
	leaq	-112(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -32(%rbp)
	movq	$0, -24(%rbp)
	movq	-112(%rbp), %rax
	testq	%rax, %rax
	jne	.L3
	movl	$1, -32(%rbp)
	jmp	.L4
.L3:
	movq	-112(%rbp), %rax
	negq	%rax
	movq	%rax, -24(%rbp)
.L4:
	movq	-88(%rbp), %rdx
	movl	-32(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %edi
	movq	%rax, %rsi
	call	update
	addq	$1, -88(%rbp)
.L2:
	movq	-120(%rbp), %rax
	cmpq	%rax, -88(%rbp)
	jl	.L5
	movq	$0, -80(%rbp)
	jmp	.L6
.L10:
	leaq	-96(%rbp), %rdx
	leaq	-104(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-104(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -104(%rbp)
	movq	-96(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -96(%rbp)
	movq	-104(%rbp), %rdx
	movq	n(%rip), %rax
	addq	%rdx, %rax
	subq	$1, %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	tree(%rip), %rax
	leaq	(%rdx,%rax), %rdx
	movq	(%rdx), %rax
	movq	8(%rdx), %rdx
	movq	%rax, -64(%rbp)
	movq	%rdx, -56(%rbp)
	movq	-96(%rbp), %rdx
	movq	n(%rip), %rax
	addq	%rdx, %rax
	subq	$1, %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	tree(%rip), %rax
	leaq	(%rdx,%rax), %rdx
	movq	(%rdx), %rax
	movq	8(%rdx), %rdx
	movq	%rax, -48(%rbp)
	movq	%rdx, -40(%rbp)
	movq	-96(%rbp), %rdx
	movl	-64(%rbp), %ecx
	movq	-56(%rbp), %rax
	movl	%ecx, %edi
	movq	%rax, %rsi
	call	update
	movq	-104(%rbp), %rdx
	movl	-48(%rbp), %ecx
	movq	-40(%rbp), %rax
	movl	%ecx, %edi
	movq	%rax, %rsi
	call	update
	call	sum
	movl	%eax, %ecx
	movq	%rdx, %rax
	movl	%ecx, -32(%rbp)
	movq	%rax, -24(%rbp)
	movq	-24(%rbp), %rax
	testq	%rax, %rax
	jns	.L7
	movq	-24(%rbp), %rdx
	movq	k(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, -24(%rbp)
.L7:
	movq	-24(%rbp), %rax
	addq	$1, %rax
	movq	%rax, -72(%rbp)
	movl	-32(%rbp), %eax
	testl	%eax, %eax
	je	.L8
	cmpq	$1, -72(%rbp)
	jne	.L9
	negq	-72(%rbp)
	jmp	.L8
.L9:
	movq	k(%rip), %rax
	addq	$2, %rax
	subq	%rax, -72(%rbp)
.L8:
	movq	-72(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addq	$1, -80(%rbp)
.L6:
	movq	q(%rip), %rax
	cmpq	%rax, -80(%rbp)
	jl	.L10
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	build
	.type	build, @function
build:
.LFB1:
	.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	$1, n(%rip)
	jmp	.L14
.L15:
	movq	n(%rip), %rax
	addq	%rax, %rax
	movq	%rax, n(%rip)
.L14:
	movq	n(%rip), %rax
	cmpq	%rax, -24(%rbp)
	jg	.L15
	movq	$0, -8(%rbp)
	jmp	.L16
.L17:
	movq	-8(%rbp), %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	tree(%rip), %rax
	movl	$0, (%rdx,%rax)
	movq	-8(%rbp), %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	8+tree(%rip), %rax
	movq	$0, (%rdx,%rax)
	addq	$1, -8(%rbp)
.L16:
	movq	n(%rip), %rax
	addq	%rax, %rax
	cmpq	%rax, -8(%rbp)
	jl	.L17
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	build, .-build
	.globl	merge
	.type	merge, @function
merge:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	.cfi_offset 3, -24
	movq	%rsi, %rax
	movl	%edi, %r8d
	movq	%r8, %rsi
	movq	%r9, %rdi
	movq	%rax, %rdi
	movq	%rsi, -48(%rbp)
	movq	%rdi, -40(%rbp)
	movl	%edx, %eax
	movq	%rcx, %rdx
	movq	%rax, -64(%rbp)
	movq	%rdx, -56(%rbp)
	movl	-48(%rbp), %edx
	movl	-64(%rbp), %eax
	addl	%edx, %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%eax, -32(%rbp)
	movl	-64(%rbp), %eax
	testl	%eax, %eax
	je	.L20
	movq	-56(%rbp), %rax
	movq	-40(%rbp), %rdx
	subq	%rdx, %rax
	movq	k(%rip), %rcx
	cqto
	idivq	%rcx
	movq	%rdx, %rax
	movq	%rax, -24(%rbp)
	jmp	.L21
.L20:
	movq	-40(%rbp), %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	movq	k(%rip), %rcx
	cqto
	idivq	%rcx
	movq	%rdx, %rax
	movq	%rax, -24(%rbp)
.L21:
	movq	-32(%rbp), %rax
	movq	-24(%rbp), %rdx
	movq	%rax, %rcx
	movq	%rdx, %rbx
	movl	%ecx, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	merge, .-merge
	.globl	update
	.type	update, @function
update:
.LFB3:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r12
	pushq	%rbx
	subq	$32, %rsp
	.cfi_offset 12, -24
	.cfi_offset 3, -32
	movl	%edi, %ecx
	movq	%rsi, %rax
	movq	%rax, %rbx
	movq	%rcx, -32(%rbp)
	movq	%rbx, -24(%rbp)
	movq	%rdx, -40(%rbp)
	movq	n(%rip), %rax
	subq	$1, %rax
	addq	%rax, -40(%rbp)
	movq	-40(%rbp), %rax
	salq	$4, %rax
	movq	%rax, %rsi
	leaq	tree(%rip), %rcx
	movq	-32(%rbp), %rax
	movq	-24(%rbp), %rdx
	movq	%rax, (%rsi,%rcx)
	movq	%rdx, 8(%rsi,%rcx)
	jmp	.L24
.L25:
	movq	-40(%rbp), %rax
	subq	$1, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -40(%rbp)
	movq	-40(%rbp), %rax
	addq	$1, %rax
	leaq	(%rax,%rax), %rdx
	movq	-40(%rbp), %rax
	addq	%rax, %rax
	leaq	1(%rax), %rsi
	movq	-40(%rbp), %rax
	salq	$4, %rax
	movq	%rax, %r12
	leaq	tree(%rip), %rbx
	salq	$4, %rdx
	leaq	tree(%rip), %rax
	movl	(%rdx,%rax), %edi
	movq	8(%rdx,%rax), %rcx
	salq	$4, %rsi
	movq	%rsi, %rdx
	leaq	tree(%rip), %rax
	movl	(%rdx,%rax), %esi
	movq	8(%rdx,%rax), %rax
	movl	%edi, %edx
	movl	%esi, %edi
	movq	%rax, %rsi
	call	merge
	movl	%eax, %ecx
	movq	%rdx, %rax
	movl	%ecx, (%r12,%rbx)
	movq	%rax, 8(%r12,%rbx)
.L24:
	cmpq	$0, -40(%rbp)
	jne	.L25
	nop
	addq	$32, %rsp
	popq	%rbx
	popq	%r12
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3:
	.size	update, .-update
	.globl	sum
	.type	sum, @function
sum:
.LFB4:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	.cfi_offset 3, -24
	movq	tree(%rip), %rax
	movq	8+tree(%rip), %rdx
	movq	%rax, %rcx
	movq	%rdx, %rbx
	movl	%ecx, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE4:
	.size	sum, .-sum
	.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:
