// File: /workspace/github_cpp_makefile_star2_O2/alan0201tw[P]RayTracer/include/stb_image.h
// Function: stbi__hdr_load(stbi__context*, int*, int*, int*, int, stbi__result_info*)
static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)
{
   char buffer[STBI__HDR_BUFLEN];
   char *token;
   int valid = 0;
   int width, height;
   stbi_uc *scanline;
   float *hdr_data;
   int len;
   unsigned char count, value;
   int i, j, k, c1,c2, z;
   const char *headerToken;
   STBI_NOTUSED(ri);

   // Check identifier
   headerToken = stbi__hdr_gettoken(s,buffer);
   if (strcmp(headerToken, "#?RADIANCE") != 0 && strcmp(headerToken, "#?RGBE") != 0)
      return stbi__errpf("not HDR", "Corrupt HDR image");

   // Parse header
   for(;;) {
      token = stbi__hdr_gettoken(s,buffer);
      if (token[0] == 0) break;
      if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1;
   }

   if (!valid)    return stbi__errpf("unsupported format", "Unsupported HDR format");

   // Parse width and height
   // can't use sscanf() if we're not using stdio!
   token = stbi__hdr_gettoken(s,buffer);
   if (strncmp(token, "-Y ", 3))  return stbi__errpf("unsupported data layout", "Unsupported HDR format");
   token += 3;
   height = (int) strtol(token, &token, 10);
   while (*token == ' ') ++token;
   if (strncmp(token, "+X ", 3))  return stbi__errpf("unsupported data layout", "Unsupported HDR format");
   token += 3;
   width = (int) strtol(token, NULL, 10);

   *x = width;
   *y = height;

   if (comp) *comp = 3;
   if (req_comp == 0) req_comp = 3;

   if (!stbi__mad4sizes_valid(width, height, req_comp, sizeof(float), 0))
      return stbi__errpf("too large", "HDR image is too large");

   // Read data
   hdr_data = (float *) stbi__malloc_mad4(width, height, req_comp, sizeof(float), 0);
   if (!hdr_data)
      return stbi__errpf("outofmem", "Out of memory");

   // Load image data
   // image data is stored as some number of sca
   if ( width < 8 || width >= 32768) {
      // Read flat data
      for (j=0; j < height; ++j) {
         for (i=0; i < width; ++i) {
            stbi_uc rgbe[4];
           main_decode_loop:
            stbi__getn(s, rgbe, 4);
            stbi__hdr_convert(hdr_data + j * width * req_comp + i * req_comp, rgbe, req_comp);
         }
      }
   } else {
      // Read RLE-encoded data
      scanline = NULL;

      for (j = 0; j < height; ++j) {
         c1 = stbi__get8(s);
         c2 = stbi__get8(s);
         len = stbi__get8(s);
         if (c1 != 2 || c2 != 2 || (len & 0x80)) {
            // not run-length encoded, so we have to actually use THIS data as a decoded
            // pixel (note this can't be a valid pixel--one of RGB must be >= 128)
            stbi_uc rgbe[4];
            rgbe[0] = (stbi_uc) c1;
            rgbe[1] = (stbi_uc) c2;
            rgbe[2] = (stbi_uc) len;
            rgbe[3] = (stbi_uc) stbi__get8(s);
            stbi__hdr_convert(hdr_data, rgbe, req_comp);
            i = 1;
            j = 0;
            STBI_FREE(scanline);
            goto main_decode_loop; // yes, this makes no sense
         }
         len <<= 8;
         len |= stbi__get8(s);
         if (len != width) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("invalid decoded scanline length", "corrupt HDR"); }
         if (scanline == NULL) {
            scanline = (stbi_uc *) stbi__malloc_mad2(width, 4, 0);
            if (!scanline) {
               STBI_FREE(hdr_data);
               return stbi__errpf("outofmem", "Out of memory");
            }
         }

         for (k = 0; k < 4; ++k) {
            int nleft;
            i = 0;
            while ((nleft = width - i) > 0) {
               count = stbi__get8(s);
               if (count > 128) {
                  // Run
                  value = stbi__get8(s);
                  count -= 128;
                  if (count > nleft) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); }
                  for (z = 0; z < count; ++z)
                     scanline[i++ * 4 + k] = value;
               } else {
                  // Dump
                  if (count > nleft) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); }
                  for (z = 0; z < count; ++z)
                     scanline[i++ * 4 + k] = stbi__get8(s);
               }
            }
         }
         for (i=0; i < width; ++i)
            stbi__hdr_convert(hdr_data+(j*width + i)*req_comp, scanline + i*4, req_comp);
      }
      if (scanline)
         STBI_FREE(scanline);
   }

   return hdr_data;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
