// File: lvandeve[P]lodepng/lodepng.cpp
// Function: lodepng_compute_color_stats(LodePNGColorStats*, unsigned char const*, unsigned int, unsigned int, LodePNGColorMode const*)
unsigned lodepng_compute_color_stats(LodePNGColorStats* stats,
                                     const unsigned char* in, unsigned w, unsigned h,
                                     const LodePNGColorMode* mode_in) {
  size_t i;
  ColorTree tree;
  size_t numpixels = (size_t)w * (size_t)h;
  unsigned error = 0;

  /* mark things as done already if it would be impossible to have a more expensive case */
  unsigned colored_done = lodepng_is_greyscale_type(mode_in) ? 1 : 0;
  unsigned alpha_done = lodepng_can_have_alpha(mode_in) ? 0 : 1;
  unsigned numcolors_done = 0;
  unsigned bpp = lodepng_get_bpp(mode_in);
  unsigned bits_done = (stats->bits == 1 && bpp == 1) ? 1 : 0;
  unsigned sixteen = 0; /* whether the input image is 16 bit */
  unsigned maxnumcolors = 257;
  if(bpp <= 8) maxnumcolors = LODEPNG_MIN(257, stats->numcolors + (1u << bpp));

  stats->numpixels += numpixels;

  /*if palette not allowed, no need to compute numcolors*/
  if(!stats->allow_palette) numcolors_done = 1;

  color_tree_init(&tree);

  /*If the stats was already filled in from previous data, fill its palette in tree
  and mark things as done already if we know they are the most expensive case already*/
  if(stats->alpha) alpha_done = 1;
  if(stats->colored) colored_done = 1;
  if(stats->bits == 16) numcolors_done = 1;
  if(stats->bits >= bpp) bits_done = 1;
  if(stats->numcolors >= maxnumcolors) numcolors_done = 1;

  if(!numcolors_done) {
    for(i = 0; i < stats->numcolors; i++) {
      const unsigned char* color = &stats->palette[i * 4];
      error = color_tree_add(&tree, color[0], color[1], color[2], color[3], (unsigned)i);
      if(error) goto cleanup;
    }
  }

  /*Check if the 16-bit input is truly 16-bit*/
  if(mode_in->bitdepth == 16 && !sixteen) {
    unsigned short r = 0, g = 0, b = 0, a = 0;
    for(i = 0; i != numpixels; ++i) {
      getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in);
      if((r & 255) != ((r >> 8) & 255) || (g & 255) != ((g >> 8) & 255) ||
         (b & 255) != ((b >> 8) & 255) || (a & 255) != ((a >> 8) & 255)) /*first and second byte differ*/ {
        stats->bits = 16;
        sixteen = 1;
        bits_done = 1;
        numcolors_done = 1; /*counting colors no longer useful, palette doesn't support 16-bit*/
        break;
      }
    }
  }

  if(sixteen) {
    unsigned short r = 0, g = 0, b = 0, a = 0;

    for(i = 0; i != numpixels; ++i) {
      getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in);

      if(!colored_done && (r != g || r != b)) {
        stats->colored = 1;
        colored_done = 1;
      }

      if(!alpha_done) {
        unsigned matchkey = (r == stats->key_r && g == stats->key_g && b == stats->key_b);
        if(a != 65535 && (a != 0 || (stats->key && !matchkey))) {
          stats->alpha = 1;
          stats->key = 0;
          alpha_done = 1;
        } else if(a == 0 && !stats->alpha && !stats->key) {
          stats->key = 1;
          stats->key_r = r;
          stats->key_g = g;
          stats->key_b = b;
        } else if(a == 65535 && stats->key && matchkey) {
          /* Color key cannot be used if an opaque pixel also has that RGB color. */
          stats->alpha = 1;
          stats->key = 0;
          alpha_done = 1;
        }
      }
      if(alpha_done && numcolors_done && colored_done && bits_done) break;
    }

    if(stats->key && !stats->alpha) {
      for(i = 0; i != numpixels; ++i) {
        getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in);
        if(a != 0 && r == stats->key_r && g == stats->key_g && b == stats->key_b) {
          /* Color key cannot be used if an opaque pixel also has that RGB color. */
          stats->alpha = 1;
          stats->key = 0;
          alpha_done = 1;
        }
      }
    }
  } else /* < 16-bit */ {
    unsigned char r = 0, g = 0, b = 0, a = 0;
    unsigned char pr = 0, pg = 0, pb = 0, pa = 0;
    for(i = 0; i != numpixels; ++i) {
      getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in);

      /*skip if color same as before, this speeds up large non-photographic
      images with many same colors by avoiding 'color_tree_has' below */
      if(i != 0 && r == pr && g == pg && b == pb && a == pa) continue;
      pr = r;
      pg = g;
      pb = b;
      pa = a;

      if(!bits_done && stats->bits < 8) {
        /*only r is checked, < 8 bits is only relevant for grayscale*/
        unsigned bits = getValueRequiredBits(r);
        if(bits > stats->bits) stats->bits = bits;
      }
      bits_done = (stats->bits >= bpp);

      if(!colored_done && (r != g || r != b)) {
        stats->colored = 1;
        colored_done = 1;
        if(stats->bits < 8) stats->bits = 8; /*PNG has no colored modes with less than 8-bit per channel*/
      }

      if(!alpha_done) {
        unsigned matchkey = (r == stats->key_r && g == stats->key_g && b == stats->key_b);
        if(a != 255 && (a != 0 || (stats->key && !matchkey))) {
          stats->alpha = 1;
          stats->key = 0;
          alpha_done = 1;
          if(stats->bits < 8) stats->bits = 8; /*PNG has no alphachannel modes with less than 8-bit per channel*/
        } else if(a == 0 && !stats->alpha && !stats->key) {
          stats->key = 1;
          stats->key_r = r;
          stats->key_g = g;
          stats->key_b = b;
        } else if(a == 255 && stats->key && matchkey) {
          /* Color key cannot be used if an opaque pixel also has that RGB color. */
          stats->alpha = 1;
          stats->key = 0;
          alpha_done = 1;
          if(stats->bits < 8) stats->bits = 8; /*PNG has no alphachannel modes with less than 8-bit per channel*/
        }
      }

      if(!numcolors_done) {
        if(!color_tree_has(&tree, r, g, b, a)) {
          error = color_tree_add(&tree, r, g, b, a, stats->numcolors);
          if(error) goto cleanup;
          if(stats->numcolors < 256) {
            unsigned char* p = stats->palette;
            unsigned n = stats->numcolors;
            p[n * 4 + 0] = r;
            p[n * 4 + 1] = g;
            p[n * 4 + 2] = b;
            p[n * 4 + 3] = a;
          }
          ++stats->numcolors;
          numcolors_done = stats->numcolors >= maxnumcolors;
        }
      }

      if(alpha_done && numcolors_done && colored_done && bits_done) break;
    }

    if(stats->key && !stats->alpha) {
      for(i = 0; i != numpixels; ++i) {
        getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in);
        if(a != 0 && r == stats->key_r && g == stats->key_g && b == stats->key_b) {
          /* Color key cannot be used if an opaque pixel also has that RGB color. */
          stats->alpha = 1;
          stats->key = 0;
          alpha_done = 1;
          if(stats->bits < 8) stats->bits = 8; /*PNG has no alphachannel modes with less than 8-bit per channel*/
        }
      }
    }

    /*make the stats's key always 16-bit for consistency - repeat each byte twice*/
    stats->key_r += (stats->key_r << 8);
    stats->key_g += (stats->key_g << 8);
    stats->key_b += (stats->key_b << 8);
  }

