// File: cloudinary[P]fuif/./import/read_jpeg.h
// Function: read_JPEG_file(char const*)
Image read_JPEG_file(const char *input_image) {

  FILE *fp = fopen(input_image,"rb");
  if (!fp) return Image();

  struct jpeg_decompress_struct cinfo;

  jpegErrorManager jerr;
  cinfo.err = jpeg_std_error(&jerr.pub);
  jerr.pub.error_exit = jpegErrorExit;
  /* Establish the setjmp return context for my_error_exit to use. */
  if (setjmp(jerr.setjmp_buffer)) {
    /* If we get here, the JPEG code has signaled an error. */
    v_printf(10, "libjpeg: %s\n",jpegLastErrorMsg);
    jpeg_destroy_decompress(&cinfo);
    fclose(fp);
    return Image();
  }

  jpeg_create_decompress(&cinfo);
  jpeg_stdio_src(&cinfo, fp);
  (void) jpeg_read_header(&cinfo, TRUE);


  jvirt_barray_ptr *coeffs_array = jpeg_read_coefficients(&cinfo);

  int nbcomp = cinfo.num_components;
  int w = cinfo.image_width;
  int h = cinfo.image_height;
  int bitdepth = cinfo.data_precision;

  Image image;
  image.w = w;
  image.h = h;
  image.nb_channels = nbcomp;
  image.real_nb_channels = nbcomp;
  image.minval = 0;
  image.maxval = (1<<bitdepth)-1;

  if (nbcomp == 4) image.colormodel = 16; // CMYK

  Transform subsampling(TRANSFORM_ChromaSubsample);
  int max_factor_h = 1;
  int max_factor_v = 1;
  for (int ci=0; ci < nbcomp; ci++) {
      jpeg_component_info* compptr = cinfo.comp_info + ci;
      int srh = compptr->h_samp_factor;
      int srv = compptr->v_samp_factor;
      if (srh > max_factor_h) max_factor_h = srh;
      if (srv > max_factor_v) max_factor_v = srv;
  }
  std::vector<int> & p = subsampling.parameters;
  for (int ci=0; ci < nbcomp; ci++) {
      jpeg_component_info* compptr = cinfo.comp_info + ci;
      int srh = compptr->h_samp_factor;
      int srv = compptr->v_samp_factor;
      if (srh < max_factor_h || srv < max_factor_v) {
         p.push_back(ci);
         p.push_back(ci);
         p.push_back(max_factor_h/srh);
         p.push_back(max_factor_v/srv);
      }
  }
  if (p.size() >= 8) {
    if (p[2] == p[6] && p[3] == p[7] && p[4] == p[1]+1) {
        p[1] = p[4];
        p.erase(p.begin()+4, p.end());
    }
    if (p.size() == 4 && p[0] == 1 && p[1] == 2) {
        if (p[2] == 2 && p[3] == 2) { p[0] = 0; p.erase(p.begin()+1, p.end()); } // 4:2:0
    }
  }

  if (cinfo.jpeg_color_space == JCS_YCbCr ||
      cinfo.jpeg_color_space == JCS_YCCK) image.transform.push_back(Transform(TRANSFORM_YCbCr));

  if (p.size()) image.transform.push_back(subsampling);

  image.transform.push_back(Transform(TRANSFORM_DCT));

  image.transform.push_back(Transform(TRANSFORM_QUANTIZE));

  std::vector<std::vector<int>> ordering;
  std::vector<int> comp;
  std::vector<int> coeff;
  default_DCT_scanscript(nbcomp,ordering,comp,coeff);

  for (int i=0; i < 64*nbcomp; i++) {
    int bi=0;
    for (; bi<64 ; bi++) if (coeff[i]==jpeg_zigzag[bi]) break;
    int ci = comp[i];
    jpeg_component_info* compptr = cinfo.comp_info + ci;
    int hib = compptr->height_in_blocks;
    int wib = compptr->width_in_blocks;
    int q = compptr->quant_table->quantval[bi];
    v_printf(5,"Quantization for component %i, coefficient %i: %i\n",comp[i],coeff[i],q);

    Channel c(wib,hib,LARGEST_VAL,SMALLEST_VAL);
    c.q = q;
    c.component = ci;
    c.hshift = 3 + (compptr->h_samp_factor < max_factor_h ? 1 : 0);
    c.vshift = 3 + (compptr->v_samp_factor < max_factor_v ? 1 : 0);
    c.hcshift = dct_cshifts[coeff[i]];
    c.vcshift = dct_cshifts[coeff[i]];
    int zeroes=0;
    int nonzeroes=0;
    for (int by=0; by < hib; by++) {
      JBLOCKARRAY buffer = (cinfo.mem->access_virt_barray)((j_common_ptr)&cinfo, coeffs_array[ci], by, (JDIMENSION) 1, FALSE);
      for (int bx=0; bx < wib; bx++) {
        JCOEFPTR blockptr = buffer[0][bx];
        c.value(by,bx) = blockptr[bi];
        if (c.value(by,bx) > c.maxval) c.maxval = c.value(by,bx);
        if (c.value(by,bx) < c.minval) c.minval = c.value(by,bx);
        if (c.value(by,bx)) nonzeroes++; else zeroes++;
      }
    }
    v_printf(10,"Comp %i, coeff %i (natural %i) : %f %% zeroes (%i zeroes, %i nonzeroes)\n",ci,coeff[i],bi,100.0*zeroes/(zeroes+nonzeroes),zeroes,nonzeroes);
    image.channel.push_back(c);
  }

  jpeg_finish_decompress( &cinfo );
  jpeg_destroy_decompress( &cinfo );
  fclose(fp);

  image.error = false;


  return image;
}

