// File: /workspace/github_c_makefile_star2_O2/patriciogonzalezvivo[P]tprint/include/std/stb_image.h
// 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 0x16ccf
leaq 0x634d(%rip), %rsi      # 0x194cb
pushq $0xb
popq %rdx
movq %r15, %rdi
callq 0x8320
testl %eax, %eax
je 0x13199
leaq 0x6342(%rip), %rax      # 0x194d6
jmp 0x1346e
movq %r13, 0x8(%rsp)
movq %r12, 0x28(%rsp)
movl %ebp, 0x30(%rsp)
xorl %ebp, %ebp
leaq 0x70(%rsp), %r12
leaq 0x6329(%rip), %r15      # 0x194de
pushq $0x17
popq %r13
pushq $0x1
popq %rax
movl %eax, 0x14(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x16ccf
cmpb $0x0, 0x70(%rsp)
je 0x131ea
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x8320
testl %eax, %eax
pushq $0x1
popq %rax
cmovel %eax, %ebp
jmp 0x131c0
testl %ebp, %ebp
je 0x13467
leaq 0x70(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x16ccf
leaq 0x62ff(%rip), %rsi      # 0x19508
pushq $0x3
popq %rdx
movq %r15, %rdi
callq 0x8320
testl %eax, %eax
jne 0x1345e
leaq 0x73(%rsp), %rdi
leaq 0x60(%rsp), %r15
movq %rdi, (%r15)
pushq $0xa
popq %rdx
movq %r15, %rsi
callq 0x8460
movq %rax, 0x18(%rsp)
movq (%r15), %rdi
addq $0x2, %rdi
movb -0x2(%rdi), %al
incq %rdi
cmpb $0x20, %al
je 0x13240
cmpb $0x2b, %al
movq 0x8(%rsp), %r13
jne 0x1345e
cmpb $0x58, -0x2(%rdi)
jne 0x1345e
cmpb $0x20, -0x1(%rdi)
jne 0x1345e
movq %rdi, 0x60(%rsp)
xorl %r15d, %r15d
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x8460
movq %rax, %r12
movl %r12d, (%r14)
movq 0x18(%rsp), %rax
movl %eax, (%r13)
movq 0x28(%rsp), %rax
testq %rax, %rax
je 0x1329c
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 0x8420
movq %rax, (%rsp)
leal -0x8000(%r12), %eax
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
jb 0x134e9
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 0x13489
movq %rbx, %rdi
callq 0x142b0
movl %eax, %ebp
movq %rbx, %rdi
callq 0x142b0
movl %eax, %r14d
movq %rbx, %rdi
callq 0x142b0
cmpb $0x2, %bpl
jne 0x13493
cmpb $0x2, %r14b
jne 0x13493
testb %al, %al
js 0x13493
movzbl %al, %ebp
shll $0x8, %ebp
movq %rbx, %rdi
callq 0x142b0
movzbl %al, %eax
orl %ebp, %eax
cmpl %r12d, %eax
jne 0x134cc
movq %r15, 0x50(%rsp)
testq %r13, %r13
jne 0x133ac
movq 0x38(%rsp), %rdi
callq 0x8420
movq %rax, %r13
movq %r13, %r14
xorl %r15d, %r15d
movq %r13, 0x28(%rsp)
cmpq $0x4, %r15
je 0x13418
xorl %r13d, %r13d
cmpl %r12d, %r13d
jge 0x1340b
movq %rbx, %rdi
callq 0x142b0
movzbl %al, %ebp
cmpb $-0x80, %bpl
jbe 0x133f2
movq %rbx, %rdi
callq 0x142b0
andl $0x7f, %ebp
movslq %r13d, %r13
subl $0x1, %ebp
jb 0x133c0
movb %al, (%r14,%r13,4)
incq %r13
jmp 0x133e4
movslq %r13d, %r13
subl $0x1, %ebp
jb 0x133c0
movq %rbx, %rdi
callq 0x142b0
movb %al, (%r14,%r13,4)
incq %r13
jmp 0x133f5
incq %r15
incq %r14
movq 0x28(%rsp), %r13
jmp 0x133b7
movq 0x20(%rsp), %r14
xorl %r15d, %r15d
cmpq %r15, 0x30(%rsp)
je 0x13442
leaq (%r15,%r13), %rsi
movq %r14, %rdi
movl 0x8(%rsp), %edx
callq 0x16d3c
addq $0x4, %r15
addq 0x58(%rsp), %r14
jmp 0x13420
movq 0x50(%rsp), %r15
incq %r15
movq 0x20(%rsp), %rax
addq 0x40(%rsp), %rax
movq %rax, 0x20(%rsp)
jmp 0x13335
leaq 0x60a7(%rip), %rax      # 0x1950c
jmp 0x1346e
leaq 0x6087(%rip), %rax      # 0x194f5
movq %rax, 0xcf93(%rip)      # 0x20408
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 0x83d0
jmp 0x134f2
leaq 0x68(%rsp), %r15
movb %bpl, (%r15)
movb %r14b, 0x1(%r15)
movb %al, 0x2(%r15)
movq %rbx, %rdi
callq 0x142b0
movb %al, 0x3(%r15)
movq (%rsp), %rdi
movq %r15, %rsi
movl 0x8(%rsp), %edx
callq 0x16d3c
movq %r13, %rdi
callq 0x83d0
xorl %r15d, %r15d
jmp 0x13504
movq (%rsp), %rdi
callq 0x83d0
movq %r13, %rdi
callq 0x83d0
leaq 0x6040(%rip), %rax      # 0x19524
jmp 0x1346e
incl %r15d
xorl %ebp, %ebp
cmpl 0x18(%rsp), %r15d
jl 0x134fb
movq (%rsp), %rax
jmp 0x13477
cmpl %r12d, %ebp
jge 0x134e6
movl %ebp, 0x14(%rsp)
leaq 0x6c(%rsp), %r14
pushq $0x4
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x15ac6
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 0x16d3c
incl %ebp
jmp 0x134fb