// File: /workspace/github_c_makefile_star2_O0/DavidSM64[P]n64graphics_ci/./stb/stb_image.h
// Function: stbi__gif_load_next
static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, int req_comp, stbi_uc *two_back)
{
   int dispose; 
   int first_frame; 
   int pi; 
   int pcount; 

   // on first frame, any non-written pixels get the background colour (non-transparent)
   first_frame = 0; 
   if (g->out == 0) {
      if (!stbi__gif_header(s, g, comp,0))     return 0; // stbi__g_failure_reason set by stbi__gif_header
      g->out = (stbi_uc *) stbi__malloc(4 * g->w * g->h);
      g->background = (stbi_uc *) stbi__malloc(4 * g->w * g->h); 
      g->history = (stbi_uc *) stbi__malloc(g->w * g->h); 
      if (g->out == 0)                      return stbi__errpuc("outofmem", "Out of memory");

      // image is treated as "tranparent" at the start - ie, nothing overwrites the current background; 
      // background colour is only used for pixels that are not rendered first frame, after that "background"
      // color refers to teh color that was there the previous frame. 
      memset( g->out, 0x00, 4 * g->w * g->h ); 
      memset( g->background, 0x00, 4 * g->w * g->h ); // state of the background (starts transparent)
      memset( g->history, 0x00, g->w * g->h );        // pixels that were affected previous frame
      first_frame = 1; 
   } else {
      // second frame - how do we dispoase of the previous one?
      dispose = (g->eflags & 0x1C) >> 2; 
      pcount = g->w * g->h; 

      if ((dispose == 3) && (two_back == 0)) {
         dispose = 2; // if I don't have an image to revert back to, default to the old background
      }

      if (dispose == 3) { // use previous graphic
         for (pi = 0; pi < pcount; ++pi) {
            if (g->history[pi]) {
               memcpy( &g->out[pi * 4], &two_back[pi * 4], 4 ); 
            }
         }
      } else if (dispose == 2) { 
         // restore what was changed last frame to background before that frame; 
         for (pi = 0; pi < pcount; ++pi) {
            if (g->history[pi]) {
               memcpy( &g->out[pi * 4], &g->background[pi * 4], 4 ); 
            }
         }
      } else {
         // This is a non-disposal case eithe way, so just 
         // leave the pixels as is, and they will become the new background
         // 1: do not dispose
         // 0:  not specified.
      }

      // background is what out is after the undoing of the previou frame; 
      memcpy( g->background, g->out, 4 * g->w * g->h ); 
   }

   // clear my history; 
   memset( g->history, 0x00, g->w * g->h );        // pixels that were affected previous frame

   for (;;) {
      int tag = stbi__get8(s); 
      switch (tag) {
         case 0x2C: /* Image Descriptor */
         {
            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) {
               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 this was the first frame, 
            pcount = g->w * g->h; 
            if (first_frame && (g->bgindex > 0)) {
               // if first frame, any pixel not drawn to gets the background color
               for (pi = 0; pi < pcount; ++pi) {
                  if (g->history[pi] == 0) {
                     g->pal[g->bgindex][3] = 255; // just in case it was made transparent, undo that; It will be reset next frame if need be; 
                     memcpy( &g->out[pi * 4], &g->pal[g->bgindex], 4 ); 
                  }
               }
            }

            return o;
         }

         case 0x21: // Comment Extension.
         {
            int len;
            int ext = stbi__get8(s); 
            if (ext == 0xF9) { // Graphic Control Extension.
               len = stbi__get8(s);
               if (len == 4) {
                  g->eflags = stbi__get8(s);
                  g->delay = 10 * stbi__get16le(s); // delay - 1/100th of a second, saving as 1/1000ths.

                  // unset old transparent
                  if (g->transparent >= 0) {
                     g->pal[g->transparent][3] = 255; 
                  } 
                  if (g->eflags & 0x01) {
                     g->transparent = stbi__get8(s);
                     if (g->transparent >= 0) {
                        g->pal[g->transparent][3] = 0; 
                     }
                  } else {
                     // don't need transparent
                     stbi__skip(s, 1); 
                     g->transparent = -1; 
                  }
               } 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");
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x1c0bf
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
xorl %ecx, %ecx
callq 0x1c6a0
cmpl $0x0, %eax
jne 0x1bfb9
movq $0x0, -0x8(%rbp)
jmp 0x1c68b
movq -0x18(%rbp), %rax
movl (%rax), %eax
shll $0x2, %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movslq %eax, %rdi
callq 0x55d0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
shll $0x2, %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movslq %eax, %rdi
callq 0x55d0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movslq %eax, %rdi
callq 0x55d0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x1c04d
leaq 0x726a(%rip), %rdi      # 0x2329e
callq 0x49c0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x1c68b
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %eax
shll $0x2, %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x1110
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %eax
shll $0x2, %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x1110
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x1110
movl $0x1, -0x38(%rbp)
jmp 0x1c1d9
movq -0x18(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1c, %eax
sarl $0x2, %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movl %eax, -0x40(%rbp)
cmpl $0x3, -0x34(%rbp)
jne 0x1c0f4
cmpq $0x0, -0x30(%rbp)
jne 0x1c0f4
movl $0x2, -0x34(%rbp)
cmpl $0x3, -0x34(%rbp)
jne 0x1c14e
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x1c14c
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x1c13f
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x3c(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movq -0x30(%rbp), %rdx
movl -0x3c(%rbp), %esi
shll $0x2, %esi
movslq %esi, %rsi
movl (%rdx,%rsi), %edx
movl %edx, (%rax,%rcx)
jmp 0x1c141
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1c101
jmp 0x1c1b0
cmpl $0x2, -0x34(%rbp)
jne 0x1c1ac
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x1c1aa
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x1c19d
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x3c(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movq -0x18(%rbp), %rdx
movq 0x10(%rdx), %rdx
movl -0x3c(%rbp), %esi
shll $0x2, %esi
movslq %esi, %rsi
movl (%rdx,%rsi), %edx
movl %edx, (%rax,%rcx)
jmp 0x1c19f
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1c15b
jmp 0x1c1ae
jmp 0x1c1ae
jmp 0x1c1b0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
movl (%rax), %eax
shll $0x2, %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movslq %eax, %rdx
callq 0x11b0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x1110
movq -0x10(%rbp), %rdi
callq 0x13f50
movzbl %al, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x6c(%rbp)
subl $0x21, %eax
je 0x1c556
jmp 0x1c219
movl -0x6c(%rbp), %eax
subl $0x2c, %eax
je 0x1c234
jmp 0x1c223
movl -0x6c(%rbp), %eax
subl $0x3b, %eax
je 0x1c65f
jmp 0x1c669
movq -0x10(%rbp), %rdi
callq 0x1b830
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1b830
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1b830
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1b830
movl %eax, -0x54(%rbp)
movl -0x48(%rbp), %eax
addl -0x50(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jg 0x1c281
movl -0x4c(%rbp), %eax
addl -0x54(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jle 0x1c2a1
leaq 0x75bf(%rip), %rdi      # 0x23847
callq 0x49c0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x1c68b
movq -0x18(%rbp), %rax
movl (%rax), %ecx
shll $0x2, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8864(%rax)
movl -0x48(%rbp), %ecx
shll $0x2, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x884c(%rax)
movl -0x4c(%rbp), %ecx
movq -0x18(%rbp), %rax
imull 0x8864(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8850(%rax)
movq -0x18(%rbp), %rax
movl 0x884c(%rax), %ecx
movl -0x50(%rbp), %eax
shll $0x2, %eax
addl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8854(%rax)
movq -0x18(%rbp), %rax
movl 0x8850(%rax), %ecx
movl -0x54(%rbp), %eax
movq -0x18(%rbp), %rdx
imull 0x8864(%rdx), %eax
addl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8858(%rax)
movq -0x18(%rbp), %rax
movl 0x884c(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x885c(%rax)
movq -0x18(%rbp), %rax
movl 0x8850(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8860(%rax)
movq -0x10(%rbp), %rdi
callq 0x13f50
movzbl %al, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8848(%rax)
movq -0x18(%rbp), %rax
movl 0x8848(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x1c393
movq -0x18(%rbp), %rax
movl 0x8864(%rax), %ecx
shll $0x3, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8844(%rax)
movq -0x18(%rbp), %rax
movl $0x3, 0x8840(%rax)
jmp 0x1c3b5
movq -0x18(%rbp), %rax
movl 0x8864(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8844(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x8840(%rax)
movq -0x18(%rbp), %rax
movl 0x8848(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x1c453
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
addq $0x434, %rax            # imm = 0x434
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movl 0x8848(%rax), %ecx
andl $0x7, %ecx
movl $0x2, %eax
shll %cl, %eax
movl %eax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1c418
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x84(%rbp)
jmp 0x1c425
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x84(%rbp)
jmp 0x1c425
movl -0x70(%rbp), %edx
movq -0x78(%rbp), %rsi
movq -0x80(%rbp), %rdi
movl -0x84(%rbp), %ecx
callq 0x1c850
movq -0x18(%rbp), %rcx
addq $0x434, %rcx            # imm = 0x434
movq -0x18(%rbp), %rax
movq %rcx, 0x8838(%rax)
jmp 0x1c49b
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x1c479
movq -0x18(%rbp), %rcx
addq $0x34, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8838(%rax)
jmp 0x1c499
leaq 0x73dc(%rip), %rdi      # 0x2385c
callq 0x49c0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x1c68b
jmp 0x1c49b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1c8f0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x1c4c0
movq $0x0, -0x8(%rbp)
jmp 0x1c68b
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x1c549
movq -0x18(%rbp), %rax
cmpl $0x0, 0x24(%rax)
jle 0x1c549
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x1c547
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1c53a
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0x24(%rcx), %rcx
movb $-0x1, 0x37(%rax,%rcx,4)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x3c(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movq -0x18(%rbp), %rdx
movq -0x18(%rbp), %rsi
movslq 0x24(%rsi), %rsi
movl 0x34(%rdx,%rsi,4), %edx
movl %edx, (%rax,%rcx)
jmp 0x1c53c
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1c4e8
jmp 0x1c549
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1c68b
movq -0x10(%rbp), %rdi
callq 0x13f50
movzbl %al, %eax
movl %eax, -0x68(%rbp)
cmpl $0xf9, -0x68(%rbp)
jne 0x1c639
movq -0x10(%rbp), %rdi
callq 0x13f50
movzbl %al, %eax
movl %eax, -0x64(%rbp)
cmpl $0x4, -0x64(%rbp)
jne 0x1c629
movq -0x10(%rbp), %rdi
callq 0x13f50
movzbl %al, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x10(%rbp), %rdi
callq 0x1b830
imull $0xa, %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8868(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jl 0x1c5cf
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0x2c(%rcx), %rcx
movb $-0x1, 0x37(%rax,%rcx,4)
movq -0x18(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1c60e
movq -0x10(%rbp), %rdi
callq 0x13f50
movzbl %al, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jl 0x1c60c
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0x2c(%rcx), %rcx
movb $0x0, 0x37(%rax,%rcx,4)
jmp 0x1c627
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x14440
movq -0x18(%rbp), %rax
movl $0xffffffff, 0x2c(%rax) # imm = 0xFFFFFFFF
jmp 0x1c637
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x14440
jmp 0x1c686
jmp 0x1c639
jmp 0x1c63b
movq -0x10(%rbp), %rdi
callq 0x13f50
movzbl %al, %eax
movl %eax, -0x64(%rbp)
cmpl $0x0, %eax
je 0x1c65d
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x14440
jmp 0x1c63b
jmp 0x1c686
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1c68b
leaq 0x7200(%rip), %rdi      # 0x23870
callq 0x49c0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x1c68b
jmp 0x1c1f9
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)