// File: /workspace/github_cpp_makefile_star2_O2/cloudinary[P]fuif/./export/write_pam.h
// Function: write_PAM_file(char const*, Image const&)
bool write_PAM_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 PAM.\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;}

  FILE *fp = fopen(output_image,"wb");
  if (!fp) {
    return false;
  }


  int components=3;
  bool cmyk = false;
  if ((image.colormodel & 48) == 0) { // RGB
    if (nb_channels == 4) components=4;
  } else if ((image.colormodel & 48) == 16) { // CMYK
    if (nb_channels == 5) components=4;
    if (nb_channels > 3) cmyk = true;
  }
  if (image.colormodel != 0 && image.colormodel != 16) {
    v_printf(1,"Warning: saving raw pixel data without a color profile, even though the image is not sRGB.\n");
  }
  if (nb_channels == 1) components = 1;
  if (nb_channels == 2) components = 2;

  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("Warning: cannot save as PAM since bit depth is higher than 16-bit. Doing it anyway.\n");}

  if (image.nb_channels == 0) {
    // visualize signed stuff
    int range = image.channel[0].maxval - image.channel[0].minval;
    v_printf(3,"Visualizing %ix%i channel with range %i..%i\n",w,h,image.channel[0].minval,image.channel[0].maxval);
    if (range > 255) {bit_depth = 16; bytes_per_value=2;}
    if (image.real_nb_channels == 0) {
    fprintf(fp,"P6\n%u %u\n%i\n", w, h, 255);
    for (int y = 0; y < h; y++) {
     for (int x = 0; x < w; x++) {
      for (int c=0; c<components; c++) {
        // 5461 is one bit
        fputc(CLAMP(image.channel[c].value(y,x)*255/5461, 0, 255),fp);
        fputc(CLAMP(image.channel[c].value(y,x)*50/5461, 0, 255),fp);
        fputc(CLAMP(image.channel[c].value(y,x)*12/5461, 0, 255),fp);
      }
     }
    }
    } else {
    fprintf(fp,"P5\n%u %u\n%i\n", w, h, range);
    for (int y = 0; y < h; y++) {
     for (int x = 0; x < w; x++) {
      for (int c=0; c<components; c++) {
        if (bytes_per_value > 1) fputc((image.channel[c].value(y,x) - image.channel[0].minval) >> 8,fp);
        fputc((image.channel[c].value(y,x) - image.channel[0].minval) & 0xFF,fp);
      }
     }
    }
    }
    fclose(fp);
    return 0;
  }

  if (components == 1) fprintf(fp,"P5\n%u %u\n%i\n", w, h, image.maxval);
  if (components == 2) fprintf(fp,"P7\nWIDTH %u\nHEIGHT %u\nDEPTH 2\nMAXVAL %i\nTUPLTYPE GRAYSCALE_ALPHA\nENDHDR\n", w, h, image.maxval);
  if (components == 3) fprintf(fp,"P6\n%u %u\n%i\n", w, h, image.maxval);
  if (components == 4) fprintf(fp,"P7\nWIDTH %u\nHEIGHT %u\nDEPTH 4\nMAXVAL %i\nTUPLTYPE RGB_ALPHA\nENDHDR\n", w, h, image.maxval);
  v_printf(10,"Writing %i-channel PAM file (range %i..%i)\n",components,image.minval,image.maxval);

  if (cmyk) {
    v_printf(1,"Warning: converting CMYK image to RGB in order to save it as PAM.\n");
    for (int y = 0; y < h; y++) {
     for (int x = 0; x < w; x++) {
      for (int c=0; c<3; c++) {
        if (bytes_per_value > 1) fputc(CLAMP( (image.maxval-image.channel[c].value_nocheck(y,x))*image.channel[3].value_nocheck(y,x)/image.maxval,image.minval,image.maxval) >> 8,fp);
        fputc(CLAMP( (image.maxval-image.channel[c].value_nocheck(y,x))*image.channel[3].value_nocheck(y,x)/image.maxval,image.minval,image.maxval) & 0xFF,fp);
      }
      if (nb_channels == 5) {
        if (bytes_per_value > 1) fputc(CLAMP(image.channel[4].value_nocheck(y,x),image.minval,image.maxval) >> 8,fp);
        fputc(CLAMP(image.channel[4].value_nocheck(y,x),image.minval,image.maxval) & 0xFF,fp);
      }
     }
    }
  } else {
    if (bytes_per_value > 1) {
    for (int y = 0; y < h; y++) {
     for (int x = 0; x < w; x++) {
      for (int c=0; c<components; c++) {
        fputc(CLAMP(image.channel[c].value_nocheck(y,x),image.minval,image.maxval) >> 8,fp);
        fputc(CLAMP(image.channel[c].value_nocheck(y,x),image.minval,image.maxval) & 0xFF,fp);
      }
     }
    }
    } else {
      if (components == 3) {
        for (int y = 0; y < h; y++) {
         for (int x = 0; x < w; x++) {
            fputc(CLAMP(image.channel[0].value_nocheck(y,x),image.minval,image.maxval) & 0xFF,fp);
            fputc(CLAMP(image.channel[1].value_nocheck(y,x),image.minval,image.maxval) & 0xFF,fp);
            fputc(CLAMP(image.channel[2].value_nocheck(y,x),image.minval,image.maxval) & 0xFF,fp);
         }
        }
      } else {
        for (int y = 0; y < h; y++) {
         for (int x = 0; x < w; x++) {
          for (int c=0; c<components; c++) {
            fputc(CLAMP(image.channel[c].value_nocheck(y,x),image.minval,image.maxval) & 0xFF,fp);
          }
         }
        }
      }
    }
  }

  fclose(fp);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq (%rsi), %rax
