// File: Lut99[P]RayTracer/src/lib/LodePNG.cpp
// Function: lodepng_encode(unsigned char**, unsigned long*, unsigned char const*, unsigned int, unsigned int, LodePNGState*)
unsigned lodepng_encode(unsigned char** out, size_t* outsize,
                        const unsigned char* image, unsigned w, unsigned h,
                        LodePNGState* state) {
  unsigned char* data = 0; /*uncompressed version of the IDAT chunk data*/
  size_t datasize = 0;
  ucvector outv;
  LodePNGInfo info;
  const LodePNGInfo* info_png = &state->info_png;

  ucvector_init(&outv);
  lodepng_info_init(&info);

  /*provide some proper output values if error will happen*/
  *out = 0;
  *outsize = 0;
  state->error = 0;

  /*check input values validity*/
  if((info_png->color.colortype == LCT_PALETTE || state->encoder.force_palette)
      && (info_png->color.palettesize == 0 || info_png->color.palettesize > 256)) {
    state->error = 68; /*invalid palette size, it is only allowed to be 1-256*/
    goto cleanup;
  }
  if(state->encoder.zlibsettings.btype > 2) {
    state->error = 61; /*error: nonexistent btype*/
    goto cleanup;
  }
  if(info_png->interlace_method > 1) {
    state->error = 71; /*error: nonexistent interlace mode*/
    goto cleanup;
  }
  state->error = checkColorValidity(info_png->color.colortype, info_png->color.bitdepth);
  if(state->error) goto cleanup; /*error: nonexistent color type given*/
  state->error = checkColorValidity(state->info_raw.colortype, state->info_raw.bitdepth);
  if(state->error) goto cleanup; /*error: nonexistent color type given*/

  /* color convert and compute scanline filter types */
  lodepng_info_copy(&info, &state->info_png);
  if(state->encoder.auto_convert) {
    LodePNGColorStats stats;
    lodepng_color_stats_init(&stats);
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
    if(info_png->iccp_defined &&
        isGrayICCProfile(info_png->iccp_profile, info_png->iccp_profile_size)) {
      /*the PNG specification does not allow to use palette with a GRAY ICC profile, even
      if the palette has only gray colors, so disallow it.*/
      stats.allow_palette = 0;
    }
    if(info_png->iccp_defined &&
        isRGBICCProfile(info_png->iccp_profile, info_png->iccp_profile_size)) {
      /*the PNG specification does not allow to use grayscale color with RGB ICC profile, so disallow gray.*/
      stats.allow_greyscale = 0;
    }
#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */
    lodepng_compute_color_stats(&stats, image, w, h, &state->info_raw);
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
    if(info_png->background_defined) {
      /*the background chunk's color must be taken into account as well*/
      unsigned r = 0, g = 0, b = 0;
      LodePNGColorMode mode16 = lodepng_color_mode_make(LCT_RGB, 16);
      lodepng_convert_rgb(&r, &g, &b, info_png->background_r, info_png->background_g, info_png->background_b, &mode16, &info_png->color);
      lodepng_color_stats_add(&stats, r, g, b, 65535);
    }
#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */
    state->error = auto_choose_color(&info.color, &state->info_raw, &stats);
    if(state->error) goto cleanup;
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
    /*also convert the background chunk*/
    if(info_png->background_defined) {
      if(lodepng_convert_rgb(&info.background_r, &info.background_g, &info.background_b,
          info_png->background_r, info_png->background_g, info_png->background_b, &info.color, &info_png->color)) {
        state->error = 104;
        goto cleanup;
      }
    }
#endif /* LODEPNG_COMPILE_ANCILLARY_CHUNKS */
  }
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
  if(info_png->iccp_defined) {
    unsigned gray_icc = isGrayICCProfile(info_png->iccp_profile, info_png->iccp_profile_size);
    unsigned rgb_icc = isRGBICCProfile(info_png->iccp_profile, info_png->iccp_profile_size);
    unsigned gray_png = info.color.colortype == LCT_GREY || info.color.colortype == LCT_GREY_ALPHA;
    if(!gray_icc && !rgb_icc) {
      state->error = 100; /* Disallowed profile color type for PNG */
      goto cleanup;
    }
    if(gray_icc != gray_png) {
      /*Not allowed to use RGB/RGBA/palette with GRAY ICC profile or vice versa,
      or in case of auto_convert, it wasn't possible to find appropriate model*/
      state->error = state->encoder.auto_convert ? 102 : 101;
      goto cleanup;
    }
  }
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
  if(!lodepng_color_mode_equal(&state->info_raw, &info.color)) {
    unsigned char* converted;
    size_t size = ((size_t)w * (size_t)h * (size_t)lodepng_get_bpp(&info.color) + 7u) / 8u;

    converted = (unsigned char*)lodepng_malloc(size);
    if(!converted && size) state->error = 83; /*alloc fail*/
    if(!state->error) {
      state->error = lodepng_convert(converted, image, &info.color, &state->info_raw, w, h);
    }
    if(!state->error) preProcessScanlines(&data, &datasize, converted, w, h, &info, &state->encoder);
    lodepng_free(converted);
    if(state->error) goto cleanup;
  }
  else preProcessScanlines(&data, &datasize, image, w, h, &info, &state->encoder);

  /* output all PNG chunks */ {
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
    size_t i;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
    /*write signature and chunks*/
    writeSignature(&outv);
    /*IHDR*/
    addChunk_IHDR(&outv, w, h, info.color.colortype, info.color.bitdepth, info.interlace_method);
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
    /*unknown chunks between IHDR and PLTE*/
    if(info.unknown_chunks_data[0]) {
      state->error = addUnknownChunks(&outv, info.unknown_chunks_data[0], info.unknown_chunks_size[0]);
      if(state->error) goto cleanup;
    }
    /*color profile chunks must come before PLTE */
    if(info.iccp_defined) addChunk_iCCP(&outv, &info, &state->encoder.zlibsettings);
    if(info.srgb_defined) addChunk_sRGB(&outv, &info);
    if(info.gama_defined) addChunk_gAMA(&outv, &info);
    if(info.chrm_defined) addChunk_cHRM(&outv, &info);
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
    /*PLTE*/
    if(info.color.colortype == LCT_PALETTE) {
      addChunk_PLTE(&outv, &info.color);
    }
    if(state->encoder.force_palette && (info.color.colortype == LCT_RGB || info.color.colortype == LCT_RGBA)) {
      addChunk_PLTE(&outv, &info.color);
    }
    /*tRNS*/
    if(info.color.colortype == LCT_PALETTE && getPaletteTranslucency(info.color.palette, info.color.palettesize) != 0) {
      addChunk_tRNS(&outv, &info.color);
    }
    if((info.color.colortype == LCT_GREY || info.color.colortype == LCT_RGB) && info.color.key_defined) {
      addChunk_tRNS(&outv, &info.color);
    }
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
    /*bKGD (must come between PLTE and the IDAt chunks*/
    if(info.background_defined) {
      state->error = addChunk_bKGD(&outv, &info);
      if(state->error) goto cleanup;
    }
    /*pHYs (must come before the IDAT chunks)*/
    if(info.phys_defined) addChunk_pHYs(&outv, &info);

    /*unknown chunks between PLTE and IDAT*/
    if(info.unknown_chunks_data[1]) {
      state->error = addUnknownChunks(&outv, info.unknown_chunks_data[1], info.unknown_chunks_size[1]);
      if(state->error) goto cleanup;
    }
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
    /*IDAT (multiple IDAT chunks must be consecutive)*/
    state->error = addChunk_IDAT(&outv, data, datasize, &state->encoder.zlibsettings);
    if(state->error) goto cleanup;
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
    /*tIME*/
    if(info.time_defined) addChunk_tIME(&outv, &info.time);
    /*tEXt and/or zTXt*/
    for(i = 0; i != info.text_num; ++i) {
      if(lodepng_strlen(info.text_keys[i]) > 79) {
        state->error = 66; /*text chunk too large*/
        goto cleanup;
      }
      if(lodepng_strlen(info.text_keys[i]) < 1) {
        state->error = 67; /*text chunk too small*/
        goto cleanup;
      }
      if(state->encoder.text_compression) {
        addChunk_zTXt(&outv, info.text_keys[i], info.text_strings[i], &state->encoder.zlibsettings);
      } else {
        addChunk_tEXt(&outv, info.text_keys[i], info.text_strings[i]);
      }
    }
    /*LodePNG version id in text chunk*/
    if(state->encoder.add_id) {
      unsigned already_added_id_text = 0;
      for(i = 0; i != info.text_num; ++i) {
        const char* k = info.text_keys[i];
        /* Could use strcmp, but we're not calling or reimplementing this C library function for this use only */
        if(k[0] == 'L' && k[1] == 'o' && k[2] == 'd' && k[3] == 'e' &&
           k[4] == 'P' && k[5] == 'N' && k[6] == 'G' && k[7] == '\0') {
          already_added_id_text = 1;
          break;
        }
      }
      if(already_added_id_text == 0) {
        addChunk_tEXt(&outv, "LodePNG", LODEPNG_VERSION_STRING); /*it's shorter as tEXt than as zTXt chunk*/
      }
    }
    /*iTXt*/
    for(i = 0; i != info.itext_num; ++i) {
      if(lodepng_strlen(info.itext_keys[i]) > 79) {
        state->error = 66; /*text chunk too large*/
        goto cleanup;
      }
      if(lodepng_strlen(info.itext_keys[i]) < 1) {
        state->error = 67; /*text chunk too small*/
        goto cleanup;
      }
      addChunk_iTXt(&outv, state->encoder.text_compression,
                    info.itext_keys[i], info.itext_langtags[i], info.itext_transkeys[i], info.itext_strings[i],
                    &state->encoder.zlibsettings);
    }

    /*unknown chunks between IDAT and IEND*/
    if(info.unknown_chunks_data[2]) {
      state->error = addUnknownChunks(&outv, info.unknown_chunks_data[2], info.unknown_chunks_size[2]);
      if(state->error) goto cleanup;
    }
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
    addChunk_IEND(&outv);
  }

cleanup:
  lodepng_info_cleanup(&info);
  lodepng_free(data);

  /*instead of cleaning the vector up, give it to the output*/
  *out = outv.data;
  *outsize = outv.size;

  return state->error;
}

