// File: /workspace/github_c_makefile_star2_O2/zhiyb[P]png2tlg/./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 0xe9b3
leaq 0x7ba2(%rip), %rsi      # 0x1118e
pushq $0xb
popq %rdx
movq %r15, %rdi
callq 0x2190
testl %eax, %eax
je 0x961f
leaq 0x7b97(%rip), %rsi      # 0x11199
leaq 0x70(%rsp), %rdi
pushq $0x7
popq %rdx
callq 0x2190
testl %eax, %eax
je 0x961f
leaq 0x7b86(%rip), %rax      # 0x111a0
jmp 0x9958
movq %r13, 0x28(%rsp)
movq %r12, (%rsp)
movq %r14, 0x8(%rsp)
movl %ebp, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0x70(%rsp), %r12
leaq 0x7b68(%rip), %r15      # 0x111a8
pushq $0x17
popq %r13
pushq $0x1
popq %rbp
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe9b3
cmpb $0x0, 0x70(%rsp)
je 0x966f
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2190
testl %eax, %eax
cmovel %ebp, %r14d
jmp 0x9647
testl %r14d, %r14d
je 0x9951
leaq 0x70(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe9b3
leaq 0x7b43(%rip), %rsi      # 0x111d2
pushq $0x3
popq %rdx
movq %r15, %rdi
callq 0x2190
testl %eax, %eax
jne 0x9948
leaq 0x73(%rsp), %rdi
leaq 0x60(%rsp), %r15
movq %rdi, (%r15)
pushq $0xa
popq %rdx
movq %r15, %rsi
callq 0x2220
movq %rax, %r13
movq (%r15), %rdi
addq $0x2, %rdi
movb -0x2(%rdi), %al
incq %rdi
cmpb $0x20, %al
je 0x96c4
cmpb $0x2b, %al
jne 0x9948
cmpb $0x58, -0x2(%rdi)
jne 0x9948
cmpb $0x20, -0x1(%rdi)
jne 0x9948
movq %rdi, 0x60(%rsp)
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x2220
movq %rax, %r14
movq 0x28(%rsp), %rax
movl %r14d, (%rax)
movq (%rsp), %rax
movl %r13d, (%rax)
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x971b
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 0xea20
testl %eax, %eax
je 0x9977
movl %r14d, %edi
movl %r13d, %esi
movl %r15d, 0x8(%rsp)
movl %r15d, %edx
callq 0xea7c
testq %rax, %rax
je 0x9a03
movq %rax, %r15
leal -0x8000(%r14), %eax
xorl %r12d, %r12d
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
movq %r14, 0x10(%rsp)
jb 0x9a12
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 0x999c
movq %rdi, (%rsp)
movq %rbx, %rdi
callq 0xae91
movl %eax, %r12d
movq %rbx, %rdi
callq 0xae91
movl %eax, %r14d
movq %rbx, %rdi
callq 0xae91
cmpb $0x2, %r12b
jne 0x99a3
cmpb $0x2, %r14b
jne 0x99a3
testb %al, %al
js 0x99a3
movzbl %al, %r14d
shll $0x8, %r14d
movq %rbx, %rdi
callq 0xae91
movzbl %al, %eax
orl %r14d, %eax
movq 0x10(%rsp), %rdi
cmpl %edi, %eax
jne 0x99de
movq (%rsp), %rax
testq %rax, %rax
jne 0x9847
pushq $0x4
popq %rsi
xorl %edx, %edx
callq 0xb13b
testq %rax, %rax
je 0x99fb
movq %rax, (%rsp)
movq %rax, %r14
xorl %eax, %eax
movq %r13, 0x48(%rsp)
movq %r15, 0x20(%rsp)
cmpq $0x4, %rax
je 0x98ef
movq %rax, 0x50(%rsp)
xorl %r13d, %r13d
movq 0x10(%rsp), %rax
movl %eax, %r15d
subl %r13d, %r15d
jle 0x98d5
movq %rbx, %rdi
callq 0xae91
movzbl %al, %r12d
cmpb $-0x7f, %r12b
jb 0x98b2
movq %rbx, %rdi
callq 0xae91
andl $0x7f, %r12d
cmpl %r12d, %r15d
jb 0x9980
movslq %r13d, %r13
subl $0x1, %r12d
jb 0x986c
movb %al, (%r14,%r13,4)
incq %r13
jmp 0x98a3
cmpl %r12d, %r15d
jb 0x9980
movslq %r13d, %r13
subl $0x1, %r12d
jb 0x986c
movq %rbx, %rdi
callq 0xae91
movb %al, (%r14,%r13,4)
incq %r13
jmp 0x98be
movq 0x50(%rsp), %rax
incq %rax
incq %r14
movq 0x48(%rsp), %r13
movq 0x20(%rsp), %r15
jmp 0x985a
movq %r15, %r12
movq 0x18(%rsp), %r14
xorl %r15d, %r15d
cmpq %r15, 0x28(%rsp)
je 0x9920
movq (%rsp), %rax
leaq (%rax,%r15), %rsi
movq %r14, %rdi
movl 0x8(%rsp), %edx
callq 0xeaad
addq $0x4, %r15
addq 0x58(%rsp), %r14
jmp 0x98fa
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 0x97bc
leaq 0x7887(%rip), %rax      # 0x111d6
jmp 0x9958
leaq 0x7867(%rip), %rax      # 0x111bf
movq %rax, 0xb8b9(%rip)      # 0x15218
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 0x7151(%rip), %rax      # 0x10acf
jmp 0x9958
movq 0x20(%rsp), %rdi
callq 0x21c0
movq (%rsp), %rdi
callq 0x21c0
leaq 0x7a0b(%rip), %rax      # 0x113a5
jmp 0x9958
callq 0x21c0
jmp 0x9962
leaq 0x68(%rsp), %rcx
movb %r12b, (%rcx)
movb %r14b, 0x1(%rcx)
movb %al, 0x2(%rcx)
movq %rcx, %r14
movq %rbx, %rdi
callq 0xae91
movb %al, 0x3(%r14)
movq %r15, %rdi
movq %r14, %rsi
movl 0x8(%rsp), %edx
callq 0xeaad
movq (%rsp), %rdi
callq 0x21c0
xorl %r12d, %r12d
jmp 0x9a25
movq %r15, %rdi
callq 0x21c0
movq (%rsp), %rdi
callq 0x21c0
leaq 0x77f8(%rip), %rax      # 0x111ee
jmp 0x9958
movq %r15, %rdi
callq 0x21c0
leaq 0x70cf(%rip), %rax      # 0x10ad9
jmp 0x9958
incl %r12d
movl $0x0, %ebp
cmpl %r13d, %r12d
jge 0x9962
cmpl %r14d, %ebp
jge 0x9a0f
leaq 0x6c(%rsp), %r14
pushq $0x4
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xcd35
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 0xeaad
incl %ebp
jmp 0x9a20