cleanup:
  color_tree_cleanup(&tree);
  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl -0x14(%rbp), %eax
movl -0x18(%rbp), %ecx
imulq %rcx, %rax
movq %rax, -0xb8(%rbp)
movl $0x0, -0xbc(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5b60
movl %eax, %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0xc0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5c30
movl %eax, %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0xc4(%rbp)
movl $0x0, -0xc8(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5a60
movl %eax, -0xcc(%rbp)
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpl $0x1, 0x418(%rcx)
movb %al, -0x115(%rbp)
jne 0x9412
cmpl $0x1, -0xcc(%rbp)
sete %al
movb %al, -0x115(%rbp)
movb -0x115(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0xd0(%rbp)
movl $0x0, -0xd4(%rbp)
movl $0x101, -0xd8(%rbp)     # imm = 0x101
cmpl $0x8, -0xcc(%rbp)
ja 0x94aa
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x11c(%rbp)
movl -0xcc(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl -0x11c(%rbp), %ecx
addl %eax, %ecx
movl $0x101, %eax            # imm = 0x101
cmpl %ecx, %eax
jae 0x9480
movl $0x101, %eax            # imm = 0x101
movl %eax, -0x120(%rbp)
jmp 0x949e
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movl -0xcc(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
addl %ecx, %eax
movl %eax, -0x120(%rbp)
movl -0x120(%rbp), %eax
movl %eax, -0xd8(%rbp)
movq -0xb8(%rbp), %rcx
movq -0x8(%rbp), %rax
addq 0x420(%rax), %rcx
movq %rcx, 0x420(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x428(%rax)
jne 0x94da
movl $0x1, -0xc8(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x7320
movq -0x8(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x94fa
movl $0x1, -0xc4(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, (%rax)
je 0x950d
movl $0x1, -0xc0(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x10, 0x418(%rax)
jne 0x9524
movl $0x1, -0xc8(%rbp)
movq -0x8(%rbp), %rax
movl 0x418(%rax), %eax
cmpl -0xcc(%rbp), %eax
jb 0x9540
movl $0x1, -0xd0(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
cmpl -0xd8(%rbp), %eax
jb 0x9559
movl $0x1, -0xc8(%rbp)
cmpl $0x0, -0xc8(%rbp)
jne 0x960e
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
cmpq %rcx, %rax
jae 0x960c
movq -0x8(%rbp), %rax
addq $0x18, %rax
movq -0x28(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movb (%rax), %sil
movq -0xe0(%rbp), %rax
movb 0x1(%rax), %dl
movq -0xe0(%rbp), %rax
movb 0x2(%rax), %cl
movq -0xe0(%rbp), %rax
movb 0x3(%rax), %al
movq -0x28(%rbp), %rdi
movl %edi, %r9d
leaq -0xb0(%rbp), %rdi
movzbl %sil, %esi
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl %al, %r8d
callq 0x7350
movl %eax, -0xbc(%rbp)
cmpl $0x0, -0xbc(%rbp)
je 0x95f9
jmp 0xa0eb
jmp 0x95fb
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x956e
jmp 0x960e
movq -0x20(%rbp), %rax
cmpl $0x10, 0x4(%rax)
jne 0x975a
cmpl $0x0, -0xd4(%rbp)
jne 0x975a
movw $0x0, -0xe2(%rbp)
movw $0x0, -0xe4(%rbp)
movw $0x0, -0xe6(%rbp)
movw $0x0, -0xe8(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0xb8(%rbp), %rax
je 0x9758
movq -0x10(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x20(%rbp), %rax
leaq -0xe2(%rbp), %rdi
leaq -0xe4(%rbp), %rsi
leaq -0xe6(%rbp), %rdx
leaq -0xe8(%rbp), %rcx
movq %rax, (%rsp)
callq 0x7460
movzwl -0xe2(%rbp), %eax
andl $0xff, %eax
movzwl -0xe2(%rbp), %ecx
sarl $0x8, %ecx
andl $0xff, %ecx
cmpl %ecx, %eax
jne 0x9717
movzwl -0xe4(%rbp), %eax
andl $0xff, %eax
movzwl -0xe4(%rbp), %ecx
sarl $0x8, %ecx
andl $0xff, %ecx
cmpl %ecx, %eax
jne 0x9717
movzwl -0xe6(%rbp), %eax
andl $0xff, %eax
movzwl -0xe6(%rbp), %ecx
sarl $0x8, %ecx
andl $0xff, %ecx
cmpl %ecx, %eax
jne 0x9717
movzwl -0xe8(%rbp), %eax
andl $0xff, %eax
movzwl -0xe8(%rbp), %ecx
sarl $0x8, %ecx
andl $0xff, %ecx
cmpl %ecx, %eax
je 0x9745
movq -0x8(%rbp), %rax
movl $0x10, 0x418(%rax)
movl $0x1, -0xd4(%rbp)
movl $0x1, -0xd0(%rbp)
movl $0x1, -0xc8(%rbp)
jmp 0x9758
jmp 0x9747
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x9655
jmp 0x975a
cmpl $0x0, -0xd4(%rbp)
je 0x9a95
movw $0x0, -0xea(%rbp)
movw $0x0, -0xec(%rbp)
movw $0x0, -0xee(%rbp)
movw $0x0, -0xf0(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0xb8(%rbp), %rax
je 0x99b0
movq -0x10(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x20(%rbp), %rax
leaq -0xea(%rbp), %rdi
leaq -0xec(%rbp), %rsi
leaq -0xee(%rbp), %rdx
leaq -0xf0(%rbp), %rcx
movq %rax, (%rsp)
callq 0x7460
cmpl $0x0, -0xc0(%rbp)
jne 0x9816
movzwl -0xea(%rbp), %eax
movzwl -0xec(%rbp), %ecx
cmpl %ecx, %eax
jne 0x9802
movzwl -0xea(%rbp), %eax
movzwl -0xee(%rbp), %ecx
cmpl %ecx, %eax
je 0x9816
movq -0x8(%rbp), %rax
movl $0x1, (%rax)
movl $0x1, -0xc0(%rbp)
cmpl $0x0, -0xc4(%rbp)
jne 0x9977
movzwl -0xea(%rbp), %ecx
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x121(%rbp)
jne 0x9873
movzwl -0xec(%rbp), %ecx
movq -0x8(%rbp), %rax
movzwl 0xa(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x121(%rbp)
jne 0x9873
movzwl -0xee(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x121(%rbp)
movb -0x121(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xf4(%rbp)
movzwl -0xf0(%rbp), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x98d6
movzwl -0xf0(%rbp), %eax
cmpl $0x0, %eax
jne 0x98b1
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x98d6
cmpl $0x0, -0xf4(%rbp)
jne 0x98d6
movq -0x8(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x4(%rax)
movl $0x1, -0xc4(%rbp)
jmp 0x9975
movzwl -0xf0(%rbp), %eax
cmpl $0x0, %eax
jne 0x9930
movq -0x8(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x9930
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x9930
movq -0x8(%rbp), %rax
movl $0x1, 0x4(%rax)
movw -0xea(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8(%rax)
movw -0xec(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0xa(%rax)
movw -0xee(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0xc(%rax)
jmp 0x9973
movzwl -0xf0(%rbp), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x9971
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x9971
cmpl $0x0, -0xf4(%rbp)
je 0x9971
movq -0x8(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x4(%rax)
movl $0x1, -0xc4(%rbp)
jmp 0x9973
jmp 0x9975
jmp 0x9977
cmpl $0x0, -0xc4(%rbp)
je 0x999d
cmpl $0x0, -0xc8(%rbp)
je 0x999d
cmpl $0x0, -0xc0(%rbp)
je 0x999d
cmpl $0x0, -0xd0(%rbp)
je 0x999d
jmp 0x99b0
jmp 0x999f
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x9793
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x9a90
movq -0x8(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x9a90
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0xb8(%rbp), %rax
je 0x9a8e
movq -0x10(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x20(%rbp), %rax
leaq -0xea(%rbp), %rdi
leaq -0xec(%rbp), %rsi
leaq -0xee(%rbp), %rdx
leaq -0xf0(%rbp), %rcx
movq %rax, (%rsp)
callq 0x7460
movzwl -0xf0(%rbp), %eax
cmpl $0x0, %eax
je 0x9a7b
movzwl -0xea(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jne 0x9a7b
movzwl -0xec(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
cmpl %ecx, %eax
jne 0x9a7b
movzwl -0xee(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
cmpl %ecx, %eax
jne 0x9a7b
movq -0x8(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x4(%rax)
movl $0x1, -0xc4(%rbp)
jmp 0x9a7d
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x99d4
jmp 0x9a90
jmp 0xa0e9
movb $0x0, -0xf5(%rbp)
movb $0x0, -0xf6(%rbp)
movb $0x0, -0xf7(%rbp)
movb $0x0, -0xf8(%rbp)
movb $0x0, -0xf9(%rbp)
movb $0x0, -0xfa(%rbp)
movb $0x0, -0xfb(%rbp)
movb $0x0, -0xfc(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0xb8(%rbp), %rax
je 0x9fa1
movq -0x10(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x20(%rbp), %rax
leaq -0xf5(%rbp), %rdi
leaq -0xf6(%rbp), %rsi
leaq -0xf7(%rbp), %rdx
leaq -0xf8(%rbp), %rcx
movq %rax, (%rsp)
callq 0x86a0
cmpq $0x0, -0x28(%rbp)
je 0x9b6b
movzbl -0xf5(%rbp), %eax
movzbl -0xf9(%rbp), %ecx
cmpl %ecx, %eax
jne 0x9b6b
movzbl -0xf6(%rbp), %eax
movzbl -0xfa(%rbp), %ecx
cmpl %ecx, %eax
jne 0x9b6b
movzbl -0xf7(%rbp), %eax
movzbl -0xfb(%rbp), %ecx
cmpl %ecx, %eax
jne 0x9b6b
movzbl -0xf8(%rbp), %eax
movzbl -0xfc(%rbp), %ecx
cmpl %ecx, %eax
jne 0x9b6b
jmp 0x9f90
movb -0xf5(%rbp), %al
movb %al, -0xf9(%rbp)
movb -0xf6(%rbp), %al
movb %al, -0xfa(%rbp)
movb -0xf7(%rbp), %al
movb %al, -0xfb(%rbp)
movb -0xf8(%rbp), %al
movb %al, -0xfc(%rbp)
cmpl $0x0, -0xd0(%rbp)
jne 0x9be7
movq -0x8(%rbp), %rax
cmpl $0x8, 0x418(%rax)
jae 0x9be7
movzbl -0xf5(%rbp), %edi
callq 0xa110
movl %eax, -0x100(%rbp)
movl -0x100(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x418(%rcx), %eax
jbe 0x9be5
movl -0x100(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x418(%rax)
jmp 0x9be7
movq -0x8(%rbp), %rax
movl 0x418(%rax), %eax
cmpl -0xcc(%rbp), %eax
setae %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xd0(%rbp)
cmpl $0x0, -0xc0(%rbp)
jne 0x9c63
movzbl -0xf5(%rbp), %eax
movzbl -0xf6(%rbp), %ecx
cmpl %ecx, %eax
jne 0x9c32
movzbl -0xf5(%rbp), %eax
movzbl -0xf7(%rbp), %ecx
cmpl %ecx, %eax
je 0x9c63
movq -0x8(%rbp), %rax
movl $0x1, (%rax)
movl $0x1, -0xc0(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x8, 0x418(%rax)
jae 0x9c61
movq -0x8(%rbp), %rax
movl $0x8, 0x418(%rax)
jmp 0x9c63
cmpl $0x0, -0xc4(%rbp)
jne 0x9e05
movzbl -0xf5(%rbp), %ecx
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x122(%rbp)
jne 0x9cc0
movzbl -0xf6(%rbp), %ecx
movq -0x8(%rbp), %rax
movzwl 0xa(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x122(%rbp)
jne 0x9cc0
movzbl -0xf7(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x122(%rbp)
movb -0x122(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x104(%rbp)
movzbl -0xf8(%rbp), %eax
cmpl $0xff, %eax
je 0x9d3e
movzbl -0xf8(%rbp), %eax
cmpl $0x0, %eax
jne 0x9cfe
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x9d3e
cmpl $0x0, -0x104(%rbp)
jne 0x9d3e
movq -0x8(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x4(%rax)
movl $0x1, -0xc4(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x8, 0x418(%rax)
jae 0x9d39
movq -0x8(%rbp), %rax
movl $0x8, 0x418(%rax)
jmp 0x9e03
movzbl -0xf8(%rbp), %eax
cmpl $0x0, %eax
jne 0x9da1
movq -0x8(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x9da1
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x9da1
movq -0x8(%rbp), %rax
movl $0x1, 0x4(%rax)
movzbl -0xf5(%rbp), %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8(%rax)
movzbl -0xf6(%rbp), %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0xa(%rax)
movzbl -0xf7(%rbp), %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0xc(%rax)
jmp 0x9e01
movzbl -0xf8(%rbp), %eax
cmpl $0xff, %eax
jne 0x9dff
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x9dff
cmpl $0x0, -0x104(%rbp)
je 0x9dff
movq -0x8(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x4(%rax)
movl $0x1, -0xc4(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x8, 0x418(%rax)
jae 0x9dfd
movq -0x8(%rbp), %rax
movl $0x8, 0x418(%rax)
jmp 0x9dff
jmp 0x9e01
jmp 0x9e03
jmp 0x9e05
cmpl $0x0, -0xc8(%rbp)
jne 0x9f68
movb -0xf5(%rbp), %dl
movb -0xf6(%rbp), %cl
movb -0xf7(%rbp), %al
leaq -0xb0(%rbp), %rdi
movzbl %dl, %esi
movzbl %cl, %edx
movzbl %al, %ecx
movzbl -0xf8(%rbp), %r8d
callq 0xa180
cmpl $0x0, %eax
jne 0x9f66
movb -0xf5(%rbp), %sil
movb -0xf6(%rbp), %dl
movb -0xf7(%rbp), %cl
movb -0xf8(%rbp), %al
movq -0x8(%rbp), %rdi
movl 0x14(%rdi), %r9d
leaq -0xb0(%rbp), %rdi
movzbl %sil, %esi
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl %al, %r8d
callq 0x7350
movl %eax, -0xbc(%rbp)
cmpl $0x0, -0xbc(%rbp)
je 0x9e99
jmp 0xa0eb
movq -0x8(%rbp), %rax
cmpl $0x100, 0x14(%rax)      # imm = 0x100
jae 0x9f3e
movq -0x8(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x110(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x114(%rbp)
movb -0xf5(%rbp), %dl
movq -0x110(%rbp), %rax
movl -0x114(%rbp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movb -0xf6(%rbp), %dl
movq -0x110(%rbp), %rax
movl -0x114(%rbp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movb -0xf7(%rbp), %dl
movq -0x110(%rbp), %rax
movl -0x114(%rbp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movb -0xf8(%rbp), %dl
movq -0x110(%rbp), %rax
movl -0x114(%rbp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
cmpl -0xd8(%rbp), %eax
setae %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xc8(%rbp)
jmp 0x9f68
cmpl $0x0, -0xc4(%rbp)
je 0x9f8e
cmpl $0x0, -0xc8(%rbp)
je 0x9f8e
cmpl $0x0, -0xc0(%rbp)
je 0x9f8e
cmpl $0x0, -0xd0(%rbp)
je 0x9f8e
jmp 0x9fa1
jmp 0x9f90
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x9ad5
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0xa09e
movq -0x8(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0xa09e
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0xb8(%rbp), %rax
je 0xa09c
movq -0x10(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x20(%rbp), %rax
leaq -0xf5(%rbp), %rdi
leaq -0xf6(%rbp), %rsi
leaq -0xf7(%rbp), %rdx
leaq -0xf8(%rbp), %rcx
movq %rax, (%rsp)
callq 0x86a0
movzbl -0xf8(%rbp), %eax
cmpl $0x0, %eax
je 0xa089
movzbl -0xf5(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jne 0xa089
movzbl -0xf6(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
cmpl %ecx, %eax
jne 0xa089
movzbl -0xf7(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
cmpl %ecx, %eax
jne 0xa089
movq -0x8(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x4(%rax)
movl $0x1, -0xc4(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x8, 0x418(%rax)
jae 0xa087
movq -0x8(%rbp), %rax
movl $0x8, 0x418(%rax)
jmp 0xa089
jmp 0xa08b
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x9fc5
jmp 0xa09e
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %edx
shll $0x8, %edx
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x8(%rax)
movq -0x8(%rbp), %rax
movzwl 0xa(%rax), %edx
shll $0x8, %edx
movq -0x8(%rbp), %rax
movzwl 0xa(%rax), %ecx
addl %edx, %ecx
movw %cx, 0xa(%rax)
movq -0x8(%rbp), %rax
movzwl 0xc(%rax), %edx
shll $0x8, %edx
movq -0x8(%rbp), %rax
movzwl 0xc(%rax), %ecx
addl %edx, %ecx
movw %cx, 0xc(%rax)
jmp 0xa0eb
leaq -0xb0(%rbp), %rdi
callq 0x8f90
movl -0xbc(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw %cs:(%rax,%rax)