// File: /workspace/github_c_makefile_star2_O3/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, 0x648e(%rip)      # 0x8150
leaq 0x653f(%rip), %rax      # 0x8208
movq %rax, 0x6538(%rip)      # 0x8208
movq %rax, 0x6539(%rip)      # 0x8210
movl $0x1e, %edi
callq 0x1100
movq 0x62f8(%rip), %rax      # 0x7fe0
movq (%rax), %rdi
xorl %esi, %esi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x1180
movq 0x62d8(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
xorl %esi, %esi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x1180
callq 0x1c06
leaq 0x2af7(%rip), %rdi      # 0x4814
callq 0x1060
callq 0x1a6d
imull $0xaaaaaaab, 0x642f(%rip), %eax # imm = 0xAAAAAAAB
addl $0x55555555, %eax       # imm = 0x55555555
cmpl $0x55555554, %eax       # imm = 0x55555554
ja 0x1d4c
movl $0x10, %edi
callq 0x1170
movq %rax, %rbx
jmp 0x1d50
leaq -0x40(%rbp), %rbx
callq 0x1bad
cmpl $0x4, 0x63e4(%rip)      # 0x8140
jg 0x1e3a
leaq 0x2837(%rip), %r14      # 0x45a0
leaq -0x29(%rbp), %r15
leaq 0x22ac(%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 0x1daa
movb %al, (%rbx,%r12)
incq %r12
cmpq $0x10, %r12
jne 0x1d87
movzbl (%rbx), %eax
cmpl $0x71, %eax
jg 0x1dcb
addl $-0x61, %eax
cmpl $0x4, %eax
ja 0x1dfd
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
callq 0x1ffa
jmp 0x1e2d
cmpl $0x72, %eax
je 0x1def
cmpl $0x73, %eax
je 0x1df6
cmpl $0x75, %eax
jne 0x1dfd
callq 0x2202
jmp 0x1e2d
callq 0x1e5e
jmp 0x1e2d
callq 0x20a9
jmp 0x1e2d
callq 0x228e
jmp 0x1e2d
callq 0x210c
jmp 0x1e2d
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 0x2b22(%rip), %rdi      # 0x494a
callq 0x1060
cmpl $0x5, 0x630c(%rip)      # 0x8140
jl 0x1d74
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2751(%rip), %rdi      # 0x45a3
callq 0x1060
xorl %edi, %edi
callq 0x11d0