// File: /workspace/github_c_makefile_star2_O0/pje[P]pixelsort/main.c
// Function: main
int main (int argc, char **argv) {
    char* orientation_arg_value = ARG_ROW;
    char* method_arg_value = ARG_LIGHT;
    char* comparator_arg_value = ARG_MIN;
    long threshold_arg_value = -1;

    if (argc < 3) {
        print_usage(argc, argv);
        return 1;
    }

    int c;
    while (1) {
        static struct option long_options[] = {
            { "orientation",  required_argument, 0, 'o'},
            { "method",       required_argument, 0, 'm'},
            { "comparator",   required_argument, 0, 'c'},
            { "threshold",    required_argument, 0, 't'},
            { 0, 0, 0, 0 }
        };

        int option_index = 0;

        c = getopt_long(argc, argv, "a:f:", long_options, &option_index);

        if (c == -1) break;

        switch (c) {
        case 'o':
            orientation_arg_value = optarg;
            break;
        case 'm':
            method_arg_value = optarg;
            break;
        case 'c':
            comparator_arg_value = optarg;
            break;
        case 't':
            threshold_arg_value = strtol(optarg, NULL, 10);
            break;
        case '?':
            break;
        default:
            abort();
        }
    }

    char *source = argv[argc - 2];
    char *destination = argv[argc - 1];

    struct image *img = read_image(source);

    pixel_sorting_context_t *ctx = (pixel_sorting_context_t*)malloc(sizeof(pixel_sorting_context_t));

    if (0 == strcmp(ARG_ROW, orientation_arg_value)) {
        ctx->orientation = ROW;
    } else if (0 == strcmp(ARG_COLUMN, orientation_arg_value)) {
        ctx->orientation = COLUMN;
    } else if (0 == strcmp(ARG_BOTH, orientation_arg_value)) {
        ctx->orientation = BOTH;
    } else {
        printf("invalid value for orientation argument; must be one of [row|column|both]");
        return 1;
    }

    if (0 == strcmp(ARG_DARK, method_arg_value)) {
        ctx->run_type = DARK;
        if (threshold_arg_value == -1) {
            ctx->threshold = 45;
        } else {
            ctx->threshold = threshold_arg_value;
        }
    } else if (0 == strcmp(ARG_LIGHT, method_arg_value)) {
        ctx->run_type = LIGHT;
        if (threshold_arg_value == -1) {
            ctx->threshold = 210;
        } else {
            ctx->threshold = threshold_arg_value;
        }
    } else if (0 == strcmp(ARG_ALL, method_arg_value)) {
        ctx->run_type = ALL;
    } else {
        printf("invalid value for method argument; must be one of [all|dark|light]");
        return 1;
    }

    if (0 == strcmp(ARG_AVG, comparator_arg_value)) {
        ctx->comparison = AVG;
    } else if (0 == strcmp(ARG_MUL, comparator_arg_value)) {
        ctx->comparison = MUL;
    } else if (0 == strcmp(ARG_MAX, comparator_arg_value)) {
        ctx->comparison = MAX;
    } else if (0 == strcmp(ARG_MIN, comparator_arg_value)) {
        ctx->comparison = MIN;
    } else if (0 == strcmp(ARG_XOR, comparator_arg_value)) {
        ctx->comparison = XOR;
    } else {
        printf("invalid value for comparator argument; must be one of [avg|mul|max|min|xor]");
        return 1;
    }

    sort(img, ctx);
    write_image(img, destination);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x331c(%rip), %rax      # 0x14489
movq %rax, -0x18(%rbp)
leaq 0x3315(%rip), %rax      # 0x1448d
movq %rax, -0x20(%rbp)
leaq 0x3310(%rip), %rax      # 0x14493
movq %rax, -0x28(%rbp)
movq $-0x1, -0x30(%rbp)
cmpl $0x3, -0x8(%rbp)
jge 0x111ad
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x110c0
movl $0x1, -0x4(%rbp)
jmp 0x1150a
jmp 0x111af
movl $0x0, -0x38(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x32f4(%rip), %rdx      # 0x144b8
leaq 0x72f5(%rip), %rcx      # 0x184c0
leaq -0x38(%rbp), %r8
callq 0x1090
movl %eax, -0x34(%rbp)
cmpl $-0x1, -0x34(%rbp)
jne 0x111e2
jmp 0x11271
movl -0x34(%rbp), %eax
movl %eax, -0x5c(%rbp)
subl $0x3f, %eax
je 0x11265
jmp 0x111ef
movl -0x5c(%rbp), %eax
subl $0x63, %eax
je 0x11237
jmp 0x111f9
movl -0x5c(%rbp), %eax
subl $0x6d, %eax
je 0x11227
jmp 0x11203
movl -0x5c(%rbp), %eax
subl $0x6f, %eax
je 0x11217
jmp 0x1120d
movl -0x5c(%rbp), %eax
subl $0x74, %eax
je 0x11247
jmp 0x11267
movq 0x6dc2(%rip), %rax      # 0x17fe0
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x1126c
movq 0x6db2(%rip), %rax      # 0x17fe0
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x1126c
movq 0x6da2(%rip), %rax      # 0x17fe0
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x1126c
movq 0x6d92(%rip), %rax      # 0x17fe0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x10f0
movq %rax, -0x30(%rbp)
jmp 0x1126c
jmp 0x1126c
callq 0x1040
jmp 0x111af
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
callq 0x11520
movq %rax, -0x50(%rbp)
movl $0x18, %edi
callq 0x1110
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rsi
leaq 0x31c8(%rip), %rdi      # 0x14489
callq 0x10d0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x112da
movq -0x58(%rbp), %rax
movl $0x1, (%rax)
jmp 0x11340
movq -0x18(%rbp), %rsi
leaq 0x31d8(%rip), %rdi      # 0x144bd
callq 0x10d0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x112fe
movq -0x58(%rbp), %rax
movl $0x0, (%rax)
jmp 0x1133e
movq -0x18(%rbp), %rsi
leaq 0x31bb(%rip), %rdi      # 0x144c4
callq 0x10d0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x11322
movq -0x58(%rbp), %rax
movl $0x2, (%rax)
jmp 0x1133c
leaq 0x31a0(%rip), %rdi      # 0x144c9
movb $0x0, %al
callq 0x10a0
movl $0x1, -0x4(%rbp)
jmp 0x1150a
jmp 0x1133e
jmp 0x11340
movq -0x20(%rbp), %rsi
leaq 0x31c7(%rip), %rdi      # 0x14512
callq 0x10d0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x11389
movq -0x58(%rbp), %rax
movl $0x1, 0x8(%rax)
cmpq $-0x1, -0x30(%rbp)
jne 0x11378
movq -0x58(%rbp), %rax
movq $0x2d, 0x10(%rax)
jmp 0x11384
movq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x11412
movq -0x20(%rbp), %rsi
leaq 0x30f9(%rip), %rdi      # 0x1448d
callq 0x10d0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x113cf
movq -0x58(%rbp), %rax
movl $0x2, 0x8(%rax)
cmpq $-0x1, -0x30(%rbp)
jne 0x113c1
movq -0x58(%rbp), %rax
movq $0xd2, 0x10(%rax)
jmp 0x113cd
movq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x11410
movq -0x20(%rbp), %rsi
leaq 0x27d1(%rip), %rdi      # 0x13bab
callq 0x10d0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x113f4
movq -0x58(%rbp), %rax
movl $0x0, 0x8(%rax)
jmp 0x1140e
leaq 0x311c(%rip), %rdi      # 0x14517
movb $0x0, %al
callq 0x10a0
movl $0x1, -0x4(%rbp)
jmp 0x1150a
jmp 0x11410
jmp 0x11412
movq -0x28(%rbp), %rsi
leaq 0x313d(%rip), %rdi      # 0x1455a
callq 0x10d0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1143a
movq -0x58(%rbp), %rax
movl $0x0, 0x4(%rax)
jmp 0x114f0
movq -0x28(%rbp), %rsi
leaq 0x3119(%rip), %rdi      # 0x1455e
callq 0x10d0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x11462
movq -0x58(%rbp), %rax
movl $0x1, 0x4(%rax)
jmp 0x114ee
movq -0x28(%rbp), %rsi
leaq 0x30f5(%rip), %rdi      # 0x14562
callq 0x10d0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x11487
movq -0x58(%rbp), %rax
movl $0x2, 0x4(%rax)
jmp 0x114ec
movq -0x28(%rbp), %rsi
leaq 0x3001(%rip), %rdi      # 0x14493
callq 0x10d0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x114ac
movq -0x58(%rbp), %rax
movl $0x3, 0x4(%rax)
jmp 0x114ea
movq -0x28(%rbp), %rsi
leaq 0x30af(%rip), %rdi      # 0x14566
callq 0x10d0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x114d1
movq -0x58(%rbp), %rax
movl $0x4, 0x4(%rax)
jmp 0x114e8
leaq 0x3092(%rip), %rdi      # 0x1456a
movb $0x0, %al
callq 0x10a0
movl $0x1, -0x4(%rbp)
jmp 0x1150a
jmp 0x114ea
jmp 0x114ec
jmp 0x114ee
jmp 0x114f0
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x11670
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x115e0
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)