// File: srajangarg[P]raytracer/src/core/stb_image.hpp
// Function: stbi__process_gif_raster(stbi__context*, stbi__gif*)
static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g)
{
   stbi_uc lzw_cs;
   stbi__int32 len, init_code;
   stbi__uint32 first;
   stbi__int32 codesize, codemask, avail, oldcode, bits, valid_bits, clear;
   stbi__gif_lzw *p;

   lzw_cs = stbi__get8(s);
   if (lzw_cs > 12) return NULL;
   clear = 1 << lzw_cs;
   first = 1;
   codesize = lzw_cs + 1;
   codemask = (1 << codesize) - 1;
   bits = 0;
   valid_bits = 0;
   for (init_code = 0; init_code < clear; init_code++) {
      g->codes[init_code].prefix = -1;
      g->codes[init_code].first = (stbi_uc) init_code;
      g->codes[init_code].suffix = (stbi_uc) init_code;
   }

   // support no starting clear code
   avail = clear+2;
   oldcode = -1;

   len = 0;
   for(;;) {
      if (valid_bits < codesize) {
         if (len == 0) {
            len = stbi__get8(s); // start new block
            if (len == 0)
               return g->out;
         }
         --len;
         bits |= (stbi__int32) stbi__get8(s) << valid_bits;
         valid_bits += 8;
      } else {
         stbi__int32 code = bits & codemask;
         bits >>= codesize;
         valid_bits -= codesize;
         // @OPTIMIZE: is there some way we can accelerate the non-clear path?
         if (code == clear) {  // clear code
            codesize = lzw_cs + 1;
            codemask = (1 << codesize) - 1;
            avail = clear + 2;
            oldcode = -1;
            first = 0;
         } else if (code == clear + 1) { // end of stream code
            stbi__skip(s, len);
            while ((len = stbi__get8(s)) > 0)
               stbi__skip(s,len);
            return g->out;
         } else if (code <= avail) {
            if (first) return stbi__errpuc("no clear code", "Corrupt GIF");

            if (oldcode >= 0) {
               p = &g->codes[avail++];
               if (avail > 4096)        return stbi__errpuc("too many codes", "Corrupt GIF");
               p->prefix = (stbi__int16) oldcode;
               p->first = g->codes[oldcode].first;
               p->suffix = (code == avail) ? p->first : g->codes[code].first;
            } else if (code == avail)
               return stbi__errpuc("illegal code in raster", "Corrupt GIF");

            stbi__out_gif_code(g, (stbi__uint16) code);

            if ((avail & codemask) == 0 && avail <= 0x0FFF) {
               codesize++;
               codemask = (1 << codesize) - 1;
            }

            oldcode = code;
         } else {
            return stbi__errpuc("illegal code in raster", "Corrupt GIF");
         }
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2ce50
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0xc, %eax
jle 0x34432
movq $0x0, -0x8(%rbp)
jmp 0x34757
movzbl -0x19(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x44(%rbp)
movl $0x1, -0x28(%rbp)
movzbl -0x19(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x344c3
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movw $0xffff, 0x830(%rax,%rcx,4) # imm = 0xFFFF
movl -0x24(%rbp), %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movb %dl, 0x832(%rax,%rcx,4)
movl -0x24(%rbp), %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movb %dl, 0x833(%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x34476
movl -0x44(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x34(%rbp)
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x20(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x3453e
cmpl $0x0, -0x20(%rbp)
jne 0x34510
movq -0x10(%rbp), %rdi
callq 0x2ce50
movzbl %al, %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x3450e
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x34757
jmp 0x34510
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2ce50
movzbl %al, %eax
movl -0x40(%rbp), %ecx
shll %cl, %eax
orl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x40(%rbp)
jmp 0x34752
movl -0x3c(%rbp), %eax
andl -0x30(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x2c(%rbp), %ecx
movl -0x3c(%rbp), %eax
sarl %cl, %eax
movl %eax, -0x3c(%rbp)
movl -0x2c(%rbp), %ecx
movl -0x40(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x44(%rbp), %eax
jne 0x3459b
movzbl -0x19(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x44(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x34(%rbp)
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x28(%rbp)
jmp 0x34750
movl -0x54(%rbp), %eax
movl -0x44(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x345e7
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x2d340
movq -0x10(%rbp), %rdi
callq 0x2ce50
movzbl %al, %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, %eax
jle 0x345d6
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x2d340
jmp 0x345b4
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x34757
movl -0x54(%rbp), %eax
cmpl -0x34(%rbp), %eax
jg 0x3472f
cmpl $0x0, -0x28(%rbp)
je 0x34619
leaq 0x13ef7(%rip), %rdi     # 0x484f7
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x34757
cmpl $0x0, -0x38(%rbp)
jl 0x346c4
movq -0x18(%rbp), %rax
addq $0x830, %rax            # imm = 0x830
movl -0x34(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x34(%rbp)
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
cmpl $0x1000, -0x34(%rbp)    # imm = 0x1000
jle 0x3466f
leaq 0x13eaf(%rip), %rdi     # 0x48505
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x34757
movl -0x38(%rbp), %eax
movw %ax, %cx
movq -0x50(%rbp), %rax
movw %cx, (%rax)
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb 0x832(%rax,%rcx,4), %cl
movq -0x50(%rbp), %rax
movb %cl, 0x2(%rax)
movl -0x54(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x346a6
movq -0x50(%rbp), %rax
movb 0x2(%rax), %al
movb %al, -0x55(%rbp)
jmp 0x346b8
movq -0x18(%rbp), %rax
movslq -0x54(%rbp), %rcx
movb 0x832(%rax,%rcx,4), %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %cl
movq -0x50(%rbp), %rax
movb %cl, 0x3(%rax)
jmp 0x346eb
movl -0x54(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x346e9
leaq 0x13e41(%rip), %rdi     # 0x48514
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x34757
jmp 0x346eb
movq -0x18(%rbp), %rdi
movl -0x54(%rbp), %eax
movzwl %ax, %esi
callq 0x34770
movl -0x34(%rbp), %eax
andl -0x30(%rbp), %eax
cmpl $0x0, %eax
jne 0x34727
cmpl $0xfff, -0x34(%rbp)     # imm = 0xFFF
jg 0x34727
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x3474c
leaq 0x13dde(%rip), %rdi     # 0x48514
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x34757
jmp 0x3474e
jmp 0x34750
jmp 0x34752
jmp 0x344da
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)