// File: lvandeve[P]lodepng/lodepng.cpp
// Function: filter(unsigned char*, unsigned char const*, unsigned int, unsigned int, LodePNGColorMode const*, LodePNGEncoderSettings const*)
static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h,
                       const LodePNGColorMode* color, const LodePNGEncoderSettings* settings) {
  /*
  For PNG filter method 0
  out must be a buffer with as size: h + (w * h * bpp + 7u) / 8u, because there are
  the scanlines with 1 extra byte per scanline
  */

  unsigned bpp = lodepng_get_bpp(color);
  /*the width of a scanline in bytes, not including the filter type*/
  size_t linebytes = lodepng_get_raw_size_idat(w, 1, bpp) - 1u;

  /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/
  size_t bytewidth = (bpp + 7u) / 8u;
  const unsigned char* prevline = 0;
  unsigned x, y;
  unsigned error = 0;
  LodePNGFilterStrategy strategy = settings->filter_strategy;

  if(settings->filter_palette_zero && (color->colortype == LCT_PALETTE || color->bitdepth < 8)) {
    /*if the filter_palette_zero setting is enabled, override the filter strategy with
    zero for all scanlines for palette and less-than-8-bitdepth images*/
    strategy = LFS_ZERO;
  }

  if(bpp == 0) return 31; /*error: invalid color type*/

  if(strategy >= LFS_ZERO && strategy <= LFS_FOUR) {
    unsigned char type = (unsigned char)strategy;
    for(y = 0; y != h; ++y) {
      size_t outindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/
      size_t inindex = linebytes * y;
      out[outindex] = type; /*filter type byte*/
      filterScanline(&out[outindex + 1], &in[inindex], prevline, linebytes, bytewidth, type);
      prevline = &in[inindex];
    }
  } else if(strategy == LFS_MINSUM) {
    /*adaptive filtering: independently for each row, try all five filter types and select the one that produces the
    smallest sum of absolute values per row.*/
    unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/
    size_t smallest = 0;
    unsigned char type, bestType = 0;

    for(type = 0; type != 5; ++type) {
      attempt[type] = (unsigned char*)lodepng_malloc(linebytes);
      if(!attempt[type]) error = 83; /*alloc fail*/
    }

    if(!error) {
      for(y = 0; y != h; ++y) {
        /*try the 5 filter types*/
        for(type = 0; type != 5; ++type) {
          size_t sum = 0;
          filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type);

          /*calculate the sum of the result*/
          if(type == 0) {
            for(x = 0; x != linebytes; ++x) sum += (unsigned char)(attempt[type][x]);
          } else {
            for(x = 0; x != linebytes; ++x) {
              /*For differences, each byte should be treated as signed, values above 127 are negative
              (converted to signed char). Filtertype 0 isn't a difference though, so use unsigned there.
              This means filtertype 0 is almost never chosen, but that is justified.*/
              unsigned char s = attempt[type][x];
              sum += s < 128 ? s : (255U - s);
            }
          }

          /*check if this is smallest sum (or if type == 0 it's the first case so always store the values)*/
          if(type == 0 || sum < smallest) {
            bestType = type;
            smallest = sum;
          }
        }

        prevline = &in[y * linebytes];

        /*now fill the out values*/
        out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/
        for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType][x];
      }
    }

    for(type = 0; type != 5; ++type) lodepng_free(attempt[type]);
  } else if(strategy == LFS_ENTROPY) {
    unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/
    size_t bestSum = 0;
    unsigned type, bestType = 0;
    unsigned count[256];

    for(type = 0; type != 5; ++type) {
      attempt[type] = (unsigned char*)lodepng_malloc(linebytes);
      if(!attempt[type]) error = 83; /*alloc fail*/
    }

    if(!error) {
      for(y = 0; y != h; ++y) {
        /*try the 5 filter types*/
        for(type = 0; type != 5; ++type) {
          size_t sum = 0;
          filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type);
          lodepng_memset(count, 0, 256 * sizeof(*count));
          for(x = 0; x != linebytes; ++x) ++count[attempt[type][x]];
          ++count[type]; /*the filter type itself is part of the scanline*/
          for(x = 0; x != 256; ++x) {
            sum += ilog2i(count[x]);
          }
          /*check if this is smallest sum (or if type == 0 it's the first case so always store the values)*/
          if(type == 0 || sum > bestSum) {
            bestType = type;
            bestSum = sum;
          }
        }

        prevline = &in[y * linebytes];

        /*now fill the out values*/
        out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/
        for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType][x];
      }
    }

    for(type = 0; type != 5; ++type) lodepng_free(attempt[type]);
  } else if(strategy == LFS_PREDEFINED) {
    for(y = 0; y != h; ++y) {
      size_t outindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/
      size_t inindex = linebytes * y;
      unsigned char type = settings->predefined_filters[y];
      out[outindex] = type; /*filter type byte*/
      filterScanline(&out[outindex + 1], &in[inindex], prevline, linebytes, bytewidth, type);
      prevline = &in[inindex];
    }
  } else if(strategy == LFS_BRUTE_FORCE) {
    /*brute force filter chooser.
    deflate the scanline after every filter attempt to see which one deflates best.
    This is very slow and gives only slightly smaller, sometimes even larger, result*/
    size_t size[5];
    unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/
    size_t smallest = 0;
    unsigned type = 0, bestType = 0;
    unsigned char* dummy;
    LodePNGCompressSettings zlibsettings;
    lodepng_memcpy(&zlibsettings, &settings->zlibsettings, sizeof(LodePNGCompressSettings));
    /*use fixed tree on the attempts so that the tree is not adapted to the filtertype on purpose,
    to simulate the true case where the tree is the same for the whole image. Sometimes it gives
    better result with dynamic tree anyway. Using the fixed tree sometimes gives worse, but in rare
    cases better compression. It does make this a bit less slow, so it's worth doing this.*/
    zlibsettings.btype = 1;
    /*a custom encoder likely doesn't read the btype setting and is optimized for complete PNG
    images only, so disable it*/
    zlibsettings.custom_zlib = 0;
    zlibsettings.custom_deflate = 0;
    for(type = 0; type != 5; ++type) {
      attempt[type] = (unsigned char*)lodepng_malloc(linebytes);
      if(!attempt[type]) error = 83; /*alloc fail*/
    }
    if(!error) {
      for(y = 0; y != h; ++y) /*try the 5 filter types*/ {
        for(type = 0; type != 5; ++type) {
          unsigned testsize = (unsigned)linebytes;
          /*if(testsize > 8) testsize /= 8;*/ /*it already works good enough by testing a part of the row*/

          filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type);
          size[type] = 0;
          dummy = 0;
          zlib_compress(&dummy, &size[type], attempt[type], testsize, &zlibsettings);
          lodepng_free(dummy);
          /*check if this is smallest size (or if type == 0 it's the first case so always store the values)*/
          if(type == 0 || size[type] < smallest) {
            bestType = type;
            smallest = size[type];
          }
        }
        prevline = &in[y * linebytes];
        out[y * (linebytes + 1)] = bestType; /*the first byte of a scanline will be the filter type*/
        for(x = 0; x != linebytes; ++x) out[y * (linebytes + 1) + 1 + x] = attempt[bestType][x];
      }
    }
    for(type = 0; type != 5; ++type) lodepng_free(attempt[type]);
  }
  else return 88; /* unknown filter strategy */

  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5d0, %rsp            # imm = 0x5D0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x5a60
