// File: phillip-h[P]fractal-gen/lodepng.cpp
// Function: deflateDynamic(ucvector*, unsigned long*, Hash*, unsigned char const*, unsigned long, unsigned long, LodePNGCompressSettings const*, unsigned int)
static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash,
                               const unsigned char* data, size_t datapos, size_t dataend,
                               const LodePNGCompressSettings* settings, unsigned final)
{
  unsigned error = 0;

  /*
  A block is compressed as follows: The PNG data is lz77 encoded, resulting in
  literal bytes and length/distance pairs. This is then huffman compressed with
  two huffman trees. One huffman tree is used for the lit and len values ("ll"),
  another huffman tree is used for the dist values ("d"). These two trees are
  stored using their code lengths, and to compress even more these code lengths
  are also run-length encoded and huffman compressed. This gives a huffman tree
  of code lengths "cl". The code lenghts used to describe this third tree are
  the code length code lengths ("clcl").
  */

  /*The lz77 encoded data, represented with integers since there will also be length and distance codes in it*/
  uivector lz77_encoded;
  HuffmanTree tree_ll; /*tree for lit,len values*/
  HuffmanTree tree_d; /*tree for distance codes*/
  HuffmanTree tree_cl; /*tree for encoding the code lengths representing tree_ll and tree_d*/
  uivector frequencies_ll; /*frequency of lit,len codes*/
  uivector frequencies_d; /*frequency of dist codes*/
  uivector frequencies_cl; /*frequency of code length codes*/
  uivector bitlen_lld; /*lit,len,dist code lenghts (int bits), literally (without repeat codes).*/
  uivector bitlen_lld_e; /*bitlen_lld encoded with repeat codes (this is a rudemtary run length compression)*/
  /*bitlen_cl is the code length code lengths ("clcl"). The bit lengths of codes to represent tree_cl
  (these are written as is in the file, it would be crazy to compress these using yet another huffman
  tree that needs to be represented by yet another set of code lengths)*/
  uivector bitlen_cl;
  size_t datasize = dataend - datapos;

  /*
  Due to the huffman compression of huffman tree representations ("two levels"), there are some anologies:
  bitlen_lld is to tree_cl what data is to tree_ll and tree_d.
  bitlen_lld_e is to bitlen_lld what lz77_encoded is to data.
  bitlen_cl is to bitlen_lld_e what bitlen_lld is to lz77_encoded.
  */

  unsigned BFINAL = final;
  size_t numcodes_ll, numcodes_d, i;
  unsigned HLIT, HDIST, HCLEN;

  uivector_init(&lz77_encoded);
  HuffmanTree_init(&tree_ll);
  HuffmanTree_init(&tree_d);
  HuffmanTree_init(&tree_cl);
  uivector_init(&frequencies_ll);
  uivector_init(&frequencies_d);
  uivector_init(&frequencies_cl);
  uivector_init(&bitlen_lld);
  uivector_init(&bitlen_lld_e);
  uivector_init(&bitlen_cl);

  /*This while loop never loops due to a break at the end, it is here to
  allow breaking out of it to the cleanup phase on error conditions.*/
  while(!error)
  {
    if(settings->use_lz77)
    {
      error = encodeLZ77(&lz77_encoded, hash, data, datapos, dataend, settings->windowsize,
                         settings->minmatch, settings->nicematch, settings->lazymatching);
      if(error) break;
    }
    else
    {
      if(!uivector_resize(&lz77_encoded, datasize)) ERROR_BREAK(83 /*alloc fail*/);
      for(i = datapos; i < dataend; ++i) lz77_encoded.data[i - datapos] = data[i]; /*no LZ77, but still will be Huffman compressed*/
    }

    if(!uivector_resizev(&frequencies_ll, 286, 0)) ERROR_BREAK(83 /*alloc fail*/);
    if(!uivector_resizev(&frequencies_d, 30, 0)) ERROR_BREAK(83 /*alloc fail*/);

    /*Count the frequencies of lit, len and dist codes*/
    for(i = 0; i != lz77_encoded.size; ++i)
    {
      unsigned symbol = lz77_encoded.data[i];
      ++frequencies_ll.data[symbol];
      if(symbol > 256)
      {
        unsigned dist = lz77_encoded.data[i + 2];
        ++frequencies_d.data[dist];
        i += 3;
      }
    }
    frequencies_ll.data[256] = 1; /*there will be exactly 1 end code, at the end of the block*/

    /*Make both huffman trees, one for the lit and len codes, one for the dist codes*/
    error = HuffmanTree_makeFromFrequencies(&tree_ll, frequencies_ll.data, 257, frequencies_ll.size, 15);
    if(error) break;
    /*2, not 1, is chosen for mincodes: some buggy PNG decoders require at least 2 symbols in the dist tree*/
    error = HuffmanTree_makeFromFrequencies(&tree_d, frequencies_d.data, 2, frequencies_d.size, 15);
    if(error) break;

    numcodes_ll = tree_ll.numcodes; if(numcodes_ll > 286) numcodes_ll = 286;
    numcodes_d = tree_d.numcodes; if(numcodes_d > 30) numcodes_d = 30;
    /*store the code lengths of both generated trees in bitlen_lld*/
    for(i = 0; i != numcodes_ll; ++i) uivector_push_back(&bitlen_lld, HuffmanTree_getLength(&tree_ll, (unsigned)i));
    for(i = 0; i != numcodes_d; ++i) uivector_push_back(&bitlen_lld, HuffmanTree_getLength(&tree_d, (unsigned)i));

    /*run-length compress bitlen_ldd into bitlen_lld_e by using repeat codes 16 (copy length 3-6 times),
    17 (3-10 zeroes), 18 (11-138 zeroes)*/
    for(i = 0; i != (unsigned)bitlen_lld.size; ++i)
    {
      unsigned j = 0; /*amount of repititions*/
      while(i + j + 1 < (unsigned)bitlen_lld.size && bitlen_lld.data[i + j + 1] == bitlen_lld.data[i]) ++j;

      if(bitlen_lld.data[i] == 0 && j >= 2) /*repeat code for zeroes*/
      {
        ++j; /*include the first zero*/
        if(j <= 10) /*repeat code 17 supports max 10 zeroes*/
        {
          uivector_push_back(&bitlen_lld_e, 17);
          uivector_push_back(&bitlen_lld_e, j - 3);
        }
        else /*repeat code 18 supports max 138 zeroes*/
        {
          if(j > 138) j = 138;
          uivector_push_back(&bitlen_lld_e, 18);
          uivector_push_back(&bitlen_lld_e, j - 11);
        }
        i += (j - 1);
      }
      else if(j >= 3) /*repeat code for value other than zero*/
      {
        size_t k;
        unsigned num = j / 6, rest = j % 6;
        uivector_push_back(&bitlen_lld_e, bitlen_lld.data[i]);
        for(k = 0; k < num; ++k)
        {
          uivector_push_back(&bitlen_lld_e, 16);
          uivector_push_back(&bitlen_lld_e, 6 - 3);
        }
        if(rest >= 3)
        {
          uivector_push_back(&bitlen_lld_e, 16);
          uivector_push_back(&bitlen_lld_e, rest - 3);
        }
        else j -= rest;
        i += j;
      }
      else /*too short to benefit from repeat code*/
      {
        uivector_push_back(&bitlen_lld_e, bitlen_lld.data[i]);
      }
    }

    /*generate tree_cl, the huffmantree of huffmantrees*/

    if(!uivector_resizev(&frequencies_cl, NUM_CODE_LENGTH_CODES, 0)) ERROR_BREAK(83 /*alloc fail*/);
    for(i = 0; i != bitlen_lld_e.size; ++i)
    {
      ++frequencies_cl.data[bitlen_lld_e.data[i]];
      /*after a repeat code come the bits that specify the number of repetitions,
      those don't need to be in the frequencies_cl calculation*/
      if(bitlen_lld_e.data[i] >= 16) ++i;
    }

    error = HuffmanTree_makeFromFrequencies(&tree_cl, frequencies_cl.data,
                                            frequencies_cl.size, frequencies_cl.size, 7);
    if(error) break;

    if(!uivector_resize(&bitlen_cl, tree_cl.numcodes)) ERROR_BREAK(83 /*alloc fail*/);
    for(i = 0; i != tree_cl.numcodes; ++i)
    {
      /*lenghts of code length tree is in the order as specified by deflate*/
      bitlen_cl.data[i] = HuffmanTree_getLength(&tree_cl, CLCL_ORDER[i]);
    }
    while(bitlen_cl.data[bitlen_cl.size - 1] == 0 && bitlen_cl.size > 4)
    {
      /*remove zeros at the end, but minimum size must be 4*/
      if(!uivector_resize(&bitlen_cl, bitlen_cl.size - 1)) ERROR_BREAK(83 /*alloc fail*/);
    }
    if(error) break;

    /*
    Write everything into the output

    After the BFINAL and BTYPE, the dynamic block consists out of the following:
    - 5 bits HLIT, 5 bits HDIST, 4 bits HCLEN
    - (HCLEN+4)*3 bits code lengths of code length alphabet
    - HLIT + 257 code lenghts of lit/length alphabet (encoded using the code length
      alphabet, + possible repetition codes 16, 17, 18)
    - HDIST + 1 code lengths of distance alphabet (encoded using the code length
      alphabet, + possible repetition codes 16, 17, 18)
    - compressed data
    - 256 (end code)
    */

    /*Write block type*/
    addBitToStream(bp, out, BFINAL);
    addBitToStream(bp, out, 0); /*first bit of BTYPE "dynamic"*/
    addBitToStream(bp, out, 1); /*second bit of BTYPE "dynamic"*/

    /*write the HLIT, HDIST and HCLEN values*/
    HLIT = (unsigned)(numcodes_ll - 257);
    HDIST = (unsigned)(numcodes_d - 1);
    HCLEN = (unsigned)bitlen_cl.size - 4;
    /*trim zeroes for HCLEN. HLIT and HDIST were already trimmed at tree creation*/
    while(!bitlen_cl.data[HCLEN + 4 - 1] && HCLEN > 0) --HCLEN;
    addBitsToStream(bp, out, HLIT, 5);
    addBitsToStream(bp, out, HDIST, 5);
    addBitsToStream(bp, out, HCLEN, 4);

    /*write the code lenghts of the code length alphabet*/
    for(i = 0; i != HCLEN + 4; ++i) addBitsToStream(bp, out, bitlen_cl.data[i], 3);

    /*write the lenghts of the lit/len AND the dist alphabet*/
    for(i = 0; i != bitlen_lld_e.size; ++i)
    {
      addHuffmanSymbol(bp, out, HuffmanTree_getCode(&tree_cl, bitlen_lld_e.data[i]),
                       HuffmanTree_getLength(&tree_cl, bitlen_lld_e.data[i]));
      /*extra bits of repeat codes*/
      if(bitlen_lld_e.data[i] == 16) addBitsToStream(bp, out, bitlen_lld_e.data[++i], 2);
      else if(bitlen_lld_e.data[i] == 17) addBitsToStream(bp, out, bitlen_lld_e.data[++i], 3);
      else if(bitlen_lld_e.data[i] == 18) addBitsToStream(bp, out, bitlen_lld_e.data[++i], 7);
    }

    /*write the compressed data symbols*/
    writeLZ77data(bp, out, &lz77_encoded, &tree_ll, &tree_d);
    /*error: the length of the end code 256 must be larger than 0*/
    if(HuffmanTree_getLength(&tree_ll, 256) == 0) ERROR_BREAK(64);

    /*write the end code*/
    addHuffmanSymbol(bp, out, HuffmanTree_getCode(&tree_ll, 256), HuffmanTree_getLength(&tree_ll, 256));

    break; /*end of error-while*/
  }

  /*cleanup*/
  uivector_cleanup(&lz77_encoded);
  HuffmanTree_cleanup(&tree_ll);
  HuffmanTree_cleanup(&tree_d);
  HuffmanTree_cleanup(&tree_cl);
  uivector_cleanup(&frequencies_ll);
  uivector_cleanup(&frequencies_d);
  uivector_cleanup(&frequencies_cl);
  uivector_cleanup(&bitlen_lld_e);
  uivector_cleanup(&bitlen_lld);
  uivector_cleanup(&bitlen_cl);

  return error;
}

