// File: /workspace/github_c_makefile_star2_O0/DavidSM64[P]n64graphics_ci/n64graphics_ci.c
// Function: raw2rgba
rgba *raw2rgba(const uint8_t *raw, int width, int height, int depth)
{
    rgba *img;
    int img_size;

    img_size = width * height * sizeof(*img);
    img = malloc(img_size);
    if (!img) {
        ERROR("Error allocating %d bytes\n", img_size);
        return NULL;
    }

    if (depth == 16) {
        for (int i = 0; i < width * height; i++) {
            img[i].red = SCALE_5_8((raw[i * 2] & 0xF8) >> 3);
            img[i].green = SCALE_5_8(((raw[i * 2] & 0x07) << 2) | ((raw[i * 2 + 1] & 0xC0) >> 6));
            img[i].blue = SCALE_5_8((raw[i * 2 + 1] & 0x3E) >> 1);
            img[i].alpha = (raw[i * 2 + 1] & 0x01) ? 0xFF : 0x00;
        }
    }
    else if (depth == 32) {
        for (int i = 0; i < width * height; i++) {
            img[i].red = raw[i * 4];
            img[i].green = raw[i * 4 + 1];
            img[i].blue = raw[i * 4 + 2];
            img[i].alpha = raw[i * 4 + 3];
        }
    }

    return img;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl -0x14(%rbp), %eax
imull -0x18(%rbp), %eax
cltq
shlq $0x2, %rax
movl %eax, -0x2c(%rbp)
movslq -0x2c(%rbp), %rdi
callq 0x11d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x9581
movq 0x1ea90(%rip), %rax     # 0x27ff0
movq (%rax), %rdi
movl -0x2c(%rbp), %edx
leaq 0x1991e(%rip), %rsi     # 0x22e8b
movb $0x0, %al
callq 0x1170
movq $0x0, -0x8(%rbp)
jmp 0x9754
cmpl $0x10, -0x1c(%rbp)
jne 0x969f
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl -0x14(%rbp), %ecx
imull -0x18(%rbp), %ecx
cmpl %ecx, %eax
jge 0x969a
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
andl $0xf8, %eax
sarl $0x3, %eax
imull $0xff, %eax, %eax
movl $0x1f, %ecx
cltd
idivl %ecx
movb %al, %dl
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movb %dl, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
andl $0x7, %eax
shll $0x2, %eax
movq -0x10(%rbp), %rcx
movl -0x30(%rbp), %edx
shll %edx
addl $0x1, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
andl $0xc0, %ecx
sarl $0x6, %ecx
orl %ecx, %eax
imull $0xff, %eax, %eax
movl $0x1f, %ecx
cltd
idivl %ecx
movb %al, %dl
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx,4)
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
shll %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
andl $0x3e, %eax
sarl %eax
imull $0xff, %eax, %eax
movl $0x1f, %ecx
cltd
idivl %ecx
movb %al, %dl
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movb %dl, 0x2(%rax,%rcx,4)
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
shll %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
andl $0x1, %edx
xorl %eax, %eax
movl $0xff, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %dl
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movb %dl, 0x3(%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x9592
jmp 0x974c
cmpl $0x20, -0x1c(%rbp)
jne 0x974a
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl -0x14(%rbp), %ecx
imull -0x18(%rbp), %ecx
cmpl %ecx, %eax
jge 0x9748
movq -0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movb %dl, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx,4)
movq -0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movb %dl, 0x2(%rax,%rcx,4)
movq -0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movb %dl, 0x3(%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x96b0
jmp 0x974a
jmp 0x974c
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nop