// File: /workspace/github_cpp_makefile_star2_O1/srajangarg[P]raytracer/src/core/stb_image.hpp
// Function: stbi__convert_format(unsigned char*, int, int, unsigned int, unsigned int)
static unsigned char *stbi__convert_format(unsigned char *data, int img_n, int req_comp, unsigned int x, unsigned int y)
{
   int i,j;
   unsigned char *good;

   if (req_comp == img_n) return data;
   STBI_ASSERT(req_comp >= 1 && req_comp <= 4);

   good = (unsigned char *) stbi__malloc(req_comp * x * y);
   if (good == NULL) {
      STBI_FREE(data);
      return stbi__errpuc("outofmem", "Out of memory");
   }

   for (j=0; j < (int) y; ++j) {
      unsigned char *src  = data + j * x * img_n   ;
      unsigned char *dest = good + j * x * req_comp;

      #define COMBO(a,b)  ((a)*8+(b))
      #define CASE(a,b)   case COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b)
      // convert source image with img_n components to one with req_comp components;
      // avoid switch per pixel, so use switch per scanline and massive macros
      switch (COMBO(img_n, req_comp)) {
         CASE(1,2) dest[0]=src[0], dest[1]=255; break;
         CASE(1,3) dest[0]=dest[1]=dest[2]=src[0]; break;
         CASE(1,4) dest[0]=dest[1]=dest[2]=src[0], dest[3]=255; break;
         CASE(2,1) dest[0]=src[0]; break;
         CASE(2,3) dest[0]=dest[1]=dest[2]=src[0]; break;
         CASE(2,4) dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; break;
         CASE(3,4) dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=255; break;
         CASE(3,1) dest[0]=stbi__compute_y(src[0],src[1],src[2]); break;
         CASE(3,2) dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = 255; break;
         CASE(4,1) dest[0]=stbi__compute_y(src[0],src[1],src[2]); break;
         CASE(4,2) dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = src[3]; break;
         CASE(4,3) dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; break;
         default: STBI_ASSERT(0);
      }
      #undef CASE
   }

   STBI_FREE(data);
   return good;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movq %rsi, 0x8(%rsp)
cmpl %esi, %edx
je 0x20449
movl %edx, %r15d
leal -0x1(%r15), %eax
cmpl $0x4, %eax
jae 0x2045b
movl %r8d, %ebp
movl %ecx, %r14d
movl %ecx, %eax
imull %r15d, %eax
movl %eax, 0x14(%rsp)
movl %eax, %edi
imull %r8d, %edi
callq 0x4400
testq %rax, %rax
je 0x20431
movq %rax, %r12
testl %ebp, %ebp
jle 0x20424
movq 0x8(%rsp), %rax
leal (%r15,%rax,8), %ecx
cmpl $0x23, %ecx
ja 0x2047a
movabsq $0xe161a1c00, %rax      # imm = 0xE161A1C00
btq %rcx, %rax
jae 0x2047a
leal -0x1(%r14), %eax
movl %eax, 0x4(%rsp)
cmpl $0x2, %ebp
movl $0x1, %eax
cmovgel %ebp, %eax
movq %rax, 0x30(%rsp)
movl %r14d, %eax
imull 0x8(%rsp), %eax
movl %eax, 0x10(%rsp)
leaq 0x3(%r12), %rax
movq %rax, 0x28(%rsp)
leaq 0x2(%r12), %rax
movq %rax, 0x18(%rsp)
xorl %r9d, %r9d
addl $-0xa, %ecx
xorl %r11d, %r11d
xorl %edi, %edi
movq %rcx, 0x20(%rsp)
leaq 0xcb91(%rip), %r13      # 0x2cca0
movl %edi, %ebp
imull %r14d, %ebp
movl %ebp, %r8d
imull 0x8(%rsp), %r8d
addq %rbx, %r8
imull %r15d, %ebp
addq %r12, %rbp
cmpl $0x18, %ecx
ja 0x203db
movl %r11d, %edx
leaq (%r12,%rdx), %rcx
movl %r9d, %r10d
addq %rbx, %r10
movq 0x28(%rsp), %rax
leaq (%rax,%rdx), %rsi
movq 0x20(%rsp), %rax
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
cmpl $0x0, 0x4(%rsp)
js 0x20407
xorl %edx, %edx
movl %r14d, %eax
movb (%r10,%rdx), %sil
movb %sil, (%rcx,%rdx,2)
movb $-0x1, 0x1(%rcx,%rdx,2)
decl %eax
incq %rdx
testl %eax, %eax
jg 0x20166
jmp 0x20407
cmpl $0x0, 0x4(%rsp)
js 0x20407
xorl %edx, %edx
movl %r14d, %esi
movzbl (%r10,%rdx,2), %r8d
movzbl 0x1(%r10,%rdx,2), %ebp
movzbl 0x2(%r10,%rdx,2), %eax
imull $0x4d, %r8d, %r8d
imull $0x96, %ebp, %ebp
addl %r8d, %ebp
leal (%rax,%rax,8), %r8d
leal (%r8,%r8,2), %r8d
addl %eax, %eax
addl %r8d, %eax
addl %ebp, %eax
movb %ah, (%rcx,%rdx)
movb 0x3(%r10,%rdx,2), %al
movb %al, 0x1(%rcx,%rdx)
decl %esi
addq $0x2, %rdx
testl %esi, %esi
jg 0x20191
jmp 0x20407
cmpl $0x0, 0x4(%rsp)
js 0x20407
addq 0x18(%rsp), %rdx
movl %r14d, %ecx
movb (%r8), %al
movb %al, (%rdx)
movb %al, -0x1(%rdx)
movb %al, -0x2(%rdx)
addq $0x2, %r8
decl %ecx
addq $0x3, %rdx
testl %ecx, %ecx
jg 0x201ec
jmp 0x20407
cmpl $0x0, 0x4(%rsp)
js 0x20407
xorl %ecx, %ecx
movl %r14d, %edx
movb (%r10,%rcx), %al
movb %al, -0x1(%rsi,%rcx,2)
movb %al, -0x2(%rsi,%rcx,2)
movb %al, -0x3(%rsi,%rcx,2)
movb 0x1(%r10,%rcx), %al
movb %al, (%rsi,%rcx,2)
decl %edx
addq $0x2, %rcx
testl %edx, %edx
jg 0x2021a
jmp 0x20407
cmpl $0x0, 0x4(%rsp)
js 0x20407
xorl %edx, %edx
movl %r14d, %eax
movb (%r10,%rdx,2), %sil
movb %sil, (%rcx,%rdx)
decl %eax
incq %rdx
testl %eax, %eax
jg 0x20251
jmp 0x20407
cmpl $0x0, 0x4(%rsp)
js 0x20407
xorl %ecx, %ecx
movl %r14d, %edx
movb (%r10,%rcx), %al
movb %al, -0x1(%rsi,%rcx,4)
movb %al, -0x2(%rsi,%rcx,4)
movb %al, -0x3(%rsi,%rcx,4)
movb $-0x1, (%rsi,%rcx,4)
decl %edx
incq %rcx
testl %edx, %edx
jg 0x20277
jmp 0x20407
cmpl $0x0, 0x4(%rsp)
js 0x20407
addq 0x18(%rsp), %rdx
movl %r14d, %ecx
movb (%r8), %al
movb %al, (%rdx)
movb %al, -0x1(%rdx)
movb %al, -0x2(%rdx)
incq %r8
decl %ecx
addq $0x3, %rdx
testl %ecx, %ecx
jg 0x202ac
jmp 0x20407
movl %r14d, %ecx
cmpl $0x0, 0x4(%rsp)
js 0x20407
movzbl (%r8), %edx
movzbl 0x1(%r8), %esi
movzbl 0x2(%r8), %eax
imull $0x4d, %edx, %edx
imull $0x96, %esi, %esi
addl %edx, %esi
leal (%rax,%rax,8), %edx
leal (%rdx,%rdx,2), %edx
addl %eax, %eax
addl %edx, %eax
addl %esi, %eax
movb %ah, (%rbp)
addq $0x3, %r8
incq %rbp
decl %ecx
testl %ecx, %ecx
jg 0x202d7
jmp 0x20407
movl %r14d, %ecx
cmpl $0x0, 0x4(%rsp)
js 0x20407
movzbl (%r8), %edx
movzbl 0x1(%r8), %esi
movzbl 0x2(%r8), %eax
imull $0x4d, %edx, %edx
imull $0x96, %esi, %esi
addl %edx, %esi
leal (%rax,%rax,8), %edx
leal (%rdx,%rdx,2), %edx
addl %eax, %eax
addl %edx, %eax
addl %esi, %eax
movb %ah, (%rbp)
movb $-0x1, 0x1(%rbp)
addq $0x3, %r8
addq $0x2, %rbp
decl %ecx
testl %ecx, %ecx
jg 0x2031f
jmp 0x20407
cmpl $0x0, 0x4(%rsp)
js 0x20407
xorl %edx, %edx
movl %r14d, %esi
movzbl (%r10,%rdx,4), %r8d
movzbl 0x1(%r10,%rdx,4), %ebp
movzbl 0x2(%r10,%rdx,4), %eax
imull $0x4d, %r8d, %r8d
imull $0x96, %ebp, %ebp
addl %r8d, %ebp
leal (%rax,%rax,8), %r8d
leal (%r8,%r8,2), %r8d
addl %eax, %eax
addl %r8d, %eax
addl %ebp, %eax
movb %ah, (%rcx,%rdx)
decl %esi
incq %rdx
testl %esi, %esi
jg 0x2036e
jmp 0x20407
movl %r14d, %ecx
cmpl $0x0, 0x4(%rsp)
js 0x20407
movb (%r8), %al
movb %al, (%rbp)
movb 0x1(%r8), %al
movb %al, 0x1(%rbp)
movb 0x2(%r8), %al
movb %al, 0x2(%rbp)
movb $-0x1, 0x3(%rbp)
addq $0x3, %r8
addq $0x4, %rbp
decl %ecx
testl %ecx, %ecx
jg 0x203b3
jmp 0x20407
movl %r14d, %ecx
cmpl $0x0, 0x4(%rsp)
js 0x20407
movb (%r8), %al
movb %al, (%rbp)
movb 0x1(%r8), %al
movb %al, 0x1(%rbp)
movb 0x2(%r8), %al
movb %al, 0x2(%rbp)
addq $0x4, %r8
addq $0x3, %rbp
decl %ecx
testl %ecx, %ecx
jg 0x203e5
incq %rdi
addl 0x14(%rsp), %r11d
addl 0x10(%rsp), %r9d
cmpq 0x30(%rsp), %rdi
movq 0x20(%rsp), %rcx
jne 0x2010f
movq %rbx, %rdi
callq 0x4390
movq %r12, %rbx
jmp 0x20449
movq %rbx, %rdi
callq 0x4390
leaq 0xcdc9(%rip), %rax      # 0x2d209
movq %rax, 0x17f69(%rip)     # 0x383b0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd1b8(%rip), %rdi      # 0x2d61a
leaq 0xce70(%rip), %rsi      # 0x2d2d9
leaq 0xd1c9(%rip), %rcx      # 0x2d639
movl $0x542, %edx            # imm = 0x542
callq 0x4200
leaq 0xd4b6(%rip), %rdi      # 0x2d937
leaq 0xce51(%rip), %rsi      # 0x2d2d9
leaq 0xd1aa(%rip), %rcx      # 0x2d639
movl $0x55f, %edx            # imm = 0x55F
callq 0x4200