// File: /workspace/github_cpp_makefile_star2_O2/srajangarg[P]raytracer/src/core/stb_image.hpp
// Function: stbi__hdr_load(stbi__context*, int*, int*, int*, int)
static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
{
   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;


   // Check identifier
   if (strcmp(stbi__hdr_gettoken(s,buffer), "#?RADIANCE") != 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;

   // Read data
   hdr_data = (float *) stbi__malloc(height * width * req_comp * sizeof(float));

   // 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(width * 4);

         for (k = 0; k < 4; ++k) {
            i = 0;
            while (i < width) {
               count = stbi__get8(s);
               if (count > 128) {
                  // Run
                  value = stbi__get8(s);
                  count -= 128;
                  for (z = 0; z < count; ++z)
                     scanline[i++ * 4 + k] = value;
               } else {
                  // Dump
                  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);
      }
      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, %r12
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x70(%rsp), %r15
movq %r15, %rsi
callq 0x1a76d
leaq 0xbe9b(%rip), %rsi      # 0x227a0
pushq $0xb
popq %rdx
movq %r15, %rdi
callq 0x4340
testl %eax, %eax
je 0x16920
leaq 0xbe90(%rip), %rax      # 0x227ab
jmp 0x16bf5
movq %r13, 0x8(%rsp)
movq %r12, 0x28(%rsp)
movl %ebp, 0x30(%rsp)
xorl %ebp, %ebp
leaq 0x70(%rsp), %r12
leaq 0xbe77(%rip), %r15      # 0x227b3
pushq $0x17
popq %r13
pushq $0x1
popq %rax
movl %eax, 0x14(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1a76d
cmpb $0x0, 0x70(%rsp)
je 0x16971
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4340
testl %eax, %eax
pushq $0x1
popq %rax
cmovel %eax, %ebp
jmp 0x16947
testl %ebp, %ebp
je 0x16bee
leaq 0x70(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1a76d
leaq 0xbe4d(%rip), %rsi      # 0x227dd
pushq $0x3
popq %rdx
movq %r15, %rdi
callq 0x4340
testl %eax, %eax
jne 0x16be5
leaq 0x73(%rsp), %rdi
leaq 0x60(%rsp), %r15
movq %rdi, (%r15)
pushq $0xa
popq %rdx
movq %r15, %rsi
callq 0x4480
movq %rax, 0x18(%rsp)
movq (%r15), %rdi
addq $0x2, %rdi
movb -0x2(%rdi), %al
incq %rdi
cmpb $0x20, %al
je 0x169c7
cmpb $0x2b, %al
movq 0x8(%rsp), %r13
jne 0x16be5
cmpb $0x58, -0x2(%rdi)
jne 0x16be5
cmpb $0x20, -0x1(%rdi)
jne 0x16be5
movq %rdi, 0x60(%rsp)
xorl %r15d, %r15d
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x4480
movq %rax, %r12
movl %r12d, (%r14)
movq 0x18(%rsp), %rax
movl %eax, (%r13)
movq 0x28(%rsp), %rax
testq %rax, %rax
je 0x16a23
movl $0x3, (%rax)
movl 0x30(%rsp), %eax
testl %eax, %eax
pushq $0x3
popq %rcx
cmovnel %eax, %ecx
movq 0x18(%rsp), %rax
imull %r12d, %eax
movl %ecx, 0x8(%rsp)
imull %ecx, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x4420
movq %rax, (%rsp)
leal -0x8000(%r12), %eax
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
jb 0x16c70
leal (,%r12,4), %eax
movq %rax, 0x38(%rsp)
movslq 0x8(%rsp), %rcx
xorl %r15d, %r15d
movq 0x18(%rsp), %rax
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
movq %rdx, 0x48(%rsp)
movl %r12d, %eax
movq %rcx, %rdx
imulq %rax, %rdx
shlq $0x2, %rax
movq %rax, 0x30(%rsp)
shlq $0x2, %rdx
movq %rdx, 0x40(%rsp)
shlq $0x2, %rcx
movq %rcx, 0x58(%rsp)
movq (%rsp), %rax
movq %rax, 0x20(%rsp)
xorl %r13d, %r13d
cmpq 0x48(%rsp), %r15
je 0x16c10
movq %rbx, %rdi
callq 0x17a36
movl %eax, %ebp
movq %rbx, %rdi
callq 0x17a36
movl %eax, %r14d
movq %rbx, %rdi
callq 0x17a36
cmpb $0x2, %bpl
jne 0x16c1a
cmpb $0x2, %r14b
jne 0x16c1a
testb %al, %al
js 0x16c1a
movzbl %al, %ebp
shll $0x8, %ebp
movq %rbx, %rdi
callq 0x17a36
movzbl %al, %eax
orl %ebp, %eax
cmpl %r12d, %eax
jne 0x16c53
movq %r15, 0x50(%rsp)
testq %r13, %r13
jne 0x16b33
movq 0x38(%rsp), %rdi
callq 0x4420
movq %rax, %r13
movq %r13, %r14
xorl %r15d, %r15d
movq %r13, 0x28(%rsp)
cmpq $0x4, %r15
je 0x16b9f
xorl %r13d, %r13d
cmpl %r12d, %r13d
jge 0x16b92
movq %rbx, %rdi
callq 0x17a36
movzbl %al, %ebp
cmpb $-0x80, %bpl
jbe 0x16b79
movq %rbx, %rdi
callq 0x17a36
andl $0x7f, %ebp
movslq %r13d, %r13
subl $0x1, %ebp
jb 0x16b47
movb %al, (%r14,%r13,4)
incq %r13
jmp 0x16b6b
movslq %r13d, %r13
subl $0x1, %ebp
jb 0x16b47
movq %rbx, %rdi
callq 0x17a36
movb %al, (%r14,%r13,4)
incq %r13
jmp 0x16b7c
incq %r15
incq %r14
movq 0x28(%rsp), %r13
jmp 0x16b3e
movq 0x20(%rsp), %r14
xorl %r15d, %r15d
cmpq %r15, 0x30(%rsp)
je 0x16bc9
leaq (%r15,%r13), %rsi
movq %r14, %rdi
movl 0x8(%rsp), %edx
callq 0x1a7da
addq $0x4, %r15
addq 0x58(%rsp), %r14
jmp 0x16ba7
movq 0x50(%rsp), %r15
incq %r15
movq 0x20(%rsp), %rax
addq 0x40(%rsp), %rax
movq %rax, 0x20(%rsp)
jmp 0x16abc
leaq 0xbbf5(%rip), %rax      # 0x227e1
jmp 0x16bf5
leaq 0xbbd5(%rip), %rax      # 0x227ca
movq %rax, 0x187d4(%rip)     # 0x2f3d0
xorl %eax, %eax
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x43a0
jmp 0x16c79
leaq 0x68(%rsp), %r15
movb %bpl, (%r15)
movb %r14b, 0x1(%r15)
movb %al, 0x2(%r15)
movq %rbx, %rdi
callq 0x17a36
movb %al, 0x3(%r15)
movq (%rsp), %rdi
movq %r15, %rsi
movl 0x8(%rsp), %edx
callq 0x1a7da
movq %r13, %rdi
callq 0x43a0
xorl %r15d, %r15d
jmp 0x16c8b
movq (%rsp), %rdi
callq 0x43a0
movq %r13, %rdi
callq 0x43a0
leaq 0xbb8e(%rip), %rax      # 0x227f9
jmp 0x16bf5
incl %r15d
xorl %ebp, %ebp
cmpl 0x18(%rsp), %r15d
jl 0x16c82
movq (%rsp), %rax
jmp 0x16bfe
cmpl %r12d, %ebp
jge 0x16c6d
movl %ebp, 0x14(%rsp)
leaq 0x6c(%rsp), %r14
pushq $0x4
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1924c
movl 0x8(%rsp), %edx
movl %edx, %eax
imull %r12d, %eax
imull %r15d, %eax
cltq
movq (%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movl 0x14(%rsp), %ebp
movl %ebp, %ecx
imull %edx, %ecx
movslq %ecx, %rcx
leaq (%rax,%rcx,4), %rdi
movq %r14, %rsi
callq 0x1a7da
incl %ebp
jmp 0x16c82