// File: /workspace/github_c_makefile_star2_O3/6851-2021[P]euler_tour_tree/repl.c
// Function: main
int main() {
    while (true) {
        int n;

        printf("Enter the number of nodes for your Euler Tour Tree: ");
        scanf("%d", &n);

        EulerTourTree* tree = make_euler_tour_tree(n);

        printf("Please enter an operation in the given format:\n");
        printf("link (child) (parent)\n");
        printf("cut (node)\n");
        printf("find_root (node)\n");
        printf("connected (node_1) (node_2)\n");
        printf("subtree (agg_func) (node)\n");
        printf("update (node) (new_val)\n");
        printf("increment_subtree (node) (new_value)\n");
        printf("reset\n");

        while (true) {

            printf("> ");

            char op[100];

            scanf("%s", op);
            if (strcmp(op, "link") == 0) {
                long child, parent;
                scanf("%ld %ld", &child, &parent);
                int not_linked = link(tree, child, parent);
                if (not_linked == 1) {
                    printf("ERROR: node is already linked.\n");
                } 
                else if (not_linked == 2) {
                    printf("ERROR: cannot link node to descendant.\n");
                }
            }
            else if (strcmp(op, "cut") == 0) {
                long node;
                scanf("%ld", &node);
                int not_cut = cut(tree, node);
                if (not_cut) {
                    printf("ERROR: node does not have a parent.\n");
                }
            }
            else if (strcmp(op, "find_root") == 0) {
                long node;
                scanf("%ld", &node);
                printf("%ld\n", find_root(tree, node));
            }
            else if (strcmp(op, "connected") == 0) {
                long node1, node2;
                scanf("%ld %ld", &node1, &node2);
                bool is_connected = connectivity(tree, node1, node2);
                printf(is_connected ? "true\n" : "false\n");
            }
            else if (strcmp(op, "subtree") == 0) {
                char agg[100];
                long node;
                long val;

                scanf("%s %ld", agg, &node);
                printf("agg is %s\n", agg);
                if (strcmp(agg, "min") == 0) {
                    val = subtree_aggregate_min(tree, node);
                }
                else if (strcmp(agg, "max") == 0) {
                    val = subtree_aggregate_max(tree, node);
                }
                else if (strcmp(agg, "sum") == 0) {
                    val = subtree_aggregate_sum(tree, node);
                }
                else if (strcmp(agg, "size") == 0) {
                    val = subtree_aggregate_size(tree, node);
                }
                printf("%ld\n", val);
            }
            else if (strcmp(op, "update") == 0) {
                long node, new_val;
                scanf("%ld %ld", &node, &new_val);

                point_update(tree, node, new_val);
            }
            else if (strcmp(op, "increment_subtree") == 0) {
                long node, inc_val;
                scanf("%ld %ld", &node, &inc_val);

                subtree_update(tree, node, inc_val);
            }
            else if (strcmp(op, "reset") == 0) {
                destroy_euler_tour_tree(tree);

                printf("Enter the number of nodes for your Euler Tour Tree: ");
                scanf("%d", &n);

                tree = make_euler_tour_tree(n);
            }
        }



    }
    

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
leaq 0x514(%rip), %rdi       # 0x2070
xorl %eax, %eax
callq 0x1050
leaq 0x53b(%rip), %rdi       # 0x20a5
leaq 0x14(%rsp), %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1080
movslq (%rbx), %rdi
callq 0x16b0
movq %rax, %r12
leaq 0x586(%rip), %rdi       # 0x2111
callq 0x1040
leaq 0x5a9(%rip), %rdi       # 0x2140
callq 0x1040
leaq 0x5b3(%rip), %rdi       # 0x2156
callq 0x1040
leaq 0x5b2(%rip), %rdi       # 0x2161
callq 0x1040
leaq 0x5b7(%rip), %rdi       # 0x2172
callq 0x1040
leaq 0x5c7(%rip), %rdi       # 0x218e
callq 0x1040
leaq 0x5d5(%rip), %rdi       # 0x21a8
callq 0x1040
leaq 0x5e1(%rip), %rdi       # 0x21c0
callq 0x1040
leaq 0x5fa(%rip), %rdi       # 0x21e5
callq 0x1040
leaq 0x4b1(%rip), %r13       # 0x20a8
leaq 0x4ad(%rip), %rbp       # 0x20ab
leaq 0x20(%rsp), %rbx
movl $0x6b6e696c, %r14d      # imm = 0x6B6E696C
leaq 0x90(%rsp), %r15
movq %r13, %rdi
xorl %eax, %eax
callq 0x1050
movq %rbp, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1080
movl 0x20(%rsp), %eax
xorl %r14d, %eax
movzbl 0x24(%rsp), %ecx
orl %eax, %ecx
je 0x1c70
cmpl $0x747563, 0x20(%rsp)   # imm = 0x747563
jne 0x1cc1
leaq 0x46e(%rip), %rdi       # 0x20b7
movq %r15, %rsi
xorl %eax, %eax
callq 0x1080
movq 0x90(%rsp), %rsi
movq %r12, %rdi
callq 0x1845
testl %eax, %eax
je 0x1c11
leaq 0x57d(%rip), %rdi       # 0x21eb
jmp 0x1cb7
leaq 0x43c(%rip), %rdi       # 0x20b3
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1080
movq 0x90(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rdi
callq 0x18eb
leaq 0x594(%rip), %rdi       # 0x2236
cmpl $0x1, %eax
je 0x1cb7
cmpl $0x2, %eax
jne 0x1c11
leaq 0x558(%rip), %rdi       # 0x220f
callq 0x1040
jmp 0x1c11
movq 0x20(%rsp), %rax
movabsq $0x6f6f725f646e6966, %rcx # imm = 0x6F6F725F646E6966
xorq %rcx, %rax
movzwl 0x28(%rsp), %ecx
xorq $0x74, %rcx
orq %rax, %rcx
je 0x1d7f
movq 0x20(%rsp), %rax
movabsq $0x657463656e6e6f63, %rcx # imm = 0x657463656E6E6F63
xorq %rcx, %rax
movzwl 0x28(%rsp), %ecx
xorq $0x64, %rcx
orq %rax, %rcx
je 0x1dac
movabsq $0x65657274627573, %rax # imm = 0x65657274627573
cmpq %rax, 0x20(%rsp)
jne 0x1df7
leaq 0x3bc(%rip), %rdi       # 0x20e1
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1080
leaq 0x3ad(%rip), %rdi       # 0x20e8
movq %r15, %rsi
xorl %eax, %eax
callq 0x1050
movl 0x90(%rsp), %eax
cmpl $0x6d7573, %eax         # imm = 0x6D7573
je 0x1ed7
cmpl $0x78616d, %eax         # imm = 0x78616D
je 0x1ec8
cmpl $0x6e696d, %eax         # imm = 0x6E696D
jne 0x1ee6
movq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x1a86
jmp 0x1f12
leaq 0x331(%rip), %rdi       # 0x20b7
movq %r15, %rsi
xorl %eax, %eax
callq 0x1080
movq 0x90(%rsp), %rsi
movq %r12, %rdi
callq 0x181a
leaq 0x31e(%rip), %rdi       # 0x20c5
jmp 0x1f1e
leaq 0x300(%rip), %rdi       # 0x20b3
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1080
movq 0x90(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rdi
callq 0x1a07
testb %al, %al
leaq 0x2fa(%rip), %rdi       # 0x20da
leaq 0x2ed(%rip), %rax       # 0x20d4
cmovneq %rax, %rdi
xorl %eax, %eax
callq 0x1050
jmp 0x1c11
movl 0x20(%rsp), %eax
movl $0x61647075, %ecx       # imm = 0x61647075
xorl %ecx, %eax
movl 0x23(%rsp), %ecx
movl $0x657461, %edx         # imm = 0x657461
xorl %edx, %ecx
orl %eax, %ecx
je 0x1e98
movzwl 0x30(%rsp), %eax
vmovd %eax, %xmm0
vmovdqa 0x22a(%rip), %xmm1      # 0x2050
vpxor 0x20(%rsp), %xmm1, %xmm1
vpternlogq $0xf6, 0x229(%rip), %xmm0, %xmm1 # 0x2060
vptest %xmm1, %xmm1
je 0x1f2d
movl 0x20(%rsp), %eax
movl $0x65736572, %ecx       # imm = 0x65736572
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x74, %ecx
orl %eax, %ecx
jne 0x1c11
movq %r12, %rdi
callq 0x17af
leaq 0x204(%rip), %rdi       # 0x2070
xorl %eax, %eax
callq 0x1050
leaq 0x22b(%rip), %rdi       # 0x20a5
leaq 0x14(%rsp), %rsi
xorl %eax, %eax
callq 0x1080
movslq 0x14(%rsp), %rdi
callq 0x16b0
movq %rax, %r12
jmp 0x1c11
leaq 0x214(%rip), %rdi       # 0x20b3
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1080
movq 0x90(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rdi
callq 0x1a5e
jmp 0x1c11
movq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x1ab4
jmp 0x1f12
movq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x1ae3
jmp 0x1f12
movl 0x90(%rsp), %eax
movl $0x657a6973, %ecx       # imm = 0x657A6973
xorl %ecx, %eax
movzbl 0x94(%rsp), %ecx
orl %eax, %ecx
movq 0x18(%rsp), %rax
jne 0x1f12
movq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x1b12
leaq 0x1ac(%rip), %rdi       # 0x20c5
movq %rax, 0x18(%rsp)
movq %rax, %rsi
xorl %eax, %eax
callq 0x1050
jmp 0x1c11
leaq 0x17f(%rip), %rdi       # 0x20b3
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1080
movq 0x90(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rdi
callq 0x1a71
jmp 0x1c11