movl %eax, -0x34(%rbp)
movl -0x1c(%rbp), %edi
movl -0x34(%rbp), %edx
movl $0x1, %esi
callq 0x16c80
subq $0x1, %rax
movq %rax, -0x40(%rbp)
movl -0x34(%rbp), %eax
addl $0x7, %eax
shrl $0x3, %eax
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x30(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x60(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x190a1
movq -0x28(%rbp), %rax
cmpl $0x3, (%rax)
je 0x1909a
movq -0x28(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jae 0x190a1
movl $0x0, -0x60(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x190b3
movl $0x1f, -0x4(%rbp)
jmp 0x19a5e
cmpl $0x0, -0x60(%rbp)
jl 0x19155
cmpl $0x4, -0x60(%rbp)
jg 0x19155
movl -0x60(%rbp), %eax
movb %al, -0x61(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x19150
movq -0x40(%rbp), %rax
addq $0x1, %rax
movl -0x58(%rbp), %ecx
imulq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq %rcx, %rax
movq %rax, -0x78(%rbp)
movb -0x61(%rbp), %dl
movq -0x10(%rbp), %rax
movq -0x70(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rdi
movq -0x70(%rbp), %rax
addq $0x1, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
addq -0x78(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movzbl -0x61(%rbp), %r9d
callq 0x19e40
movq -0x18(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x190d4
jmp 0x19a58
cmpl $0x5, -0x60(%rbp)
jne 0x19424
movq $0x0, -0xa8(%rbp)
movb $0x0, -0xaa(%rbp)
movb $0x0, -0xa9(%rbp)
movzbl -0xa9(%rbp), %eax
cmpl $0x5, %eax
je 0x191ca
movq -0x40(%rbp), %rdi
callq 0x3bc0
movq %rax, %rcx
movzbl -0xa9(%rbp), %eax
movq %rcx, -0xa0(%rbp,%rax,8)
movzbl -0xa9(%rbp), %eax
cmpq $0x0, -0xa0(%rbp,%rax,8)
jne 0x191b8
movl $0x53, -0x5c(%rbp)
jmp 0x191ba
movb -0xa9(%rbp), %al
addb $0x1, %al
movb %al, -0xa9(%rbp)
jmp 0x19178
cmpl $0x0, -0x5c(%rbp)
jne 0x193e8
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x193e6
movb $0x0, -0xa9(%rbp)
movzbl -0xa9(%rbp), %eax
cmpl $0x5, %eax
je 0x19357
movq $0x0, -0xb8(%rbp)
movzbl -0xa9(%rbp), %eax
movq -0xa0(%rbp,%rax,8), %rdi
movq -0x18(%rbp), %rsi
movl -0x58(%rbp), %eax
imulq -0x40(%rbp), %rax
addq %rax, %rsi
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movzbl -0xa9(%rbp), %r9d
callq 0x19e40
movzbl -0xa9(%rbp), %eax
cmpl $0x0, %eax
jne 0x1928d
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpq -0x40(%rbp), %rax
je 0x1928b
movzbl -0xa9(%rbp), %eax
movq -0xa0(%rbp,%rax,8), %rax
movl -0x54(%rbp), %ecx
movzbl (%rax,%rcx), %eax
addq -0xb8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x19253
jmp 0x1930c
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpq -0x40(%rbp), %rax
je 0x1930a
movzbl -0xa9(%rbp), %eax
movq -0xa0(%rbp,%rax,8), %rax
movl -0x54(%rbp), %ecx
movb (%rax,%rcx), %al
movb %al, -0xb9(%rbp)
movzbl -0xb9(%rbp), %eax
cmpl $0x80, %eax
jge 0x192d5
movzbl -0xb9(%rbp), %eax
movl %eax, -0x5d0(%rbp)
jmp 0x192e9
movzbl -0xb9(%rbp), %ecx
movl $0xff, %eax
subl %ecx, %eax
movl %eax, -0x5d0(%rbp)
movl -0x5d0(%rbp), %eax
movl %eax, %eax
addq -0xb8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x19294
jmp 0x1930c
movzbl -0xa9(%rbp), %eax
cmpl $0x0, %eax
je 0x19328
movq -0xb8(%rbp), %rax
cmpq -0xa8(%rbp), %rax
jae 0x19342
movb -0xa9(%rbp), %al
movb %al, -0xaa(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0x19344
movb -0xa9(%rbp), %al
addb $0x1, %al
movb %al, -0xa9(%rbp)
jmp 0x191ee
movq -0x18(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq -0x40(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movb -0xaa(%rbp), %dl
movq -0x10(%rbp), %rax
movl -0x58(%rbp), %ecx
movq -0x40(%rbp), %rsi
addq $0x1, %rsi
imulq %rsi, %rcx
movb %dl, (%rax,%rcx)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpq -0x40(%rbp), %rax
je 0x193d6
movzbl -0xaa(%rbp), %eax
movq -0xa0(%rbp,%rax,8), %rax
movl -0x54(%rbp), %ecx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movl -0x58(%rbp), %ecx
movq -0x40(%rbp), %rsi
addq $0x1, %rsi
imulq %rsi, %rcx
addq $0x1, %rcx
movl -0x54(%rbp), %esi
addq %rsi, %rcx
movb %dl, (%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1938d
jmp 0x193d8
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x191db
jmp 0x193e8
movb $0x0, -0xa9(%rbp)
movzbl -0xa9(%rbp), %eax
cmpl $0x5, %eax
je 0x1941f
movzbl -0xa9(%rbp), %eax
movq -0xa0(%rbp,%rax,8), %rdi
callq 0x4230
movb -0xa9(%rbp), %al
addb $0x1, %al
movb %al, -0xa9(%rbp)
jmp 0x193ef
jmp 0x19a56
cmpl $0x6, -0x60(%rbp)
jne 0x196ce
movq $0x0, -0xf8(%rbp)
movl $0x0, -0x100(%rbp)
movl $0x0, -0xfc(%rbp)
cmpl $0x5, -0xfc(%rbp)
je 0x1949b
movq -0x40(%rbp), %rdi
callq 0x3bc0
movq %rax, %rcx
movl -0xfc(%rbp), %eax
movq %rcx, -0xf0(%rbp,%rax,8)
movl -0xfc(%rbp), %eax
cmpq $0x0, -0xf0(%rbp,%rax,8)
jne 0x19488
movl $0x53, -0x5c(%rbp)
jmp 0x1948a
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0x1944d
cmpl $0x0, -0x5c(%rbp)
jne 0x19692
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x19690
movl $0x0, -0xfc(%rbp)
cmpl $0x5, -0xfc(%rbp)
je 0x19600
movq $0x0, -0x508(%rbp)
movl -0xfc(%rbp), %eax
movq -0xf0(%rbp,%rax,8), %rdi
movq -0x18(%rbp), %rsi
movl -0x58(%rbp), %eax
imulq -0x40(%rbp), %rax
addq %rax, %rsi
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movl -0xfc(%rbp), %eax
movzbl %al, %r9d
callq 0x19e40
leaq -0x500(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x3be0
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpq -0x40(%rbp), %rax
je 0x19566
movl -0xfc(%rbp), %eax
movq -0xf0(%rbp,%rax,8), %rax
movl -0x54(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movl -0x500(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x500(%rbp,%rax,4)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1952c
movl -0xfc(%rbp), %eax
movl -0x500(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x500(%rbp,%rax,4)
movl $0x0, -0x54(%rbp)
cmpl $0x100, -0x54(%rbp)     # imm = 0x100
je 0x195b7
movl -0x54(%rbp), %eax
movl -0x500(%rbp,%rax,4), %eax
movl %eax, %edi
callq 0x1a280
addq -0x508(%rbp), %rax
movq %rax, -0x508(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x19584
cmpl $0x0, -0xfc(%rbp)
je 0x195d0
movq -0x508(%rbp), %rax
cmpq -0xf8(%rbp), %rax
jbe 0x195ea
movl -0xfc(%rbp), %eax
movl %eax, -0x100(%rbp)
movq -0x508(%rbp), %rax
movq %rax, -0xf8(%rbp)
jmp 0x195ec
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0x194c2
movq -0x18(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq -0x40(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl -0x100(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x58(%rbp), %ecx
movq -0x40(%rbp), %rsi
addq $0x1, %rsi
imulq %rsi, %rcx
movb %dl, (%rax,%rcx)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpq -0x40(%rbp), %rax
je 0x19680
movl -0x100(%rbp), %eax
movq -0xf0(%rbp,%rax,8), %rax
movl -0x54(%rbp), %ecx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movl -0x58(%rbp), %ecx
movq -0x40(%rbp), %rsi
addq $0x1, %rsi
imulq %rsi, %rcx
addq $0x1, %rcx
movl -0x54(%rbp), %esi
addq %rsi, %rcx
movb %dl, (%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x19638
jmp 0x19682
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x194ac
jmp 0x19692
movl $0x0, -0xfc(%rbp)
cmpl $0x5, -0xfc(%rbp)
je 0x196c9
movl -0xfc(%rbp), %eax
movq -0xf0(%rbp,%rax,8), %rdi
callq 0x4230
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0x1969c
jmp 0x19a54
cmpl $0x8, -0x60(%rbp)
jne 0x19793
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x1978e
movq -0x40(%rbp), %rax
addq $0x1, %rax
movl -0x58(%rbp), %ecx
imulq %rcx, %rax
movq %rax, -0x510(%rbp)
movq -0x40(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq %rcx, %rax
movq %rax, -0x518(%rbp)
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x58(%rbp), %ecx
movb (%rax,%rcx), %al
movb %al, -0x519(%rbp)
movb -0x519(%rbp), %dl
movq -0x10(%rbp), %rax
movq -0x510(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rdi
movq -0x510(%rbp), %rax
addq $0x1, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
addq -0x518(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movzbl -0x519(%rbp), %r9d
callq 0x19e40
movq -0x18(%rbp), %rax
addq -0x518(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x196df
jmp 0x19a52
cmpl $0x7, -0x60(%rbp)
jne 0x19a47
movq $0x0, -0x588(%rbp)
movl $0x0, -0x58c(%rbp)
movl $0x0, -0x590(%rbp)
movq -0x30(%rbp), %rsi
leaq -0x5c8(%rbp), %rdi
movl $0x30, %edx
callq 0x5820
movl $0x1, -0x5c8(%rbp)
movq $0x0, -0x5b0(%rbp)
movq $0x0, -0x5a8(%rbp)
movl $0x0, -0x58c(%rbp)
cmpl $0x5, -0x58c(%rbp)
je 0x19849
movq -0x40(%rbp), %rdi
callq 0x3bc0
movq %rax, %rcx
movl -0x58c(%rbp), %eax
movq %rcx, -0x580(%rbp,%rax,8)
movl -0x58c(%rbp), %eax
cmpq $0x0, -0x580(%rbp,%rax,8)
jne 0x19836
movl $0x53, -0x5c(%rbp)
jmp 0x19838
movl -0x58c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58c(%rbp)
jmp 0x197fb
cmpl $0x0, -0x5c(%rbp)
jne 0x19a0e
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x19a0c
movl $0x0, -0x58c(%rbp)
cmpl $0x5, -0x58c(%rbp)
je 0x1997c
movq -0x40(%rbp), %rax
movl %eax, -0x5cc(%rbp)
movl -0x58c(%rbp), %eax
movq -0x580(%rbp,%rax,8), %rdi
movq -0x18(%rbp), %rsi
movl -0x58(%rbp), %eax
imulq -0x40(%rbp), %rax
addq %rax, %rsi
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movl -0x58c(%rbp), %eax
movzbl %al, %r9d
callq 0x19e40
movl -0x58c(%rbp), %eax
movq $0x0, -0x550(%rbp,%rax,8)
movq $0x0, -0x598(%rbp)
movl -0x58c(%rbp), %eax
leaq -0x550(%rbp), %rsi
shlq $0x3, %rax
addq %rax, %rsi
movl -0x58c(%rbp), %eax
movq -0x580(%rbp,%rax,8), %rdx
movl -0x5cc(%rbp), %eax
movl %eax, %ecx
leaq -0x598(%rbp), %rdi
leaq -0x5c8(%rbp), %r8
callq 0x119d0
movq -0x598(%rbp), %rdi
callq 0x4230
cmpl $0x0, -0x58c(%rbp)
je 0x19945
movl -0x58c(%rbp), %eax
movq -0x550(%rbp,%rax,8), %rax
cmpq -0x588(%rbp), %rax
jae 0x19966
movl -0x58c(%rbp), %eax
movl %eax, -0x590(%rbp)
movl -0x58c(%rbp), %eax
movq -0x550(%rbp,%rax,8), %rax
movq %rax, -0x588(%rbp)
jmp 0x19968
movl -0x58c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58c(%rbp)
jmp 0x19870
movq -0x18(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq -0x40(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl -0x590(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x58(%rbp), %ecx
movq -0x40(%rbp), %rsi
addq $0x1, %rsi
imulq %rsi, %rcx
movb %dl, (%rax,%rcx)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpq -0x40(%rbp), %rax
je 0x199fc
movl -0x590(%rbp), %eax
movq -0x580(%rbp,%rax,8), %rax
movl -0x54(%rbp), %ecx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movl -0x58(%rbp), %ecx
movq -0x40(%rbp), %rsi
addq $0x1, %rsi
imulq %rsi, %rcx
addq $0x1, %rcx
movl -0x54(%rbp), %esi
addq %rsi, %rcx
movb %dl, (%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x199b4
jmp 0x199fe
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x1985a
jmp 0x19a0e
movl $0x0, -0x58c(%rbp)
cmpl $0x5, -0x58c(%rbp)
je 0x19a45
movl -0x58c(%rbp), %eax
movq -0x580(%rbp,%rax,8), %rdi
callq 0x4230
movl -0x58c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58c(%rbp)
jmp 0x19a18
jmp 0x19a50
movl $0x58, -0x4(%rbp)
jmp 0x19a5e
jmp 0x19a52
jmp 0x19a54
jmp 0x19a56
jmp 0x19a58
movl -0x5c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x5d0, %rsp            # imm = 0x5D0
popq %rbp
retq
nopw (%rax,%rax)