// File: /workspace/github_c_makefile_star2_O1/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 0x4f8(%rip), %rdi       # 0x2050
xorl %eax, %eax
callq 0x1050
leaq 0x51f(%rip), %rdi       # 0x2085
leaq 0x14(%rsp), %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1080
movslq (%rbx), %rdi
callq 0x16b4
movq %rax, %r12
leaq 0x56a(%rip), %rdi       # 0x20f1
callq 0x1040
leaq 0x58d(%rip), %rdi       # 0x2120
callq 0x1040
leaq 0x597(%rip), %rdi       # 0x2136
callq 0x1040
leaq 0x596(%rip), %rdi       # 0x2141
callq 0x1040
leaq 0x59b(%rip), %rdi       # 0x2152
callq 0x1040
leaq 0x5ab(%rip), %rdi       # 0x216e
callq 0x1040
leaq 0x5b9(%rip), %rdi       # 0x2188
callq 0x1040
leaq 0x5c5(%rip), %rdi       # 0x21a0
callq 0x1040
leaq 0x5de(%rip), %rdi       # 0x21c5
callq 0x1040
leaq 0x495(%rip), %r13       # 0x2088
leaq 0x491(%rip), %rbp       # 0x208b
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 0x1c6c
cmpl $0x747563, 0x20(%rsp)   # imm = 0x747563
jne 0x1cbd
leaq 0x452(%rip), %rdi       # 0x2097
movq %r15, %rsi
xorl %eax, %eax
callq 0x1080
movq 0x90(%rsp), %rsi
movq %r12, %rdi
callq 0x1849
testl %eax, %eax
je 0x1c0d
leaq 0x561(%rip), %rdi       # 0x21cb
jmp 0x1cb3
leaq 0x420(%rip), %rdi       # 0x2093
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1080
movq 0x90(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rdi
callq 0x18ef
leaq 0x578(%rip), %rdi       # 0x2216
cmpl $0x1, %eax
je 0x1cb3
cmpl $0x2, %eax
jne 0x1c0d
leaq 0x53c(%rip), %rdi       # 0x21ef
callq 0x1040
jmp 0x1c0d
movq 0x20(%rsp), %rax
movabsq $0x6f6f725f646e6966, %rcx # imm = 0x6F6F725F646E6966
xorq %rcx, %rax
movzwl 0x28(%rsp), %ecx
xorq $0x74, %rcx
orq %rax, %rcx
je 0x1d7b
movq 0x20(%rsp), %rax
movabsq $0x657463656e6e6f63, %rcx # imm = 0x657463656E6E6F63
xorq %rcx, %rax
movzwl 0x28(%rsp), %ecx
xorq $0x64, %rcx
orq %rax, %rcx
je 0x1da8
movabsq $0x65657274627573, %rax # imm = 0x65657274627573
cmpq %rax, 0x20(%rsp)
jne 0x1df3
leaq 0x3a0(%rip), %rdi       # 0x20c1
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1080
leaq 0x391(%rip), %rdi       # 0x20c8
movq %r15, %rsi
xorl %eax, %eax
callq 0x1050
movl 0x90(%rsp), %eax
cmpl $0x6d7573, %eax         # imm = 0x6D7573
je 0x1ed3
cmpl $0x78616d, %eax         # imm = 0x78616D
je 0x1ec4
cmpl $0x6e696d, %eax         # imm = 0x6E696D
jne 0x1ee2
movq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x1a84
jmp 0x1f0e
leaq 0x315(%rip), %rdi       # 0x2097
movq %r15, %rsi
xorl %eax, %eax
callq 0x1080
movq 0x90(%rsp), %rsi
movq %r12, %rdi
callq 0x181e
leaq 0x302(%rip), %rdi       # 0x20a5
jmp 0x1f1a
leaq 0x2e4(%rip), %rdi       # 0x2093
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1080
movq 0x90(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rdi
callq 0x1a05
testb %al, %al
leaq 0x2de(%rip), %rdi       # 0x20ba
leaq 0x2d1(%rip), %rax       # 0x20b4
cmovneq %rax, %rdi
xorl %eax, %eax
callq 0x1050
jmp 0x1c0d
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 0x1e94
movzwl 0x30(%rsp), %eax
vmovd %eax, %xmm0
vmovdqa 0x20e(%rip), %xmm1      # 0x2030
vpxor 0x20(%rsp), %xmm1, %xmm1
vpternlogq $0xf6, 0x20d(%rip), %xmm0, %xmm1 # 0x2040
vptest %xmm1, %xmm1
je 0x1f29
movl 0x20(%rsp), %eax
movl $0x65736572, %ecx       # imm = 0x65736572
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x74, %ecx
orl %eax, %ecx
jne 0x1c0d
movq %r12, %rdi
callq 0x17b3
leaq 0x1e8(%rip), %rdi       # 0x2050
xorl %eax, %eax
callq 0x1050
leaq 0x20f(%rip), %rdi       # 0x2085
leaq 0x14(%rsp), %rsi
xorl %eax, %eax
callq 0x1080
movslq 0x14(%rsp), %rdi
callq 0x16b4
movq %rax, %r12
jmp 0x1c0d
leaq 0x1f8(%rip), %rdi       # 0x2093
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1080
movq 0x90(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rdi
callq 0x1a5c
jmp 0x1c0d
movq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x1ab2
jmp 0x1f0e
movq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x1ae1
jmp 0x1f0e
movl 0x90(%rsp), %eax
movl $0x657a6973, %ecx       # imm = 0x657A6973
xorl %ecx, %eax
movzbl 0x94(%rsp), %ecx
orl %eax, %ecx
movq 0x18(%rsp), %rax
jne 0x1f0e
movq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x1b10
leaq 0x190(%rip), %rdi       # 0x20a5
movq %rax, 0x18(%rsp)
movq %rax, %rsi
xorl %eax, %eax
callq 0x1050
jmp 0x1c0d
leaq 0x163(%rip), %rdi       # 0x2093
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1080
movq 0x90(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rdi
callq 0x1a6f
jmp 0x1c0d