// File: /workspace/github_cpp_makefile_star2_O3/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 0x22a42
movabsq $0x4e41494441523f23, %rax # imm = 0x4E41494441523F23
xorq (%r12), %rax
movabsq $0x45434e41494441, %rcx # imm = 0x45434E41494441
xorq 0x3(%r12), %rcx
orq %rax, %rcx
je 0x1ba45
leaq 0x10e6b(%rip), %rax     # 0x2c8ab
jmp 0x1c08f
movq %r13, 0x10(%rsp)
leaq 0x90(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x22a42
cmpb $0x0, (%r12)
je 0x1c07f
movq %r14, 0x8(%rsp)
movq %rbp, %r14
movl %r15d, %ebp
xorl %r15d, %r15d
movl $0x1, %r13d
leaq 0x90(%rsp), %r12
movdqu 0x97(%rsp), %xmm0
pcmpeqb 0x1026b(%rip), %xmm0    # 0x2bd00
movdqa 0x90(%rsp), %xmm1
pcmpeqb 0x1026a(%rip), %xmm1    # 0x2bd10
pand %xmm0, %xmm1
pmovmskb %xmm1, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
cmovel %r13d, %r15d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x22a42
cmpb $0x0, 0x90(%rsp)
jne 0x1ba84
testl %r15d, %r15d
movl %ebp, %r13d
movq %r14, %rbp
movq 0x8(%rsp), %r14
je 0x1c07f
leaq 0x90(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x22a42
movl $0x592d, %eax           # imm = 0x592D
xorl (%r12), %eax
movzbl 0x2(%r12), %ecx
xorl $0x20, %ecx
orw %ax, %cx
jne 0x1c088
leaq 0x93(%rsp), %rdi
leaq 0x80(%rsp), %r12
movq %rdi, (%r12)
movq %r12, %rsi
movl $0xa, %edx
callq 0x4440
movq %rax, %r15
movq (%r12), %rdi
addq $0x2, %rdi
movb -0x2(%rdi), %al
incq %rdi
cmpb $0x20, %al
je 0x1bb3a
cmpb $0x2b, %al
jne 0x1c088
cmpb $0x58, -0x2(%rdi)
jne 0x1c088
cmpb $0x20, -0x1(%rdi)
jne 0x1c088
movq %rdi, 0x80(%rsp)
xorl %esi, %esi
movl $0xa, %edx
callq 0x4440
movl %eax, (%r14)
movq %rax, %r14
movl %r15d, (%rbp)
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x1bb8e
movl $0x3, (%rax)
testl %r13d, %r13d
movl %r13d, %eax
movl $0x3, %r13d
cmovnel %eax, %r13d
movq %r15, 0x40(%rsp)
movl %r15d, %eax
imull %r14d, %eax
imull %r13d, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x43f0
movq %rax, %r12
leal -0x8000(%r14), %eax
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
movq %r14, 0x30(%rsp)
movl $0x0, %eax
jb 0x1c133
movq %r12, 0x20(%rsp)
movq 0x40(%rsp), %r15
testl %r15d, %r15d
jle 0x1c0ae
movl %r13d, %eax
leaq 0x38(%rbx), %r13
leaq 0x39(%rbx), %rcx
movq %rcx, 0x8(%rsp)
leal (,%r14,4), %ecx
movq %rcx, 0x48(%rsp)
movl %eax, 0x1c(%rsp)
movslq %eax, %rcx
movl %r14d, %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %r15
movq %r15, 0x58(%rsp)
andq %rax, %r14
movq %r14, 0x50(%rsp)
imulq %rcx, %rdx
shlq $0x2, %rdx
movq %rdx, 0x60(%rsp)
shlq $0x2, %rcx
movq %rcx, 0x68(%rsp)
xorl %r12d, %r12d
movq 0x20(%rsp), %rax
movq %rax, 0x38(%rsp)
xorl %r15d, %r15d
movq 0xb8(%rbx), %rcx
movq 0xc0(%rbx), %rax
cmpq %rax, %rcx
jae 0x1bc74
leaq 0x1(%rcx), %rdx
movq %rdx, 0xb8(%rbx)
movb (%rcx), %sil
movq %rdx, %rcx
jmp 0x1bcc2
cmpl $0x0, 0x30(%rbx)
je 0x1bc9b
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1bc9f
cltq
addq %r13, %rax
movb (%r13), %sil
movq 0x8(%rsp), %rcx
jmp 0x1bcb4
xorl %esi, %esi
jmp 0x1bcc2
movl $0x0, 0x30(%rbx)
movb $0x0, 0x38(%rbx)
xorl %esi, %esi
movq 0x8(%rsp), %rcx
movq %rcx, %rax
movq %rax, 0xc0(%rbx)
movq %rcx, 0xb8(%rbx)
cmpq %rax, %rcx
jae 0x1bcda
leaq 0x1(%rcx), %rdx
movq %rdx, 0xb8(%rbx)
movb (%rcx), %r14b
movq %rdx, %rcx
jmp 0x1bd2e
cmpl $0x0, 0x30(%rbx)
je 0x1bd03
movl %esi, %ebp
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1bd08
cltq
addq %r13, %rax
movb (%r13), %r14b
movq 0x8(%rsp), %rcx
jmp 0x1bd1e
xorl %r14d, %r14d
jmp 0x1bd2e
movl $0x0, 0x30(%rbx)
movb $0x0, 0x38(%rbx)
xorl %r14d, %r14d
movq 0x8(%rsp), %rcx
movq %rcx, %rax
movq %rax, 0xc0(%rbx)
movq %rcx, 0xb8(%rbx)
movl %ebp, %esi
cmpq %rax, %rcx
jae 0x1bd46
leaq 0x1(%rcx), %rdx
movq %rdx, 0xb8(%rbx)
movb (%rcx), %bpl
movq %rdx, %rcx
jmp 0x1bd9c
cmpl $0x0, 0x30(%rbx)
je 0x1bd71
movl %esi, 0x10(%rsp)
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1bd75
cltq
addq %r13, %rax
movb (%r13), %bpl
movq 0x8(%rsp), %rcx
jmp 0x1bd8a
xorl %ebp, %ebp
jmp 0x1bd9c
movl $0x0, 0x30(%rbx)
movb $0x0, 0x38(%rbx)
xorl %ebp, %ebp
movq 0x8(%rsp), %rcx
movq %rcx, %rax
movl 0x10(%rsp), %esi
movq %rax, 0xc0(%rbx)
movq %rcx, 0xb8(%rbx)
cmpb $0x2, %sil
jne 0x1c0c0
cmpb $0x2, %r14b
jne 0x1c0c0
testb %bpl, %bpl
js 0x1c0c0
cmpq %rax, %rcx
jae 0x1bdd2
leaq 0x1(%rcx), %rax
movq %rax, 0xb8(%rbx)
movb (%rcx), %al
movq 0x30(%rsp), %r14
jmp 0x1be26
cmpl $0x0, 0x30(%rbx)
movq 0x30(%rsp), %r14
je 0x1bdff
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1be03
movslq %eax, %rcx
addq %r13, %rcx
movb (%r13), %al
movq 0x8(%rsp), %rdx
jmp 0x1be18
xorl %eax, %eax
jmp 0x1be26
movl $0x0, 0x30(%rbx)
movb $0x0, 0x38(%rbx)
xorl %eax, %eax
movq 0x8(%rsp), %rdx
movq %rdx, %rcx
movq %rcx, 0xc0(%rbx)
movq %rdx, 0xb8(%rbx)
movzbl %bpl, %ecx
shll $0x8, %ecx
movzbl %al, %eax
orl %ecx, %eax
cmpl %r14d, %eax
jne 0x1c110
testq %r15, %r15
jne 0x1be4d
movq 0x48(%rsp), %rdi
callq 0x43f0
movq %rax, %r15
movq %r12, 0x70(%rsp)
movq %r15, 0x28(%rsp)
xorl %eax, %eax
movq %rax, 0x78(%rsp)
xorl %ebp, %ebp
movq %r15, 0x10(%rsp)
movq 0xb8(%rbx), %rdx
movq 0xc0(%rbx), %rax
cmpq %rax, %rdx
jae 0x1be88
leaq 0x1(%rdx), %rcx
movq %rcx, 0xb8(%rbx)
movb (%rdx), %r12b
jmp 0x1bed7
cmpl $0x0, 0x30(%rbx)
je 0x1c009
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1beb3
cltq
addq %r13, %rax
movb (%r13), %r12b
movq 0x8(%rsp), %rcx
jmp 0x1bec9
movl $0x0, 0x30(%rbx)
movb $0x0, 0x38(%rbx)
xorl %r12d, %r12d
movq 0x8(%rsp), %rcx
movq %rcx, %rax
movq %rax, 0xc0(%rbx)
movq %rcx, 0xb8(%rbx)
cmpb $-0x80, %r12b
jbe 0x1bef8
cmpq %rax, %rcx
jae 0x1bf98
leaq 0x1(%rcx), %rax
movq %rax, 0xb8(%rbx)
movb (%rcx), %al
jmp 0x1bfe7
testb %r12b, %r12b
je 0x1c009
movslq %ebp, %rax
leaq (%r15,%rax,4), %r14
movzbl %r12b, %r12d
xorl %r15d, %r15d
movq 0xb8(%rbx), %rax
cmpq 0xc0(%rbx), %rax
jae 0x1bf2e
leaq 0x1(%rax), %rcx
movq %rcx, 0xb8(%rbx)
movb (%rax), %al
jmp 0x1bf7d
cmpl $0x0, 0x30(%rbx)
je 0x1bf56
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1bf5a
movslq %eax, %rcx
addq %r13, %rcx
movb (%r13), %al
movq 0x8(%rsp), %rdx
jmp 0x1bf6f
xorl %eax, %eax
jmp 0x1bf7d
movl $0x0, 0x30(%rbx)
movb $0x0, 0x38(%rbx)
xorl %eax, %eax
movq 0x8(%rsp), %rdx
movq %rdx, %rcx
movq %rcx, 0xc0(%rbx)
movq %rdx, 0xb8(%rbx)
movb %al, (%r14,%r15,4)
incq %r15
cmpl %r15d, %r12d
jne 0x1bf0f
addl %r15d, %ebp
movq 0x30(%rsp), %r14
movq 0x10(%rsp), %r15
jmp 0x1c009
cmpl $0x0, 0x30(%rbx)
je 0x1bfc0
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r13, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x1bfc4
movslq %eax, %rcx
addq %r13, %rcx
movb (%r13), %al
movq 0x8(%rsp), %rdx
jmp 0x1bfd9
xorl %eax, %eax
jmp 0x1bfe7
movl $0x0, 0x30(%rbx)
movb $0x0, 0x38(%rbx)
xorl %eax, %eax
movq 0x8(%rsp), %rdx
movq %rdx, %rcx
movq %rcx, 0xc0(%rbx)
movq %rdx, 0xb8(%rbx)
testb $0x7f, %r12b
je 0x1c009
movslq %ebp, %rcx
leaq (%r15,%rcx,4), %rcx
movzbl %r12b, %edx
andl $0x7f, %edx
xorl %esi, %esi
movb %al, (%rcx,%rsi,4)
incq %rsi
cmpl %esi, %edx
jne 0x1bffd
addl %esi, %ebp
cmpl %r14d, %ebp
jl 0x1be65
movq 0x78(%rsp), %rax
incq %rax
incq %r15
cmpq $0x4, %rax
jne 0x1be59
movq 0x50(%rsp), %r15
movq 0x28(%rsp), %r14
movq 0x38(%rsp), %rbp
movq 0x68(%rsp), %r12
movq %rbp, %rdi
movq %r14, %rsi
movl 0x1c(%rsp), %edx
callq 0x22c66
addq %r12, %rbp
addq $0x4, %r14
decq %r15
jne 0x1c03b
movq 0x70(%rsp), %r12
incq %r12
movq 0x38(%rsp), %rax
addq 0x60(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpq 0x58(%rsp), %r12
movq 0x28(%rsp), %r15
jne 0x1bc4e
jmp 0x1c0b1
leaq 0x10844(%rip), %rax     # 0x2c8ca
jmp 0x1c08f
leaq 0x10852(%rip), %rax     # 0x2c8e1
movq %rax, 0x1b2fa(%rip)     # 0x37390
xorl %r12d, %r12d
movq %r12, %rax
addq $0x498, %rsp            # imm = 0x498
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
movq %r15, %rdi
callq 0x4380
movq 0x20(%rsp), %r12
jmp 0x1c099
movq %r15, 0x28(%rsp)
leaq 0x88(%rsp), %r15
movb %sil, (%r15)
movb %r14b, 0x1(%r15)
movb %bpl, 0x2(%r15)
movq %rbx, %rdi
callq 0x1e49c
movb %al, 0x3(%r15)
movq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movl 0x1c(%rsp), %r13d
movl %r13d, %edx
callq 0x22c66
movq 0x28(%rsp), %rdi
callq 0x4380
xorl %r15d, %r15d
movl $0x1, %ebp
jmp 0x1c147
movq 0x20(%rsp), %rdi
callq 0x4380
movq %r15, %rdi
callq 0x4380
leaq 0x107d0(%rip), %rax     # 0x2c8f9
jmp 0x1c08f
movq %r15, %rax
incl %eax
xorl %ebp, %ebp
movq %rax, %r15
cmpl 0x40(%rsp), %eax
jge 0x1c099
cmpl %r14d, %ebp
jge 0x1c12e
leaq 0x8c(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
movl $0x4, %edx
callq 0x20a46
movl %r13d, %eax
movq 0x30(%rsp), %rdx
imull %edx, %eax
imull %r15d, %eax
cltq
leaq (%r12,%rax,4), %rax
movl %ebp, %ecx
imull %r13d, %ecx
movslq %ecx, %rcx
leaq (%rax,%rcx,4), %rdi
movq %r14, %rsi
movq %rdx, %r14
movl %r13d, %edx
callq 0x22c66
incl %ebp
jmp 0x1c142