// File: alan0201tw[P]RayTracer/include/stb_image.h
// Function: stbi__convert_format16(unsigned short*, int, int, unsigned int, unsigned int)
static stbi__uint16 *stbi__convert_format16(stbi__uint16 *data, int img_n, int req_comp, unsigned int x, unsigned int y)
{
   int i,j;
   stbi__uint16 *good;

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

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

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

      #define STBI__COMBO(a,b)  ((a)*8+(b))
      #define STBI__CASE(a,b)   case STBI__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 (STBI__COMBO(img_n, req_comp)) {
         STBI__CASE(1,2) { dest[0]=src[0]; dest[1]=0xffff;                                     } break;
         STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0];                                     } break;
         STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=0xffff;                     } break;
         STBI__CASE(2,1) { dest[0]=src[0];                                                     } break;
         STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0];                                     } break;
         STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=src[1];                     } break;
         STBI__CASE(3,4) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2];dest[3]=0xffff;        } break;
         STBI__CASE(3,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]);                   } break;
         STBI__CASE(3,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); dest[1] = 0xffff; } break;
         STBI__CASE(4,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]);                   } break;
         STBI__CASE(4,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); dest[1] = src[3]; } break;
         STBI__CASE(4,3) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2];                       } break;
         default: STBI_ASSERT(0);
      }
      #undef STBI__CASE
   }

   STBI_FREE(data);
   return good;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x6ae2e
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6b3d2
xorl %eax, %eax
cmpl $0x1, -0x18(%rbp)
movb %al, -0x41(%rbp)
jl 0x6ae43
cmpl $0x4, -0x18(%rbp)
setle %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x6ae4c
jmp 0x6ae4e
jmp 0x6ae6d
leaq 0x166f5(%rip), %rdi     # 0x8154a
leaq 0x16138(%rip), %rsi     # 0x80f94
movl $0x664, %edx            # imm = 0x664
leaq 0x1675c(%rip), %rcx     # 0x815c4
callq 0x7310
movl -0x18(%rbp), %eax
imull -0x1c(%rbp), %eax
imull -0x20(%rbp), %eax
shll %eax
movl %eax, %eax
movl %eax, %edi
callq 0x57060
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x6aeb7
movq -0x10(%rbp), %rdi
callq 0x75e0
leaq 0x16264(%rip), %rdi     # 0x81102
callq 0x56040
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x6b3d2
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x6b3c1
movq -0x10(%rbp), %rax
movl -0x28(%rbp), %ecx
movl -0x1c(%rbp), %edx
imull %edx, %ecx
movl -0x14(%rbp), %edx
imull %edx, %ecx
leaq (%rax,%rcx,2), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %ecx
movl -0x1c(%rbp), %edx
imull %edx, %ecx
movl -0x18(%rbp), %edx
imull %edx, %ecx
leaq (%rax,%rcx,2), %rax
movq %rax, -0x40(%rbp)
movl -0x14(%rbp), %eax
movl -0x18(%rbp), %edx
movl %eax, %ecx
movl %edx, %eax
leal -0xa(%rax,%rcx,8), %eax
movl %eax, %ecx
movq %rcx, -0x50(%rbp)
subl $0x19, %eax
ja 0x6b392
movq -0x50(%rbp), %rax
leaq 0x143a0(%rip), %rcx     # 0x7f2c8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x6af7b
movq -0x38(%rbp), %rax
movw (%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, (%rax)
movq -0x40(%rbp), %rax
movw $0xffff, 0x2(%rax)      # imm = 0xFFFF
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
jmp 0x6af3a
jmp 0x6b3b1
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x6afd0
movq -0x38(%rbp), %rax
movw (%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x40(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x40(%rbp), %rax
movw %cx, (%rax)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x40(%rbp)
jmp 0x6af89
jmp 0x6b3b1
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x6b02f
movq -0x38(%rbp), %rax
movw (%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x40(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x40(%rbp), %rax
movw %cx, (%rax)
movq -0x40(%rbp), %rax
movw $0xffff, 0x6(%rax)      # imm = 0xFFFF
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
jmp 0x6afde
jmp 0x6b3b1
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x6b074
movq -0x38(%rbp), %rax
movw (%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, (%rax)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
jmp 0x6b03d
jmp 0x6b3b1
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x6b0c9
movq -0x38(%rbp), %rax
movw (%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x40(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x40(%rbp), %rax
movw %cx, (%rax)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x40(%rbp)
jmp 0x6b082
jmp 0x6b3b1
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x6b12e
movq -0x38(%rbp), %rax
movw (%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x40(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x40(%rbp), %rax
movw %cx, (%rax)
movq -0x38(%rbp), %rax
movw 0x2(%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, 0x6(%rax)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
jmp 0x6b0d7
jmp 0x6b3b1
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x6b19d
movq -0x38(%rbp), %rax
movw (%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, (%rax)
movq -0x38(%rbp), %rax
movw 0x2(%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x38(%rbp), %rax
movw 0x4(%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x40(%rbp), %rax
movw $0xffff, 0x6(%rax)      # imm = 0xFFFF
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
jmp 0x6b13c
jmp 0x6b3b1
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x6b1fa
movq -0x38(%rbp), %rax
movzwl (%rax), %edi
movq -0x38(%rbp), %rax
movzwl 0x2(%rax), %esi
movq -0x38(%rbp), %rax
movzwl 0x4(%rax), %edx
callq 0x6d530
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, (%rax)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
jmp 0x6b1ab
jmp 0x6b3b1
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x6b261
movq -0x38(%rbp), %rax
movzwl (%rax), %edi
movq -0x38(%rbp), %rax
movzwl 0x2(%rax), %esi
movq -0x38(%rbp), %rax
movzwl 0x4(%rax), %edx
callq 0x6d530
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, (%rax)
movq -0x40(%rbp), %rax
movw $0xffff, 0x2(%rax)      # imm = 0xFFFF
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
jmp 0x6b208
jmp 0x6b3b1
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x6b2be
movq -0x38(%rbp), %rax
movzwl (%rax), %edi
movq -0x38(%rbp), %rax
movzwl 0x2(%rax), %esi
movq -0x38(%rbp), %rax
movzwl 0x4(%rax), %edx
callq 0x6d530
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, (%rax)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
jmp 0x6b26f
jmp 0x6b3b1
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x6b32b
movq -0x38(%rbp), %rax
movzwl (%rax), %edi
movq -0x38(%rbp), %rax
movzwl 0x2(%rax), %esi
movq -0x38(%rbp), %rax
movzwl 0x4(%rax), %edx
callq 0x6d530
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, (%rax)
movq -0x38(%rbp), %rax
movw 0x6(%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, 0x2(%rax)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
jmp 0x6b2cc
jmp 0x6b3b1
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x6b390
movq -0x38(%rbp), %rax
movw (%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, (%rax)
movq -0x38(%rbp), %rax
movw 0x2(%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x38(%rbp), %rax
movw 0x4(%rax), %cx
movq -0x40(%rbp), %rax
movw %cx, 0x4(%rax)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x40(%rbp)
jmp 0x6b339
jmp 0x6b3b1
leaq 0x16601(%rip), %rdi     # 0x8199a
leaq 0x15bf4(%rip), %rsi     # 0x80f94
movl $0x681, %edx            # imm = 0x681
leaq 0x16218(%rip), %rcx     # 0x815c4
callq 0x7310
jmp 0x6b3b3
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x6aebe
movq -0x10(%rbp), %rdi
callq 0x75e0
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)