// Assembly:
subq $0x658, %rsp            # imm = 0x658
movq %rdi, 0x650(%rsp)
movq %rsi, 0x648(%rsp)
movq %rdx, 0x640(%rsp)
movl %ecx, 0x63c(%rsp)
movl %r8d, 0x638(%rsp)
movq %r9, 0x630(%rsp)
movq $0x0, 0x628(%rsp)
movq $0x0, 0x620(%rsp)
movq 0x630(%rsp), %rax
addq $0xb8, %rax
movq %rax, 0x4c8(%rsp)
leaq 0x608(%rsp), %rdi
callq 0x148440
leaq 0x4d0(%rsp), %rdi
callq 0x140510
movq 0x650(%rsp), %rax
movq $0x0, (%rax)
movq 0x648(%rsp), %rax
movq $0x0, (%rax)
movq 0x630(%rsp), %rax
movl $0x0, 0x1f0(%rax)
movq 0x4c8(%rsp), %rax
cmpl $0x3, 0x10(%rax)
je 0x14770d
movq 0x630(%rsp), %rax
cmpl $0x0, 0x80(%rax)
je 0x147745
movq 0x4c8(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x14772e
movq 0x4c8(%rsp), %rax
cmpq $0x100, 0x20(%rax)      # imm = 0x100
jbe 0x147745
movq 0x630(%rsp), %rax
movl $0x44, 0x1f0(%rax)
jmp 0x1483e8
movq 0x630(%rsp), %rax
cmpl $0x2, 0x38(%rax)
jbe 0x14776a
movq 0x630(%rsp), %rax
movl $0x3d, 0x1f0(%rax)
jmp 0x1483e8
movq 0x4c8(%rsp), %rax
cmpl $0x1, 0x8(%rax)
jbe 0x14778f
movq 0x630(%rsp), %rax
movl $0x47, 0x1f0(%rax)
jmp 0x1483e8
movq 0x4c8(%rsp), %rax
movl 0x10(%rax), %edi
movq 0x4c8(%rsp), %rax
movl 0x14(%rax), %esi
callq 0x144870
movl %eax, %ecx
movq 0x630(%rsp), %rax
movl %ecx, 0x1f0(%rax)
movq 0x630(%rsp), %rax
cmpl $0x0, 0x1f0(%rax)
je 0x1477d0
jmp 0x1483e8
movq 0x630(%rsp), %rax
movl 0x90(%rax), %edi
movq 0x630(%rsp), %rax
movl 0x94(%rax), %esi
callq 0x144870
movl %eax, %ecx
movq 0x630(%rsp), %rax
movl %ecx, 0x1f0(%rax)
movq 0x630(%rsp), %rax
cmpl $0x0, 0x1f0(%rax)
je 0x147817
jmp 0x1483e8
movq 0x630(%rsp), %rsi
addq $0xb8, %rsi
leaq 0x4d0(%rsp), %rdi
callq 0x140770
movq 0x630(%rsp), %rax
cmpl $0x0, 0x68(%rax)
je 0x147ac0
leaq 0x98(%rsp), %rdi
callq 0x143640
movq 0x4c8(%rsp), %rax
cmpl $0x0, 0xe8(%rax)
je 0x147895
movq 0x4c8(%rsp), %rax
movq 0xf8(%rax), %rdi
movq 0x4c8(%rsp), %rax
movl 0x100(%rax), %esi
callq 0x148470
cmpl $0x0, %eax
je 0x147895
movl $0x0, 0x4c0(%rsp)
movq 0x4c8(%rsp), %rax
cmpl $0x0, 0xe8(%rax)
je 0x1478d8
movq 0x4c8(%rsp), %rax
movq 0xf8(%rax), %rdi
movq 0x4c8(%rsp), %rax
movl 0x100(%rax), %esi
callq 0x1484f0
cmpl $0x0, %eax
je 0x1478d8
movl $0x0, 0x4c4(%rsp)
movq 0x640(%rsp), %rsi
movl 0x63c(%rsp), %edx
movl 0x638(%rsp), %ecx
movq 0x630(%rsp), %r8
addq $0x90, %r8
leaq 0x98(%rsp), %rdi
callq 0x1436e0
movq 0x4c8(%rsp), %rax
cmpl $0x0, 0x38(%rax)
je 0x1479d3
movl $0x0, 0x94(%rsp)
movl $0x0, 0x90(%rsp)
movl $0x0, 0x8c(%rsp)
leaq 0x60(%rsp), %rdi
movl $0x2, %esi
movl $0x10, %edx
callq 0x13fa00
movq 0x4c8(%rsp), %rax
movl 0x3c(%rax), %ecx
movq 0x4c8(%rsp), %rax
movl 0x40(%rax), %r8d
movq 0x4c8(%rsp), %rax
movl 0x44(%rax), %r9d
movq 0x4c8(%rsp), %rax
addq $0x10, %rax
leaq 0x94(%rsp), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x8c(%rsp), %rdx
leaq 0x60(%rsp), %r10
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x143310
movl 0x94(%rsp), %esi
movl 0x90(%rsp), %edx
movl 0x8c(%rsp), %ecx
leaq 0x98(%rsp), %rdi
movl $0xffff, %r8d           # imm = 0xFFFF
callq 0x148570
leaq 0x4d0(%rsp), %rdi
addq $0x10, %rdi
movq 0x630(%rsp), %rsi
addq $0x90, %rsi
leaq 0x98(%rsp), %rdx
callq 0x148620
movl %eax, %ecx
movq 0x630(%rsp), %rax
movl %ecx, 0x1f0(%rax)
movq 0x630(%rsp), %rax
cmpl $0x0, 0x1f0(%rax)
je 0x147a21
jmp 0x1483e8
movq 0x4c8(%rsp), %rax
cmpl $0x0, 0x38(%rax)
je 0x147abe
leaq 0x4d0(%rsp), %rdi
addq $0x3c, %rdi
leaq 0x4d0(%rsp), %rsi
addq $0x40, %rsi
leaq 0x4d0(%rsp), %rdx
addq $0x44, %rdx
movq 0x4c8(%rsp), %rax
movl 0x3c(%rax), %ecx
movq 0x4c8(%rsp), %rax
movl 0x40(%rax), %r8d
movq 0x4c8(%rsp), %rax
movl 0x44(%rax), %r9d
leaq 0x4d0(%rsp), %r10
addq $0x10, %r10
movq 0x4c8(%rsp), %rax
addq $0x10, %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x143310
cmpl $0x0, %eax
je 0x147abc
movq 0x630(%rsp), %rax
movl $0x68, 0x1f0(%rax)
jmp 0x1483e8
jmp 0x147abe
jmp 0x147ac0
movq 0x4c8(%rsp), %rax
cmpl $0x0, 0xe8(%rax)
je 0x147bac
movq 0x4c8(%rsp), %rax
movq 0xf8(%rax), %rdi
movq 0x4c8(%rsp), %rax
movl 0x100(%rax), %esi
callq 0x148470
movl %eax, 0x5c(%rsp)
movq 0x4c8(%rsp), %rax
movq 0xf8(%rax), %rdi
movq 0x4c8(%rsp), %rax
movl 0x100(%rax), %esi
callq 0x1484f0
movl %eax, 0x58(%rsp)
movb $0x1, %al
cmpl $0x0, 0x4e0(%rsp)
movb %al, 0x27(%rsp)
je 0x147b40
cmpl $0x4, 0x4e0(%rsp)
sete %al
movb %al, 0x27(%rsp)
movb 0x27(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x54(%rsp)
cmpl $0x0, 0x5c(%rsp)
jne 0x147b72
cmpl $0x0, 0x58(%rsp)
jne 0x147b72
movq 0x630(%rsp), %rax
movl $0x64, 0x1f0(%rax)
jmp 0x1483e8
movl 0x5c(%rsp), %eax
cmpl 0x54(%rsp), %eax
je 0x147baa
movq 0x630(%rsp), %rax
movl 0x68(%rax), %edx
movl $0x65, %ecx
movl $0x66, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
movq 0x630(%rsp), %rax
movl %ecx, 0x1f0(%rax)
jmp 0x1483e8
jmp 0x147bac
movq 0x630(%rsp), %rdi
addq $0x90, %rdi
leaq 0x4d0(%rsp), %rsi
addq $0x10, %rsi
callq 0x141150
cmpl $0x0, %eax
jne 0x147d1a
movl 0x63c(%rsp), %eax
movl 0x638(%rsp), %ecx
imulq %rcx, %rax
movq %rax, 0x18(%rsp)
leaq 0x4d0(%rsp), %rdi
addq $0x10, %rdi
callq 0x13fb50
movl %eax, %ecx
movq 0x18(%rsp), %rax
movl %ecx, %ecx
imulq %rcx, %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
callq 0x13ce80
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
jne 0x147c48
cmpq $0x0, 0x40(%rsp)
je 0x147c48
movq 0x630(%rsp), %rax
movl $0x53, 0x1f0(%rax)
movq 0x630(%rsp), %rax
cmpl $0x0, 0x1f0(%rax)
jne 0x147ca6
movq 0x48(%rsp), %rdi
movq 0x640(%rsp), %rsi
leaq 0x4d0(%rsp), %rdx
addq $0x10, %rdx
movq 0x630(%rsp), %rcx
addq $0x90, %rcx
movl 0x63c(%rsp), %r8d
movl 0x638(%rsp), %r9d
callq 0x140bc0
movl %eax, %ecx
movq 0x630(%rsp), %rax
movl %ecx, 0x1f0(%rax)
movq 0x630(%rsp), %rax
cmpl $0x0, 0x1f0(%rax)
jne 0x147cf8
movq 0x48(%rsp), %rdx
movl 0x63c(%rsp), %ecx
movl 0x638(%rsp), %r8d
movq 0x630(%rsp), %rax
addq $0x38, %rax
leaq 0x628(%rsp), %rdi
leaq 0x620(%rsp), %rsi
leaq 0x4d0(%rsp), %r9
movq %rax, (%rsp)
callq 0x1489c0
movq 0x48(%rsp), %rdi
callq 0x13e2d0
movq 0x630(%rsp), %rax
cmpl $0x0, 0x1f0(%rax)
je 0x147d18
jmp 0x1483e8
jmp 0x147d5e
movq 0x640(%rsp), %rdx
movl 0x63c(%rsp), %ecx
movl 0x638(%rsp), %r8d
movq 0x630(%rsp), %rax
addq $0x38, %rax
leaq 0x628(%rsp), %rdi
leaq 0x620(%rsp), %rsi
leaq 0x4d0(%rsp), %r9
movq %rax, (%rsp)
callq 0x1489c0
leaq 0x608(%rsp), %rdi
callq 0x148ed0
movl 0x63c(%rsp), %esi
movl 0x638(%rsp), %edx
movl 0x4e0(%rsp), %ecx
movl 0x4e4(%rsp), %r8d
movl 0x4d8(%rsp), %r9d
leaq 0x608(%rsp), %rdi
callq 0x148f50
cmpq $0x0, 0x5d8(%rsp)
je 0x147ded
movq 0x5d8(%rsp), %rsi
movq 0x5f0(%rsp), %rdx
leaq 0x608(%rsp), %rdi
callq 0x148fe0
movl %eax, %ecx
movq 0x630(%rsp), %rax
movl %ecx, 0x1f0(%rax)
movq 0x630(%rsp), %rax
cmpl $0x0, 0x1f0(%rax)
je 0x147deb
jmp 0x1483e8
jmp 0x147ded
cmpl $0x0, 0x5b8(%rsp)
je 0x147e18
movq 0x630(%rsp), %rdx
addq $0x38, %rdx
leaq 0x608(%rsp), %rdi
leaq 0x4d0(%rsp), %rsi
callq 0x149080
cmpl $0x0, 0x5b0(%rsp)
je 0x147e37
leaq 0x608(%rsp), %rdi
leaq 0x4d0(%rsp), %rsi
callq 0x149200
cmpl $0x0, 0x584(%rsp)
je 0x147e56
leaq 0x608(%rsp), %rdi
leaq 0x4d0(%rsp), %rsi
callq 0x149240
cmpl $0x0, 0x58c(%rsp)
je 0x147e75
leaq 0x608(%rsp), %rdi
leaq 0x4d0(%rsp), %rsi
callq 0x149290
cmpl $0x3, 0x4e0(%rsp)
jne 0x147e98
leaq 0x4d0(%rsp), %rsi
addq $0x10, %rsi
leaq 0x608(%rsp), %rdi
callq 0x149370
movq 0x630(%rsp), %rax
cmpl $0x0, 0x80(%rax)
je 0x147ed6
cmpl $0x2, 0x4e0(%rsp)
je 0x147ebd
cmpl $0x6, 0x4e0(%rsp)
jne 0x147ed6
leaq 0x4d0(%rsp), %rsi
addq $0x10, %rsi
leaq 0x608(%rsp), %rdi
callq 0x149370
cmpl $0x3, 0x4e0(%rsp)
jne 0x147f13
movq 0x4e8(%rsp), %rdi
movq 0x4f0(%rsp), %rsi
callq 0x149420
cmpl $0x0, %eax
je 0x147f13
leaq 0x4d0(%rsp), %rsi
addq $0x10, %rsi
leaq 0x608(%rsp), %rdi
callq 0x149590
cmpl $0x0, 0x4e0(%rsp)
je 0x147f27
cmpl $0x2, 0x4e0(%rsp)
jne 0x147f4a
cmpl $0x0, 0x4f8(%rsp)
je 0x147f4a
leaq 0x4d0(%rsp), %rsi
addq $0x10, %rsi
leaq 0x608(%rsp), %rdi
callq 0x149590
cmpl $0x0, 0x508(%rsp)
je 0x147f91
leaq 0x608(%rsp), %rdi
leaq 0x4d0(%rsp), %rsi
callq 0x1497b0
movl %eax, %ecx
movq 0x630(%rsp), %rax
movl %ecx, 0x1f0(%rax)
movq 0x630(%rsp), %rax
cmpl $0x0, 0x1f0(%rax)
je 0x147f8f
jmp 0x1483e8
jmp 0x147f91
cmpl $0x0, 0x574(%rsp)
je 0x147fb0
leaq 0x608(%rsp), %rdi
leaq 0x4d0(%rsp), %rsi
callq 0x1498e0
cmpq $0x0, 0x5e0(%rsp)
je 0x148000
movq 0x5e0(%rsp), %rsi
movq 0x5f8(%rsp), %rdx
leaq 0x608(%rsp), %rdi
callq 0x148fe0
movl %eax, %ecx
movq 0x630(%rsp), %rax
movl %ecx, 0x1f0(%rax)
movq 0x630(%rsp), %rax
cmpl $0x0, 0x1f0(%rax)
je 0x147ffe
jmp 0x1483e8
jmp 0x148000
movq 0x628(%rsp), %rsi
movq 0x620(%rsp), %rdx
movq 0x630(%rsp), %rcx
addq $0x38, %rcx
leaq 0x608(%rsp), %rdi
callq 0x149950
movl %eax, %ecx
movq 0x630(%rsp), %rax
movl %ecx, 0x1f0(%rax)
movq 0x630(%rsp), %rax
cmpl $0x0, 0x1f0(%rax)
je 0x14804f
jmp 0x1483e8
cmpl $0x0, 0x558(%rsp)
je 0x148075
leaq 0x4d0(%rsp), %rsi
addq $0x8c, %rsi
leaq 0x608(%rsp), %rdi
callq 0x1499e0
movq $0x0, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x518(%rsp), %rax
je 0x148189
movq 0x520(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x13ef90
cmpq $0x4f, %rax
jbe 0x1480c4
movq 0x630(%rsp), %rax
movl $0x42, 0x1f0(%rax)
jmp 0x1483e8
movq 0x520(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x13ef90
cmpq $0x1, %rax
jae 0x1480f7
movq 0x630(%rsp), %rax
movl $0x43, 0x1f0(%rax)
jmp 0x1483e8
movq 0x630(%rsp), %rax
cmpl $0x0, 0x88(%rax)
je 0x148145
movq 0x520(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x528(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x630(%rsp), %rcx
addq $0x38, %rcx
leaq 0x608(%rsp), %rdi
callq 0x149a70
jmp 0x148174
movq 0x520(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x528(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x608(%rsp), %rdi
callq 0x149be0
jmp 0x148176
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x14807e
movq 0x630(%rsp), %rax
cmpl $0x0, 0x84(%rax)
je 0x14828a
movl $0x0, 0x34(%rsp)
movq $0x0, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x518(%rsp), %rax
je 0x148266
movq 0x520(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x4c, %eax
jne 0x148251
movq 0x28(%rsp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x6f, %eax
jne 0x148251
movq 0x28(%rsp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x64, %eax
jne 0x148251
movq 0x28(%rsp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x65, %eax
jne 0x148251
movq 0x28(%rsp), %rax
movsbl 0x4(%rax), %eax
cmpl $0x50, %eax
jne 0x148251
movq 0x28(%rsp), %rax
movsbl 0x5(%rax), %eax
cmpl $0x4e, %eax
jne 0x148251
movq 0x28(%rsp), %rax
movsbl 0x6(%rax), %eax
cmpl $0x47, %eax
jne 0x148251
movq 0x28(%rsp), %rax
movsbl 0x7(%rax), %eax
cmpl $0x0, %eax
jne 0x148251
movl $0x1, 0x34(%rsp)
jmp 0x148266
jmp 0x148253
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x1481af
cmpl $0x0, 0x34(%rsp)
jne 0x148288
movq 0x6475c(%rip), %rdx     # 0x1ac9d0
leaq 0x608(%rsp), %rdi
leaq 0x2e486(%rip), %rsi     # 0x176709
callq 0x149be0
jmp 0x14828a
movq $0x0, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x530(%rsp), %rax
je 0x14838e
movq 0x538(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x13ef90
cmpq $0x4f, %rax
jbe 0x1482d9
movq 0x630(%rsp), %rax
movl $0x42, 0x1f0(%rax)
jmp 0x1483e8
movq 0x538(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x13ef90
cmpq $0x1, %rax
jae 0x14830c
movq 0x630(%rsp), %rax
movl $0x43, 0x1f0(%rax)
jmp 0x1483e8
movq 0x630(%rsp), %rax
movl 0x88(%rax), %esi
movq 0x538(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x540(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x548(%rsp), %rax
movq 0x38(%rsp), %rdi
movq (%rax,%rdi,8), %r8
movq 0x550(%rsp), %rax
movq 0x38(%rsp), %rdi
movq (%rax,%rdi,8), %r9
movq 0x630(%rsp), %rax
addq $0x38, %rax
leaq 0x608(%rsp), %rdi
movq %rax, (%rsp)
callq 0x149cf0
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x148293
cmpq $0x0, 0x5e8(%rsp)
je 0x1483db
movq 0x5e8(%rsp), %rsi
movq 0x600(%rsp), %rdx
leaq 0x608(%rsp), %rdi
callq 0x148fe0
movl %eax, %ecx
movq 0x630(%rsp), %rax
movl %ecx, 0x1f0(%rax)
movq 0x630(%rsp), %rax
cmpl $0x0, 0x1f0(%rax)
je 0x1483d9
jmp 0x1483e8
jmp 0x1483db
leaq 0x608(%rsp), %rdi
callq 0x149fa0
leaq 0x4d0(%rsp), %rdi
callq 0x1406f0
movq 0x628(%rsp), %rdi
callq 0x13e2d0
movq 0x608(%rsp), %rcx
movq 0x650(%rsp), %rax
movq %rcx, (%rax)
movq 0x610(%rsp), %rcx
movq 0x648(%rsp), %rax
movq %rcx, (%rax)
movq 0x630(%rsp), %rax
movl 0x1f0(%rax), %eax
addq $0x658, %rsp            # imm = 0x658
retq
nop