// File: /workspace/github_c_makefile_star2_O2/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 0x4fc(%rip), %rdi       # 0x2044
xorl %eax, %eax
callq 0x1050
leaq 0x523(%rip), %rdi       # 0x2079
leaq 0x14(%rsp), %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1090
movslq (%rbx), %rdi
callq 0x16ac
movq %rax, (%rsp)
leaq 0x56d(%rip), %rdi       # 0x20e5
callq 0x1040
leaq 0x590(%rip), %rdi       # 0x2114
callq 0x1040
leaq 0x59a(%rip), %rdi       # 0x212a
callq 0x1040
leaq 0x599(%rip), %rdi       # 0x2135
callq 0x1040
leaq 0x59e(%rip), %rdi       # 0x2146
callq 0x1040
leaq 0x5ae(%rip), %rdi       # 0x2162
callq 0x1040
leaq 0x5bc(%rip), %rdi       # 0x217c
callq 0x1040
leaq 0x5c8(%rip), %rdi       # 0x2194
callq 0x1040
leaq 0x5e1(%rip), %rdi       # 0x21b9
callq 0x1040
leaq 0x49b(%rip), %rbx       # 0x207f
leaq 0x90(%rsp), %r14
leaq 0x48f(%rip), %r13       # 0x2082
pushq $0x5
popq %r12
pushq $0xa
popq %r15
leaq 0x47a(%rip), %rdi       # 0x207c
xorl %eax, %eax
callq 0x1050
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x1090
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x1070
testl %eax, %eax
je 0x1c63
cmpl $0x747563, 0x90(%rsp) # imm = 0x747563
jne 0x1cb4
leaq 0x44f(%rip), %rdi       # 0x208b
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x1090
movq 0x20(%rsp), %rsi
movq (%rsp), %rdi
callq 0x183a
testl %eax, %eax
je 0x1bfb
leaq 0x55e(%rip), %rdi       # 0x21bf
jmp 0x1caa
leaq 0x41d(%rip), %rdi       # 0x2087
leaq 0x20(%rsp), %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1090
movq 0x20(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq (%rsp), %rdi
callq 0x18db
leaq 0x575(%rip), %rdi       # 0x220a
cmpl $0x1, %eax
je 0x1caa
cmpl $0x2, %eax
jne 0x1bfb
leaq 0x539(%rip), %rdi       # 0x21e3
callq 0x1040
jmp 0x1bfb
movq %r13, %rbp
movq %rbx, %r13
movq %r14, %rdi
leaq 0x3cb(%rip), %rsi       # 0x208f
movq %r15, %rbx
movq %r15, %rdx
callq 0x1070
testl %eax, %eax
je 0x1d73
movq %r14, %rdi
leaq 0x3bd(%rip), %rsi       # 0x209e
movq %rbx, %rdx
callq 0x1070
testl %eax, %eax
je 0x1dad
movabsq $0x65657274627573, %rax # imm = 0x65657274627573
cmpq %rax, 0x90(%rsp)
jne 0x1df8
leaq 0x3a5(%rip), %rdi       # 0x20b5
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1090
leaq 0x391(%rip), %rdi       # 0x20bc
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1050
movl 0x20(%rsp), %eax
cmpl $0x6d7573, %eax         # imm = 0x6D7573
je 0x1ecb
cmpl $0x78616d, %eax         # imm = 0x78616D
movq %r13, %rbx
je 0x1ebb
cmpl $0x6e696d, %eax         # imm = 0x6E696D
movq %rbp, %r13
jne 0x1ee1
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
callq 0x1a74
jmp 0x1f0c
leaq 0x311(%rip), %rdi       # 0x208b
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x1090
movq 0x20(%rsp), %rsi
movq (%rsp), %rdi
callq 0x180f
leaq 0x2fe(%rip), %rdi       # 0x2099
movq %rax, %rsi
xorl %eax, %eax
callq 0x1050
movq %rbx, %r15
jmp 0x1eb0
leaq 0x2d3(%rip), %rdi       # 0x2087
leaq 0x20(%rsp), %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1090
movq 0x20(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq (%rsp), %rdi
callq 0x19f5
testb %al, %al
leaq 0x2cd(%rip), %rdi       # 0x20ae
leaq 0x2c0(%rip), %rax       # 0x20a8
cmovneq %rax, %rdi
xorl %eax, %eax
callq 0x1050
jmp 0x1eb0
movq %r14, %rdi
leaq 0x2ca(%rip), %rsi       # 0x20cc
pushq $0x7
popq %rdx
callq 0x1070
testl %eax, %eax
je 0x1e85
movq %r14, %rdi
leaq 0x2bb(%rip), %rsi       # 0x20d3
pushq $0x12
popq %rdx
callq 0x1070
testl %eax, %eax
movq %r13, %rbx
je 0x1f27
movq %r14, %rdi
leaq 0x384(%rip), %rsi       # 0x21b9
pushq $0x6
popq %rdx
callq 0x1070
testl %eax, %eax
movq %rbp, %r13
jne 0x1bfb
movq (%rsp), %rdi
callq 0x17a7
leaq 0x1ec(%rip), %rdi       # 0x2044
xorl %eax, %eax
callq 0x1050
leaq 0x213(%rip), %rdi       # 0x2079
leaq 0x14(%rsp), %rsi
xorl %eax, %eax
callq 0x1090
movslq 0x14(%rsp), %rdi
callq 0x16ac
movq %rax, (%rsp)
jmp 0x1bfb
leaq 0x1fb(%rip), %rdi       # 0x2087
leaq 0x20(%rsp), %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1090
movq 0x20(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq (%rsp), %rdi
callq 0x1a4c
movq %r13, %rbx
movq %rbp, %r13
jmp 0x1bfb
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
callq 0x1aa2
jmp 0x1edc
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
callq 0x1ad1
movq %r13, %rbx
movq %rbp, %r13
jmp 0x1f0c
leaq 0x20(%rsp), %rdi
leaq 0x1da(%rip), %rsi       # 0x20c7
movq %r12, %rdx
callq 0x1070
testl %eax, %eax
movq 0x18(%rsp), %rax
jne 0x1f0c
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
callq 0x1b00
leaq 0x186(%rip), %rdi       # 0x2099
movq %rax, 0x18(%rsp)
movq %rax, %rsi
xorl %eax, %eax
callq 0x1050
jmp 0x1bfb
leaq 0x159(%rip), %rdi       # 0x2087
leaq 0x20(%rsp), %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1090
movq 0x20(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq (%rsp), %rdi
callq 0x1a5f
movq %rbp, %r13
jmp 0x1bfb