// File: /workspace/github_c_makefile_star2_O0/jani-nykanen[P]mushrooms/./tools/src/png2spr.c
// Function: rearrange
static bool rearrange(u8* pixels, u8* mask, i32 w, i32 h, i32 fw, i32 fh, u8** pout, u8** mout) {

    i32 x, y, sx, sy;
    i32 sw = w / fw;
    i32 sh = h / fh;
    u32 i, j;

    (*pout) = (u8*) calloc(w * h, 1);
    if ((*pout) == NULL)
        return true;

    if (mask != NULL) {

        (*mout) = (u8*) calloc(w * h, 1);
        if ((*mout) == NULL)
            return true;
    }

    if ((*pout) == NULL)
        return true;

    i = 0;
    for (sy = 0; sy < sh; ++ sy) {

        for (sx = 0; sx < sw; ++ sx) {

            for (y = 0; y < fh; ++ y) {

                for (x = 0; x < fw; ++ x) {

                    j = (sy * fh + y) * w + sx * fw + x;

                    (*pout)[i] = pixels[j];
                    if (mask != NULL)
                        (*mout)[i] = mask[j]; 

                    ++ i;
                }
            }
        }
    }

    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movl -0x1c(%rbp), %eax
cltd
idivl -0x24(%rbp)
movl %eax, -0x3c(%rbp)
movl -0x20(%rbp), %eax
cltd
idivl -0x28(%rbp)
movl %eax, -0x40(%rbp)
movl -0x1c(%rbp), %eax
imull -0x20(%rbp), %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x10b0
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movq 0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x19dab
movb $0x1, -0x1(%rbp)
jmp 0x19ee1
cmpq $0x0, -0x18(%rbp)
je 0x19de5
movl -0x1c(%rbp), %eax
imull -0x20(%rbp), %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x10b0
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq 0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x19de3
movb $0x1, -0x1(%rbp)
jmp 0x19ee1
jmp 0x19de5
movq 0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x19df8
movb $0x1, -0x1(%rbp)
jmp 0x19ee1
movl $0x0, -0x44(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x19edd
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x19ecd
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x19ebd
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x19ead
movl -0x38(%rbp), %eax
imull -0x28(%rbp), %eax
addl -0x30(%rbp), %eax
imull -0x1c(%rbp), %eax
movl -0x34(%rbp), %ecx
imull -0x24(%rbp), %ecx
addl %ecx, %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl -0x48(%rbp), %ecx
movb (%rax,%rcx), %dl
movq 0x10(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
movb %dl, (%rax,%rcx)
cmpq $0x0, -0x18(%rbp)
je 0x19e99
movq -0x18(%rbp), %rax
movl -0x48(%rbp), %ecx
movb (%rax,%rcx), %dl
movq 0x18(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x19e3f
jmp 0x19eaf
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x19e2c
jmp 0x19ebf
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x19e19
jmp 0x19ecf
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x19e06
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)