// Assembly:
subq $0x1d8, %rsp            # imm = 0x1D8
movl 0x1e8(%rsp), %eax
movq 0x1e0(%rsp), %rax
movq %rdi, 0x1d0(%rsp)
movq %rsi, 0x1c8(%rsp)
movq %rdx, 0x1c0(%rsp)
movq %rcx, 0x1b8(%rsp)
movq %r8, 0x1b0(%rsp)
movq %r9, 0x1a8(%rsp)
movl $0x0, 0x1a4(%rsp)
movq 0x1a8(%rsp), %rax
subq 0x1b0(%rsp), %rax
movq %rax, 0x90(%rsp)
movl 0x1e8(%rsp), %eax
movl %eax, 0x8c(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x13160
leaq 0x168(%rsp), %rdi
callq 0x12420
leaq 0x148(%rsp), %rdi
callq 0x12420
leaq 0x128(%rsp), %rdi
callq 0x12420
leaq 0x110(%rsp), %rdi
callq 0x13160
leaq 0xf8(%rsp), %rdi
callq 0x13160
leaq 0xe0(%rsp), %rdi
callq 0x13160
leaq 0xc8(%rsp), %rdi
callq 0x13160
leaq 0xb0(%rsp), %rdi
callq 0x13160
leaq 0x98(%rsp), %rdi
callq 0x13160
cmpl $0x0, 0x1a4(%rsp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x13e6f
jmp 0x14aab
movq 0x1e0(%rsp), %rax
cmpl $0x0, 0x4(%rax)
je 0x13f05
movq 0x1c0(%rsp), %rsi
movq 0x1b8(%rsp), %rdx
movq 0x1b0(%rsp), %rcx
movq 0x1a8(%rsp), %r8
movq 0x1e0(%rsp), %rax
movl 0x8(%rax), %r9d
movq 0x1e0(%rsp), %rax
movl 0xc(%rax), %r11d
movq 0x1e0(%rsp), %rax
movl 0x10(%rax), %r10d
movq 0x1e0(%rsp), %rax
movl 0x14(%rax), %eax
leaq 0x188(%rsp), %rdi
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x14ba0
movl %eax, 0x1a4(%rsp)
cmpl $0x0, 0x1a4(%rsp)
je 0x13f00
jmp 0x14aab
jmp 0x13f86
movq 0x90(%rsp), %rsi
leaq 0x188(%rsp), %rdi
callq 0x134d0
cmpl $0x0, %eax
jne 0x13f2f
movl $0x53, 0x1a4(%rsp)
jmp 0x14aab
movq 0x1b0(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpq 0x1a8(%rsp), %rax
jae 0x13f84
movq 0x1b8(%rsp), %rax
movq 0x70(%rsp), %rcx
movzbl (%rax,%rcx), %edx
movq 0x188(%rsp), %rax
movq 0x70(%rsp), %rcx
subq 0x1b0(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x13f3c
jmp 0x13f86
leaq 0x110(%rsp), %rdi
movl $0x11e, %esi            # imm = 0x11E
xorl %edx, %edx
callq 0x13190
cmpl $0x0, %eax
jne 0x13faf
movl $0x53, 0x1a4(%rsp)
jmp 0x14aab
leaq 0xf8(%rsp), %rdi
movl $0x1e, %esi
xorl %edx, %edx
callq 0x13190
cmpl $0x0, %eax
jne 0x13fd8
movl $0x53, 0x1a4(%rsp)
jmp 0x14aab
movq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpq 0x190(%rsp), %rax
je 0x14074
movq 0x188(%rsp), %rax
movq 0x70(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x60(%rsp)
movq 0x110(%rsp), %rax
movl 0x60(%rsp), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
cmpl $0x100, 0x60(%rsp)      # imm = 0x100
jbe 0x1405f
movq 0x188(%rsp), %rax
movq 0x70(%rsp), %rcx
movl 0x8(%rax,%rcx,4), %eax
movl %eax, 0x5c(%rsp)
movq 0xf8(%rsp), %rax
movl 0x5c(%rsp), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq 0x70(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x70(%rsp)
jmp 0x14061
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x13fe1
movq 0x110(%rsp), %rax
movl $0x1, 0x400(%rax)
movq 0x110(%rsp), %rsi
movq 0x118(%rsp), %rcx
leaq 0x168(%rsp), %rdi
movl $0x101, %edx            # imm = 0x101
movl $0xf, %r8d
callq 0x15cf0
movl %eax, 0x1a4(%rsp)
cmpl $0x0, 0x1a4(%rsp)
je 0x140c4
jmp 0x14aab
movq 0xf8(%rsp), %rsi
movq 0x100(%rsp), %rcx
leaq 0x148(%rsp), %rdi
movl $0x2, %edx
movl $0xf, %r8d
callq 0x15cf0
movl %eax, 0x1a4(%rsp)
cmpl $0x0, 0x1a4(%rsp)
je 0x14102
jmp 0x14aab
movl 0x184(%rsp), %eax
movq %rax, 0x80(%rsp)
cmpq $0x11e, 0x80(%rsp) # imm = 0x11E
jbe 0x1412b
movq $0x11e, 0x80(%rsp) # imm = 0x11E
movl 0x164(%rsp), %eax
movq %rax, 0x78(%rsp)
cmpq $0x1e, 0x78(%rsp)
jbe 0x14148
movq $0x1e, 0x78(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpq 0x80(%rsp), %rax
je 0x14193
movq 0x70(%rsp), %rax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x156f0
movl %eax, %esi
leaq 0xc8(%rsp), %rdi
callq 0x159b0
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x14151
movq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpq 0x78(%rsp), %rax
je 0x141db
movq 0x70(%rsp), %rax
movl %eax, %esi
leaq 0x148(%rsp), %rdi
callq 0x156f0
movl %eax, %esi
leaq 0xc8(%rsp), %rdi
callq 0x159b0
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x1419c
movq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq 0xd0(%rsp), %rcx
movl %ecx, %ecx
cmpq %rcx, %rax
je 0x14433
movl $0x0, 0x58(%rsp)
movq 0x70(%rsp), %rcx
movl 0x58(%rsp), %eax
addq %rax, %rcx
addq $0x1, %rcx
movq 0xd0(%rsp), %rax
movl %eax, %eax
movl %eax, %edx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0x47(%rsp)
jae 0x1425a
movq 0xc8(%rsp), %rax
movq 0x70(%rsp), %rcx
movl 0x58(%rsp), %edx
addq %rdx, %rcx
movl 0x4(%rax,%rcx,4), %eax
movq 0xc8(%rsp), %rcx
movq 0x70(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
sete %al
movb %al, 0x47(%rsp)
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x14264
jmp 0x14271
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x14204
movq 0xc8(%rsp), %rax
movq 0x70(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x1431d
cmpl $0x2, 0x58(%rsp)
jb 0x1431d
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
cmpl $0xa, 0x58(%rsp)
ja 0x142cd
leaq 0xb0(%rsp), %rdi
movl $0x11, %esi
callq 0x159b0
movl 0x58(%rsp), %esi
subl $0x3, %esi
leaq 0xb0(%rsp), %rdi
callq 0x159b0
jmp 0x14305
cmpl $0x8a, 0x58(%rsp)
jbe 0x142df
movl $0x8a, 0x58(%rsp)
leaq 0xb0(%rsp), %rdi
movl $0x12, %esi
callq 0x159b0
movl 0x58(%rsp), %esi
subl $0xb, %esi
leaq 0xb0(%rsp), %rdi
callq 0x159b0
movl 0x58(%rsp), %eax
subl $0x1, %eax
movl %eax, %eax
addq 0x70(%rsp), %rax
movq %rax, 0x70(%rsp)
jmp 0x1441e
cmpl $0x3, 0x58(%rsp)
jb 0x143ff
movl 0x58(%rsp), %eax
movl $0x6, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, 0x4c(%rsp)
movl 0x58(%rsp), %eax
movl $0x6, %ecx
xorl %edx, %edx
divl %ecx
movl %edx, 0x48(%rsp)
movq 0xc8(%rsp), %rax
movq 0x70(%rsp), %rcx
movl (%rax,%rcx,4), %esi
leaq 0xb0(%rsp), %rdi
callq 0x159b0
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
movl 0x4c(%rsp), %ecx
cmpq %rcx, %rax
jae 0x143b2
leaq 0xb0(%rsp), %rdi
movl $0x10, %esi
callq 0x159b0
leaq 0xb0(%rsp), %rdi
movl $0x3, %esi
callq 0x159b0
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x14370
cmpl $0x3, 0x48(%rsp)
jb 0x143e1
leaq 0xb0(%rsp), %rdi
movl $0x10, %esi
callq 0x159b0
movl 0x48(%rsp), %esi
subl $0x3, %esi
leaq 0xb0(%rsp), %rdi
callq 0x159b0
jmp 0x143ef
movl 0x48(%rsp), %ecx
movl 0x58(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x58(%rsp)
movl 0x58(%rsp), %eax
addq 0x70(%rsp), %rax
movq %rax, 0x70(%rsp)
jmp 0x1441c
movq 0xc8(%rsp), %rax
movq 0x70(%rsp), %rcx
movl (%rax,%rcx,4), %esi
leaq 0xb0(%rsp), %rdi
callq 0x159b0
jmp 0x1441e
jmp 0x14420
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x141e4
leaq 0xe0(%rsp), %rdi
movl $0x13, %esi
xorl %edx, %edx
callq 0x13190
cmpl $0x0, %eax
jne 0x1445c
movl $0x53, 0x1a4(%rsp)
jmp 0x14aab
movq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpq 0xb8(%rsp), %rax
je 0x144c8
movq 0xe0(%rsp), %rax
movq 0xb0(%rsp), %rcx
movq 0x70(%rsp), %rdx
movl (%rcx,%rdx,4), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq 0xb0(%rsp), %rax
movq 0x70(%rsp), %rcx
cmpl $0x10, (%rax,%rcx,4)
jb 0x144b6
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x144b8
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x14465
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rdx
movq 0xe8(%rsp), %rcx
leaq 0x128(%rsp), %rdi
movl $0x7, %r8d
callq 0x15cf0
movl %eax, 0x1a4(%rsp)
cmpl $0x0, 0x1a4(%rsp)
je 0x14509
jmp 0x14aab
movl 0x144(%rsp), %eax
movl %eax, %esi
leaq 0x98(%rsp), %rdi
callq 0x134d0
cmpl $0x0, %eax
jne 0x14534
movl $0x53, 0x1a4(%rsp)
jmp 0x14aab
movq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
movl 0x144(%rsp), %ecx
cmpq %rcx, %rax
je 0x1458c
movq 0x70(%rsp), %rcx
leaq 0x8226(%rip), %rax      # 0x1c780
movl (%rax,%rcx,4), %esi
leaq 0x128(%rsp), %rdi
callq 0x156f0
movl %eax, %edx
movq 0x98(%rsp), %rax
movq 0x70(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x1453d
jmp 0x1458e
movq 0x98(%rsp), %rcx
movq 0xa0(%rsp), %rdx
subq $0x1, %rdx
xorl %eax, %eax
cmpl $0x0, (%rcx,%rdx,4)
movb %al, 0x46(%rsp)
jne 0x145be
cmpq $0x4, 0xa0(%rsp)
seta %al
movb %al, 0x46(%rsp)
movb 0x46(%rsp), %al
testb $0x1, %al
jne 0x145c8
jmp 0x145f5
movq 0xa0(%rsp), %rsi
subq $0x1, %rsi
leaq 0x98(%rsp), %rdi
callq 0x134d0
cmpl $0x0, %eax
jne 0x145f3
movl $0x53, 0x1a4(%rsp)
jmp 0x145f5
jmp 0x1458e
cmpl $0x0, 0x1a4(%rsp)
je 0x14604
jmp 0x14aab
movq 0x1c8(%rsp), %rax
movq (%rax), %rax
andq $0x7, %rax
cmpq $0x0, %rax
jne 0x14628
movq 0x1d0(%rsp), %rdi
xorl %esi, %esi
callq 0x81d0
movl 0x8c(%rsp), %esi
movq 0x1c8(%rsp), %rax
movq (%rax), %rax
andq $0x7, %rax
movl %eax, %ecx
shll %cl, %esi
movq 0x1d0(%rsp), %rax
movq (%rax), %rax
movq 0x1d0(%rsp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq 0x1c8(%rsp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq 0x1c8(%rsp), %rax
movq (%rax), %rax
andq $0x7, %rax
cmpq $0x0, %rax
jne 0x1469c
movq 0x1d0(%rsp), %rdi
xorl %esi, %esi
callq 0x81d0
movq 0x1c8(%rsp), %rax
movq (%rax), %rax
andq $0x7, %rax
movl %eax, %ecx
xorl %esi, %esi
shll %cl, %esi
movq 0x1d0(%rsp), %rax
movq (%rax), %rax
movq 0x1d0(%rsp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq 0x1c8(%rsp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq 0x1c8(%rsp), %rax
movq (%rax), %rax
andq $0x7, %rax
cmpq $0x0, %rax
jne 0x1470b
movq 0x1d0(%rsp), %rdi
xorl %esi, %esi
callq 0x81d0
movq 0x1c8(%rsp), %rax
movq (%rax), %rax
andq $0x7, %rax
movl %eax, %ecx
movl $0x1, %esi
shll %cl, %esi
movq 0x1d0(%rsp), %rax
movq (%rax), %rax
movq 0x1d0(%rsp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq 0x1c8(%rsp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq 0x80(%rsp), %rax
subq $0x101, %rax            # imm = 0x101
movl %eax, 0x6c(%rsp)
movq 0x78(%rsp), %rax
subq $0x1, %rax
movl %eax, 0x68(%rsp)
movq 0xa0(%rsp), %rax
subl $0x4, %eax
movl %eax, 0x64(%rsp)
movq 0x98(%rsp), %rcx
movl 0x64(%rsp), %eax
addl $0x4, %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
xorl %eax, %eax
cmpl $0x0, (%rcx,%rdx,4)
movb %al, 0x45(%rsp)
jne 0x147b5
cmpl $0x0, 0x64(%rsp)
seta %al
movb %al, 0x45(%rsp)
movb 0x45(%rsp), %al
testb $0x1, %al
jne 0x147bf
jmp 0x147cc
movl 0x64(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x14787
movq 0x1c8(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
movl 0x6c(%rsp), %edx
movl $0x5, %ecx
callq 0x15b80
movq 0x1c8(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
movl 0x68(%rsp), %edx
movl $0x5, %ecx
callq 0x15b80
movq 0x1c8(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
movl 0x64(%rsp), %edx
movl $0x4, %ecx
callq 0x15b80
movq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
movl 0x64(%rsp), %ecx
addl $0x4, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
je 0x1487c
movq 0x1c8(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
movq 0x98(%rsp), %rax
movq 0x70(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movl $0x3, %ecx
callq 0x15b80
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x1482f
movq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpq 0xb8(%rsp), %rax
je 0x14a03
movq 0x1c8(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x1d0(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xb0(%rsp), %rax
movq 0x70(%rsp), %rcx
movl (%rax,%rcx,4), %esi
leaq 0x128(%rsp), %rdi
callq 0x156d0
movl %eax, 0x40(%rsp)
movq 0xb0(%rsp), %rax
movq 0x70(%rsp), %rcx
movl (%rax,%rcx,4), %esi
leaq 0x128(%rsp), %rdi
callq 0x156f0
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl 0x40(%rsp), %edx
movl %eax, %ecx
callq 0x15690
movq 0xb0(%rsp), %rax
movq 0x70(%rsp), %rcx
cmpl $0x10, (%rax,%rcx,4)
jne 0x14954
movq 0x1c8(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
movq 0xb0(%rsp), %rax
movq 0x70(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x70(%rsp)
movl 0x4(%rax,%rcx,4), %edx
movl $0x2, %ecx
callq 0x15b80
jmp 0x149ee
movq 0xb0(%rsp), %rax
movq 0x70(%rsp), %rcx
cmpl $0x11, (%rax,%rcx,4)
jne 0x149a0
movq 0x1c8(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
movq 0xb0(%rsp), %rax
movq 0x70(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x70(%rsp)
movl 0x4(%rax,%rcx,4), %edx
movl $0x3, %ecx
callq 0x15b80
jmp 0x149ec
movq 0xb0(%rsp), %rax
movq 0x70(%rsp), %rcx
cmpl $0x12, (%rax,%rcx,4)
jne 0x149ea
movq 0x1c8(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
movq 0xb0(%rsp), %rax
movq 0x70(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x70(%rsp)
movl 0x4(%rax,%rcx,4), %edx
movl $0x7, %ecx
callq 0x15b80
jmp 0x149ec
jmp 0x149ee
jmp 0x149f0
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x14885
movq 0x1c8(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
leaq 0x188(%rsp), %rdx
leaq 0x168(%rsp), %rcx
leaq 0x148(%rsp), %r8
callq 0x15490
leaq 0x168(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x156f0
cmpl $0x0, %eax
jne 0x14a54
movl $0x40, 0x1a4(%rsp)
jmp 0x14aab
movq 0x1c8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x1d0(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x168(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x156d0
movl %eax, 0x2c(%rsp)
leaq 0x168(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x156f0
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x2c(%rsp), %edx
movl %eax, %ecx
callq 0x15690
leaq 0x188(%rsp), %rdi
callq 0x13220
leaq 0x168(%rsp), %rdi
callq 0x12cc0
leaq 0x148(%rsp), %rdi
callq 0x12cc0
leaq 0x128(%rsp), %rdi
callq 0x12cc0
leaq 0x110(%rsp), %rdi
callq 0x13220
leaq 0xf8(%rsp), %rdi
callq 0x13220
leaq 0xe0(%rsp), %rdi
callq 0x13220
leaq 0xb0(%rsp), %rdi
callq 0x13220
leaq 0xc8(%rsp), %rdi
callq 0x13220
leaq 0x98(%rsp), %rdi
callq 0x13220
movl 0x1a4(%rsp), %eax
addq $0x1d8, %rsp            # imm = 0x1D8
retq
nopl (%rax)