// Assembly:
subq $0x738, %rsp            # imm = 0x738
movq %rdi, 0xe8(%rsp)
movq %rdi, %rax
movq %rax, 0xf0(%rsp)
movq %rdi, 0x730(%rsp)
movq %rsi, 0x728(%rsp)
movq 0x728(%rsp), %rdi
leaq 0xb7e4(%rip), %rsi      # 0x4796d
callq 0x3460
movq %rax, 0x720(%rsp)
cmpq $0x0, 0x720(%rsp)
jne 0x3c1b3
movq 0xe8(%rsp), %rdi
callq 0x1f570
jmp 0x3d122
leaq 0x320(%rsp), %rdi
callq 0x3090
movq %rax, 0x490(%rsp)
leaq -0xcf(%rip), %rax       # 0x3c100
movq %rax, 0x320(%rsp)
leaq 0x320(%rsp), %rdi
addq $0xa8, %rdi
callq 0x3530
cmpl $0x0, %eax
je 0x3c236
movl $0xa, %edi
leaq 0xbe5f(%rip), %rsi      # 0x4805b
leaq 0x206ad(%rip), %rdx     # 0x5c8b0
movb $0x0, %al
callq 0x3a770
leaq 0x490(%rsp), %rdi
callq 0x3100
movq 0x720(%rsp), %rdi
callq 0x3350
movq 0xe8(%rsp), %rdi
callq 0x1f570
jmp 0x3d122
leaq 0x490(%rsp), %rdi
movl $0x50, %esi
movl $0x290, %edx            # imm = 0x290
callq 0x3670
movq 0x720(%rsp), %rsi
leaq 0x490(%rsp), %rdi
callq 0x3570
leaq 0x490(%rsp), %rdi
movl $0x1, %esi
callq 0x35d0
leaq 0x490(%rsp), %rdi
callq 0x30e0
movq 0xe8(%rsp), %rdi
movq %rax, 0x318(%rsp)
movl 0x4c8(%rsp), %eax
movl %eax, 0x314(%rsp)
movl 0x4c0(%rsp), %eax
movl %eax, 0x310(%rsp)
movl 0x4c4(%rsp), %eax
movl %eax, 0x30c(%rsp)
movl 0x5b8(%rsp), %eax
movl %eax, 0x308(%rsp)
movb $0x0, 0x307(%rsp)
callq 0x1f570
movq 0xe8(%rsp), %rax
movl 0x310(%rsp), %ecx
movl %ecx, 0x30(%rax)
movl 0x30c(%rsp), %ecx
movl %ecx, 0x34(%rax)
movl 0x314(%rsp), %ecx
movl %ecx, 0x64(%rax)
movl 0x314(%rsp), %ecx
movl %ecx, 0x68(%rax)
movl $0x0, 0x5c(%rax)
movl 0x308(%rsp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
subl $0x1, %ecx
movl %ecx, 0x60(%rax)
cmpl $0x4, 0x314(%rsp)
jne 0x3c33c
movq 0xe8(%rsp), %rax
movl $0x10, 0x70(%rax)
leaq 0x2e0(%rsp), %rdi
movl $0x3, %esi
callq 0x259f0
jmp 0x3c350
movl $0x1, 0x2d0(%rsp)
movl $0x1, 0x2cc(%rsp)
movl $0x0, 0x2c8(%rsp)
movl 0x2c8(%rsp), %eax
cmpl 0x314(%rsp), %eax
jge 0x3c437
movq 0x5c0(%rsp), %rax
movslq 0x2c8(%rsp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x2c0(%rsp)
movq 0x2c0(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x2bc(%rsp)
movq 0x2c0(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, 0x2b8(%rsp)
movl 0x2bc(%rsp), %eax
cmpl 0x2d0(%rsp), %eax
jle 0x3c401
movl 0x2bc(%rsp), %eax
movl %eax, 0x2d0(%rsp)
jmp 0x3c401
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2d8(%rsp)
movl %eax, 0x2d4(%rsp)
jmp 0x3d113
movl 0x2b8(%rsp), %eax
cmpl 0x2cc(%rsp), %eax
jle 0x3c41f
movl 0x2b8(%rsp), %eax
movl %eax, 0x2cc(%rsp)
jmp 0x3c421
movl 0x2c8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c8(%rsp)
jmp 0x3c371
leaq 0x2e0(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x2b0(%rsp)
movl $0x0, 0x2ac(%rsp)
movl 0x2ac(%rsp), %eax
cmpl 0x314(%rsp), %eax
jge 0x3c590
movq 0x5c0(%rsp), %rax
movslq 0x2ac(%rsp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x2a0(%rsp)
movq 0x2a0(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x29c(%rsp)
movq 0x2a0(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, 0x298(%rsp)
movl 0x29c(%rsp), %eax
cmpl 0x2d0(%rsp), %eax
jl 0x3c4d1
movl 0x298(%rsp), %eax
cmpl 0x2cc(%rsp), %eax
jge 0x3c578
movq 0x2b0(%rsp), %rdi
leaq 0x2ac(%rsp), %rsi
callq 0x12560
jmp 0x3c4e8
movq 0x2b0(%rsp), %rdi
leaq 0x2ac(%rsp), %rsi
callq 0x12560
jmp 0x3c4ff
movq 0x2b0(%rsp), %rdi
movl 0x2d0(%rsp), %eax
movl 0x29c(%rsp), %ecx
cltd
idivl %ecx
movl %eax, 0x294(%rsp)
leaq 0x294(%rsp), %rsi
callq 0x121b0
jmp 0x3c52e
movq 0x2b0(%rsp), %rdi
movl 0x2cc(%rsp), %eax
movl 0x298(%rsp), %ecx
cltd
idivl %ecx
movl %eax, 0x290(%rsp)
leaq 0x290(%rsp), %rsi
callq 0x121b0
jmp 0x3c55d
jmp 0x3c578
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2d8(%rsp)
movl %eax, 0x2d4(%rsp)
jmp 0x3d0f5
jmp 0x3c57a
movl 0x2ac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2ac(%rsp)
jmp 0x3c456
movq 0x2b0(%rsp), %rdi
callq 0x4d50
cmpq $0x8, %rax
jb 0x3c8a1
movq 0x2b0(%rsp), %rdi
movl $0x2, %esi
callq 0x12190
movl (%rax), %eax
movl %eax, 0xe4(%rsp)
movq 0x2b0(%rsp), %rdi
movl $0x6, %esi
callq 0x12190
movq %rax, %rcx
movl 0xe4(%rsp), %eax
cmpl (%rcx), %eax
jne 0x3c757
movq 0x2b0(%rsp), %rdi
movl $0x3, %esi
callq 0x12190
movl (%rax), %eax
movl %eax, 0xe0(%rsp)
movq 0x2b0(%rsp), %rdi
movl $0x7, %esi
callq 0x12190
movq %rax, %rcx
movl 0xe0(%rsp), %eax
cmpl (%rcx), %eax
jne 0x3c757
movq 0x2b0(%rsp), %rdi
movl $0x4, %esi
callq 0x12190
movl (%rax), %eax
movl %eax, 0xdc(%rsp)
movq 0x2b0(%rsp), %rdi
movl $0x1, %esi
callq 0x12190
movq %rax, %rcx
movl 0xdc(%rsp), %eax
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x3c757
movq 0x2b0(%rsp), %rdi
movl $0x4, %esi
movq %rsi, 0xc0(%rsp)
callq 0x12190
movl (%rax), %eax
movl %eax, 0xbc(%rsp)
movq 0x2b0(%rsp), %rdi
movl $0x1, %esi
callq 0x12190
movl 0xbc(%rsp), %ecx
movl %ecx, (%rax)
movq 0x2b0(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0x13780
movq 0xc0(%rsp), %rsi
movq %rax, 0x278(%rsp)
leaq 0x278(%rsp), %rdi
callq 0x137f0
movq %rax, 0x280(%rsp)
leaq 0x288(%rsp), %rdi
leaq 0x280(%rsp), %rsi
callq 0x137b0
movq 0x2b0(%rsp), %rdi
callq 0x17720
movq %rax, 0x268(%rsp)
leaq 0x270(%rsp), %rdi
leaq 0x268(%rsp), %rsi
callq 0x137b0
movq 0xc8(%rsp), %rdi
movq 0x288(%rsp), %rsi
movq 0x270(%rsp), %rdx
callq 0x136e0
movq %rax, 0xd0(%rsp)
jmp 0x3c747
movq 0xd0(%rsp), %rax
movq %rax, 0x260(%rsp)
movq 0x2b0(%rsp), %rdi
callq 0x4d50
cmpq $0x4, %rax
jne 0x3c89f
movq 0x2b0(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x12190
cmpl $0x1, (%rax)
jne 0x3c89f
movq 0x2b0(%rsp), %rdi
movl $0x1, %esi
callq 0x12190
cmpl $0x2, (%rax)
jne 0x3c89f
movq 0x2b0(%rsp), %rdi
movl $0x2, %esi
callq 0x12190
cmpl $0x2, (%rax)
jne 0x3c89d
movq 0x2b0(%rsp), %rdi
movl $0x3, %esi
callq 0x12190
cmpl $0x2, (%rax)
jne 0x3c89d
movq 0x2b0(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x12190
movl $0x0, (%rax)
movq 0x2b0(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x13780
movq %rax, 0x248(%rsp)
leaq 0x248(%rsp), %rdi
movl $0x1, %esi
callq 0x137f0
movq %rax, 0x250(%rsp)
leaq 0x258(%rsp), %rdi
leaq 0x250(%rsp), %rsi
callq 0x137b0
movq 0x2b0(%rsp), %rdi
callq 0x17720
movq %rax, 0x238(%rsp)
leaq 0x240(%rsp), %rdi
leaq 0x238(%rsp), %rsi
callq 0x137b0
movq 0xa8(%rsp), %rdi
movq 0x258(%rsp), %rsi
movq 0x240(%rsp), %rdx
callq 0x136e0
movq %rax, 0xb0(%rsp)
jmp 0x3c88d
movq 0xb0(%rsp), %rax
movq %rax, 0x230(%rsp)
jmp 0x3c89f
jmp 0x3c8a1
cmpl $0x3, 0x4cc(%rsp)
je 0x3c8b5
cmpl $0x5, 0x4cc(%rsp)
jne 0x3c926
movq 0xe8(%rsp), %rax
addq $0x18, %rax
movq %rax, 0xa0(%rsp)
leaq 0x210(%rsp), %rdi
xorl %esi, %esi
callq 0x259f0
jmp 0x3c8da
movq 0xa0(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x45350
jmp 0x3c8f1
leaq 0x210(%rsp), %rdi
callq 0x4b60
jmp 0x3c926
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2d8(%rsp)
movl %eax, 0x2d4(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x4b60
jmp 0x3d0f5
movq 0x2b0(%rsp), %rdi
callq 0x4d50
cmpq $0x0, %rax
je 0x3c956
movq 0xe8(%rsp), %rdi
addq $0x18, %rdi
leaq 0x2e0(%rsp), %rsi
callq 0x4be0
jmp 0x3c954
jmp 0x3c956
movq 0xe8(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x98(%rsp)
leaq 0x1f0(%rsp), %rdi
movl $0x4, %esi
callq 0x259f0
jmp 0x3c97e
movq 0x98(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x45350
jmp 0x3c995
leaq 0x1f0(%rsp), %rdi
callq 0x4b60
movq 0xe8(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x90(%rsp)
leaq 0x1d0(%rsp), %rdi
movl $0x5, %esi
callq 0x259f0
jmp 0x3c9ca
movq 0x90(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x45350
jmp 0x3c9e1
leaq 0x1d0(%rsp), %rdi
callq 0x4b60
leaq 0x1b8(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x125d0
leaq 0x1a0(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x125e0
leaq 0x188(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x125e0
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq 0x88(%rsp), %rcx
movl 0x314(%rsp), %edi
callq 0x8180
jmp 0x3ca4d
movl $0x0, 0x184(%rsp)
movl 0x184(%rsp), %eax
movl 0x314(%rsp), %ecx
shll $0x6, %ecx
cmpl %ecx, %eax
jge 0x3d04a
movl $0x0, 0x180(%rsp)
cmpl $0x40, 0x180(%rsp)
jge 0x3cb34
movslq 0x184(%rsp), %rsi
leaq 0x188(%rsp), %rdi
callq 0x12190
movl (%rax), %eax
movslq 0x180(%rsp), %rdx
leaq 0x99b0(%rip), %rcx      # 0x46460
cmpl (%rcx,%rdx,4), %eax
jne 0x3cb1c
jmp 0x3cb34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2d8(%rsp)
movl %eax, 0x2d4(%rsp)
leaq 0x1f0(%rsp), %rdi
callq 0x4b60
jmp 0x3d0f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2d8(%rsp)
movl %eax, 0x2d4(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x4b60
jmp 0x3d0f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2d8(%rsp)
movl %eax, 0x2d4(%rsp)
jmp 0x3d0ce
jmp 0x3cb1e
movl 0x180(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x180(%rsp)
jmp 0x3ca7c
movslq 0x184(%rsp), %rsi
leaq 0x1a0(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x12190
movq 0x68(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x17c(%rsp)
movq 0x5c0(%rsp), %rax
movslq 0x17c(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x170(%rsp)
movq 0x170(%rsp), %rax
movl 0x20(%rax), %eax
movl %eax, 0x16c(%rsp)
movq 0x170(%rsp), %rax
movl 0x1c(%rax), %eax
movl %eax, 0x168(%rsp)
movq 0x170(%rsp), %rax
movq 0x50(%rax), %rax
movslq 0x180(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
movl %eax, 0x164(%rsp)
movslq 0x184(%rsp), %rsi
callq 0x12190
movl (%rax), %eax
movl %eax, 0x74(%rsp)
movslq 0x184(%rsp), %rsi
leaq 0x188(%rsp), %rdi
callq 0x12190
movl 0x74(%rsp), %edx
movl (%rax), %ecx
movl 0x164(%rsp), %r8d
leaq 0xb469(%rip), %rsi      # 0x48068
xorl %eax, %eax
movl $0x5, %edi
callq 0x3a770
jmp 0x3cc0d
movl 0x168(%rsp), %esi
movl 0x16c(%rsp), %edx
movq %rsp, %rax
movl $0x0, 0x18(%rax)
movl $0x0, 0x10(%rax)
movl $0x0, 0x8(%rax)
movl $0x0, (%rax)
leaq 0x120(%rsp), %rdi
movl $0x7fff, %ecx           # imm = 0x7FFF
movl $0xffff8001, %r8d       # imm = 0xFFFF8001
movl $0x1, %r9d
callq 0x12200
jmp 0x3cc59
movl 0x164(%rsp), %eax
movl %eax, 0x148(%rsp)
movl 0x17c(%rsp), %eax
movl %eax, 0x15c(%rsp)
movq 0x170(%rsp), %rax
movl 0x8(%rax), %edx
movl 0x2d0(%rsp), %esi
xorl %eax, %eax
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
addl $0x3, %eax
movl %eax, 0x14c(%rsp)
movq 0x170(%rsp), %rax
movl 0xc(%rax), %edx
movl 0x2cc(%rsp), %esi
xorl %eax, %eax
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
addl $0x3, %eax
movl %eax, 0x150(%rsp)
movslq 0x184(%rsp), %rsi
leaq 0x188(%rsp), %rdi
callq 0x12190
movslq (%rax), %rcx
leaq 0x987c(%rip), %rax      # 0x46560
movl (%rax,%rcx,4), %eax
movl %eax, 0x154(%rsp)
movslq 0x184(%rsp), %rsi
leaq 0x188(%rsp), %rdi
callq 0x12190
movslq (%rax), %rcx
leaq 0x9853(%rip), %rax      # 0x46560
movl (%rax,%rcx,4), %eax
movl %eax, 0x158(%rsp)
movl $0x0, 0x11c(%rsp)
movl $0x0, 0x118(%rsp)
movl $0x0, 0x114(%rsp)
movl 0x114(%rsp), %eax
cmpl 0x16c(%rsp), %eax
jge 0x3cf9b
movq 0x498(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x318(%rsp), %rcx
movslq 0x17c(%rsp), %rdx
movq (%rcx,%rdx,8), %rsi
movl 0x114(%rsp), %edx
leaq 0x490(%rsp), %rdi
movl $0x1, %ecx
xorl %r8d, %r8d
callq *%rax
movq %rax, 0x60(%rsp)
jmp 0x3cd8c
movq 0x60(%rsp), %rax
movq %rax, 0x108(%rsp)
movl $0x0, 0x104(%rsp)
movl 0x104(%rsp), %eax
cmpl 0x168(%rsp), %eax
jge 0x3cf83
movq 0x108(%rsp), %rax
movq (%rax), %rax
movslq 0x104(%rsp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, 0xf8(%rsp)
movq 0xf8(%rsp), %rax
movslq 0x180(%rsp), %rcx
movw (%rax,%rcx,2), %ax
movw %ax, 0x56(%rsp)
movl 0x114(%rsp), %esi
movl 0x104(%rsp), %edx
leaq 0x120(%rsp), %rdi
callq 0x12110
movq %rax, 0x58(%rsp)
jmp 0x3ce15
movq 0x58(%rsp), %rax
movw 0x56(%rsp), %cx
movw %cx, (%rax)
movl 0x114(%rsp), %esi
movl 0x104(%rsp), %edx
leaq 0x120(%rsp), %rdi
callq 0x12110
movq %rax, 0x48(%rsp)
jmp 0x3ce44
movq 0x48(%rsp), %rax
movswl (%rax), %eax
movswl 0x142(%rsp), %ecx
cmpl %ecx, %eax
jle 0x3ceb2
movl 0x114(%rsp), %esi
movl 0x104(%rsp), %edx
leaq 0x120(%rsp), %rdi
callq 0x12110
movq %rax, 0x40(%rsp)
jmp 0x3ce7a
movq 0x40(%rsp), %rax
movw (%rax), %ax
movw %ax, 0x142(%rsp)
jmp 0x3ceb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2d8(%rsp)
movl %eax, 0x2d4(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x12380
jmp 0x3d0ce
movl 0x114(%rsp), %esi
movl 0x104(%rsp), %edx
leaq 0x120(%rsp), %rdi
callq 0x12110
movq %rax, 0x38(%rsp)
jmp 0x3ced4
movq 0x38(%rsp), %rax
movswl (%rax), %eax
movswl 0x140(%rsp), %ecx
cmpl %ecx, %eax
jge 0x3cf1a
movl 0x114(%rsp), %esi
movl 0x104(%rsp), %edx
leaq 0x120(%rsp), %rdi
callq 0x12110
movq %rax, 0x30(%rsp)
jmp 0x3cf0a
movq 0x30(%rsp), %rax
movw (%rax), %ax
movw %ax, 0x140(%rsp)
movl 0x114(%rsp), %esi
movl 0x104(%rsp), %edx
leaq 0x120(%rsp), %rdi
callq 0x12110
movq %rax, 0x28(%rsp)
jmp 0x3cf3c
movq 0x28(%rsp), %rax
cmpw $0x0, (%rax)
je 0x3cf5a
movl 0x118(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x118(%rsp)
jmp 0x3cf6b
movl 0x11c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x11c(%rsp)
jmp 0x3cf6d
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0x3cda4
jmp 0x3cf85
movl 0x114(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x114(%rsp)
jmp 0x3cd38
movl 0x17c(%rsp), %eax
movl %eax, 0x24(%rsp)
movslq 0x184(%rsp), %rsi
leaq 0x188(%rsp), %rdi
callq 0x12190
movl 0x24(%rsp), %edx
movl (%rax), %ecx
movl 0x180(%rsp), %r8d
movl 0x11c(%rsp), %r9d
cvtsi2sd %r9d, %xmm0
movsd 0xa332(%rip), %xmm1     # 0x47310
mulsd %xmm1, %xmm0
movl 0x118(%rsp), %esi
movl %r9d, %eax
addl %esi, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movq %rsp, %rax
movl %esi, (%rax)
leaq 0xb099(%rip), %rsi      # 0x4809b
movl $0xa, %edi
movb $0x1, %al
callq 0x3a770
jmp 0x3d010
movq 0xe8(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x12660
jmp 0x3d027
leaq 0x120(%rsp), %rdi
callq 0x12380
movl 0x184(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x184(%rsp)
jmp 0x3ca58
leaq 0x490(%rsp), %rdi
callq 0x3430
jmp 0x3d059
leaq 0x490(%rsp), %rdi
callq 0x3100
jmp 0x3d068
movq 0x720(%rsp), %rdi
callq 0x3350
jmp 0x3d077
movq 0xe8(%rsp), %rax
movb $0x0, 0xa8(%rax)
movb $0x1, 0x307(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x54f0
leaq 0x1a0(%rsp), %rdi
callq 0x54f0
leaq 0x1b8(%rsp), %rdi
callq 0x126d0
leaq 0x2e0(%rsp), %rdi
callq 0x4b60
testb $0x1, 0x307(%rsp)
jne 0x3d111
jmp 0x3d104
leaq 0x188(%rsp), %rdi
callq 0x54f0
leaq 0x1a0(%rsp), %rdi
callq 0x54f0
leaq 0x1b8(%rsp), %rdi
callq 0x126d0
leaq 0x2e0(%rsp), %rdi
callq 0x4b60
jmp 0x3d113
movq 0xe8(%rsp), %rdi
callq 0x12ab0
jmp 0x3d122
movq 0xe8(%rsp), %rdi
callq 0x12ab0
jmp 0x3d132
movq 0xf0(%rsp), %rax
addq $0x738, %rsp            # imm = 0x738
retq
movq 0x2d8(%rsp), %rdi
callq 0x36a0
nop