movl %r8d, %ebp
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
leaq 0x70(%rsp), %r15
movq %r15, %rsi
callq 0x2c684
leaq 0xcc8c(%rip), %rsi      # 0x33f49
pushq $0xb
popq %rdx
movq %r15, %rdi
callq 0x6460
testl %eax, %eax
je 0x272f0
leaq 0xcc81(%rip), %rsi      # 0x33f54
leaq 0x70(%rsp), %rdi
pushq $0x7
popq %rdx
callq 0x6460
testl %eax, %eax
je 0x272f0
leaq 0xcc70(%rip), %rax      # 0x33f5b
jmp 0x27629
movq %r13, 0x28(%rsp)
movq %r12, (%rsp)
movq %r14, 0x8(%rsp)
movl %ebp, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0x70(%rsp), %r12
leaq 0xcc52(%rip), %r15      # 0x33f63
pushq $0x17
popq %r13
pushq $0x1
popq %rbp
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2c684
cmpb $0x0, 0x70(%rsp)
je 0x27340
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x6460
testl %eax, %eax
cmovel %ebp, %r14d
jmp 0x27318
testl %r14d, %r14d
je 0x27622
leaq 0x70(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2c684
leaq 0xcc2d(%rip), %rsi      # 0x33f8d
pushq $0x3
popq %rdx
movq %r15, %rdi
callq 0x6460
testl %eax, %eax
jne 0x27619
leaq 0x73(%rsp), %rdi
leaq 0x60(%rsp), %r15
movq %rdi, (%r15)
pushq $0xa
popq %rdx
movq %r15, %rsi
callq 0x6570
movq %rax, %r13
movq (%r15), %rdi
addq $0x2, %rdi
movb -0x2(%rdi), %al
incq %rdi
cmpb $0x20, %al
je 0x27395
cmpb $0x2b, %al
jne 0x27619
cmpb $0x58, -0x2(%rdi)
jne 0x27619
cmpb $0x20, -0x1(%rdi)
jne 0x27619
movq %rdi, 0x60(%rsp)
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x6570
movq %rax, %r14
movq 0x28(%rsp), %rax
movl %r14d, (%rax)
movq (%rsp), %rax
movl %r13d, (%rax)
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x273ec
movl $0x3, (%rax)
movl 0x10(%rsp), %eax
testl %eax, %eax
pushq $0x3
popq %r15
cmovnel %eax, %r15d
movl %r14d, %edi
movl %r13d, %esi
movl %r15d, %edx
callq 0x2c6f1
testl %eax, %eax
je 0x27648
movl %r14d, %edi
movl %r13d, %esi
movl %r15d, 0x8(%rsp)
movl %r15d, %edx
callq 0x2c74d
testq %rax, %rax
je 0x276d4
movq %rax, %r15
leal -0x8000(%r14), %eax
xorl %r12d, %r12d
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
movq %r14, 0x10(%rsp)
jb 0x276e3
movslq 0x8(%rsp), %rax
xorl %ecx, %ecx
testl %r13d, %r13d
movl $0x0, %edx
cmovgl %r13d, %edx
movl %r14d, %esi
movq %rax, %rdi
imulq %rsi, %rdi
shlq $0x2, %rsi
movq %rsi, 0x28(%rsp)
shlq $0x2, %rdi
movq %rdi, 0x30(%rsp)
shlq $0x2, %rax
movq %rax, 0x58(%rsp)
movq %r15, 0x18(%rsp)
xorl %edi, %edi
movq %rdx, 0x38(%rsp)
movq %rcx, 0x40(%rsp)
cmpq %rdx, %rcx
je 0x2766d
movq %rdi, (%rsp)
movq %rbx, %rdi
callq 0x28b62
movl %eax, %r12d
movq %rbx, %rdi
callq 0x28b62
movl %eax, %r14d
movq %rbx, %rdi
callq 0x28b62
cmpb $0x2, %r12b
jne 0x27674
cmpb $0x2, %r14b
jne 0x27674
testb %al, %al
js 0x27674
movzbl %al, %r14d
shll $0x8, %r14d
movq %rbx, %rdi
callq 0x28b62
movzbl %al, %eax
orl %r14d, %eax
movq 0x10(%rsp), %rdi
cmpl %edi, %eax
jne 0x276af
movq (%rsp), %rax
testq %rax, %rax
jne 0x27518
pushq $0x4
popq %rsi
xorl %edx, %edx
callq 0x28e0c
testq %rax, %rax
je 0x276cc
movq %rax, (%rsp)
movq %rax, %r14
xorl %eax, %eax
movq %r13, 0x48(%rsp)
movq %r15, 0x20(%rsp)
cmpq $0x4, %rax
je 0x275c0
movq %rax, 0x50(%rsp)
xorl %r13d, %r13d
movq 0x10(%rsp), %rax
movl %eax, %r15d
subl %r13d, %r15d
jle 0x275a6
movq %rbx, %rdi
callq 0x28b62
movzbl %al, %r12d
cmpb $-0x7f, %r12b
jb 0x27583
movq %rbx, %rdi
callq 0x28b62
andl $0x7f, %r12d
cmpl %r12d, %r15d
jb 0x27651
movslq %r13d, %r13
subl $0x1, %r12d
jb 0x2753d
movb %al, (%r14,%r13,4)
incq %r13
jmp 0x27574
cmpl %r12d, %r15d
jb 0x27651
movslq %r13d, %r13
subl $0x1, %r12d
jb 0x2753d
movq %rbx, %rdi
callq 0x28b62
movb %al, (%r14,%r13,4)
incq %r13
jmp 0x2758f
movq 0x50(%rsp), %rax
incq %rax
incq %r14
movq 0x48(%rsp), %r13
movq 0x20(%rsp), %r15
jmp 0x2752b
movq %r15, %r12
movq 0x18(%rsp), %r14
xorl %r15d, %r15d
cmpq %r15, 0x28(%rsp)
je 0x275f1
movq (%rsp), %rax
leaq (%rax,%r15), %rsi
movq %r14, %rdi
movl 0x8(%rsp), %edx
callq 0x2c77e
addq $0x4, %r15
addq 0x58(%rsp), %r14
jmp 0x275cb
movq 0x40(%rsp), %rcx
incq %rcx
movq 0x18(%rsp), %rax
addq 0x30(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %r12, %r15
movq (%rsp), %rdi
movq 0x38(%rsp), %rdx
jmp 0x2748d
leaq 0xc971(%rip), %rax      # 0x33f91
jmp 0x27629
leaq 0xc951(%rip), %rax      # 0x33f7a
movq %rax, 0x20ee8(%rip)     # 0x48518
xorl %r15d, %r15d
movq %r15, %rax
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc23b(%rip), %rax      # 0x3388a
jmp 0x27629
movq 0x20(%rsp), %rdi
callq 0x64d0
movq (%rsp), %rdi
callq 0x64d0
leaq 0xcaf5(%rip), %rax      # 0x34160
jmp 0x27629
callq 0x64d0
jmp 0x27633
leaq 0x68(%rsp), %rcx
movb %r12b, (%rcx)
movb %r14b, 0x1(%rcx)
movb %al, 0x2(%rcx)
movq %rcx, %r14
movq %rbx, %rdi
callq 0x28b62
movb %al, 0x3(%r14)
movq %r15, %rdi
movq %r14, %rsi
movl 0x8(%rsp), %edx
callq 0x2c77e
movq (%rsp), %rdi
callq 0x64d0
xorl %r12d, %r12d
jmp 0x276f6
movq %r15, %rdi
callq 0x64d0
movq (%rsp), %rdi
callq 0x64d0
leaq 0xc8e2(%rip), %rax      # 0x33fa9
jmp 0x27629
movq %r15, %rdi
callq 0x64d0
leaq 0xc1b9(%rip), %rax      # 0x33894
jmp 0x27629
incl %r12d
movl $0x0, %ebp
cmpl %r13d, %r12d
jge 0x27633
cmpl %r14d, %ebp
jge 0x276e0
leaq 0x6c(%rsp), %r14
pushq $0x4
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2aa06
movl 0x8(%rsp), %edx
movl %edx, %eax
movq 0x10(%rsp), %r8
imull %r8d, %eax
imull %r12d, %eax
cltq
leaq (%r15,%rax,4), %rax
movl %ebp, %ecx
imull %edx, %ecx
movslq %ecx, %rcx
leaq (%rax,%rcx,4), %rdi
movq %r14, %rsi
movq %r8, %r14
callq 0x2c77e
incl %ebp
jmp 0x276f1