// File: /workspace/github_c_makefile_star2_O0/zhiyb[P]png2tlg/./stb_image.h
// Function: stbi__gif_load_next(stbi__context*, stbi__gif*, int*, int, unsigned char*)
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; 
   STBI_NOTUSED(req_comp);

   // 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
      if (!stbi__mad3sizes_valid(4, g->w, g->h, 0))
         return stbi__errpuc("too large", "GIF image is too large");
      pcount = g->w * g->h;
      g->out = (stbi_uc *) stbi__malloc(4 * pcount);
      g->background = (stbi_uc *) stbi__malloc(4 * pcount);
      g->history = (stbi_uc *) stbi__malloc(pcount);
      if (!g->out || !g->background || !g->history)
         return stbi__errpuc("outofmem", "Out of memory");

      // image is treated as "transparent" 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 the color that was there the previous frame. 
      memset(g->out, 0x00, 4 * pcount);
      memset(g->background, 0x00, 4 * pcount); // state of the background (starts transparent)
      memset(g->history, 0x00, pcount);        // 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;

            // if the width of the specified rectangle is 0, that means
            // we may not see *any* pixels or the image is malformed;
            // to make sure this is caught, move the current y down to
            // max_y (which is what out_gif_code checks).
            if (w == 0)
               g->cur_y = g->max_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) 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 0x1b09e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
xorl %ecx, %ecx
callq 0x1b6a0
cmpl $0x0, %eax
jne 0x1af79
movq $0x0, -0x8(%rbp)
jmp 0x1b684
movq -0x18(%rbp), %rax
movl (%rax), %esi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
movl $0x4, %edi
xorl %ecx, %ecx
callq 0x13400
cmpl $0x0, %eax
jne 0x1afb7
leaq 0x5996(%rip), %rdi      # 0x20934
callq 0x2680
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x1b684
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
shll $0x2, %eax
movslq %eax, %rdi
callq 0x36a0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x40(%rbp), %eax
shll $0x2, %eax
movslq %eax, %rdi
callq 0x36a0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movslq -0x40(%rbp), %rdi
callq 0x36a0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1b02f
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x1b02f
movq -0x18(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x1b04f
leaq 0x5908(%rip), %rdi      # 0x2093e
callq 0x2680
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x1b684
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x40(%rbp), %eax
shll $0x2, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x2100
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x40(%rbp), %eax
shll $0x2, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x2100
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movslq -0x40(%rbp), %rdx
xorl %esi, %esi
callq 0x2100
movl $0x1, -0x38(%rbp)
jmp 0x1b1b8
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 0x1b0d3
cmpq $0x0, -0x30(%rbp)
jne 0x1b0d3
movl $0x2, -0x34(%rbp)
cmpl $0x3, -0x34(%rbp)
jne 0x1b12d
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x1b12b
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x1b11e
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 0x1b120
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1b0e0
jmp 0x1b18f
cmpl $0x2, -0x34(%rbp)
jne 0x1b18b
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x1b189
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x1b17c
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 0x1b17e
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1b13a
jmp 0x1b18d
jmp 0x1b18d
jmp 0x1b18f
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 0x21b0
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 0x2100
movq -0x10(%rbp), %rdi
callq 0x12e60
movzbl %al, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x6c(%rbp)
subl $0x21, %eax
je 0x1b54f
jmp 0x1b1f8
movl -0x6c(%rbp), %eax
subl $0x2c, %eax
je 0x1b213
jmp 0x1b202
movl -0x6c(%rbp), %eax
subl $0x3b, %eax
je 0x1b658
jmp 0x1b662
movq -0x10(%rbp), %rdi
callq 0x1a7d0
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1a7d0
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1a7d0
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1a7d0
movl %eax, -0x54(%rbp)
movl -0x48(%rbp), %eax
addl -0x50(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jg 0x1b260
movl -0x4c(%rbp), %eax
addl -0x54(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jle 0x1b280
leaq 0x5c89(%rip), %rdi      # 0x20ef0
callq 0x2680
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x1b684
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)
cmpl $0x0, -0x50(%rbp)
jne 0x1b33d
movq -0x18(%rbp), %rax
movl 0x8858(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8860(%rax)
movq -0x10(%rbp), %rdi
callq 0x12e60
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 0x1b38c
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 0x1b3ae
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 0x1b44c
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 0x1b411
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x84(%rbp)
jmp 0x1b41e
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x84(%rbp)
jmp 0x1b41e
movl -0x70(%rbp), %edx
movq -0x78(%rbp), %rsi
movq -0x80(%rbp), %rdi
movl -0x84(%rbp), %ecx
callq 0x1b850
movq -0x18(%rbp), %rcx
addq $0x434, %rcx            # imm = 0x434
movq -0x18(%rbp), %rax
movq %rcx, 0x8838(%rax)
jmp 0x1b494
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x1b472
movq -0x18(%rbp), %rcx
addq $0x34, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8838(%rax)
jmp 0x1b492
leaq 0x5a8c(%rip), %rdi      # 0x20f05
callq 0x2680
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x1b684
jmp 0x1b494
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1b8f0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x1b4b9
movq $0x0, -0x8(%rbp)
jmp 0x1b684
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
imull 0x4(%rcx), %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x1b542
movq -0x18(%rbp), %rax
cmpl $0x0, 0x24(%rax)
jle 0x1b542
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x1b540
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1b533
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 0x1b535
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1b4e1
jmp 0x1b542
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1b684
movq -0x10(%rbp), %rdi
callq 0x12e60
movzbl %al, %eax
movl %eax, -0x68(%rbp)
cmpl $0xf9, -0x68(%rbp)
jne 0x1b632
movq -0x10(%rbp), %rdi
callq 0x12e60
movzbl %al, %eax
movl %eax, -0x64(%rbp)
cmpl $0x4, -0x64(%rbp)
jne 0x1b622
movq -0x10(%rbp), %rdi
callq 0x12e60
movzbl %al, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x10(%rbp), %rdi
callq 0x1a7d0
imull $0xa, %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8868(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jl 0x1b5c8
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 0x1b607
movq -0x10(%rbp), %rdi
callq 0x12e60
movzbl %al, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jl 0x1b605
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0x2c(%rcx), %rcx
movb $0x0, 0x37(%rax,%rcx,4)
jmp 0x1b620
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x13350
movq -0x18(%rbp), %rax
movl $0xffffffff, 0x2c(%rax) # imm = 0xFFFFFFFF
jmp 0x1b630
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x13350
jmp 0x1b67f
jmp 0x1b632
jmp 0x1b634
movq -0x10(%rbp), %rdi
callq 0x12e60
movzbl %al, %eax
movl %eax, -0x64(%rbp)
cmpl $0x0, %eax
je 0x1b656
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x13350
jmp 0x1b634
jmp 0x1b67f
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1b684
leaq 0x58b0(%rip), %rdi      # 0x20f19
callq 0x2680
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x1b684
jmp 0x1b1d8
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)