// File: /workspace/github_c_makefile_star2_O2/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
andl $0x0, 0x6560(%rip)      # 0x8150
leaq 0x6611(%rip), %rax      # 0x8208
movq %rax, 0x660a(%rip)      # 0x8208
movq %rax, 0x660b(%rip)      # 0x8210
pushq $0x1e
popq %rdi
callq 0x1100
movq 0x63cc(%rip), %rax      # 0x7fe0
movq (%rax), %rdi
pushq $0x2
popq %rbx
xorl %esi, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x1180
movq 0x63ac(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
xorl %esi, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x1180
callq 0x1b39
callq 0x1acf
callq 0x199e
movl 0x6511(%rip), %eax      # 0x8160
pushq $0x3
popq %rcx
xorl %edx, %edx
divl %ecx
cmpl $0x1, %edx
jne 0x1c68
pushq $0x10
popq %rdi
callq 0x1170
movq %rax, %rbx
jmp 0x1c6c
leaq -0x40(%rbp), %rbx
callq 0x1ae0
leaq 0x2928(%rip), %r14      # 0x45a0
pushq $0x10
popq %r15
pushq $0xa
popq %r12
leaq 0x2399(%rip), %r13      # 0x4020
cmpl $0x4, 0x64b2(%rip)      # 0x8140
jg 0x1d41
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq %r14, %rdi
xorl %eax, %eax
callq 0x10d0
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x1357
movzbl (%rbx), %eax
leal -0x61(%rax), %ecx
cmpl $0x4, %ecx
ja 0x1cce
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
callq 0x1ecf
jmp 0x1c87
cmpl $0x72, %eax
je 0x1d37
cmpl $0x73, %eax
je 0x1d2d
cmpl $0x75, %eax
jne 0x1ce4
callq 0x2098
jmp 0x1c87
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 0x2c3b(%rip), %rdi      # 0x494a
callq 0x1060
jmp 0x1c87
callq 0x1d65
jmp 0x1c87
callq 0x1f53
jmp 0x1c87
callq 0x1fb0
jmp 0x1c87
callq 0x2120
jmp 0x1c87
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x284a(%rip), %rdi      # 0x45a3
callq 0x1060
xorl %edi, %edi
callq 0x11d0