// File: srajangarg[P]raytracer/src/core/stb_image.hpp
// Function: stbi__process_scan_header(stbi__jpeg*)
static int stbi__process_scan_header(stbi__jpeg *z)
{
   int i;
   int Ls = stbi__get16be(z->s);
   z->scan_n = stbi__get8(z->s);
   if (z->scan_n < 1 || z->scan_n > 4 || z->scan_n > (int) z->s->img_n) return stbi__err("bad SOS component count","Corrupt JPEG");
   if (Ls != 6+2*z->scan_n) return stbi__err("bad SOS len","Corrupt JPEG");
   for (i=0; i < z->scan_n; ++i) {
      int id = stbi__get8(z->s), which;
      int q = stbi__get8(z->s);
      for (which = 0; which < z->s->img_n; ++which)
         if (z->img_comp[which].id == id)
            break;
      if (which == z->s->img_n) return 0; // no match
      z->img_comp[which].hd = q >> 4;   if (z->img_comp[which].hd > 3) return stbi__err("bad DC huff","Corrupt JPEG");
      z->img_comp[which].ha = q & 15;   if (z->img_comp[which].ha > 3) return stbi__err("bad AC huff","Corrupt JPEG");
      z->order[i] = which;
   }

   {
      int aa;
      z->spec_start = stbi__get8(z->s);
      z->spec_end   = stbi__get8(z->s); // should be 63, but might be 0
      aa = stbi__get8(z->s);
      z->succ_high = (aa >> 4);
      z->succ_low  = (aa & 15);
      if (z->progressive) {
         if (z->spec_start > 63 || z->spec_end > 63  || z->spec_start > z->spec_end || z->succ_high > 13 || z->succ_low > 13)
            return stbi__err("bad SOS", "Corrupt JPEG");
      } else {
         if (z->spec_start != 0) return stbi__err("bad SOS","Corrupt JPEG");
         if (z->succ_high != 0 || z->succ_low != 0) return stbi__err("bad SOS","Corrupt JPEG");
         z->spec_end = 63;
      }
   }

   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2cf90
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2ce50
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4748(%rax)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x4748(%rax)
jl 0x2e1b4
movq -0x10(%rbp), %rax
cmpl $0x4, 0x4748(%rax)
jg 0x2e1b4
movq -0x10(%rbp), %rax
movl 0x4748(%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jle 0x2e1c8
leaq 0x19e53(%rip), %rdi     # 0x4800e
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x2e472
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x4748(%rcx), %ecx
shll %ecx
addl $0x6, %ecx
cmpl %ecx, %eax
je 0x2e1f2
leaq 0x19e41(%rip), %rdi     # 0x48026
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x2e472
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4748(%rcx), %eax
jge 0x2e346
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2ce50
movzbl %al, %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2ce50
movzbl %al, %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0x2e271
movq -0x10(%rbp), %rax
addq $0x45a0, %rax           # imm = 0x45A0
movslq -0x20(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x2e264
jmp 0x2e271
jmp 0x2e266
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2e237
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jne 0x2e28c
movl $0x0, -0x4(%rbp)
jmp 0x2e472
movl -0x24(%rbp), %ecx
sarl $0x4, %ecx
movq -0x10(%rbp), %rax
addq $0x45a0, %rax           # imm = 0x45A0
movslq -0x20(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
addq $0x45a0, %rax           # imm = 0x45A0
movslq -0x20(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
cmpl $0x3, 0x10(%rax)
jle 0x2e2d9
leaq 0x19d66(%rip), %rdi     # 0x48032
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x2e472
movl -0x24(%rbp), %ecx
andl $0xf, %ecx
movq -0x10(%rbp), %rax
addq $0x45a0, %rax           # imm = 0x45A0
movslq -0x20(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
addq $0x45a0, %rax           # imm = 0x45A0
movslq -0x20(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
cmpl $0x3, 0x14(%rax)
jle 0x2e326
leaq 0x19d25(%rip), %rdi     # 0x4803e
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x2e472
movl -0x20(%rbp), %edx
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl %edx, 0x474c(%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2e1f9
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2ce50
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4734(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2ce50
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4738(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2ce50
movzbl %al, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %ecx
sarl $0x4, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x473c(%rax)
movl -0x28(%rbp), %ecx
andl $0xf, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4740(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4730(%rax)
je 0x2e414
movq -0x10(%rbp), %rax
cmpl $0x3f, 0x4734(%rax)
jg 0x2e401
movq -0x10(%rbp), %rax
cmpl $0x3f, 0x4738(%rax)
jg 0x2e401
movq -0x10(%rbp), %rax
movl 0x4734(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4738(%rcx), %eax
jg 0x2e401
movq -0x10(%rbp), %rax
cmpl $0xd, 0x473c(%rax)
jg 0x2e401
movq -0x10(%rbp), %rax
cmpl $0xd, 0x4740(%rax)
jle 0x2e412
leaq 0x19c42(%rip), %rdi     # 0x4804a
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x2e472
jmp 0x2e46b
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4734(%rax)
je 0x2e432
leaq 0x19c22(%rip), %rdi     # 0x4804a
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x2e472
movq -0x10(%rbp), %rax
cmpl $0x0, 0x473c(%rax)
jne 0x2e44c
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4740(%rax)
je 0x2e45d
leaq 0x19bf7(%rip), %rdi     # 0x4804a
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x2e472
movq -0x10(%rbp), %rax
movl $0x3f, 0x4738(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)