// File: /workspace/github_cpp_makefile_star2_O3/cloudinary[P]fuif/./export/write_png.h
// Function: write_PNG_file(char const*, Image const&)
bool write_PNG_file(const char *output_image, const Image &image) {

  int nb_channels = image.channel.size();
  bool debugstuff = false;

  if (nb_channels > ((image.colormodel & 48) == 16 ? 5 : 4)) {
    e_printf("Too many channels. Saving just the first 3 channels (instead of %i)\n",nb_channels);
    nb_channels = 3; // just use the first 3. debug stuff
    debugstuff = true;
  }
  if (nb_channels == 0) {
    e_printf("Cannot save a zero-channel 'image' as PNG.\n");
    return false;
  }


  int w = image.channel[0].w;
  int h = image.channel[0].h;
  if (image.w < w) w = image.w;
  if (image.h < h) h = image.h;
  for (int i=1; i<nb_channels; i++) {
    if (image.channel[i].w < w) nb_channels = 1;
    if (image.channel[i].h < h) nb_channels = 1;
    if (nb_channels == 1) e_printf("Not saving channel %i since dimensions (%ix%i) do not correspond with the image dimensions (%ix%i).\n",i,image.channel[i].w,image.channel[i].h,w,h);
  }

  if (nb_channels > image.nb_channels) {debugstuff=true; nb_channels=1;}

  if (w > 0x7fffffffL || h > 0x7fffffffL) {
    printf("Image too large to be saved as PNG.\n");
    return false;
  }

  FILE *fp = fopen(output_image,"wb");
  if (!fp) {
    return false;
  }
  png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,(png_voidp) NULL,NULL,NULL);
  if (!png_ptr) {
    fclose(fp);
    return false;
  }

  png_infop info_ptr = png_create_info_struct(png_ptr);
  if (!info_ptr) {
    png_destroy_write_struct(&png_ptr,(png_infopp) NULL);
    fclose(fp);
    return false;
  }

  png_init_io(png_ptr,fp);
  png_set_user_limits(png_ptr, 0x7fffffffL, 0x7fffffffL);
//  png_set_filter(png_ptr,0,PNG_FILTER_PAETH);
//  png_set_compression_level(png_ptr,Z_BEST_COMPRESSION);


  int colortype=PNG_COLOR_TYPE_RGB;
  bool cmyk = false;
  if ((image.colormodel & 48) == 0) { // RGB
    if (nb_channels == 4) colortype=PNG_COLOR_TYPE_RGB_ALPHA;
  } else if ((image.colormodel & 48) == 16) { // CMYK
    if (nb_channels == 5) colortype=PNG_COLOR_TYPE_RGB_ALPHA;
    if (nb_channels > 3) cmyk = true;
  }

  if (nb_channels == 1) colortype=PNG_COLOR_TYPE_GRAY;
  if (nb_channels == 2) colortype=PNG_COLOR_TYPE_GRAY_ALPHA;
  int bit_depth = 8, bytes_per_value=1;
  if (image.channel[0].minval < 0) {bit_depth = 8; bytes_per_value=1;} // this is just for debugging things

  if (image.maxval > 255) {bit_depth = 16; bytes_per_value=2;}
  if (image.maxval > 65535) { e_printf("Cannot save as PNG since bit depth is higher than 16-bit.\n");    return false; }

  if (image.channel[0].maxval > 255 && debugstuff && nb_channels == 1) {colortype=PNG_COLOR_TYPE_RGB; nb_channels=3;}

  int shift = 0;
