// File: srajangarg[P]raytracer/src/core/stb_image.hpp
// Function: stbi__bmp_parse_header(stbi__context*, stbi__bmp_data*)
static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info)
{
   int hsz;
   if (stbi__get8(s) != 'B' || stbi__get8(s) != 'M') return stbi__errpuc("not BMP", "Corrupt BMP");
   stbi__get32le(s); // discard filesize
   stbi__get16le(s); // discard reserved
   stbi__get16le(s); // discard reserved
   info->offset = stbi__get32le(s);
   info->hsz = hsz = stbi__get32le(s);
   
   if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108 && hsz != 124) return stbi__errpuc("unknown BMP", "BMP type not supported: unknown");
   if (hsz == 12) {
      s->img_x = stbi__get16le(s);
      s->img_y = stbi__get16le(s);
   } else {
      s->img_x = stbi__get32le(s);
      s->img_y = stbi__get32le(s);
   }
   if (stbi__get16le(s) != 1) return stbi__errpuc("bad BMP", "bad BMP");
   info->bpp = stbi__get16le(s);
   if (info->bpp == 1) return stbi__errpuc("monochrome", "BMP type not supported: 1-bit");
   if (hsz != 12) {
      int compress = stbi__get32le(s);
      if (compress == 1 || compress == 2) return stbi__errpuc("BMP RLE", "BMP type not supported: RLE");
      stbi__get32le(s); // discard sizeof
      stbi__get32le(s); // discard hres
      stbi__get32le(s); // discard vres
      stbi__get32le(s); // discard colorsused
      stbi__get32le(s); // discard max important
      if (hsz == 40 || hsz == 56) {
         if (hsz == 56) {
            stbi__get32le(s);
            stbi__get32le(s);
            stbi__get32le(s);
            stbi__get32le(s);
         }
         if (info->bpp == 16 || info->bpp == 32) {
            info->mr = info->mg = info->mb = 0;
            if (compress == 0) {
               if (info->bpp == 32) {
                  info->mr = 0xffu << 16;
                  info->mg = 0xffu <<  8;
                  info->mb = 0xffu <<  0;
                  info->ma = 0xffu << 24;
                  info->all_a = 0; // if all_a is 0 at end, then we loaded alpha channel but it was all 0
               } else {
                  info->mr = 31u << 10;
                  info->mg = 31u <<  5;
                  info->mb = 31u <<  0;
               }
            } else if (compress == 3) {
               info->mr = stbi__get32le(s);
               info->mg = stbi__get32le(s);
               info->mb = stbi__get32le(s);
               // not documented, but generated by photoshop and handled by mspaint
               if (info->mr == info->mg && info->mg == info->mb) {
                  // ?!?!?
                  return stbi__errpuc("bad BMP", "bad BMP");
               }
            } else
               return stbi__errpuc("bad BMP", "bad BMP");
         }
      } else {
         int i;
         if (hsz != 108 && hsz != 124)
            return stbi__errpuc("bad BMP", "bad BMP");
         info->mr = stbi__get32le(s);
         info->mg = stbi__get32le(s);
         info->mb = stbi__get32le(s);
         info->ma = stbi__get32le(s);
         stbi__get32le(s); // discard color space
         for (i=0; i < 12; ++i)
            stbi__get32le(s); // discard color space parameters
         if (hsz == 124) {
            stbi__get32le(s); // discard rendering intent
            stbi__get32le(s); // discard offset of profile data
            stbi__get32le(s); // discard size of profile data
            stbi__get32le(s); // discard reserved
         }
      }
   }
   return (void *) 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2ce50
