// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x158, %rsp            # imm = 0x158
movl $0x0, 0x154(%rsp)
leaq 0x9cd(%rip), %rdi       # 0x3026
movb $0x0, %al
callq 0x1040
leaq 0x9f4(%rip), %rdi       # 0x305b
leaq 0x150(%rsp), %rsi
movb $0x0, %al
callq 0x1090
movslq 0x150(%rsp), %rdi
callq 0x1cb0
movq %rax, 0x148(%rsp)
leaq 0x9cc(%rip), %rdi       # 0x305e
movb $0x0, %al
callq 0x1040
leaq 0x9ee(%rip), %rdi       # 0x308e
movb $0x0, %al
callq 0x1040
leaq 0x9f7(%rip), %rdi       # 0x30a5
movb $0x0, %al
callq 0x1040
leaq 0x9f5(%rip), %rdi       # 0x30b1
movb $0x0, %al
callq 0x1040
leaq 0x9f9(%rip), %rdi       # 0x30c3
movb $0x0, %al
callq 0x1040
leaq 0xa08(%rip), %rdi       # 0x30e0
movb $0x0, %al
callq 0x1040
leaq 0xa15(%rip), %rdi       # 0x30fb
movb $0x0, %al
callq 0x1040
leaq 0xa20(%rip), %rdi       # 0x3114
movb $0x0, %al
callq 0x1040
leaq 0xa38(%rip), %rdi       # 0x313a
movb $0x0, %al
callq 0x1040
leaq 0xa31(%rip), %rdi       # 0x3141
movb $0x0, %al
callq 0x1040
leaq 0xe0(%rsp), %rsi
leaq 0xa1e(%rip), %rdi       # 0x3144
movb $0x0, %al
callq 0x1090
leaq 0xe0(%rsp), %rdi
leaq 0xa0b(%rip), %rsi       # 0x3147
callq 0x1050
cmpl $0x0, %eax
jne 0x27c1
leaq 0x9ff(%rip), %rdi       # 0x314c
leaq 0xd8(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
movb $0x0, %al
callq 0x1090
movq 0x148(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
callq 0x2120
movl %eax, 0xcc(%rsp)
cmpl $0x1, 0xcc(%rsp)
jne 0x27a2
leaq 0x9bb(%rip), %rdi       # 0x3154
movb $0x0, %al
callq 0x1040
jmp 0x27bc
cmpl $0x2, 0xcc(%rsp)
jne 0x27ba
leaq 0x9c1(%rip), %rdi       # 0x3174
movb $0x0, %al
callq 0x1040
jmp 0x27bc
jmp 0x2b2c
leaq 0xe0(%rsp), %rdi
leaq 0x9cc(%rip), %rsi       # 0x319c
callq 0x1050
cmpl $0x0, %eax
jne 0x2829
leaq 0x96f(%rip), %rdi       # 0x3150
leaq 0xc0(%rsp), %rsi
movb $0x0, %al
callq 0x1090
movq 0x148(%rsp), %rdi
movq 0xc0(%rsp), %rsi
callq 0x1fd0
movl %eax, 0xbc(%rsp)
cmpl $0x0, 0xbc(%rsp)
je 0x2824
leaq 0x983(%rip), %rdi       # 0x31a0
movb $0x0, %al
callq 0x1040
jmp 0x2b2a
leaq 0xe0(%rsp), %rdi
leaq 0x98d(%rip), %rsi       # 0x31c5
callq 0x1050
cmpl $0x0, %eax
jne 0x2883
leaq 0x907(%rip), %rdi       # 0x3150
leaq 0xb0(%rsp), %rsi
movb $0x0, %al
callq 0x1090
movq 0x148(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0x1f50
movq %rax, %rsi
leaq 0x958(%rip), %rdi       # 0x31cf
movb $0x0, %al
callq 0x1040
jmp 0x2b28
leaq 0xe0(%rsp), %rdi
leaq 0x942(%rip), %rsi       # 0x31d4
callq 0x1050
cmpl $0x0, %eax
jne 0x2908
leaq 0x8a9(%rip), %rdi       # 0x314c
leaq 0xa8(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
movb $0x0, %al
callq 0x1090
movq 0x148(%rsp), %rdi
movq 0xa8(%rsp), %rsi
movq 0xa0(%rsp), %rdx
callq 0x2330
andb $0x1, %al
movb %al, 0x9f(%rsp)
movb 0x9f(%rsp), %cl
leaq 0x8f6(%rip), %rdi       # 0x31e4
leaq 0x8e9(%rip), %rax       # 0x31de
testb $0x1, %cl
cmovneq %rax, %rdi
movb $0x0, %al
callq 0x1040
jmp 0x2b26
leaq 0xe0(%rsp), %rdi
leaq 0x908(%rip), %rsi       # 0x321f
callq 0x1050
cmpl $0x0, %eax
jne 0x2a2b
leaq 0x30(%rsp), %rsi
leaq 0x8ba(%rip), %rdi       # 0x31eb
leaq 0x28(%rsp), %rdx
movb $0x0, %al
callq 0x1090
leaq 0x30(%rsp), %rsi
leaq 0x8a9(%rip), %rdi       # 0x31f2
movb $0x0, %al
callq 0x1040
leaq 0x30(%rsp), %rdi
leaq 0x8a1(%rip), %rsi       # 0x31fd
callq 0x1050
cmpl $0x0, %eax
jne 0x2982
movq 0x148(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x2480
movq %rax, 0x20(%rsp)
jmp 0x2a13
leaq 0x30(%rsp), %rdi
leaq 0x873(%rip), %rsi       # 0x3201
callq 0x1050
cmpl $0x0, %eax
jne 0x29b1
movq 0x148(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x24f0
movq %rax, 0x20(%rsp)
jmp 0x2a11
leaq 0x30(%rsp), %rdi
leaq 0x848(%rip), %rsi       # 0x3205
callq 0x1050
cmpl $0x0, %eax
jne 0x29e0
movq 0x148(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x2560
movq %rax, 0x20(%rsp)
jmp 0x2a0f
leaq 0x30(%rsp), %rdi
leaq 0x81d(%rip), %rsi       # 0x3209
callq 0x1050
cmpl $0x0, %eax
jne 0x2a0d
movq 0x148(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x25d0
movq %rax, 0x20(%rsp)
jmp 0x2a0f
jmp 0x2a11
jmp 0x2a13
movq 0x20(%rsp), %rsi
leaq 0x7b0(%rip), %rdi       # 0x31cf
movb $0x0, %al
callq 0x1040
jmp 0x2b24
leaq 0xe0(%rsp), %rdi
leaq 0x7d4(%rip), %rsi       # 0x320e
callq 0x1050
cmpl $0x0, %eax
jne 0x2a78
leaq 0x701(%rip), %rdi       # 0x314c
leaq 0x18(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movb $0x0, %al
callq 0x1090
movq 0x148(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x23d0
jmp 0x2b22
leaq 0xe0(%rsp), %rdi
leaq 0x78e(%rip), %rsi       # 0x3215
callq 0x1050
cmpl $0x0, %eax
jne 0x2abf
leaq 0x6b4(%rip), %rdi       # 0x314c
leaq 0x8(%rsp), %rsi
movq %rsp, %rdx
movb $0x0, %al
callq 0x1090
movq 0x148(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq (%rsp), %rdx
callq 0x2410
jmp 0x2b20
leaq 0xe0(%rsp), %rdi
leaq 0x759(%rip), %rsi       # 0x3227
callq 0x1050
cmpl $0x0, %eax
jne 0x2b1e
movq 0x148(%rsp), %rdi
callq 0x1ea0
leaq 0x53a(%rip), %rdi       # 0x3026
movb $0x0, %al
callq 0x1040
leaq 0x561(%rip), %rdi       # 0x305b
leaq 0x150(%rsp), %rsi
movb $0x0, %al
callq 0x1090
movslq 0x150(%rsp), %rdi
callq 0x1cb0
movq %rax, 0x148(%rsp)
jmp 0x2b20
jmp 0x2b22
jmp 0x2b24
jmp 0x2b26
jmp 0x2b28
jmp 0x2b2a
jmp 0x2b2c
jmp 0x2709