//  if (image.channel[0].maxval == 2048) shift = 5;  // could use something like this to debug DCT values

  png_set_IHDR(png_ptr,info_ptr,w,h,bit_depth,colortype,PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);

  png_write_info(png_ptr,info_ptr);

  png_bytep row = (png_bytep) png_malloc(png_ptr,nb_channels * bytes_per_value * w);

  v_printf(10,"Writing PNG file (range %i..%i)\n",image.minval,image.maxval);
  if (image.channel[0].maxval > 255 && debugstuff) {
    v_printf(10,"Writing PNG file with false colors for debug purposes\n");
    for (size_t r = 0; r < (size_t) h; r++) {
     for (size_t c = 0; c < (size_t) w; c++) {
        row[c * 3 + 0] = (png_byte) (CLAMP((image.channel[0].value(r,c)%10)*26,0,255));
        row[c * 3 + 1] = (png_byte) (CLAMP(image.channel[0].value(r,c)/10,0,255));
        row[c * 3 + 2] = (png_byte) (CLAMP(image.channel[0].value(r,c)/500,0,255));
     }
     png_write_row(png_ptr,row);
    }
  } else if (false && image.channel[0].minval < 0) {
    v_printf(10,"Writing PNG file with negative pixels\n");
   // visualize the negative pixels somehow, for debugging.
   for (size_t r = 0; r < (size_t) h; r++) {
     for (size_t c = 0; c < (size_t) w; c++) {
      for (int p=0; p<nb_channels; p++) {
        row[c * nb_channels + p] = (png_byte) (CLAMP(127+(image.channel[p].value(r,c)),0,255));
      }
     }
    png_write_row(png_ptr,row);
    }
  } else if (cmyk) {
   v_printf(1,"Warning: converting CMYK image to RGB in order to save it as PNG.\n");
   for (size_t r = 0; r < (size_t) h; r++) {
     for (size_t c = 0; c < (size_t) w; c++) {
      for (int p=0; p<3; p++) {
        row[c * (nb_channels-1) + p] = (png_byte) (CLAMP( (255-image.channel[p].value(r,c))*(image.channel[3].value(r,c))/255,0,255));
      }
      if (nb_channels == 5) row[c * (nb_channels-1) + 3] = (png_byte) (CLAMP(image.channel[4].value(r,c),0,255)); // cmyk+alpha

     }
    png_write_row(png_ptr,row);
    }
  } else for (size_t r = 0; r < (size_t) h; r++) {
    if (bytes_per_value == 1) {
     for (size_t c = 0; c < (size_t) w; c++) {
      for (int p=0; p<nb_channels; p++) {
        row[c * nb_channels + p] = (png_byte) (CLAMP(image.channel[p].value(r,c),image.minval,image.maxval));
      }
     }
    } else {
     if (!debugstuff) {
     for (size_t c = 0; c < (size_t) w; c++) {
      for (int p=0; p<nb_channels; p++) {
        row[c * nb_channels * 2 + 2*p] = (png_byte) ((CLAMP(image.channel[p].value(r,c),image.minval,image.maxval)<<shift) >> 8);
        row[c * nb_channels * 2 + 2*p + 1] = (png_byte) ((CLAMP(image.channel[p].value(r,c),image.minval,image.maxval)<<shift) & 0xff);
      }
     }
     } else {
     for (size_t c = 0; c < (size_t) w; c++) {
      for (int p=0; p<nb_channels; p++) {
        row[c * nb_channels * 2 + 2*p] = (png_byte) ((image.channel[p].value(r,c)) >> 8);
        row[c * nb_channels * 2 + 2*p + 1] = (png_byte) ((image.channel[p].value(r,c)) & 0xff);
      }
     }
     }
    }
    png_write_row(png_ptr,row);
  }

  png_free(png_ptr,row);
  png_write_end(png_ptr,info_ptr);
  png_destroy_write_struct(&png_ptr,&info_ptr);
  fclose(fp);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %r15
