// File: /workspace/github_c_makefile_star2_O0/dolphinking[P]slimox/src/slimox-main.c
// Function: main
int main(int argc, char** argv) {
    enum {
        OPERATION_INVALID,
        OPERATION_COMP,
        OPERATION_DECOMP,
        OPERATION_PACK,
        OPERATION_UNPACK,
    } operation = OPERATION_INVALID;

    char option;
    uint32_t block_size = 16777216; /* 16MB by default */
    ppm_model_t* ppm = ppm_model_new();
    buf_t* ib = buf_new();
    buf_t* ob = buf_new();
    struct timeval time_start;
    struct timeval time_end;
    double cost_time;

    /* timer start */
    gettimeofday(&time_start, NULL);

#if defined(_WIN32) || defined(_WIN64)
    /* we need to set stdin/stdout to binary mode under windows */
    setmode(fileno(stdin), O_BINARY);
    setmode(fileno(stdout), O_BINARY);
#endif

    /* process args */
    while(argc > 1 && sscanf(argv[1], "-%c", &option) > 0) {
        if(option == 'q') { /* quiet mode */
            fclose(stderr);
            memmove(&argv[1], &argv[2], (--argc) * sizeof(*argv));
            continue;
        }
        if(option == 'b') { /* set blocksize */
            if(sscanf(argv[1] + 2, "%d", &block_size) > 0) {
                block_size *= 1048576;
            } else {
                fprintf(stderr, "error: Invalid blocksize\n");
                exit(-1);
            }
            memmove(&argv[1], &argv[2], (--argc) * sizeof(*argv));
            continue;
        }
        fprintf(stderr, "error: Invalid argument\n");
        exit(-1);
    }
    buf_resize(ib, block_size);

    /* start! */
    fprintf(stderr, msg_start);
    if(argc == 4 && strcmp(argv[1], "e") == 0) { /* pack directory */
        operation = OPERATION_PACK;
        if(pack(argv[2], argv[3], ppm, block_size) == -1) {
            abort();
        }

        /* timer end */
        gettimeofday(&time_end, NULL);
        cost_time = (time_end.tv_sec - time_start.tv_sec) + (time_end.tv_usec - time_start.tv_usec) / 1000000.0;
        fprintf(stderr, "encode done in %.2lfsec\n", cost_time);
    }
    if(argc == 4 && strcmp(argv[1], "d") == 0) { /* unpack directory */
        operation = OPERATION_PACK;
        if(unpack(argv[2], argv[3], ppm, block_size) == -1) {
            abort();
        }

        /* timer end */
        gettimeofday(&time_end, NULL);
        cost_time = (time_end.tv_sec - time_start.tv_sec) + (time_end.tv_usec - time_start.tv_usec) / 1000000.0;
        fprintf(stderr, "encode done in %.2lfsec\n", cost_time);
    }

    if(operation == OPERATION_INVALID) { /* bad operation */
        fprintf(stderr, msg_help);
    }
    ppm_model_del(ppm);
    buf_del(ib);
    buf_del(ob);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x1000000, -0x1c(%rbp) # imm = 0x1000000
callq 0x15b80
movq %rax, -0x28(%rbp)
callq 0x15d50
movq %rax, -0x30(%rbp)
callq 0x15d50
movq %rax, -0x38(%rbp)
leaq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10d0
xorl %eax, %eax
cmpl $0x1, -0x8(%rbp)
movb %al, -0x61(%rbp)
jle 0x157da
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x2a4c(%rip), %rsi      # 0x18212
leaq -0x15(%rbp), %rdx
movb $0x0, %al
callq 0x11a0
cmpl $0x0, %eax
setg %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x157e6
jmp 0x158ca
movsbl -0x15(%rbp), %eax
cmpl $0x71, %eax
jne 0x15825
movq 0x5802(%rip), %rax      # 0x1aff8
movq (%rax), %rdi
callq 0x1090
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rsi
addq $0x10, %rsi
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movslq %eax, %rdx
shlq $0x3, %rdx
callq 0x11f0
jmp 0x157ac
movsbl -0x15(%rbp), %eax
cmpl $0x62, %eax
jne 0x158a8
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x2, %rdi
leaq 0x29d5(%rip), %rsi      # 0x18216
leaq -0x1c(%rbp), %rdx
movb $0x0, %al
callq 0x11a0
cmpl $0x0, %eax
jle 0x1585c
movl -0x1c(%rbp), %eax
shll $0x14, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1587e
movq 0x5795(%rip), %rax      # 0x1aff8
movq (%rax), %rdi
leaq 0x29ac(%rip), %rsi      # 0x18219
movb $0x0, %al
callq 0x1150
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1210
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rsi
addq $0x10, %rsi
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movslq %eax, %rdx
shlq $0x3, %rdx
callq 0x11f0
jmp 0x157ac
movq 0x5749(%rip), %rax      # 0x1aff8
movq (%rax), %rdi
leaq 0x297a(%rip), %rsi      # 0x18233
movb $0x0, %al
callq 0x1150
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1210
movq -0x30(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x15a90
movq 0x571b(%rip), %rax      # 0x1aff8
movq (%rax), %rdi
movq 0x5851(%rip), %rsi      # 0x1b138
movb $0x0, %al
callq 0x1150
cmpl $0x4, -0x8(%rbp)
jne 0x1599b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x2945(%rip), %rsi      # 0x1824c
callq 0x1140
cmpl $0x0, %eax
jne 0x1599b
movl $0x3, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x28(%rbp), %rdx
movl -0x1c(%rbp), %ecx
callq 0x15df0
cmpl $-0x1, %eax
jne 0x15942
callq 0x1040
leaq -0x58(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10d0
movq -0x58(%rbp), %rax
subq -0x48(%rbp), %rax
cvtsi2sd %rax, %xmm0
movq -0x50(%rbp), %rax
subq -0x40(%rbp), %rax
cvtsi2sd %rax, %xmm1
movsd 0x2727(%rip), %xmm2     # 0x18098
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movq 0x5673(%rip), %rax      # 0x1aff8
movq (%rax), %rdi
movsd -0x60(%rbp), %xmm0
leaq 0x28ba(%rip), %rsi      # 0x1824e
movb $0x1, %al
callq 0x1150
cmpl $0x4, -0x8(%rbp)
jne 0x15a48
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x2863(%rip), %rsi      # 0x18217
callq 0x1140
cmpl $0x0, %eax
jne 0x15a48
movl $0x3, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x28(%rbp), %rdx
movl -0x1c(%rbp), %ecx
callq 0x16ae0
cmpl $-0x1, %eax
jne 0x159ef
callq 0x1040
leaq -0x58(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10d0
movq -0x58(%rbp), %rax
subq -0x48(%rbp), %rax
cvtsi2sd %rax, %xmm0
movq -0x50(%rbp), %rax
subq -0x40(%rbp), %rax
cvtsi2sd %rax, %xmm1
movsd 0x267a(%rip), %xmm2     # 0x18098
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movq 0x55c6(%rip), %rax      # 0x1aff8
movq (%rax), %rdi
movsd -0x60(%rbp), %xmm0
leaq 0x280d(%rip), %rsi      # 0x1824e
movb $0x1, %al
callq 0x1150
cmpl $0x0, -0x14(%rbp)
jne 0x15a66
movq 0x55a3(%rip), %rax      # 0x1aff8
movq (%rax), %rdi
movq 0x56e1(%rip), %rsi      # 0x1b140
movb $0x0, %al
callq 0x1150
movq -0x28(%rbp), %rdi
callq 0x15b10
movq -0x30(%rbp), %rdi
callq 0x15b50
movq -0x38(%rbp), %rdi
callq 0x15b50
xorl %eax, %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)