// File: alan0201tw[P]RayTracer/include/stb_image.h
// Function: stbi__load_gif_main(stbi__context*, int**, int*, int*, int*, int*, int)
static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp)
{
   if (stbi__gif_test(s)) {
      int layers = 0; 
      stbi_uc *u = 0;
      stbi_uc *out = 0;
      stbi_uc *two_back = 0; 
      stbi__gif g;
      int stride; 
      memset(&g, 0, sizeof(g));
      if (delays) {
         *delays = 0; 
      }

      do {
         u = stbi__gif_load_next(s, &g, comp, req_comp, two_back);
         if (u == (stbi_uc *) s) u = 0;  // end of animated gif marker

         if (u) {
            *x = g.w;
            *y = g.h;
            ++layers; 
            stride = g.w * g.h * 4; 
         
            if (out) {
               out = (stbi_uc*) STBI_REALLOC( out, layers * stride ); 
               if (delays) {
                  *delays = (int*) STBI_REALLOC( *delays, sizeof(int) * layers ); 
               }
            } else {
               out = (stbi_uc*)stbi__malloc( layers * stride ); 
               if (delays) {
                  *delays = (int*) stbi__malloc( layers * sizeof(int) ); 
               }
            }
            memcpy( out + ((layers - 1) * stride), u, stride ); 
            if (layers >= 2) {
               two_back = out - 2 * stride; 
            }

            if (delays) {
               (*delays)[layers - 1U] = g.delay; 
            }
         }
      } while (u != 0); 

      // free temp buffer; 
      STBI_FREE(g.out); 
      STBI_FREE(g.history); 
      STBI_FREE(g.background); 

      // do the final conversion after loading everything; 
      if (req_comp && req_comp != 4)
         out = stbi__convert_format(out, 4, req_comp, layers * g.w, g.h);

      *z = layers; 
      return out;
   } else {
      return stbi__errpuc("not GIF", "Image was not as a gif type."); 
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x88d0, %rsp           # imm = 0x88D0
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5c800
cmpl $0x0, %eax
je 0x56a0a
movl $0x0, -0x3c(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
leaq -0x88c8(%rbp), %rdi
xorl %esi, %esi
movl $0x8870, %edx           # imm = 0x8870
callq 0x7290
cmpq $0x0, -0x18(%rbp)
je 0x5683c
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
jmp 0x5683e
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rdx
movl 0x10(%rbp), %ecx
movq -0x58(%rbp), %r8
leaq -0x88c8(%rbp), %rsi
callq 0x6ddc0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x10(%rbp), %rax
jne 0x5686f
movq $0x0, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x56994
movl -0x88c8(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x88c4(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x88c8(%rbp), %eax
imull -0x88c4(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x88cc(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x568f9
movq -0x50(%rbp), %rdi
movl -0x3c(%rbp), %eax
imull -0x88cc(%rbp), %eax
movslq %eax, %rsi
callq 0x77d0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x568f7
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movslq -0x3c(%rbp), %rsi
shlq $0x2, %rsi
callq 0x77d0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x5692f
movl -0x3c(%rbp), %eax
imull -0x88cc(%rbp), %eax
movslq %eax, %rdi
callq 0x57060
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x5692d
movslq -0x3c(%rbp), %rdi
shlq $0x2, %rdi
callq 0x57060
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x5692f
movq -0x50(%rbp), %rdi
movl -0x3c(%rbp), %eax
subl $0x1, %eax
imull -0x88cc(%rbp), %eax
cltq
addq %rax, %rdi
movq -0x48(%rbp), %rsi
movslq -0x88cc(%rbp), %rdx
callq 0x7400
cmpl $0x2, -0x3c(%rbp)
jl 0x56976
movq -0x50(%rbp), %rax
movl -0x88cc(%rbp), %ecx
shll %ecx
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x56992
movl -0x60(%rbp), %edx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
jmp 0x56994
jmp 0x56996
cmpq $0x0, -0x48(%rbp)
jne 0x5683e
movq -0x88c0(%rbp), %rdi
callq 0x75e0
movq -0x88b0(%rbp), %rdi
callq 0x75e0
movq -0x88b8(%rbp), %rdi
callq 0x75e0
cmpl $0x0, 0x10(%rbp)
je 0x569f7
cmpl $0x4, 0x10(%rbp)
je 0x569f7
movq -0x50(%rbp), %rdi
movl 0x10(%rbp), %edx
movl -0x3c(%rbp), %ecx
imull -0x88c8(%rbp), %ecx
movl -0x88c4(%rbp), %r8d
movl $0x4, %esi
callq 0x6a860
movq %rax, -0x50(%rbp)
movl -0x3c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x56a25
leaq 0x2acd9(%rip), %rdi     # 0x816ea
callq 0x56040
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x88d0, %rsp           # imm = 0x88D0
popq %rbp
retq
nopw %cs:(%rax,%rax)