// File: /workspace/github_c_makefile_star2_O2/erik[P]gamut/opacity.c
// Function: main
int main(int argc, char** argv)
{
    uint32_t width, height;
    uint16_t opacity;
    pixel_t rgba;

    if (argc != 2) {
        fprintf(stderr, "usage: %s OPACITY_PCT\n", argv[0]);
        return 1;
    }

    long opacity_pct = strtol(argv[1], NULL, 10);

    if (opacity_pct > 100 || opacity_pct < 0) {
        fprintf(stderr, "opacity out of range: %ld%%\n", opacity_pct);
        return 1;
    }

    opacity = (uint16_t)(65535 * (opacity_pct / 100.0));

    read_header(&width, &height);
    write_header(width, height);

    for (uint32_t i = 0; i < height; i++) {
        for (uint32_t j = 0; j < width; j++) {
            read_pixel(&rgba);
            rgba.a = opacity;
            write_pixel(&rgba);
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpl $0x2, %edi
jne 0x136c
movq 0x8(%rsi), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x1060
movq %rax, %r15
cmpq $0x65, %rax
jae 0x1382
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movapd %xmm0, (%rdi)
movq 0x2e06(%rip), %rax      # 0x3fd8
movq (%rax), %rcx
pushq $0x1
popq %rsi
pushq $0x10
popq %rdx
callq 0x1030
cmpq $0x10, %rax
jne 0x13db
movabsq $0x646c656662726166, %rax # imm = 0x646C656662726166
cmpq %rax, 0x10(%rsp)
jne 0x13f0
leaq 0x10(%rsp), %r14
movl 0x8(%r14), %ebx
movl 0xc(%r14), %ebp
movq 0x2dbd(%rip), %r12      # 0x3fd0
movq (%r12), %rsi
leaq 0xe41(%rip), %rdi       # 0x205f
callq 0x1040
movl %ebx, 0x4(%rsp)
movl %ebx, (%r14)
movq (%r12), %rcx
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x1080
cmpq $0x1, %rax
jne 0x13d3
leaq 0x10(%rsp), %rdi
movl %ebp, (%rdi)
movq (%r12), %rcx
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
callq 0x1080
cmpq $0x1, %rax
jne 0x13d3
movl %ebp, %ecx
cvtsi2sd %r15, %xmm0
divsd 0xd93(%rip), %xmm0      # 0x2008
mulsd 0xd93(%rip), %xmm0      # 0x2010
cvttsd2si %xmm0, %ebp
movl 0x4(%rsp), %eax
bswapl %eax
movl %eax, 0x4(%rsp)
bswapl %ecx
movl %ebp, %ebx
rolw $0x8, %bx
pushq $0x2
popq %r15
pushq $0x4
popq %r12
leaq 0x10(%rsp), %r13
xorl %eax, %eax
movl %ecx, 0x20(%rsp)
cmpl %ecx, %eax
je 0x135b
movl %eax, 0x24(%rsp)
movl 0x4(%rsp), %r14d
subl $0x1, %r14d
jb 0x134c
movq 0x2d10(%rip), %rax      # 0x3fd8
movq (%rax), %rcx
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1030
cmpq $0x4, %rax
jne 0x13b7
movzwl 0x8(%rsp), %eax
movw %ax, 0x10(%rsp)
rolw $0x8, %ax
movzwl 0xa(%rsp), %ecx
movw %ax, 0x8(%rsp)
movw %cx, 0x12(%rsp)
rolw $0x8, %cx
movw %cx, 0xa(%rsp)
movzwl 0xc(%rsp), %eax
movw %ax, 0x14(%rsp)
rolw $0x8, %ax
movw %ax, 0xc(%rsp)
movw %bp, 0xe(%rsp)
movw %bx, 0x16(%rsp)
movq 0x2ca1(%rip), %rax      # 0x3fd0
movq (%rax), %rcx
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1080
cmpq $0x4, %rax
je 0x12b7
jmp 0x13a2
movl 0x24(%rsp), %eax
incl %eax
movl 0x20(%rsp), %ecx
jmp 0x12a6
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2c85(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq (%rsi), %rdx
leaq 0xc98(%rip), %rsi       # 0x2018
jmp 0x1396
movq 0x2c6f(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xc9c(%rip), %rsi       # 0x202f
movq %r15, %rdx
xorl %eax, %eax
callq 0x1050
pushq $0x1
popq %rax
jmp 0x135d
movq 0x2c4f(%rip), %rax      # 0x3ff8
movq (%rax), %rcx
leaq 0xcda(%rip), %rdi       # 0x208d
pushq $0xc
jmp 0x13ca
movq 0x2c3a(%rip), %rax      # 0x3ff8
movq (%rax), %rcx
leaq 0xcb5(%rip), %rdi       # 0x207d
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
callq 0x1080
pushq $0x1
popq %rdi
callq 0x1070
movq 0x2c16(%rip), %rax      # 0x3ff8
movq (%rax), %rcx
leaq 0xc60(%rip), %rdi       # 0x204c
pushq $0x12
jmp 0x13ca
movq 0x2c01(%rip), %rax      # 0x3ff8
movq (%rax), %rcx
leaq 0xc67(%rip), %rdi       # 0x2068
pushq $0x14
jmp 0x13ca