// File: drummyfish[P]flowchart/src/lodepng.cpp
// Function: deflateDynamic(ucvector*, unsigned long*, Hash*, unsigned char const*, unsigned long, unsigned long, LodePNGCompressSettings const*, int)
static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash,
                               const unsigned char* data, size_t datapos, size_t dataend,
                               const LodePNGCompressSettings* settings, int 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 is 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); /*LZ77 encoded*/
      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] = 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, frequencies_ll.size, 15);
    if(error) break;
    error = HuffmanTree_makeFromFrequencies(&tree_d, frequencies_d.data, 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, 7);
    if(error) break;

    if(!uivector_resize(&bitlen_cl, NUM_CODE_LENGTH_CODES)) ERROR_BREAK(83 /*alloc fail*/);
    for(i = 0; i < NUM_CODE_LENGTH_CODES; 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;
    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:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x30(%rbp), %rax
subq -0x28(%rbp), %rax
movq %rax, -0x148(%rbp)
movl 0x18(%rbp), %eax
movl %eax, -0x14c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xcea0
leaq -0x70(%rbp), %rdi
callq 0xd7d0
leaq -0x90(%rbp), %rdi
callq 0xd7d0
leaq -0xb0(%rbp), %rdi
callq 0xd7d0
leaq -0xc8(%rbp), %rdi
callq 0xcea0
leaq -0xe0(%rbp), %rdi
callq 0xcea0
leaq -0xf8(%rbp), %rdi
callq 0xcea0
leaq -0x110(%rbp), %rdi
callq 0xcea0
leaq -0x128(%rbp), %rdi
callq 0xcea0
leaq -0x140(%rbp), %rdi
callq 0xcea0
cmpl $0x0, -0x34(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xebdd
jmp 0xf635
movq 0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0xec18
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movq 0x10(%rbp), %rax
movl 0x8(%rax), %r9d
leaq -0x50(%rbp), %rdi
callq 0xf790
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0xec16
jmp 0xf635
jmp 0xec84
movq -0x148(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0xcf30
cmpl $0x0, %eax
jne 0xec39
movl $0x53, -0x34(%rbp)
jmp 0xf635
movq -0x28(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0xec82
movq -0x20(%rbp), %rax
movq -0x168(%rbp), %rcx
movzbl (%rax,%rcx), %edx
movq -0x50(%rbp), %rax
movq -0x168(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x168(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x168(%rbp)
jmp 0xec44
jmp 0xec84
leaq -0xc8(%rbp), %rdi
movl $0x11e, %esi            # imm = 0x11E
xorl %edx, %edx
callq 0xe3b0
cmpl $0x0, %eax
jne 0xeca8
movl $0x53, -0x34(%rbp)
jmp 0xf635
leaq -0xe0(%rbp), %rdi
movl $0x1e, %esi
xorl %edx, %edx
callq 0xe3b0
cmpl $0x0, %eax
jne 0xeccc
movl $0x53, -0x34(%rbp)
jmp 0xf635
movq $0x0, -0x168(%rbp)
movq -0x168(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0xed74
movq -0x50(%rbp), %rax
movq -0x168(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x178(%rbp)
movq -0xc8(%rbp), %rax
movl -0x178(%rbp), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
cmpl $0x100, -0x178(%rbp)    # imm = 0x100
jbe 0xed5b
movq -0x50(%rbp), %rax
movq -0x168(%rbp), %rcx
movl 0x8(%rax,%rcx,4), %eax
movl %eax, -0x17c(%rbp)
movq -0xe0(%rbp), %rax
movl -0x17c(%rbp), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x168(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x168(%rbp)
jmp 0xed5d
movq -0x168(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x168(%rbp)
jmp 0xecd7
movq -0xc8(%rbp), %rax
movl $0x1, 0x400(%rax)
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq -0x70(%rbp), %rdi
movl $0xf, %ecx
callq 0x10410
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0xedaf
jmp 0xf635
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
leaq -0x90(%rbp), %rdi
movl $0xf, %ecx
callq 0x10410
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0xeddc
jmp 0xf635
movl -0x54(%rbp), %eax
movq %rax, -0x158(%rbp)
cmpq $0x11e, -0x158(%rbp) # imm = 0x11E
jbe 0xedfe
movq $0x11e, -0x158(%rbp) # imm = 0x11E
movl -0x74(%rbp), %eax
movq %rax, -0x160(%rbp)
cmpq $0x1e, -0x160(%rbp)
jbe 0xee1d
movq $0x1e, -0x160(%rbp)
movq $0x0, -0x168(%rbp)
movq -0x168(%rbp), %rax
cmpq -0x158(%rbp), %rax
jae 0xee6c
movq -0x168(%rbp), %rax
movl %eax, %esi
leaq -0x70(%rbp), %rdi
callq 0xfff0
movl %eax, %esi
leaq -0x110(%rbp), %rdi
callq 0xced0
movq -0x168(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x168(%rbp)
jmp 0xee28
movq $0x0, -0x168(%rbp)
movq -0x168(%rbp), %rax
cmpq -0x160(%rbp), %rax
jae 0xeebe
movq -0x168(%rbp), %rax
movl %eax, %esi
leaq -0x90(%rbp), %rdi
callq 0xfff0
movl %eax, %esi
leaq -0x110(%rbp), %rdi
callq 0xced0
movq -0x168(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x168(%rbp)
jmp 0xee77
movq $0x0, -0x168(%rbp)
movq -0x168(%rbp), %rax
movq -0x108(%rbp), %rcx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0xf163
movl $0x0, -0x180(%rbp)
movq -0x168(%rbp), %rcx
movl -0x180(%rbp), %eax
addq %rax, %rcx
addq $0x1, %rcx
movq -0x108(%rbp), %rax
movl %eax, %eax
movl %eax, %edx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x191(%rbp)
jae 0xef4d
movq -0x110(%rbp), %rax
movq -0x168(%rbp), %rcx
movl -0x180(%rbp), %edx
addq %rdx, %rcx
movl 0x4(%rax,%rcx,4), %eax
movq -0x110(%rbp), %rcx
movq -0x168(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
sete %al
movb %al, -0x191(%rbp)
movb -0x191(%rbp), %al
testb $0x1, %al
jne 0xef59
jmp 0xef6a
movl -0x180(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x180(%rbp)
jmp 0xeeec
movq -0x110(%rbp), %rax
movq -0x168(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0xf029
cmpl $0x2, -0x180(%rbp)
jb 0xf029
movl -0x180(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x180(%rbp)
cmpl $0xa, -0x180(%rbp)
ja 0xefcf
leaq -0x128(%rbp), %rdi
movl $0x11, %esi
callq 0xced0
movl -0x180(%rbp), %esi
subl $0x3, %esi
leaq -0x128(%rbp), %rdi
callq 0xced0
jmp 0xf00b
cmpl $0x8a, -0x180(%rbp)
jbe 0xefe5
movl $0x8a, -0x180(%rbp)
leaq -0x128(%rbp), %rdi
movl $0x12, %esi
callq 0xced0
movl -0x180(%rbp), %esi
subl $0xb, %esi
leaq -0x128(%rbp), %rdi
callq 0xced0
movl -0x180(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
addq -0x168(%rbp), %rax
movq %rax, -0x168(%rbp)
jmp 0xf14a
cmpl $0x3, -0x180(%rbp)
jb 0xf12b
movl -0x180(%rbp), %eax
movl $0x6, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, -0x18c(%rbp)
movl -0x180(%rbp), %eax
movl $0x6, %ecx
xorl %edx, %edx
divl %ecx
movl %edx, -0x190(%rbp)
movq -0x110(%rbp), %rax
movq -0x168(%rbp), %rcx
movl (%rax,%rcx,4), %esi
leaq -0x128(%rbp), %rdi
callq 0xced0
movq $0x0, -0x188(%rbp)
movq -0x188(%rbp), %rax
movl -0x18c(%rbp), %ecx
cmpq %rcx, %rax
jae 0xf0d0
leaq -0x128(%rbp), %rdi
movl $0x10, %esi
callq 0xced0
leaq -0x128(%rbp), %rdi
movl $0x3, %esi
callq 0xced0
movq -0x188(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x188(%rbp)
jmp 0xf088
cmpl $0x3, -0x190(%rbp)
jb 0xf101
leaq -0x128(%rbp), %rdi
movl $0x10, %esi
callq 0xced0
movl -0x190(%rbp), %esi
subl $0x3, %esi
leaq -0x128(%rbp), %rdi
callq 0xced0
jmp 0xf115
movl -0x190(%rbp), %ecx
movl -0x180(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x180(%rbp)
movl -0x180(%rbp), %eax
addq -0x168(%rbp), %rax
movq %rax, -0x168(%rbp)
jmp 0xf148
movq -0x110(%rbp), %rax
movq -0x168(%rbp), %rcx
movl (%rax,%rcx,4), %esi
leaq -0x128(%rbp), %rdi
callq 0xced0
jmp 0xf14a
jmp 0xf14c
movq -0x168(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x168(%rbp)
jmp 0xeec9
leaq -0xf8(%rbp), %rdi
movl $0x13, %esi
xorl %edx, %edx
callq 0xe3b0
cmpl $0x0, %eax
jne 0xf187
movl $0x53, -0x34(%rbp)
jmp 0xf635
movq $0x0, -0x168(%rbp)
movq -0x168(%rbp), %rax
cmpq -0x120(%rbp), %rax
jae 0xf1ff
movq -0xf8(%rbp), %rax
movq -0x128(%rbp), %rcx
movq -0x168(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x128(%rbp), %rax
movq -0x168(%rbp), %rcx
cmpl $0x10, (%rax,%rcx,4)
jb 0xf1e9
movq -0x168(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x168(%rbp)
jmp 0xf1eb
movq -0x168(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x168(%rbp)
jmp 0xf192
movq -0xf8(%rbp), %rsi
movq -0xf0(%rbp), %rdx
leaq -0xb0(%rbp), %rdi
movl $0x7, %ecx
callq 0x10410
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0xf22c
jmp 0xf635
leaq -0x140(%rbp), %rdi
movl $0x13, %esi
callq 0xcf30
cmpl $0x0, %eax
jne 0xf24e
movl $0x53, -0x34(%rbp)
jmp 0xf635
movq $0x0, -0x168(%rbp)
cmpq $0x13, -0x168(%rbp)
jae 0xf2a7
movq -0x168(%rbp), %rcx
leaq 0xf1bf(%rip), %rax      # 0x1e430
movl (%rax,%rcx,4), %esi
leaq -0xb0(%rbp), %rdi
callq 0xfff0
movl %eax, %edx
movq -0x140(%rbp), %rax
movq -0x168(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x168(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x168(%rbp)
jmp 0xf259
jmp 0xf2a9
movq -0x140(%rbp), %rcx
movq -0x138(%rbp), %rdx
subq $0x1, %rdx
xorl %eax, %eax
cmpl $0x0, (%rcx,%rdx,4)
movb %al, -0x192(%rbp)
jne 0xf2da
cmpq $0x4, -0x138(%rbp)
seta %al
movb %al, -0x192(%rbp)
movb -0x192(%rbp), %al
testb $0x1, %al
jne 0xf2e6
jmp 0xf30d
movq -0x138(%rbp), %rsi
subq $0x1, %rsi
leaq -0x140(%rbp), %rdi
callq 0xcf30
cmpl $0x0, %eax
jne 0xf30b
movl $0x53, -0x34(%rbp)
jmp 0xf30d
jmp 0xf2a9
cmpl $0x0, -0x34(%rbp)
je 0xf318
jmp 0xf635
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x14c(%rbp), %eax
movzbl %al, %edx
callq 0xf710
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
xorl %edx, %edx
callq 0xf710
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl $0x1, %edx
callq 0xf710
movq -0x158(%rbp), %rax
subq $0x101, %rax            # imm = 0x101
movl %eax, -0x16c(%rbp)
movq -0x160(%rbp), %rax
subq $0x1, %rax
movl %eax, -0x170(%rbp)
movq -0x138(%rbp), %rax
subl $0x4, %eax
movl %eax, -0x174(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x16c(%rbp), %edx
movl $0x5, %ecx
callq 0x10340
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x170(%rbp), %edx
movl $0x5, %ecx
callq 0x10340
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x174(%rbp), %edx
movl $0x4, %ecx
callq 0x10340
movq $0x0, -0x168(%rbp)
movq -0x168(%rbp), %rax
movl -0x174(%rbp), %ecx
addl $0x4, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0xf424
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x140(%rbp), %rax
movq -0x168(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movl $0x3, %ecx
callq 0x10340
movq -0x168(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x168(%rbp)
jmp 0xf3d6
movq $0x0, -0x168(%rbp)
movq -0x168(%rbp), %rax
cmpq -0x120(%rbp), %rax
jae 0xf5aa
movq -0x10(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x128(%rbp), %rax
movq -0x168(%rbp), %rcx
movl (%rax,%rcx,4), %esi
leaq -0xb0(%rbp), %rdi
callq 0xffd0
movl %eax, -0x198(%rbp)
movq -0x128(%rbp), %rax
movq -0x168(%rbp), %rcx
movl (%rax,%rcx,4), %esi
leaq -0xb0(%rbp), %rdi
callq 0xfff0
movq -0x1a8(%rbp), %rdi
movq -0x1a0(%rbp), %rsi
movl -0x198(%rbp), %edx
movl %eax, %ecx
callq 0xff90
movq -0x128(%rbp), %rax
movq -0x168(%rbp), %rcx
cmpl $0x10, (%rax,%rcx,4)
jne 0xf4ff
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x128(%rbp), %rax
movq -0x168(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x168(%rbp)
movl 0x4(%rax,%rcx,4), %edx
movl $0x2, %ecx
callq 0x10340
jmp 0xf591
movq -0x128(%rbp), %rax
movq -0x168(%rbp), %rcx
cmpl $0x11, (%rax,%rcx,4)
jne 0xf547
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x128(%rbp), %rax
movq -0x168(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x168(%rbp)
movl 0x4(%rax,%rcx,4), %edx
movl $0x3, %ecx
callq 0x10340
jmp 0xf58f
movq -0x128(%rbp), %rax
movq -0x168(%rbp), %rcx
cmpl $0x12, (%rax,%rcx,4)
jne 0xf58d
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x128(%rbp), %rax
movq -0x168(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x168(%rbp)
movl 0x4(%rax,%rcx,4), %edx
movl $0x7, %ecx
callq 0x10340
jmp 0xf58f
jmp 0xf591
jmp 0xf593
movq -0x168(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x168(%rbp)
jmp 0xf42f
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x70(%rbp), %rcx
leaq -0x90(%rbp), %r8
callq 0xfde0
leaq -0x70(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0xfff0
cmpl $0x0, %eax
jne 0xf5e2
movl $0x40, -0x34(%rbp)
jmp 0xf635
movq -0x10(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1b8(%rbp)
leaq -0x70(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0xffd0
movl %eax, -0x1ac(%rbp)
leaq -0x70(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0xfff0
movq -0x1c0(%rbp), %rdi
movq -0x1b8(%rbp), %rsi
movl -0x1ac(%rbp), %edx
movl %eax, %ecx
callq 0xff90
leaq -0x50(%rbp), %rdi
callq 0xd080
leaq -0x70(%rbp), %rdi
callq 0xdf60
leaq -0x90(%rbp), %rdi
callq 0xdf60
leaq -0xb0(%rbp), %rdi
callq 0xdf60
leaq -0xc8(%rbp), %rdi
callq 0xd080
leaq -0xe0(%rbp), %rdi
callq 0xd080
leaq -0xf8(%rbp), %rdi
callq 0xd080
leaq -0x128(%rbp), %rdi
callq 0xd080
leaq -0x110(%rbp), %rdi
callq 0xd080
leaq -0x140(%rbp), %rdi
callq 0xd080
movl -0x34(%rbp), %eax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
nopw %cs:(%rax,%rax)