// File: /workspace/github_c_makefile_star2_O0/nkanaev[P]tipsy/src/tigr.c
// Function: depalette
static void depalette(int w,
                      int h,
                      unsigned char* src,
                      TPixel* dest,
                      int bipp,
                      const unsigned char* plte,
                      const unsigned char* trns,
                      int trnsSize) {
    int x, y, c;
    unsigned char alpha;
    int mask, len;

    switch (bipp) {
        case 4:
            mask = 15;
            len = 1;
            break;
        case 2:
            mask = 3;
            len = 3;
            break;
        case 1:
            mask = 1;
            len = 7;
    }

    for (y = 0; y < h; y++) {
        src++;  // skip filter byte
        for (x = 0; x < w; x++) {
            if (bipp == 8) {
                c = *src++;
            } else {
                int pos = x & len;
                c = (src[0] >> ((len - pos) * bipp)) & mask;
                if (pos == len) {
                    src++;
                }
            }
            alpha = 255;
            if (c < trnsSize) {
                alpha = trns[c];
            }
            *dest++ = tigrRGBA(plte[c * 3 + 0], plte[c * 3 + 1], plte[c * 3 + 2], alpha);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq %r9, -0x28(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x4c(%rbp)
subl $0x1, %eax
je 0x98d6
jmp 0x98a2
movl -0x4c(%rbp), %eax
subl $0x2, %eax
je 0x98c6
jmp 0x98ac
movl -0x4c(%rbp), %eax
subl $0x4, %eax
jne 0x98e4
jmp 0x98b6
movl $0xf, -0x3c(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x98e4
movl $0x3, -0x3c(%rbp)
movl $0x3, -0x40(%rbp)
jmp 0x98e4
movl $0x1, -0x3c(%rbp)
movl $0x7, -0x40(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x9a06
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x99f6
cmpl $0x8, -0x1c(%rbp)
jne 0x9933
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movzbl (%rax), %eax
movl %eax, -0x34(%rbp)
jmp 0x996b
movl -0x2c(%rbp), %eax
andl -0x40(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movl -0x40(%rbp), %ecx
subl -0x44(%rbp), %ecx
imull -0x1c(%rbp), %ecx
sarl %cl, %eax
andl -0x3c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x40(%rbp), %eax
jne 0x9969
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x996b
movb $-0x1, -0x35(%rbp)
movl -0x34(%rbp), %eax
cmpl 0x18(%rbp), %eax
jge 0x9985
movq 0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x35(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
imull $0x3, -0x34(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x28(%rbp), %rax
imull $0x3, -0x34(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x28(%rbp), %rax
imull $0x3, -0x34(%rbp), %esi
addl $0x2, %esi
movslq %esi, %rsi
movb (%rax,%rsi), %al
movzbl %dl, %edi
movzbl %cl, %esi
movzbl %al, %edx
movzbl -0x35(%rbp), %ecx
callq 0x4f70
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, -0x48(%rbp)
movl -0x48(%rbp), %ecx
movl %ecx, (%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x990a
jmp 0x99f8
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x98eb
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)