// File: /workspace/github_c_makefile_star2_O1/ww9210[P]xnuca_final_ssp/main.c
// Function: main
int main()
{
    int ret;
    char buffer[16];
    char* option_buffer = buffer;
    unsigned int* flag_hash;
    total_ppl = 0;
    head.fd = &head;
    head.bk = &head;

    alarm(30);
    //setvbuf(stdin, stdin_buf, _IOFBF, sizeof(stdin_buf));
    setvbuf(stdin,0,2,0);
    setvbuf(stdout,0,2,0);
#ifdef DEBUG
    printf("%d\n",getpid());
#endif
    read_original_program();
    welcome();    
    flag_hash=safe_read_flag();
    if(flag_hash[0] % 3 == 1){
        option_buffer = malloc(16);
    }
    print_options();

    while(global_executor_idx < 5){
        memset(option_buffer,0,16);
        printf("$ ");
        recv_until(option_buffer,16,'\n');
        switch(option_buffer[0]){
            case 'a':
                ret=add_patch_pipeline();
                if(!ret){
                    if(ret==-1){
                        puts("invalid pipeline size");
                        exit(0);
                    }
                    if(ret==-2){
                        puts("invalid pipeline type");
                        exit(0);
                    }
                    if(ret==-9){
                        puts("cost too high");
                        exit(0);
                    }
                    if(ret==-8){
                        puts("malloc fail");
                        exit(0);
                    }
                }
                break;
            case 'c': // complain 
                ret=add_complain();
                break;
            case 'u': // upload a patch
                ret=upload_patches();
                break;
            case 's': // swap a patch
                ret=swap_a_patch();
                break;
            case 'e': // exit
                puts("bye");
                exit(0);
                break;
            case 'r': // run patches
                ret=run_patches();
                break;
            case 'd': // remove a patch pipeline
                ret=remove_pipeline();
                break;
#ifdef DEBUG
            case 'x': // get shell
                get_shell();
                break;
#endif
            default:
                printf(option_buffer, option_buffer, option_buffer, option_buffer, option_buffer, option_buffer, option_buffer, option_buffer, option_buffer); // leak heap pointer
                printf(" :invalid option.\n");
                break;

        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl $0x0, 0x6493(%rip)      # 0x8140
leaq 0x6544(%rip), %rax      # 0x81f8
movq %rax, 0x653d(%rip)      # 0x81f8
movq %rax, 0x653e(%rip)      # 0x8200
movl $0x1e, %edi
callq 0x1100
movq 0x630d(%rip), %rax      # 0x7fe0
movq (%rax), %rdi
xorl %esi, %esi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x1170
movq 0x62ed(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
xorl %esi, %esi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x1170
callq 0x1bf1
leaq 0x2b0c(%rip), %rdi      # 0x4814
callq 0x1060
callq 0x1a58
imull $0xaaaaaaab, 0x6434(%rip), %eax # imm = 0xAAAAAAAB
addl $0x55555555, %eax       # imm = 0x55555555
cmpl $0x55555554, %eax       # imm = 0x55555554
ja 0x1d37
movl $0x10, %edi
callq 0x1160
movq %rax, %rbx
jmp 0x1d3b
leaq -0x40(%rbp), %rbx
callq 0x1b98
cmpl $0x4, 0x63e9(%rip)      # 0x8130
jg 0x1e25
leaq 0x284c(%rip), %r14      # 0x45a0
leaq -0x29(%rbp), %r15
leaq 0x22c1(%rip), %r13      # 0x4020
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq %r14, %rdi
xorl %eax, %eax
callq 0x10d0
xorl %r12d, %r12d
movl $0x1, %edx
xorl %edi, %edi
movq %r15, %rsi
callq 0x1110
movb -0x29(%rbp), %al
cmpb $0xa, %al
je 0x1d95
movb %al, (%rbx,%r12)
incq %r12
cmpq $0x10, %r12
jne 0x1d72
movzbl (%rbx), %eax
cmpl $0x71, %eax
jg 0x1db6
addl $-0x61, %eax
cmpl $0x4, %eax
ja 0x1de8
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
callq 0x1fe5
jmp 0x1e18
cmpl $0x72, %eax
je 0x1dda
cmpl $0x73, %eax
je 0x1de1
cmpl $0x75, %eax
jne 0x1de8
callq 0x2214
jmp 0x1e18
callq 0x1e49
jmp 0x1e18
callq 0x20a2
jmp 0x1e18
callq 0x22b3
jmp 0x1e18
callq 0x2117
jmp 0x1e18
subq $0x8, %rsp
movq %rbx, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
movq %rbx, %rcx
movq %rbx, %r8
movq %rbx, %r9
xorl %eax, %eax
pushq %rbx
pushq %rbx
pushq %rbx
callq 0x10d0
addq $0x20, %rsp
leaq 0x2b37(%rip), %rdi      # 0x494a
callq 0x1060
cmpl $0x5, 0x6311(%rip)      # 0x8130
jl 0x1d5f
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2766(%rip), %rdi      # 0x45a3
callq 0x1060
xorl %edi, %edi
callq 0x11c0