// File: /workspace/github_c_makefile_star2_O0/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
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
leaq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, 0x821f(%rip)      # 0xa210
leaq 0x82d0(%rip), %rax      # 0xa2c8
movq %rax, 0x82c9(%rip)      # 0xa2c8
leaq 0x82c2(%rip), %rax      # 0xa2c8
movq %rax, 0x82c3(%rip)      # 0xa2d0
movl $0x1e, %edi
callq 0x1110
movq 0x7fc2(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %ecx
movl $0x2, %edx
movq %rcx, %rsi
callq 0x1180
movq 0x7f9f(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %ecx
movl $0x2, %edx
movq %rcx, %rsi
callq 0x1180
callq 0x1ef0
callq 0x1e70
callq 0x1d30
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl $0x3, %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x1, %edx
jne 0x2082
movl $0x10, %edi
callq 0x1170
movq %rax, -0x28(%rbp)
callq 0x1e90
cmpl $0x5, 0x8172(%rip)      # 0xa200
jge 0x21f9
movq -0x28(%rbp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
leaq 0x4681(%rip), %rdi      # 0x6726
xorl %eax, %eax
callq 0x10e0
movq -0x28(%rbp), %rdi
movl $0x10, %esi
movl $0xa, %edx
callq 0x13c0
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
addl $-0x61, %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x14, %eax
ja 0x21ad
movq -0x38(%rbp), %rax
leaq 0x3f2d(%rip), %rcx      # 0x6010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x2400
movl %eax, -0x8(%rbp)
cmpl $0x0, -0x8(%rbp)
jne 0x2160
cmpl $-0x1, -0x8(%rbp)
jne 0x2113
leaq 0x4622(%rip), %rdi      # 0x6729
callq 0x1070
xorl %edi, %edi
callq 0x11d0
cmpl $-0x2, -0x8(%rbp)
jne 0x212c
leaq 0x461f(%rip), %rdi      # 0x673f
callq 0x1070
xorl %edi, %edi
callq 0x11d0
cmpl $-0x9, -0x8(%rbp)
jne 0x2145
leaq 0x461c(%rip), %rdi      # 0x6755
callq 0x1070
xorl %edi, %edi
callq 0x11d0
cmpl $-0x8, -0x8(%rbp)
jne 0x215e
leaq 0x4611(%rip), %rdi      # 0x6763
callq 0x1070
xorl %edi, %edi
callq 0x11d0
jmp 0x2160
jmp 0x21f4
callq 0x2210
movl %eax, -0x8(%rbp)
jmp 0x21f4
callq 0x26f0
movl %eax, -0x8(%rbp)
jmp 0x21f4
callq 0x2580
movl %eax, -0x8(%rbp)
jmp 0x21f4
leaq 0x45e2(%rip), %rdi      # 0x676f
callq 0x1070
xorl %edi, %edi
callq 0x11d0
callq 0x27f0
movl %eax, -0x8(%rbp)
jmp 0x21f4
callq 0x24b0
movl %eax, -0x8(%rbp)
jmp 0x21f4
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x28(%rbp), %r11
movq -0x28(%rbp), %r10
movq -0x28(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x10e0
leaq 0x4586(%rip), %rdi      # 0x6773
movb $0x0, %al
callq 0x10e0
jmp 0x2087
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)