// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
cmpl $0x2, %edi
jne 0x1452
movq 0x8(%rsi), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1060
movq %rax, %rbx
cmpq $0x65, %rax
jae 0x145c
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movapd %xmm0, (%rdi)
movq 0x2d44(%rip), %rax      # 0x3fd8
movq (%rax), %rcx
movl $0x1, %esi
movl $0x10, %edx
callq 0x1030
cmpq $0x10, %rax
jne 0x1492
movabsq $0x646c656662726166, %rax # imm = 0x646C656662726166
cmpq %rax, 0x10(%rsp)
jne 0x1497
leaq 0x10(%rsp), %r14
movl 0x8(%r14), %ebp
movl 0xc(%r14), %r13d
movq 0x2cf7(%rip), %r15      # 0x3fd0
movq (%r15), %rsi
leaq 0xd7c(%rip), %rdi       # 0x205f
callq 0x1040
movl %ebp, 0xc(%rsp)
movl %ebp, (%r14)
movq (%r15), %rcx
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rdi
callq 0x1080
cmpq $0x1, %rax
jne 0x1488
leaq 0x10(%rsp), %rdi
movl %r13d, (%rdi)
movq (%r15), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x1080
cmpq $0x1, %rax
jne 0x1488
testl %r13d, %r13d
je 0x1441
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
divsd 0xcbd(%rip), %xmm0      # 0x2008
mulsd 0xcbd(%rip), %xmm0      # 0x2010
cvttsd2si %xmm0, %ebp
movl 0xc(%rsp), %eax
movl %ebp, %r12d
rolw $0x8, %r12w
bswapl %eax
cmpl $0x1, %eax
adcl $0x0, %eax
movl %eax, 0x30(%rsp)
bswapl %r13d
cmpl $0x1, %r13d
adcl $0x0, %r13d
xorl %eax, %eax
leaq 0x4(%rsp), %rbx
leaq 0x10(%rsp), %r14
movl %r13d, 0x2c(%rsp)
movl %eax, 0x34(%rsp)
movl 0x30(%rsp), %r13d
cmpl $0x0, 0xc(%rsp)
je 0x142d
movq 0x2c32(%rip), %rax      # 0x3fd8
movq (%rax), %rcx
movl $0x2, %esi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x1030
cmpq $0x4, %rax
jne 0x1483
movzwl 0x4(%rsp), %eax
movw %ax, 0x10(%rsp)
rolw $0x8, %ax
movzwl 0x6(%rsp), %ecx
movw %ax, 0x4(%rsp)
movw %cx, 0x12(%rsp)
rolw $0x8, %cx
movw %cx, 0x6(%rsp)
movzwl 0x8(%rsp), %eax
movw %ax, 0x14(%rsp)
rolw $0x8, %ax
movw %ax, 0x8(%rsp)
movw %bp, 0xa(%rsp)
movw %r12w, 0x16(%rsp)
movq (%r15), %rcx
movl $0x2, %esi
movl $0x4, %edx
movq %r14, %rdi
callq 0x1080
cmpq $0x4, %rax
jne 0x147e
decl %r13d
jne 0x139f
movl 0x34(%rsp), %eax
incl %eax
movl 0x2c(%rsp), %r13d
cmpl %r13d, %eax
jne 0x138b
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %rdi
callq 0x10a0
jmp 0x1477
movq 0x2b95(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xbc2(%rip), %rsi       # 0x202f
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1050
movl $0x1, %eax
jmp 0x1443
callq 0x112d
callq 0x1108
movl $0x1, %edi
callq 0x1070
callq 0x10be
callq 0x10e3