// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
movq %rsi, 0x18(%rsp)
cmpl %esi, %edx
jne 0x18e69
movq %r14, %rbp
jmp 0x191db
movl %edx, %r15d
leal -0x1(%r15), %eax
cmpl $0x4, %eax
jae 0x1920c
movl %r8d, %r13d
movl %ecx, %ebx
movl %ecx, %eax
imull %r15d, %eax
movl %eax, 0xc(%rsp)
movl %eax, %edi
imull %r8d, %edi
callq 0x4420
testq %rax, %rax
je 0x191c3
movq %rax, %rbp
movq %r15, 0x28(%rsp)
movq 0x18(%rsp), %rdx
leal (%r15,%rdx,8), %r12d
xorl %ecx, %ecx
testl %r13d, %r13d
cmovlel %ecx, %r13d
leal -0x1(%rbx), %eax
movl %eax, 0x4(%rsp)
movq %rbx, %rax
movq %rbx, 0x30(%rsp)
imull %edx, %eax
movl %eax, 0x8(%rsp)
leaq 0x3(%rbp), %rax
movq %rax, 0x20(%rsp)
leaq 0x2(%rbp), %rax
movq %rax, 0x10(%rsp)
addl $-0xa, %r12d
xorl %r10d, %r10d
xorl %r11d, %r11d
cmpq %r13, %r11
je 0x191b9
cmpl $0x19, %r12d
ja 0x191ed
movq %r13, %rax
movl %r10d, %r9d
addq %r14, %r9
movl %ecx, %esi
leaq (%rsi,%rbp), %rdx
movq 0x20(%rsp), %rdi
leaq (%rdi,%rsi), %r15
movl %r11d, %edi
imull 0x30(%rsp), %edi
movl %edi, %r8d
imull 0x18(%rsp), %r8d
addq %r14, %r8
imull 0x28(%rsp), %edi
addq %rbp, %rdi
leaq 0x8d2a(%rip), %rbx      # 0x21c60
movslq (%rbx,%r12,4), %r13
addq %rbx, %r13
jmpq *%r13
xorl %esi, %esi
movl 0x4(%rsp), %edi
movq %rax, %r13
testl %edi, %edi
js 0x191a8
movb (%r9,%rsi), %r8b
movb %r8b, (%rdx,%rsi,2)
movb $-0x1, 0x1(%rdx,%rsi,2)
decl %edi
incq %rsi
jmp 0x18f49
movl 0x4(%rsp), %edx
movq %rax, %r13
testl %edx, %edx
js 0x191a8
movb (%r8), %al
movb %al, (%rdi)
movb 0x1(%r8), %al
movb %al, 0x1(%rdi)
movb 0x2(%r8), %al
movb %al, 0x2(%rdi)
addq $0x4, %r8
addq $0x3, %rdi
decl %edx
jmp 0x18f6c
xorl %esi, %esi
movl 0x4(%rsp), %edi
movq %rax, %r13
testl %edi, %edi
js 0x191a8
movzbl (%r9,%rsi,4), %r8d
movzbl 0x1(%r9,%rsi,4), %ebx
movzbl 0x2(%r9,%rsi,4), %r15d
imull $0x4d, %r8d, %r8d
imull $0x96, %ebx, %ebx
addl %r8d, %ebx
imull $0x1d, %r15d, %eax
addl %ebx, %eax
movb %ah, (%rdx,%rsi)
decl %edi
incq %rsi
jmp 0x18f9c
xorl %esi, %esi
movl 0x4(%rsp), %edi
movq %rax, %r13
testl %edi, %edi
js 0x191a8
movzbl (%r9,%rsi,2), %eax
movzbl 0x1(%r9,%rsi,2), %r8d
movzbl 0x2(%r9,%rsi,2), %ebx
imull $0x4d, %eax, %eax
imull $0x96, %r8d, %r8d
addl %eax, %r8d
imull $0x1d, %ebx, %eax
addl %r8d, %eax
movb %ah, (%rdx,%rsi)
movb 0x3(%r9,%rsi,2), %al
movb %al, 0x1(%rdx,%rsi)
decl %edi
addq $0x2, %rsi
jmp 0x18fdb
movl 0x4(%rsp), %edx
movq %rax, %r13
testl %edx, %edx
js 0x191a8
movb (%r8), %sil
movb %sil, (%rdi)
movb 0x1(%r8), %sil
movb %sil, 0x1(%rdi)
movb 0x2(%r8), %sil
movb %sil, 0x2(%rdi)
movb $-0x1, 0x3(%rdi)
addq $0x3, %r8
addq $0x4, %rdi
decl %edx
jmp 0x19022
addq 0x10(%rsp), %rsi
movl 0x4(%rsp), %edx
movq %rax, %r13
testl %edx, %edx
js 0x191a8
movb (%r8), %dil
movb %dil, (%rsi)
movb %dil, -0x1(%rsi)
movb %dil, -0x2(%rsi)
addq $0x2, %r8
decl %edx
addq $0x3, %rsi
jmp 0x1905c
addq 0x10(%rsp), %rsi
movl 0x4(%rsp), %edx
movq %rax, %r13
testl %edx, %edx
js 0x191a8
movb (%r8), %dil
movb %dil, (%rsi)
movb %dil, -0x1(%rsi)
movb %dil, -0x2(%rsi)
incq %r8
decl %edx
addq $0x3, %rsi
jmp 0x1908a
xorl %edx, %edx
movl 0x4(%rsp), %esi
movq %rax, %r13
testl %esi, %esi
js 0x191a8
movb (%r9,%rdx), %dil
movb %dil, -0x1(%r15,%rdx,2)
movb %dil, -0x2(%r15,%rdx,2)
movb %dil, -0x3(%r15,%rdx,2)
movb 0x1(%r9,%rdx), %dil
movb %dil, (%r15,%rdx,2)
decl %esi
addq $0x2, %rdx
jmp 0x190b4
xorl %edx, %edx
movl 0x4(%rsp), %esi
movq %rax, %r13
testl %esi, %esi
js 0x191a8
movb (%r9,%rdx), %dil
movb %dil, -0x1(%r15,%rdx,4)
movb %dil, -0x2(%r15,%rdx,4)
movb %dil, -0x3(%r15,%rdx,4)
movb $-0x1, (%r15,%rdx,4)
decl %esi
incq %rdx
jmp 0x190e9
movl 0x4(%rsp), %edx
movq %rax, %r13
testl %edx, %edx
js 0x191a8
movzbl (%r8), %esi
movzbl 0x1(%r8), %r9d
movzbl 0x2(%r8), %ebx
imull $0x4d, %esi, %esi
imull $0x96, %r9d, %r9d
addl %esi, %r9d
imull $0x1d, %ebx, %ebx
addl %r9d, %ebx
movb %bh, (%rdi)
movb $-0x1, 0x1(%rdi)
addq $0x3, %r8
addq $0x2, %rdi
decl %edx
jmp 0x19117
xorl %esi, %esi
movl 0x4(%rsp), %edi
movq %rax, %r13
testl %edi, %edi
js 0x191a8
movb (%r9,%rsi,2), %r8b
movb %r8b, (%rdx,%rsi)
decl %edi
incq %rsi
jmp 0x1915b
movl 0x4(%rsp), %edx
movq %rax, %r13
testl %edx, %edx
js 0x191a8
movzbl (%r8), %esi
movzbl 0x1(%r8), %r9d
movzbl 0x2(%r8), %r15d
imull $0x4d, %esi, %esi
imull $0x96, %r9d, %r9d
addl %esi, %r9d
imull $0x1d, %r15d, %ebx
addl %r9d, %ebx
movb %bh, (%rdi)
addq $0x3, %r8
incq %rdi
decl %edx
jmp 0x19175
incq %r11
addl 0x8(%rsp), %r10d
addl 0xc(%rsp), %ecx
jmp 0x18ee8
movq %r14, %rdi
callq 0x43a0
jmp 0x191db
movq %r14, %rdi
callq 0x43a0
leaq 0x8ff7(%rip), %rax      # 0x221c9
movq %rax, 0x161f7(%rip)     # 0x2f3d0
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x96ff(%rip), %rdi      # 0x228f3
leaq 0x909e(%rip), %rsi      # 0x22299
leaq 0x93f7(%rip), %rcx      # 0x225f9
movl $0x55f, %edx            # imm = 0x55F
callq 0x4210
leaq 0x93c7(%rip), %rdi      # 0x225da
leaq 0x907f(%rip), %rsi      # 0x22299
leaq 0x93d8(%rip), %rcx      # 0x225f9
movl $0x542, %edx            # imm = 0x542
callq 0x4210