// File: /workspace/github_cpp_makefile_star2_O1/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 $0x498, %rsp            # imm = 0x498
movl %r8d, %r15d
movq %rcx, %r13
movq %rdx, %rbp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x90(%rsp), %r12
movq %r12, %rsi
callq 0x22620
movabsq $0x4e41494441523f23, %rax # imm = 0x4E41494441523F23
xorq (%r12), %rax
movabsq $0x45434e41494441, %rcx # imm = 0x45434E41494441
xorq 0x3(%r12), %rcx
orq %rax, %rcx
je 0x1b370
leaq 0x12480(%rip), %rax     # 0x2d7eb
jmp 0x1b492
leaq 0x90(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x22620
cmpb $0x0, (%r12)
je 0x1b486
movq %r13, 0x40(%rsp)
movl %r15d, 0x8(%rsp)
xorl %r15d, %r15d
movl $0x1, %r13d
leaq 0x90(%rsp), %r12
movdqu 0x97(%rsp), %xmm0
pcmpeqb 0x11896(%rip), %xmm0    # 0x2cc50
movdqa 0x90(%rsp), %xmm1
pcmpeqb 0x11895(%rip), %xmm1    # 0x2cc60
pand %xmm0, %xmm1
pmovmskb %xmm1, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
cmovel %r13d, %r15d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x22620
cmpb $0x0, 0x90(%rsp)
jne 0x1b3a9
movq %r12, 0x20(%rsp)
testl %r15d, %r15d
je 0x1b48b
movq %rbx, %rdi
movq %r12, %rsi
callq 0x22620
movl $0x592d, %eax           # imm = 0x592D
xorl 0x90(%rsp), %eax
movq %r12, 0x20(%rsp)
movzbl 0x92(%rsp), %ecx
xorl $0x20, %ecx
orw %ax, %cx
jne 0x1b47d
leaq 0x93(%rsp), %rdi
leaq 0x20(%rsp), %r12
movq %rdi, (%r12)
movq %r12, %rsi
movl $0xa, %edx
callq 0x4450
movq %rax, %r13
movq (%r12), %r12
decq %r12
cmpb $0x20, 0x1(%r12)
leaq 0x1(%r12), %r12
je 0x1b453
movq %r12, 0x20(%rsp)
leaq 0x123cd(%rip), %rsi     # 0x2d839
movl $0x3, %edx
movq %r12, %rdi
callq 0x4180
testl %eax, %eax
je 0x1b4b1
leaq 0x1239d(%rip), %rax     # 0x2d821
jmp 0x1b492
movq %r12, 0x20(%rsp)
leaq 0x12378(%rip), %rax     # 0x2d80a
movq %rax, 0x1cf17(%rip)     # 0x383b0
xorl %r12d, %r12d
movq %r12, %rax
addq $0x498, %rsp            # imm = 0x498
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x3, %r12
movq %r12, 0x20(%rsp)
xorl %r15d, %r15d
movq %r12, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x4450
movl %eax, (%r14)
movq %rax, %r14
movl %r13d, (%rbp)
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x1b4e6
movl $0x3, (%rax)
movl 0x8(%rsp), %ecx
testl %ecx, %ecx
movl $0x3, %eax
cmovnel %ecx, %eax
movl %eax, 0x14(%rsp)
imull %r13d, %eax
imull %r14d, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x4400
movq %rax, %r12
leal -0x8000(%r14), %eax
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
movq %r14, 0x38(%rsp)
jb 0x1baaf
testl %r13d, %r13d
jle 0x1ba2b
movq %r13, %rcx
leaq 0x38(%rbx), %r13
leaq 0x39(%rbx), %rax
movq %rax, 0x8(%rsp)
leal (,%r14,4), %eax
movq %rax, 0x50(%rsp)
movslq 0x14(%rsp), %rdx
movl %r14d, %esi
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rcx, 0x48(%rsp)
andq %rax, %rcx
movq %rcx, 0x60(%rsp)
andq %rax, %r14
movq %r14, 0x58(%rsp)
imulq %rdx, %rsi
shlq $0x2, %rsi
movq %rsi, 0x68(%rsp)
shlq $0x2, %rdx
movq %rdx, 0x70(%rsp)
xorl %ebp, %ebp
movq %r12, 0x30(%rsp)
movq $0x0, 0x18(%rsp)
movq %r12, 0x28(%rsp)
movq 0xb8(%rbx), %rax
cmpq 0xc0(%rbx), %rax
jb 0x1b5ff
cmpl $0x0, 0x30(%rbx)
je 0x1b5d5
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1b5da
movq %r13, 0xb8(%rbx)
cltq
addq %r13, %rax
movq %rax, 0xc0(%rbx)
jmp 0x1b5f8
xorl %r15d, %r15d
jmp 0x1b60d
movl $0x0, 0x30(%rbx)
movq %r13, 0xb8(%rbx)
movq 0x8(%rsp), %rax
movq %rax, 0xc0(%rbx)
movb $0x0, 0x38(%rbx)
movq 0xb8(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0xb8(%rbx)
movb (%rax), %r15b
movq 0xb8(%rbx), %rax
cmpq 0xc0(%rbx), %rax
jb 0x1b673
cmpl $0x0, 0x30(%rbx)
je 0x1b649
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1b64e
movq %r13, 0xb8(%rbx)
cltq
addq %r13, %rax
movq %rax, 0xc0(%rbx)
jmp 0x1b66c
xorl %r12d, %r12d
jmp 0x1b681
movl $0x0, 0x30(%rbx)
movq %r13, 0xb8(%rbx)
movq 0x8(%rsp), %rax
movq %rax, 0xc0(%rbx)
movb $0x0, 0x38(%rbx)
movq 0xb8(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0xb8(%rbx)
movb (%rax), %r12b
movq 0xb8(%rbx), %rax
cmpq 0xc0(%rbx), %rax
jb 0x1b6e7
cmpl $0x0, 0x30(%rbx)
je 0x1b6bd
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1b6c2
movq %r13, 0xb8(%rbx)
cltq
addq %r13, %rax
movq %rax, 0xc0(%rbx)
jmp 0x1b6e0
xorl %r14d, %r14d
jmp 0x1b6f5
movl $0x0, 0x30(%rbx)
movq %r13, 0xb8(%rbx)
movq 0x8(%rsp), %rax
movq %rax, 0xc0(%rbx)
movb $0x0, 0x38(%rbx)
movq 0xb8(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0xb8(%rbx)
movb (%rax), %r14b
cmpb $0x2, %r15b
jne 0x1ba43
cmpb $0x2, %r12b
jne 0x1ba43
testb %r14b, %r14b
js 0x1ba43
movq 0xb8(%rbx), %rax
cmpq 0xc0(%rbx), %rax
movq 0x28(%rsp), %r15
movq 0x18(%rsp), %r12
jb 0x1b781
cmpl $0x0, 0x30(%rbx)
je 0x1b758
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1b75c
movq %r13, 0xb8(%rbx)
cltq
addq %r13, %rax
movq %rax, 0xc0(%rbx)
jmp 0x1b77a
xorl %eax, %eax
jmp 0x1b78f
movl $0x0, 0x30(%rbx)
movq %r13, 0xb8(%rbx)
movq 0x8(%rsp), %rax
movq %rax, 0xc0(%rbx)
movb $0x0, 0x38(%rbx)
movq 0xb8(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0xb8(%rbx)
movzbl (%rax), %eax
movzbl %r14b, %ecx
shll $0x8, %ecx
orl %eax, %ecx
movq 0x38(%rsp), %r14
cmpl %r14d, %ecx
jne 0x1ba90
testq %r12, %r12
jne 0x1b7b8
movq 0x50(%rsp), %rdi
callq 0x4400
movq %rax, %r12
movq %rbp, 0x78(%rsp)
movq %r12, 0x18(%rsp)
movq %r12, %rbp
xorl %eax, %eax
movq %rax, 0x80(%rsp)
testl %r14d, %r14d
jle 0x1b9b4
xorl %r15d, %r15d
movq %rbp, 0x40(%rsp)
movq 0xb8(%rbx), %rax
cmpq 0xc0(%rbx), %rax
jb 0x1b846
cmpl $0x0, 0x30(%rbx)
je 0x1b81c
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1b821
movq %r13, 0xb8(%rbx)
cltq
addq %r13, %rax
movq %rax, 0xc0(%rbx)
jmp 0x1b83f
xorl %r12d, %r12d
jmp 0x1b854
movl $0x0, 0x30(%rbx)
movq %r13, 0xb8(%rbx)
movq 0x8(%rsp), %rax
movq %rax, 0xc0(%rbx)
movb $0x0, 0x38(%rbx)
movq 0xb8(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0xb8(%rbx)
movb (%rax), %r12b
cmpb $-0x80, %r12b
jbe 0x1b8a5
movq 0xb8(%rbx), %rax
cmpq 0xc0(%rbx), %rax
jb 0x1b974
cmpl $0x0, 0x30(%rbx)
je 0x1b94b
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1b94f
movq %r13, 0xb8(%rbx)
cltq
addq %r13, %rax
movq %rax, 0xc0(%rbx)
jmp 0x1b96d
testb %r12b, %r12b
je 0x1b9ab
movslq %r15d, %rax
leaq (%rbp,%rax,4), %rbp
movzbl %r12b, %r12d
xorl %r14d, %r14d
movq 0xb8(%rbx), %rax
cmpq 0xc0(%rbx), %rax
jb 0x1b922
cmpl $0x0, 0x30(%rbx)
je 0x1b8f9
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1b8fd
movq %r13, 0xb8(%rbx)
cltq
addq %r13, %rax
movq %rax, 0xc0(%rbx)
jmp 0x1b91b
xorl %eax, %eax
jmp 0x1b92f
movl $0x0, 0x30(%rbx)
movq %r13, 0xb8(%rbx)
movq 0x8(%rsp), %rax
movq %rax, 0xc0(%rbx)
movb $0x0, 0x38(%rbx)
movq 0xb8(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0xb8(%rbx)
movb (%rax), %al
movb %al, (%rbp,%r14,4)
incq %r14
cmpl %r14d, %r12d
jne 0x1b8bd
addl %r14d, %r15d
movq 0x38(%rsp), %r14
movq 0x40(%rsp), %rbp
jmp 0x1b9ab
xorl %eax, %eax
jmp 0x1b981
movl $0x0, 0x30(%rbx)
movq %r13, 0xb8(%rbx)
movq 0x8(%rsp), %rax
movq %rax, 0xc0(%rbx)
movb $0x0, 0x38(%rbx)
movq 0xb8(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0xb8(%rbx)
movb (%rax), %al
testb $0x7f, %r12b
je 0x1b9ab
movslq %r15d, %rcx
leaq (,%rcx,4), %rcx
addq %rbp, %rcx
movzbl %r12b, %edx
andl $0x7f, %edx
xorl %esi, %esi
movb %al, (%rcx,%rsi,4)
incq %rsi
cmpl %esi, %edx
jne 0x1b99e
addl %esi, %r15d
cmpl %r14d, %r15d
jl 0x1b7e0
movq 0x80(%rsp), %rax
incq %rax
incq %rbp
cmpq $0x4, %rax
jne 0x1b7c7
movq 0x58(%rsp), %r12
movq %r14, %rax
movq 0x18(%rsp), %r14
movq 0x30(%rsp), %r15
testl %eax, %eax
movq 0x70(%rsp), %rbp
jle 0x1ba02
movq %r15, %rdi
movq %r14, %rsi
movl 0x14(%rsp), %edx
callq 0x22844
addq %rbp, %r15
addq $0x4, %r14
decq %r12
jne 0x1b9e7
movq 0x78(%rsp), %rbp
incq %rbp
movq 0x30(%rsp), %rax
addq 0x68(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpq 0x60(%rsp), %rbp
movq 0x28(%rsp), %r12
jne 0x1b599
jmp 0x1ba34
movq $0x0, 0x18(%rsp)
movq 0x18(%rsp), %rdi
callq 0x4390
jmp 0x1b49c
leaq 0x88(%rsp), %r13
movb %r15b, (%r13)
movb %r12b, 0x1(%r13)
movb %r14b, 0x2(%r13)
movq %rbx, %rdi
callq 0x1df98
movb %al, 0x3(%r13)
movq 0x28(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
movl 0x14(%rsp), %edx
callq 0x22844
movq 0x18(%rsp), %rdi
callq 0x4390
xorl %r15d, %r15d
movl $0x1, %ebp
movq 0x48(%rsp), %r13
jmp 0x1babf
movq %r15, %rdi
callq 0x4390
movq %r12, %rdi
callq 0x4390
leaq 0x11d96(%rip), %rax     # 0x2d83d
jmp 0x1b492
incl %r15d
xorl %ebp, %ebp
cmpl %r13d, %r15d
jge 0x1b49c
cmpl %r14d, %ebp
jge 0x1baac
leaq 0x8c(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
movl $0x4, %edx
callq 0x20499
movl 0x14(%rsp), %edx
movl %edx, %eax
movq 0x38(%rsp), %r8
imull %r8d, %eax
imull %r15d, %eax
cltq
leaq (%r12,%rax,4), %rax
movl %ebp, %ecx
imull %edx, %ecx
movslq %ecx, %rcx
leaq (%rax,%rcx,4), %rdi
movq %r14, %rsi
movq %r8, %r14
callq 0x22844
incl %ebp
jmp 0x1baba