movzbl %al, %eax
cmpl $0x42, %eax
jne 0x33432
movq -0x10(%rbp), %rdi
callq 0x2ce50
movzbl %al, %eax
cmpl $0x4d, %eax
je 0x33452
leaq 0x15051(%rip), %rdi     # 0x4848a
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x33852
movq -0x10(%rbp), %rdi
callq 0x333c0
movq -0x10(%rbp), %rdi
callq 0x28370
movq -0x10(%rbp), %rdi
callq 0x28370
movq -0x10(%rbp), %rdi
callq 0x333c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rdi
callq 0x333c0
movl %eax, %ecx
movl %ecx, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
cmpl $0xc, -0x1c(%rbp)
je 0x334d2
cmpl $0x28, -0x1c(%rbp)
je 0x334d2
cmpl $0x38, -0x1c(%rbp)
je 0x334d2
cmpl $0x6c, -0x1c(%rbp)
je 0x334d2
cmpl $0x7c, -0x1c(%rbp)
je 0x334d2
leaq 0x14fd9(%rip), %rdi     # 0x48492
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x33852
cmpl $0xc, -0x1c(%rbp)
jne 0x334fd
movq -0x10(%rbp), %rdi
callq 0x28370
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
callq 0x28370
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x33520
movq -0x10(%rbp), %rdi
callq 0x333c0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
callq 0x333c0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rdi
callq 0x28370
cmpl $0x1, %eax
je 0x3354e
leaq 0x14f69(%rip), %rdi     # 0x4849e
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x33852
movq -0x10(%rbp), %rdi
callq 0x28370
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x33588
leaq 0x14f37(%rip), %rdi     # 0x484a6
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x33852
cmpl $0xc, -0x1c(%rbp)
je 0x33849
movq -0x10(%rbp), %rdi
callq 0x333c0
movl %eax, -0x20(%rbp)
cmpl $0x1, -0x20(%rbp)
je 0x335aa
cmpl $0x2, -0x20(%rbp)
jne 0x335ca
leaq 0x14f00(%rip), %rdi     # 0x484b1
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x33852
movq -0x10(%rbp), %rdi
callq 0x333c0
movq -0x10(%rbp), %rdi
callq 0x333c0
movq -0x10(%rbp), %rdi
callq 0x333c0
movq -0x10(%rbp), %rdi
callq 0x333c0
movq -0x10(%rbp), %rdi
callq 0x333c0
cmpl $0x28, -0x1c(%rbp)
je 0x33607
cmpl $0x38, -0x1c(%rbp)
jne 0x3377d
cmpl $0x38, -0x1c(%rbp)
jne 0x33631
movq -0x10(%rbp), %rdi
callq 0x333c0
movq -0x10(%rbp), %rdi
callq 0x333c0
movq -0x10(%rbp), %rdi
callq 0x333c0
movq -0x10(%rbp), %rdi
callq 0x333c0
movq -0x18(%rbp), %rax
cmpl $0x10, (%rax)
je 0x33647
movq -0x18(%rbp), %rax
cmpl $0x20, (%rax)
jne 0x33778
movq -0x18(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0xc(%rax)
cmpl $0x0, -0x20(%rbp)
jne 0x336d6
movq -0x18(%rbp), %rax
cmpl $0x20, (%rax)
jne 0x336b0
movq -0x18(%rbp), %rax
movl $0xff0000, 0xc(%rax)    # imm = 0xFF0000
movq -0x18(%rbp), %rax
movl $0xff00, 0x10(%rax)     # imm = 0xFF00
movq -0x18(%rbp), %rax
movl $0xff, 0x14(%rax)
movq -0x18(%rbp), %rax
movl $0xff000000, 0x18(%rax) # imm = 0xFF000000
movq -0x18(%rbp), %rax
movl $0x0, 0x1c(%rax)
jmp 0x336d1
movq -0x18(%rbp), %rax
movl $0x7c00, 0xc(%rax)      # imm = 0x7C00
movq -0x18(%rbp), %rax
movl $0x3e0, 0x10(%rax)      # imm = 0x3E0
movq -0x18(%rbp), %rax
movl $0x1f, 0x14(%rax)
jmp 0x33776
cmpl $0x3, -0x20(%rbp)
jne 0x33754
movq -0x10(%rbp), %rdi
callq 0x333c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rdi
callq 0x333c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rdi
callq 0x333c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x33752
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jne 0x33752
leaq 0x14d65(%rip), %rdi     # 0x4849e
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x33852
jmp 0x33774
leaq 0x14d43(%rip), %rdi     # 0x4849e
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x33852
jmp 0x33776
jmp 0x33778
jmp 0x33847
cmpl $0x6c, -0x1c(%rbp)
je 0x337a9
cmpl $0x7c, -0x1c(%rbp)
je 0x337a9
leaq 0x14d0e(%rip), %rdi     # 0x4849e
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x33852
movq -0x10(%rbp), %rdi
callq 0x333c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rdi
callq 0x333c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rdi
callq 0x333c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rdi
callq 0x333c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rdi
callq 0x333c0
movl $0x0, -0x24(%rbp)
cmpl $0xc, -0x24(%rbp)
jge 0x3381b
movq -0x10(%rbp), %rdi
callq 0x333c0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x33801
cmpl $0x7c, -0x1c(%rbp)
jne 0x33845
movq -0x10(%rbp), %rdi
callq 0x333c0
movq -0x10(%rbp), %rdi
callq 0x333c0
movq -0x10(%rbp), %rdi
callq 0x333c0
movq -0x10(%rbp), %rdi
callq 0x333c0
jmp 0x33847
jmp 0x33849
movl $0x1, %eax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)