movq (%rsi), %rax
movq 0x8(%rsi), %r14
subq %rax, %r14
shrq $0x6, %r14
movl 0x70(%rsi), %ecx
andl $0x30, %ecx
xorl %ebp, %ebp
cmpl $0x10, %ecx
sete %bpl
orl $0x4, %ebp
cmpl %r14d, %ebp
movq %rsi, 0x18(%rsp)
jge 0x1fe22
leaq 0x7602(%rip), %rdi      # 0x2740b
movl %r14d, %esi
xorl %eax, %eax
callq 0x379e
movq 0x18(%rsp), %rsi
movq (%rsi), %rax
movl $0x3, %ebx
jmp 0x1fe2e
movl %r14d, %ebx
testl %r14d, %r14d
je 0x1ff6e
movq %r15, 0x10(%rsp)
movl %ebp, 0x28(%rsp)
movq %r14, 0x20(%rsp)
movl 0x18(%rax), %edi
movl 0x1c(%rax), %r12d
movl 0x30(%rsi), %eax
movl 0x34(%rsi), %ecx
cmpl %edi, %eax
cmovll %eax, %edi
cmpl %r12d, %ecx
cmovll %ecx, %r12d
cmpl $0x2, %ebx
movl %edi, 0xc(%rsp)
jl 0x1febf
movl $0x1, %r15d
movl $0x5c, %ebp
movl $0x1, %r13d
leaq 0x7606(%rip), %r14      # 0x2747c
movq (%rsi), %rax
movl -0x4(%rax,%rbp), %edx
movl (%rax,%rbp), %ecx
cmpl %edi, %edx
cmovll %r13d, %ebx
cmpl %r12d, %ecx
cmovll %r13d, %ebx
cmpl $0x1, %ebx
jne 0x1feb0
movq %r14, %rdi
movl %r15d, %esi
movl 0xc(%rsp), %r8d
movl %r12d, %r9d
xorl %eax, %eax
callq 0x379e
movl 0xc(%rsp), %edi
movq 0x18(%rsp), %rsi
incq %r15
movslq %ebx, %rax
addq $0x40, %rbp
cmpq %rax, %r15
jl 0x1fe76
movl 0x64(%rsi), %r14d
cmpl %r14d, %ebx
movl $0x1, %ebp
cmovlel %ebx, %ebp
leaq 0x6b84(%rip), %rsi      # 0x26a59
movq 0x10(%rsp), %rdi
callq 0x3370
testq %rax, %rax
je 0x206db
movq %rax, %r15
leaq 0x726e(%rip), %rdi      # 0x27160
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3100
movq %rax, 0x50(%rsp)
testq %rax, %rax
je 0x1ff83
movq %rax, %r13
movq %rax, %rdi
callq 0x3580
movq %rax, 0x60(%rsp)
testq %rax, %rax
je 0x1ff77
movq %rax, 0x48(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x35c0
movq %r13, 0x30(%rsp)
movq %r13, %rdi
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
callq 0x3490
movq 0x18(%rsp), %rdi
movl 0x70(%rdi), %eax
andl $0x30, %eax
cmpl $0x10, %eax
je 0x1ff8b
movl %ebp, %esi
testl %eax, %eax
movl 0xc(%rsp), %ebp
jne 0x1ffa8
xorl %eax, %eax
cmpl $0x4, %esi
sete %al
leal 0x2(,%rax,4), %eax
jmp 0x1ffad
leaq 0x74db(%rip), %rdi      # 0x27450
jmp 0x1ffc1
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
callq 0x3230
movq %r15, %rdi
jmp 0x206d6
xorl %eax, %eax
cmpl $0x5, %ebp
sete %al
leal 0x2(,%rax,4), %eax
movl %ebp, %esi
cmpl $0x4, %ebp
setge %dl
movl 0xc(%rsp), %ebp
jmp 0x1ffaf
movl $0x2, %eax
xorl %edx, %edx
movl 0x60(%rdi), %ecx
cmpl $0x10000, %ecx          # imm = 0x10000
jl 0x1ffcd
leaq 0x7520(%rip), %rdi      # 0x274e1
xorl %eax, %eax
callq 0x379e
jmp 0x206db
movl %edx, 0x38(%rsp)
movq %r15, 0x58(%rsp)
movslq %ebp, %r15
xorl %edx, %edx
movl %ecx, 0x44(%rsp)
cmpl $0x100, %ecx            # imm = 0x100
setge %dl
movq %rdx, %r13
movq %rdx, 0x10(%rsp)
cmpl %r14d, %ebx
setg %cl
movl 0x28(%rsp), %edx
cmpl 0x20(%rsp), %edx
setl %r8b
xorl %r10d, %r10d
movl %esi, %r11d
cmpl $0x1, %esi
sete %dl
cmovel %r10d, %eax
cmpl $0x2, %esi
movl $0x4, %esi
cmovnel %eax, %esi
movq (%rdi), %rax
movw $0x100, %di             # imm = 0x100
cmpw %di, 0x22(%rax)
movslq %r12d, %rax
movq %rax, 0x28(%rsp)
setge %al
orb %cl, %r8b
movb %r8b, 0xb(%rsp)
andb %r8b, %dl
testb %dl, %al
movl $0x2, %r9d
cmovel %esi, %r9d
leal 0x8(,%r13,8), %r8d
movl $0x3, %r14d
cmovel %r11d, %r14d
subq $0x8, %rsp
movq 0x38(%rsp), %r13
movq %r13, %rdi
movq 0x50(%rsp), %rbx
movq %rbx, %rsi
movl %ebp, %edx
movl %r12d, %ecx
pushq %r10
pushq %r10
pushq %r10
callq 0x3530
addq $0x20, %rsp
movq %r13, %rdi
movq %rbx, %rsi
callq 0x31c0
movl %r14d, %eax
movq 0x10(%rsp), %rcx
shll %cl, %eax
imull %ebp, %eax
movb 0xb(%rsp), %bl
movslq %eax, %rsi
movq %r13, %rdi
callq 0x3540
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movl 0x5c(%rax), %edx
movq 0x18(%rsp), %rax
movl 0x60(%rax), %ecx
leaq 0x7455(%rip), %rsi      # 0x2751c
movl $0xa, %edi
xorl %eax, %eax
callq 0x1cede
movq 0x18(%rsp), %rax
movq (%rax), %rax
movw $0x100, %cx             # imm = 0x100
cmpw %cx, 0x22(%rax)
jl 0x2027f
testb %bl, %bl
je 0x2027f
leaq 0x7445(%rip), %rsi      # 0x2753d
xorl %ebx, %ebx
movl $0xa, %edi
xorl %eax, %eax
callq 0x1cede
testl %r12d, %r12d
je 0x206a3
cmpq $0x1, %r15
adcq $0x0, %r15
movq 0x10(%rsp), %r14
addq $0x2, %r14
xorl %r12d, %r12d
cmpl $0x0, 0xc(%rsp)
je 0x2025d
movq 0x18(%rsp), %rax
movq (%rax), %rax
leaq 0x24(%rax), %rcx
movq %r14, %rdx
xorl %esi, %esi
movl 0x18(%rax), %edi
imull %r12d, %edi
addl %esi, %edi
movslq %edi, %rdi
movq (%rax), %r8
movq 0x8(%rax), %r9
subq %r8, %r9
sarq %r9
cmpq %rdi, %r9
leaq (%r8,%rdi,2), %rdi
cmovbeq %rcx, %rdi
movswl (%rdi), %r8d
imull $0x6667, %r8d, %edi     # imm = 0x6667
movl %edi, %r9d
shrl $0x1f, %r9d
sarl $0x12, %edi
addl %r9d, %edi
addl %edi, %edi
leal (%rdi,%rdi,4), %edi
subl %edi, %r8d
xorl %edi, %edi
movl $0x0, %r9d
testw %r8w, %r8w
js 0x2019c
leal (%r8,%r8,4), %r9d
leal (%r9,%r9,4), %r9d
addl %r8d, %r9d
movb %r9b, -0x2(%rdx)
movl 0x18(%rax), %r8d
imull %r12d, %r8d
addl %esi, %r8d
movslq %r8d, %r8
movq (%rax), %r9
movq 0x8(%rax), %r10
subq %r9, %r10
sarq %r10
cmpq %r8, %r10
leaq (%r9,%r8,2), %r8
cmovbeq %rcx, %r8
movzwl (%r8), %r8d
cmpw $-0x9, %r8w
jl 0x201f5
movswl %r8w, %r8d
movb $-0x1, %dil
cmpl $0x9ff, %r8d            # imm = 0x9FF
jg 0x201f5
imull $0x6667, %r8d, %edi     # imm = 0x6667
movl %edi, %r8d
shrl $0x1f, %r8d
shrl $0x12, %edi
addl %r8d, %edi
movb %dil, -0x1(%rdx)
movl 0x18(%rax), %edi
imull %r12d, %edi
addl %esi, %edi
movslq %edi, %rdi
movq (%rax), %r8
movq 0x8(%rax), %r9
subq %r8, %r9
sarq %r9
cmpq %rdi, %r9
leaq (%r8,%rdi,2), %rdi
cmovbeq %rcx, %rdi
movswl (%rdi), %edi
imull $0xffff8313, %edi, %r8d # imm = 0xFFFF8313
shrl $0x10, %r8d
addl %edi, %r8d
movzwl %r8w, %r8d
movl %r8d, %r9d
shrl $0xf, %r9d
shrl $0x8, %r8d
addl %r9d, %r8d
cmpl $0xfffffe0d, %edi       # imm = 0xFFFFFE0D
cmovll %ebx, %r8d
movb %r8b, (%rdx)
incq %rsi
addq $0x3, %rdx
cmpq %rsi, %r15
jne 0x2013f
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3160
incq %r12
cmpq 0x28(%rsp), %r12
jne 0x20123
jmp 0x206a3
cmpb $0x0, 0x38(%rsp)
je 0x20438
leaq 0x72e3(%rip), %rsi      # 0x27574
movl $0x1, %edi
xorl %eax, %eax
callq 0x1cede
testl %r12d, %r12d
je 0x206a3
leal -0x1(%r14), %eax
movslq %eax, %r12
cmpq $0x1, %r15
adcq $0x0, %r15
xorl %ebx, %ebx
cmpl $0x0, 0xc(%rsp)
je 0x20416
movq 0x18(%rsp), %rax
movq (%rax), %rax
leaq 0xe4(%rax), %rcx
leaq 0x124(%rax), %rdx
movq %rdx, 0x20(%rsp)
leaq 0x24(%rax), %rsi
movq 0x10(%rsp), %rdi
xorl %r8d, %r8d
movq $-0x3, %r9
movq %rsi, %r10
movl -0xc(%r10), %r11d
imull %ebx, %r11d
addl %r8d, %r11d
movslq %r11d, %r11
movq -0x24(%r10), %rbp
movq -0x1c(%r10), %r13
subq %rbp, %r13
sarq %r13
cmpq %r11, %r13
leaq (%rbp,%r11,2), %r11
cmovbeq %r10, %r11
movswl (%r11), %r11d
movl $0xff, %r13d
subl %r11d, %r13d
movl 0xd8(%rax), %r11d
imull %ebx, %r11d
addl %r8d, %r11d
movslq %r11d, %r11
movq 0xc0(%rax), %rbp
movq 0xc8(%rax), %rdx
subq %rbp, %rdx
sarq %rdx
cmpq %r11, %rdx
leaq (%rbp,%r11,2), %rdx
cmovbeq %rcx, %rdx
movswl (%rdx), %ebp
imull %r13d, %ebp
cmpl $0xffffff02, %ebp       # imm = 0xFFFFFF02
jge 0x2036d
xorl %r11d, %r11d
jmp 0x20396
movb $-0x1, %r11b
cmpl $0xfeff, %ebp           # imm = 0xFEFF
jg 0x20396
movslq %ebp, %rdx
imulq $-0x7f7f7f7f, %rdx, %r11 # imm = 0x80808081
shrq $0x20, %r11
addl %ebp, %r11d
movl %r11d, %edx
shrl $0x1f, %edx
shrl $0x7, %r11d
addl %edx, %r11d
movb %r11b, 0x3(%rdi,%r9)
addq $0x40, %r10
incq %r9
jne 0x202f3
cmpl $0x5, %r14d
jne 0x20407
movl 0x118(%rax), %edx
imull %ebx, %edx
addl %r8d, %edx
movslq %edx, %rdx
movq 0x100(%rax), %r9
movq 0x108(%rax), %r10
subq %r9, %r10
sarq %r10
cmpq %rdx, %r10
leaq (%r9,%rdx,2), %rdx
cmovbeq 0x20(%rsp), %rdx
movzwl (%rdx), %edx
movl $0xff, %r10d
cmpl %r10d, %edx
movl %edx, %r9d
cmovael %r10d, %r9d
testw %dx, %dx
movl $0x0, %edx
cmovsl %edx, %r9d
movq 0x10(%rsp), %rdx
movb %r9b, 0x3(%rdx,%r8,4)
incq %r8
addq %r12, %rdi
cmpq %r15, %r8
jne 0x202e9
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3160
incq %rbx
cmpq 0x28(%rsp), %rbx
jne 0x202b7
jmp 0x206a3
testl %r12d, %r12d
je 0x206a3
movslq %r14d, %rax
movq %rax, %rbp
addq %rax, %rax
movq %rax, 0x20(%rsp)
cmpq $0x1, %r15
adcq $0x0, %r15
movl %r14d, %r13d
movq 0x10(%rsp), %rax
incq %rax
movq %rax, 0x38(%rsp)
xorl %r12d, %r12d
cmpl $0xff, 0x44(%rsp)
jle 0x2052c
cmpb $0x0, 0xb(%rsp)
movl 0xc(%rsp), %eax
je 0x205b8
testl %eax, %eax
je 0x20686
movq 0x18(%rsp), %rax
movq (%rax), %rax
addq $0x24, %rax
movq 0x38(%rsp), %rcx
xorl %edx, %edx
testl %r14d, %r14d
jle 0x20516
movq %rax, %rsi
xorl %edi, %edi
movl -0xc(%rsi), %r8d
imull %r12d, %r8d
addl %edx, %r8d
movslq %r8d, %r8
movq -0x24(%rsi), %r9
movq -0x1c(%rsi), %r10
subq %r9, %r10
sarq %r10
cmpq %r8, %r10
leaq (%r9,%r8,2), %r8
cmovbeq %rsi, %r8
movb 0x1(%r8), %r8b
movb %r8b, -0x1(%rcx,%rdi,2)
movl -0xc(%rsi), %r8d
imull %r12d, %r8d
addl %edx, %r8d
movslq %r8d, %r8
movq -0x24(%rsi), %r9
movq -0x1c(%rsi), %r10
subq %r9, %r10
sarq %r10
cmpq %r8, %r10
leaq (%r9,%r8,2), %r8
cmovbeq %rsi, %r8
movb (%r8), %r8b
movb %r8b, (%rcx,%rdi,2)
incq %rdi
addq $0x40, %rsi
cmpq %rdi, %r13
jne 0x204ac
incq %rdx
addq 0x20(%rsp), %rcx
cmpq %r15, %rdx
jne 0x204a2
jmp 0x20686
cmpl $0x0, 0xc(%rsp)
je 0x20686
movq 0x18(%rsp), %rdx
movq (%rdx), %rax
movl 0x5c(%rdx), %ecx
movl 0x60(%rdx), %edx
addq $0x24, %rax
movq 0x10(%rsp), %rsi
xorl %edi, %edi
testl %r14d, %r14d
jle 0x205a8
movq %rax, %r8
xorl %r9d, %r9d
movl -0xc(%r8), %r10d
imull %r12d, %r10d
addl %edi, %r10d
movslq %r10d, %r10
movq -0x24(%r8), %r11
movq -0x1c(%r8), %rbx
subq %r11, %rbx
sarq %rbx
cmpq %r10, %rbx
leaq (%r11,%r10,2), %r10
cmovbeq %r8, %r10
movswl (%r10), %r11d
movl %edx, %r10d
cmpl %r11d, %edx
jl 0x20591
movl %r11d, %r10d
cmpl %r11d, %ecx
cmovgl %ecx, %r10d
movb %r10b, (%rsi,%r9)
incq %r9
addq $0x40, %r8
cmpq %r9, %r13
jne 0x2055b
incq %rdi
addq %rbp, %rsi
cmpq %r15, %rdi
jne 0x20550
jmp 0x20686
testl %eax, %eax
je 0x20686
movq 0x18(%rsp), %rdx
movq (%rdx), %rax
movl 0x5c(%rdx), %ecx
movl 0x60(%rdx), %r9d
addq $0x24, %rax
movq 0x38(%rsp), %rsi
xorl %edi, %edi
testl %r14d, %r14d
jle 0x20675
movq %rax, %r8
xorl %ebx, %ebx
movl -0xc(%r8), %edx
imull %r12d, %edx
addl %edi, %edx
movslq %edx, %rdx
movq -0x24(%r8), %r10
movq -0x1c(%r8), %r11
subq %r10, %r11
sarq %r11
cmpq %rdx, %r11
leaq (%r10,%rdx,2), %rdx
cmovbeq %r8, %rdx
movswl (%rdx), %r10d
movl %r9d, %edx
cmpl %r10d, %r9d
jl 0x2061d
movl %r10d, %edx
cmpl %r10d, %ecx
cmovgl %ecx, %edx
movb %dh, -0x1(%rsi,%rbx,2)
movl -0xc(%r8), %edx
imull %r12d, %edx
addl %edi, %edx
movslq %edx, %rdx
movq -0x24(%r8), %r10
movq -0x1c(%r8), %r11
subq %r10, %r11
sarq %r11
cmpq %rdx, %r11
leaq (%r10,%rdx,2), %rdx
cmovbeq %r8, %rdx
movswl (%rdx), %r10d
movl %r9d, %edx
cmpl %r10d, %r9d
jl 0x2065c
movl %r10d, %edx
cmpl %r10d, %ecx
cmovgl %ecx, %edx
movb %dl, (%rsi,%rbx,2)
incq %rbx
addq $0x40, %r8
cmpq %rbx, %r13
jne 0x205e8
incq %rdi
addq 0x20(%rsp), %rsi
cmpq %r15, %rdi
jne 0x205da
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3160
incq %r12
cmpq 0x28(%rsp), %r12
jne 0x2046a
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x31d0
movq %rbx, %rdi
movq 0x48(%rsp), %rsi
callq 0x32d0
leaq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x3230
movq 0x58(%rsp), %rdi
callq 0x32a0
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq