// File: /workspace/github_c_makefile_star2_O0/erik[P]gamut/flip.c
// Function: main
int main(int argc, char** argv)
{
    uint32_t width = 0,
             height = 0;
    bool flip_v = false,
         flip_h = false;
    pixel_t* image = NULL, temp;

    if (argc < 2) {
        fprintf(stderr, USAGE, argv[0]);
        return 1;
    }

    ARGBEGIN {
    case 'v':
        flip_v = true; break;
    case 'h':
        flip_h = true; break;
    default:
        fprintf(stderr, USAGE, argv[0]);
        return 1;
        ARGEND;
    }

    if (!flip_v && !flip_h) {
        fprintf(stderr, "need to specify a flip direction\n");
        return 1;
    }

    read_header(&width, &height);

    if (!(image = calloc(width * height, sizeof(pixel_t)))) {
        perror("couldn't allocate memory");
        return 1;
    }

    read_image(image, width, height);
    write_header(width, height);

    if (flip_h) {
        for (uint32_t y = 0; y < height; y++) {
            for (uint32_t x = 0; x < width / 2; x++) {
                uint32_t swap = (width - 1) - x;

                memcpy(&temp, PIXEL(&image, x, y), sizeof(pixel_t));
                memcpy(PIXEL(&image, x, y), PIXEL(&image, swap, y), sizeof(pixel_t));
                memcpy(PIXEL(&image, swap, y), &temp, sizeof(pixel_t));
            }
        }
    }

    if (flip_v) {
        for (uint32_t y = 0; y < height / 2; y++) {
            uint32_t swap = (height - 1) - y;
            for (uint32_t x = 0; x < width; x++) {
                memcpy(&temp, PIXEL(&image, x, y), sizeof(pixel_t));
                memcpy(PIXEL(&image, x, y), PIXEL(&image, x, swap), sizeof(pixel_t));
                memcpy(PIXEL(&image, x, swap), &temp, sizeof(pixel_t));
            }
        }
    }

    write_image(image, width, height);

    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 $0x0, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
movb $0x0, -0x1a(%rbp)
movq $0x0, -0x28(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x1255
movq 0x2dc7(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0xdc2(%rip), %rsi       # 0x2004
movb $0x0, %al
callq 0x10a0
movl $0x1, -0x4(%rbp)
jmp 0x15d9
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, 0x2e2d(%rip)      # 0x4090
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, (%rcx)
movb %al, -0x5d(%rbp)
je 0x12af
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl 0x1(%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x5d(%rbp)
je 0x12af
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
sete %al
movb %al, -0x5d(%rbp)
movb -0x5d(%rbp), %al
testb $0x1, %al
jne 0x12bb
jmp 0x13d3
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2d, %eax
jne 0x12f5
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl 0x2(%rax), %eax
cmpl $0x0, %eax
jne 0x12f5
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x13d3
movl $0x0, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x5e(%rbp)
je 0x1332
cmpl $0x0, -0x44(%rbp)
setne %al
xorb $-0x1, %al
movb %al, -0x5e(%rbp)
movb -0x5e(%rbp), %al
testb $0x1, %al
jne 0x133b
jmp 0x13b7
movq -0x40(%rbp), %rax
cmpq -0x10(%rbp), %rax
je 0x1347
jmp 0x13b7
movq -0x10(%rbp), %rax
movq (%rax), %rax
movb (%rax), %al
movb %al, -0x31(%rbp)
movsbl -0x31(%rbp), %eax
movl %eax, -0x64(%rbp)
subl $0x68, %eax
je 0x1371
jmp 0x1361
movl -0x64(%rbp), %eax
subl $0x76, %eax
jne 0x1377
jmp 0x136b
movb $0x1, -0x19(%rbp)
jmp 0x13a2
movb $0x1, -0x1a(%rbp)
jmp 0x13a2
movq 0x2c7a(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0xc75(%rip), %rsi       # 0x2004
movb $0x0, %al
callq 0x10a0
movl $0x1, -0x4(%rbp)
jmp 0x15d9
jmp 0x13a4
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x1312
jmp 0x13b9
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x1278
testb $0x1, -0x19(%rbp)
jne 0x1403
testb $0x1, -0x1a(%rbp)
jne 0x1403
movq 0x2c12(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xc5f(%rip), %rsi       # 0x204f
movb $0x0, %al
callq 0x10a0
movl $0x1, -0x4(%rbp)
jmp 0x15d9
leaq -0x14(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x15f0
movl -0x14(%rbp), %eax
imull -0x18(%rbp), %eax
movl %eax, %eax
movl %eax, %edi
movl $0x8, %esi
callq 0x1090
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x1447
leaq 0xc3b(%rip), %rdi       # 0x2071
callq 0x10b0
movl $0x1, -0x4(%rbp)
jmp 0x15d9
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x16c0
movl -0x14(%rbp), %edi
movl -0x18(%rbp), %esi
callq 0x17a0
testb $0x1, -0x1a(%rbp)
je 0x1512
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x18(%rbp), %eax
jae 0x1510
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl -0x14(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jae 0x1500
movl -0x14(%rbp), %eax
subl $0x1, %eax
subl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movl -0x48(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x4c(%rbp), %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl -0x48(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x4c(%rbp), %ecx
movl %ecx, %ecx
movq -0x28(%rbp), %rdx
movl -0x48(%rbp), %esi
imull -0x14(%rbp), %esi
addl -0x50(%rbp), %esi
movl %esi, %esi
movq (%rdx,%rsi,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movl -0x48(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x50(%rbp), %ecx
movl %ecx, %ecx
movq -0x30(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1485
jmp 0x1502
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1472
jmp 0x1512
testb $0x1, -0x19(%rbp)
je 0x15c3
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl -0x18(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jae 0x15c1
movl -0x18(%rbp), %eax
subl $0x1, %eax
subl -0x54(%rbp), %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x15b1
movq -0x28(%rbp), %rax
movl -0x54(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x5c(%rbp), %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl -0x54(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x5c(%rbp), %ecx
movl %ecx, %ecx
movq -0x28(%rbp), %rdx
movl -0x58(%rbp), %esi
imull -0x14(%rbp), %esi
addl -0x5c(%rbp), %esi
movl %esi, %esi
movq (%rdx,%rsi,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movl -0x58(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x5c(%rbp), %ecx
movl %ecx, %ecx
movq -0x30(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1546
jmp 0x15b3
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1523
jmp 0x15c3
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x1840
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)