// File: srajangarg[P]raytracer/src/core/stb_image.hpp
// Function: stbi__gif_load_next(stbi__context*, stbi__gif*, int*, int)
static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, int req_comp)
{
   int i;
   stbi_uc *prev_out = 0;

   if (g->out == 0 && !stbi__gif_header(s, g, comp,0))
      return 0; // stbi__g_failure_reason set by stbi__gif_header

   prev_out = g->out;
   g->out = (stbi_uc *) stbi__malloc(4 * g->w * g->h);
   if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory");

   switch ((g->eflags & 0x1C) >> 2) {
      case 0: // unspecified (also always used on 1st frame)
         stbi__fill_gif_background(g, 0, 0, 4 * g->w, 4 * g->w * g->h);
         break;
      case 1: // do not dispose
         if (prev_out) memcpy(g->out, prev_out, 4 * g->w * g->h);
         g->old_out = prev_out;
         break;
      case 2: // dispose to background
         if (prev_out) memcpy(g->out, prev_out, 4 * g->w * g->h);
         stbi__fill_gif_background(g, g->start_x, g->start_y, g->max_x, g->max_y);
         break;
      case 3: // dispose to previous
         if (g->old_out) {
            for (i = g->start_y; i < g->max_y; i += 4 * g->w)
               memcpy(&g->out[i + g->start_x], &g->old_out[i + g->start_x], g->max_x - g->start_x);
         }
         break;
   }

   for (;;) {
      switch (stbi__get8(s)) {
         case 0x2C: /* Image Descriptor */
         {
            int prev_trans = -1;
            stbi__int32 x, y, w, h;
            stbi_uc *o;

            x = stbi__get16le(s);
            y = stbi__get16le(s);
            w = stbi__get16le(s);
            h = stbi__get16le(s);
            if (((x + w) > (g->w)) || ((y + h) > (g->h)))
               return stbi__errpuc("bad Image Descriptor", "Corrupt GIF");

            g->line_size = g->w * 4;
            g->start_x = x * 4;
            g->start_y = y * g->line_size;
            g->max_x   = g->start_x + w * 4;
            g->max_y   = g->start_y + h * g->line_size;
            g->cur_x   = g->start_x;
            g->cur_y   = g->start_y;

            g->lflags = stbi__get8(s);

            if (g->lflags & 0x40) {
               g->step = 8 * g->line_size; // first interlaced spacing
               g->parse = 3;
            } else {
               g->step = g->line_size;
               g->parse = 0;
            }

            if (g->lflags & 0x80) {
               stbi__gif_parse_colortable(s,g->lpal, 2 << (g->lflags & 7), g->eflags & 0x01 ? g->transparent : -1);
               g->color_table = (stbi_uc *) g->lpal;
            } else if (g->flags & 0x80) {
               if (g->transparent >= 0 && (g->eflags & 0x01)) {
                  prev_trans = g->pal[g->transparent][3];
                  g->pal[g->transparent][3] = 0;
               }
               g->color_table = (stbi_uc *) g->pal;
            } else
               return stbi__errpuc("missing color table", "Corrupt GIF");

            o = stbi__process_gif_raster(s, g);
            if (o == NULL) return NULL;

            if (prev_trans != -1)
               g->pal[g->transparent][3] = (stbi_uc) prev_trans;

            return o;
         }

         case 0x21: // Comment Extension.
         {
            int len;
            if (stbi__get8(s) == 0xF9) { // Graphic Control Extension.
               len = stbi__get8(s);
               if (len == 4) {
                  g->eflags = stbi__get8(s);
                  g->delay = stbi__get16le(s);
                  g->transparent = stbi__get8(s);
               } else {
                  stbi__skip(s, len);
                  break;
               }
            }
            while ((len = stbi__get8(s)) != 0)
               stbi__skip(s, len);
            break;
         }

         case 0x3B: // gif stream termination code
            return (stbi_uc *) s; // using '1' causes warning on some compilers

         default:
            return stbi__errpuc("unknown code", "Corrupt GIF");
      }
   }

   STBI_NOTUSED(req_comp);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x33b02
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
xorl %ecx, %ecx
callq 0x340f0
cmpl $0x0, %eax
jne 0x33b02
movq $0x0, -0x8(%rbp)
jmp 0x340d5
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
shll $0x2, %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movslq %eax, %rdi
callq 0x27f20
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x33b5d
leaq 0x144a1(%rip), %rdi     # 0x47fe5
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x340d5
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x1c, %eax
shrl $0x2, %eax
movl %eax, %ecx
movq %rcx, -0x60(%rbp)
subl $0x3, %eax
ja 0x33ce8
movq -0x60(%rbp), %rax
leaq 0x14228(%rip), %rcx     # 0x47dac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %ecx
shll $0x2, %ecx
movq -0x18(%rbp), %rax
movl (%rax), %r8d
shll $0x2, %r8d
movq -0x18(%rbp), %rax
imull 0x4(%rax), %r8d
xorl %edx, %edx
movl %edx, %esi
callq 0x342a0
jmp 0x33ce8
cmpq $0x0, -0x30(%rbp)
je 0x33be8
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x18(%rbp), %rax
movl (%rax), %eax
shll $0x2, %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movslq %eax, %rdx
callq 0x5370
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x33ce8
cmpq $0x0, -0x30(%rbp)
je 0x33c25
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x18(%rbp), %rax
movl (%rax), %eax
shll $0x2, %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movslq %eax, %rdx
callq 0x5370
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x4844(%rax), %esi
movq -0x18(%rbp), %rax
movl 0x4848(%rax), %edx
movq -0x18(%rbp), %rax
movl 0x484c(%rax), %ecx
movq -0x18(%rbp), %rax
movl 0x4850(%rax), %r8d
callq 0x342a0
jmp 0x33ce8
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x33ce6
movq -0x18(%rbp), %rax
movl 0x4848(%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4850(%rcx), %eax
jge 0x33ce4
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
addl 0x4844(%rcx), %eax
cltq
addq %rax, %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
addl 0x4844(%rcx), %eax
cltq
addq %rax, %rsi
movq -0x18(%rbp), %rax
movl 0x484c(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x4844(%rcx), %eax
movslq %eax, %rdx
callq 0x5370
movq -0x18(%rbp), %rax
movl (%rax), %eax
shll $0x2, %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x33c74
jmp 0x33ce6
jmp 0x33ce8
jmp 0x33cea
movq -0x10(%rbp), %rdi
callq 0x2ce50
movzbl %al, %ecx
movl %ecx, -0x64(%rbp)
subb $0x21, %al
je 0x34011
jmp 0x33d03
movl -0x64(%rbp), %eax
subl $0x2c, %eax
je 0x33d1e
jmp 0x33d0d
movl -0x64(%rbp), %eax
subl $0x3b, %eax
je 0x340a9
jmp 0x340b3
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
callq 0x28370
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x28370
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x28370
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x28370
movl %eax, -0x44(%rbp)
movl -0x38(%rbp), %eax
addl -0x40(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jg 0x33d72
movl -0x3c(%rbp), %eax
addl -0x44(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jle 0x33d92
leaq 0x14740(%rip), %rdi     # 0x484b9
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x340d5
movq -0x18(%rbp), %rax
movl (%rax), %ecx
shll $0x2, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x485c(%rax)
movl -0x38(%rbp), %ecx
shll $0x2, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4844(%rax)
movl -0x3c(%rbp), %ecx
movq -0x18(%rbp), %rax
imull 0x485c(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4848(%rax)
movq -0x18(%rbp), %rax
movl 0x4844(%rax), %ecx
movl -0x40(%rbp), %eax
shll $0x2, %eax
addl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x484c(%rax)
movq -0x18(%rbp), %rax
movl 0x4848(%rax), %ecx
movl -0x44(%rbp), %eax
movq -0x18(%rbp), %rdx
imull 0x485c(%rdx), %eax
addl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4850(%rax)
movq -0x18(%rbp), %rax
movl 0x4844(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4854(%rax)
movq -0x18(%rbp), %rax
movl 0x4848(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4858(%rax)
movq -0x10(%rbp), %rdi
callq 0x2ce50
movzbl %al, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4840(%rax)
movq -0x18(%rbp), %rax
movl 0x4840(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x33e84
movq -0x18(%rbp), %rax
movl 0x485c(%rax), %ecx
shll $0x3, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x483c(%rax)
movq -0x18(%rbp), %rax
movl $0x3, 0x4838(%rax)
jmp 0x33ea6
movq -0x18(%rbp), %rax
movl 0x485c(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x483c(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x4838(%rax)
movq -0x18(%rbp), %rax
movl 0x4840(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x33f3e
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
addq $0x430, %rax            # imm = 0x430
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movl 0x4840(%rax), %ecx
andl $0x7, %ecx
movl $0x2, %eax
shll %cl, %eax
movl %eax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x33f06
movq -0x18(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x7c(%rbp)
jmp 0x33f10
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x7c(%rbp)
jmp 0x33f10
movl -0x68(%rbp), %edx
movq -0x70(%rbp), %rsi
movq -0x78(%rbp), %rdi
movl -0x7c(%rbp), %ecx
callq 0x34360
movq -0x18(%rbp), %rcx
addq $0x430, %rcx            # imm = 0x430
movq -0x18(%rbp), %rax
movq %rcx, 0x4830(%rax)
jmp 0x33fc4
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x33fa2
movq -0x18(%rbp), %rax
cmpl $0x0, 0x24(%rax)
jl 0x33f8d
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x33f8d
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0x24(%rcx), %rcx
movzbl 0x33(%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0x24(%rcx), %rcx
movb $0x0, 0x33(%rax,%rcx,4)
movq -0x18(%rbp), %rcx
addq $0x30, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x4830(%rax)
jmp 0x33fc2
leaq 0x14525(%rip), %rdi     # 0x484ce
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x340d5
jmp 0x33fc4
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x34400
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x33fe9
movq $0x0, -0x8(%rbp)
jmp 0x340d5
cmpl $-0x1, -0x34(%rbp)
je 0x34004
movl -0x34(%rbp), %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0x24(%rcx), %rcx
movb %dl, 0x33(%rax,%rcx,4)
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x340d5
movq -0x10(%rbp), %rdi
callq 0x2ce50
movzbl %al, %eax
cmpl $0xf9, %eax
jne 0x34083
movq -0x10(%rbp), %rdi
callq 0x2ce50
movzbl %al, %eax
movl %eax, -0x54(%rbp)
cmpl $0x4, -0x54(%rbp)
jne 0x34073
movq -0x10(%rbp), %rdi
callq 0x2ce50
movzbl %al, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rdi
callq 0x28370
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x10(%rbp), %rdi
callq 0x2ce50
movzbl %al, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x24(%rax)
jmp 0x34081
movq -0x10(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x2d340
jmp 0x340d0
jmp 0x34083
jmp 0x34085
movq -0x10(%rbp), %rdi
callq 0x2ce50
movzbl %al, %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, %eax
je 0x340a7
movq -0x10(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x2d340
jmp 0x34085
jmp 0x340d0
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x340d5
leaq 0x14428(%rip), %rdi     # 0x484e2
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x340d5
jmp 0x33cea
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)