movq 0x8(%rsi), %r13
subq %rax, %r13
shrq $0x6, %r13
movl 0x70(%rsi), %ecx
andl $0x30, %ecx
xorl %edx, %edx
cmpl $0x10, %ecx
sete %dl
orl $0x4, %edx
cmpl %r13d, %edx
jge 0x198f9
leaq 0x5ad5(%rip), %rdi      # 0x1f3bb
movl %r13d, %esi
xorl %eax, %eax
callq 0x16b80
movq (%rbx), %rax
pushq $0x3
popq %r13
jmp 0x19902
testl %r13d, %r13d
je 0x199d3
movq %r14, 0x18(%rsp)
movl 0x18(%rax), %ebp
movl 0x1c(%rax), %ecx
movl 0x30(%rbx), %eax
cmpl %ebp, %eax
cmovll %eax, %ebp
movl 0x34(%rbx), %eax
cmpl %ecx, %eax
cmovll %eax, %ecx
movl %ecx, 0x24(%rsp)
pushq $0x1
popq %r14
pushq $0x5c
popq %r15
pushq $0x1
popq %rax
movl %eax, 0x10(%rsp)
leaq 0x5af5(%rip), %r12      # 0x1f42c
movslq %r13d, %rax
cmpq %rax, %r14
jge 0x19980
movq (%rbx), %rax
movl -0x4(%rax,%r15), %edx
movl (%rax,%r15), %ecx
cmpl %ebp, %edx
pushq $0x1
popq %rax
cmovll %eax, %r13d
cmpl 0x24(%rsp), %ecx
cmovll %eax, %r13d
cmpl $0x1, %r13d
jne 0x19977
movq %r12, %rdi
movl %r14d, %esi
movl %ebp, %r8d
movl 0x24(%rsp), %r9d
xorl %eax, %eax
callq 0x16b80
incq %r14
addq $0x40, %r15
jmp 0x19937
cmpl 0x64(%rbx), %r13d
movl 0x10(%rsp), %eax
cmovlel %r13d, %eax
movl %eax, 0x10(%rsp)
leaq 0x5072(%rip), %rsi      # 0x1ea09
movq 0x18(%rsp), %rdi
callq 0x33a0
testq %rax, %rax
je 0x1a16a
movq %rax, %r14
movl 0x70(%rbx), %eax
movl %eax, %ecx
andl $0x30, %ecx
cmpl $0x10, %ecx
je 0x199e6
testl %ecx, %ecx
jne 0x19a01
xorl %r15d, %r15d
cmpl $0x4, 0x10(%rsp)
sete %r15b
addl $0x3, %r15d
xorl %r12d, %r12d
jmp 0x19a08
leaq 0x5b8d(%rip), %rdi      # 0x1f567
xorl %eax, %eax
callq 0x16b80
jmp 0x1a16a
xorl %r15d, %r15d
movl 0x10(%rsp), %ecx
cmpl $0x5, %ecx
sete %r15b
addl $0x3, %r15d
cmpl $0x4, %ecx
setge %r12b
jmp 0x19a08
xorl %r12d, %r12d
pushq $0x3
popq %r15
testl $0xffffffef, %eax       # imm = 0xFFFFFFEF
je 0x19a20
leaq 0x5b7d(%rip), %rsi      # 0x1f593
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x16c30
movl 0x10(%rsp), %eax
cmpl $0x1, %eax
cmovel %eax, %r15d
cmpl $0x2, %eax
cmovel %eax, %r15d
movl 0x60(%rbx), %r13d
cmpl $0x10000, %r13d         # imm = 0x10000
jl 0x19a4d
leaq 0x5ba9(%rip), %rdi      # 0x1f5ef
xorl %eax, %eax
callq 0x16b80
cmpl $0x0, 0x64(%rbx)
movq %r14, 0x18(%rsp)
je 0x19a90
movl 0x60(%rbx), %r8d
cmpl $0x1, %r15d
movl %r15d, 0x34(%rsp)
movl %r12d, 0x28(%rsp)
je 0x19bb6
cmpl $0x3, %r15d
je 0x19ba7
cmpl $0x2, %r15d
jne 0x19bbf
leaq 0x5c00(%rip), %rsi      # 0x1f68b
jmp 0x19bc6
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r13d
setge 0x10(%rsp)
movq (%rbx), %rax
movswl 0x22(%rax), %r9d
movswl 0x20(%rax), %r8d
movl %r9d, %r12d
subl %r8d, %r12d
leaq 0x5b8d(%rip), %rsi      # 0x1f644
xorl %r13d, %r13d
pushq $0x3
popq %rdi
movl %ebp, %r14d
movl %ebp, %edx
movl 0x24(%rsp), %ebp
movl %ebp, %ecx
xorl %eax, %eax
callq 0x16c30
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r12d
movl %r14d, %edx
setge %al
testl %r14d, %r14d
movl $0x0, %esi
cmovgl %r14d, %esi
movl %esi, 0x28(%rsp)
testl %ebp, %ebp
movl $0x0, %esi
cmovgl %ebp, %esi
movl %esi, 0xc(%rsp)
cmpl $0x0, 0x68(%rbx)
movl %r15d, %r15d
je 0x19f71
movb 0x10(%rsp), %r14b
orb %al, %r14b
leaq 0x5b67(%rip), %rsi      # 0x1f67e
movq 0x18(%rsp), %rdi
movl %ebp, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3430
shlq $0x6, %r15
cmpl 0xc(%rsp), %r13d
je 0x1a160
xorl %ebp, %ebp
cmpl 0x28(%rsp), %ebp
je 0x19ba2
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x19b9e
testb %r14b, %r14b
je 0x19b75
movq (%rbx), %rdi
addq %r12, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0xa79e
movswl %ax, %edi
movq (%rbx), %rax
movswl 0x20(%rax), %eax
subl %eax, %edi
sarl $0x8, %edi
movq 0x18(%rsp), %rsi
callq 0x33d0
movq (%rbx), %rdi
addq %r12, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0xa79e
movq (%rbx), %rcx
subl 0x20(%rcx), %eax
movzbl %al, %edi
movq 0x18(%rsp), %rsi
callq 0x33d0
addq $0x40, %r12
jmp 0x19b42
incl %ebp
jmp 0x19b39
incl %r13d
jmp 0x19b2c
movb $0x1, %al
movl %eax, 0xc(%rsp)
leaq 0x5abd(%rip), %rsi      # 0x1f671
jmp 0x19bce
leaq 0x5ac1(%rip), %rsi      # 0x1f67e
jmp 0x19bc6
leaq 0x5b0e(%rip), %rsi      # 0x1f6d4
movl $0x0, 0xc(%rsp)
xorl %r12d, %r12d
movq %r14, %rdi
movl %ebp, %r15d
movl %ebp, %edx
movl 0x24(%rsp), %ebp
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3430
movl 0x5c(%rbx), %ecx
movl 0x60(%rbx), %r8d
leaq 0x5b23(%rip), %rsi      # 0x1f717
pushq $0xa
popq %rdi
movl 0x34(%rsp), %edx
xorl %eax, %eax
callq 0x16c30
cmpb $0x0, 0x28(%rsp)
je 0x19dbc
leaq 0x5b2f(%rip), %rsi      # 0x1f743
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x16c30
testl %r15d, %r15d
cmovlel %r12d, %r15d
testl %ebp, %ebp
cmovlel %r12d, %ebp
movl %r15d, 0x28(%rsp)
movl %ebp, 0x24(%rsp)
movq 0x18(%rsp), %r14
cmpl %ebp, %r12d
je 0x1a160
xorl %ebp, %ebp
cmpl 0x28(%rsp), %ebp
je 0x19db0
pushq $0x18
popq %r15
cmpq $0xd8, %r15
je 0x19d29
cmpl $0x100, %r13d           # imm = 0x100
jl 0x19cc4
movl 0x60(%rbx), %ecx
movq (%rbx), %rax
movl (%rax,%r15), %edx
imull %r12d, %edx
addl %ebp, %edx
movslq %edx, %rdx
movq -0x18(%rax,%r15), %rsi
movswl (%rsi,%rdx,2), %edx
movl %ecx, %esi
subl %edx, %esi
movl 0xd8(%rax), %edx
imull %r12d, %edx
addl %ebp, %edx
movslq %edx, %rdx
movq 0xc0(%rax), %rax
movswl (%rax,%rdx,2), %eax
imull %esi, %eax
cltd
idivl %ecx
movl %eax, %edx
cmpl %ecx, %eax
jl 0x19cb0
movl %ecx, %edx
movl 0x5c(%rbx), %edi
cmpl %edi, %eax
jl 0x19cb9
movl %edx, %edi
sarl $0x8, %edi
movq %r14, %rsi
callq 0x33d0
movl 0x60(%rbx), %ecx
movq (%rbx), %rax
movl (%rax,%r15), %edx
imull %r12d, %edx
addl %ebp, %edx
movslq %edx, %rdx
movq -0x18(%rax,%r15), %rsi
movswl (%rsi,%rdx,2), %edx
movl %ecx, %esi
subl %edx, %esi
movl 0xd8(%rax), %edx
imull %r12d, %edx
addl %ebp, %edx
movslq %edx, %rdx
movq 0xc0(%rax), %rax
movswl (%rax,%rdx,2), %eax
imull %esi, %eax
cltd
idivl %ecx
movl 0x5c(%rbx), %edx
movl %eax, %esi
cmpl %ecx, %eax
jl 0x19d0f
movl %ecx, %esi
cmpl %edx, %eax
jl 0x19d15
movl %esi, %edx
movzbl %dl, %edi
movq %r14, %rsi
callq 0x33d0
addq $0x40, %r15
jmp 0x19c52
cmpl $0x5, 0x10(%rsp)
jne 0x19da9
cmpl $0x100, %r13d           # imm = 0x100
jl 0x19d71
movq (%rbx), %rax
movl 0x118(%rax), %ecx
imull %r12d, %ecx
addl %ebp, %ecx
movslq %ecx, %rcx
movq 0x100(%rax), %rax
movswl (%rax,%rcx,2), %eax
movl 0x5c(%rbx), %ecx
movl 0x60(%rbx), %edi
cmpl %eax, %edi
cmovgel %eax, %edi
cmpl %eax, %ecx
cmovgl %ecx, %edi
sarl $0x8, %edi
movq %r14, %rsi
callq 0x33d0
movq (%rbx), %rax
movl 0x118(%rax), %ecx
imull %r12d, %ecx
addl %ebp, %ecx
movslq %ecx, %rcx
movq 0x100(%rax), %rax
movswl (%rax,%rcx,2), %eax
movl 0x5c(%rbx), %ecx
movl 0x60(%rbx), %edx
cmpl %eax, %edx
cmovgel %eax, %edx
cmpl %eax, %ecx
cmovgl %ecx, %edx
movzbl %dl, %edi
movq %r14, %rsi
callq 0x33d0
incl %ebp
jmp 0x19c44
incl %r12d
movl 0x24(%rsp), %ebp
jmp 0x19c39
testl %r15d, %r15d
cmovlel %r12d, %r15d
testl %ebp, %ebp
cmovgl %ebp, %r12d
cmpl $0x100, %r13d           # imm = 0x100
movl %r15d, 0x28(%rsp)
jl 0x19e87
movl 0x34(%rsp), %r14d
shlq $0x6, %r14
xorl %r13d, %r13d
cmpl %r12d, %r13d
je 0x1a160
xorl %ebp, %ebp
cmpl 0x28(%rsp), %ebp
je 0x19e7f
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x19e78
movq (%rbx), %rax
movl 0x18(%rax,%r15), %ecx
imull %r13d, %ecx
addl %ebp, %ecx
movslq %ecx, %rcx
movq (%rax,%r15), %rax
movswl (%rax,%rcx,2), %eax
movl 0x60(%rbx), %edi
cmpl %eax, %edi
jl 0x19e26
movl %eax, %edi
movl 0x5c(%rbx), %ecx
cmpl %eax, %ecx
cmovgl %ecx, %edi
sarl $0x8, %edi
movq 0x18(%rsp), %rsi
callq 0x33d0
movq (%rbx), %rax
movl 0x18(%rax,%r15), %ecx
imull %r13d, %ecx
addl %ebp, %ecx
movslq %ecx, %rcx
movq (%rax,%r15), %rax
movswl (%rax,%rcx,2), %ecx
movl 0x60(%rbx), %eax
cmpl %ecx, %eax
jl 0x19e5d
movl %ecx, %eax
movl 0x5c(%rbx), %edx
cmpl %ecx, %edx
cmovgl %edx, %eax
movzbl %al, %edi
movq 0x18(%rsp), %rsi
callq 0x33d0
addq $0x40, %r15
jmp 0x19dff
incl %ebp
jmp 0x19df2
incl %r13d
jmp 0x19de7
cmpb $0x0, 0xc(%rsp)
je 0x1a0e9
movl %r15d, %eax
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movl $0xff, %ebp
movq 0x18(%rsp), %r14
cmpl %r12d, %eax
je 0x1a160
movq %rax, 0x28(%rsp)
movslq %eax, %r13
xorl %r15d, %r15d
cmpl %r15d, 0x10(%rsp)
je 0x19f65
movq (%rbx), %rax
movslq 0x18(%rax), %rcx
imulq %r13, %rcx
addq %r15, %rcx
movq (%rax), %rax
movswl (%rax,%rcx,2), %eax
movl 0x60(%rbx), %edi
cmpl %eax, %edi
jl 0x19ee3
movl %eax, %edi
movl 0x5c(%rbx), %ecx
cmpl %eax, %ecx
cmovgl %ecx, %edi
andl %ebp, %edi
movq %r14, %rsi
callq 0x33d0
movq (%rbx), %rax
movslq 0x58(%rax), %rcx
imulq %r13, %rcx
addq %r15, %rcx
movq 0x40(%rax), %rax
movswl (%rax,%rcx,2), %eax
movl 0x60(%rbx), %edi
cmpl %eax, %edi
jl 0x19f14
movl %eax, %edi
movl 0x5c(%rbx), %ecx
cmpl %eax, %ecx
cmovgl %ecx, %edi
andl %ebp, %edi
movq %r14, %rsi
callq 0x33d0
movq (%rbx), %rax
movslq 0x98(%rax), %rcx
imulq %r13, %rcx
addq %r15, %rcx
movq 0x80(%rax), %rax
movswl (%rax,%rcx,2), %ecx
movl 0x5c(%rbx), %eax
movl 0x60(%rbx), %edi
cmpl %ecx, %edi
jl 0x19f4e
movl %ecx, %edi
cmpl %ecx, %eax
cmovgl %eax, %edi
andl %ebp, %edi
movq %r14, %rsi
callq 0x33d0
incq %r15
jmp 0x19eba
movq 0x28(%rsp), %rax
incl %eax
jmp 0x19ea6
leaq 0x56f9(%rip), %rsi      # 0x1f671
xorl %r12d, %r12d
movq 0x18(%rsp), %rdi
movl %ebp, %ecx
movl $0xff, %r8d
xorl %eax, %eax
callq 0x3430
shlq $0x6, %r15
movq %r15, 0x10(%rsp)
movq 0x18(%rsp), %r14
cmpl 0xc(%rsp), %r12d
je 0x1a160
xorl %ebp, %ebp
cmpl 0x28(%rsp), %ebp
je 0x1a0e1
xorl %r13d, %r13d
cmpq %r13, %r15
je 0x1a0da
movq (%rbx), %rdi
addq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xa79e
xorl %r15d, %r15d
movl $0x0, %edi
cmpw $-0x15, %ax
jl 0x1a01a
movq (%rbx), %rdi
addq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xa79e
movl $0xff, %edi
cmpw $0x156a, %ax            # imm = 0x156A
jg 0x1a01a
movq (%rbx), %rdi
addq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xa79e
cwtl
imull $0xff, %eax, %eax
cltd
movl $0x1555, %ecx           # imm = 0x1555
idivl %ecx
movl %eax, %edi
movq %r14, %rsi
callq 0x33d0
movq (%rbx), %rdi
addq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xa79e
cmpw $-0x6d, %ax
jl 0x1a073
movq (%rbx), %rdi
addq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xa79e
movl $0xff, %r15d
cmpw $0x6d38, %ax            # imm = 0x6D38
jg 0x1a073
movq (%rbx), %rdi
addq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xa79e
cwtl
imull $0x32, %eax, %eax
cltd
movl $0x1555, %ecx           # imm = 0x1555
idivl %ecx
movl %eax, %r15d
movl %r15d, %edi
movq %r14, %rsi
callq 0x33d0
movq (%rbx), %rdi
addq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xa79e
xorl %edi, %edi
cmpw $0xfe39, %ax            # imm = 0xFE39
jl 0x1a0c4
movq (%rbx), %rdi
addq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xa79e
movq (%rbx), %rdi
addq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xa79e
cwtl
imull $0xc, %eax, %eax
cltd
movl $0x1555, %ecx           # imm = 0x1555
idivl %ecx
movl %eax, %edi
movq %r14, %rsi
callq 0x33d0
addq $0x40, %r13
movq 0x10(%rsp), %r15
jmp 0x19fb7
incl %ebp
jmp 0x19faa
incl %r12d
jmp 0x19f9d
movl 0x34(%rsp), %eax
shlq $0x6, %rax
movq %rax, 0x10(%rsp)
xorl %edx, %edx
movq 0x18(%rsp), %r14
cmpl %r12d, %edx
je 0x1a160
xorl %r13d, %r13d
cmpl 0x28(%rsp), %r13d
je 0x1a15c
xorl %r15d, %r15d
cmpq %r15, 0x10(%rsp)
je 0x1a157
movq (%rbx), %rax
movl 0x18(%rax,%r15), %ecx
movq %rdx, %rbp
imull %edx, %ecx
addl %r13d, %ecx
movslq %ecx, %rcx
movq (%rax,%r15), %rax
movswl (%rax,%rcx,2), %ecx
movl 0x60(%rbx), %eax
cmpl %ecx, %eax
jl 0x1a13b
movl %ecx, %eax
movl 0x5c(%rbx), %edx
cmpl %ecx, %edx
cmovgl %edx, %eax
movzbl %al, %edi
movq %r14, %rsi
callq 0x33d0
addq $0x40, %r15
movq %rbp, %rdx
jmp 0x1a10f
incl %r13d
jmp 0x1a105
incl %edx
jmp 0x1a0fd
movq 0x18(%rsp), %rdi
callq 0x32c0
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq