// File: /workspace/github_cpp_makefile_star2_O1/cloudinary[P]fuif/encoding/encoding.cpp
// Function: bool fuif_encode<FileIO>(FileIO&, Image const&, fuif_options&)
bool fuif_encode(IO& realio, const Image &image, fuif_options &options) {
    if (image.error) return false;
    if (image.nb_frames < 2) realio.fputs("FUIF");  // bytes 1-4 are fixed magic
    else realio.fputs("FUAF");                      // animation has different magic
    int nb_channels = image.real_nb_channels;
    write_big_endian_varint(realio, nb_channels + '0');
    int bit_depth = 1, maxval = 1;
    while (maxval < image.maxval) { bit_depth++; maxval = maxval*2 + 1; }
    write_big_endian_varint(realio, bit_depth + '&');
    write_big_endian_varint(realio, image.w-1);
    write_big_endian_varint(realio, image.h-1);
    if (image.nb_frames > 1) {
        write_big_endian_varint(realio, image.nb_frames-2);
        write_big_endian_varint(realio, image.den-1);
        if (image.num.size() == 0) write_big_endian_varint(realio, 0);
        else for (int i=0; i<image.num.size(); i++) write_big_endian_varint(realio, image.num[i]);
        write_big_endian_varint(realio, image.loops);
    }
    write_big_endian_varint(realio, image.colormodel);

    write_big_endian_varint(realio, options.max_properties);

    v_printf(2,"Encoding %i-channel, %i-bit, %ix%i %s%s image.\n", nb_channels, bit_depth, image.w, image.h, colormodel_name(image.colormodel,nb_channels), colorprofile_name(image.colormodel));

    BlobIO io;

    if (nb_channels < 1) return true; // is there any use for a zero-channel image?


    // encode transforms
    int nb_transforms = image.transform.size();
    write_big_endian_varint(io,nb_transforms);
    for (int i=0; i<nb_transforms; i++) {
        int id = image.transform[i].ID;
        int nb_params = (image.transform[i].has_parameters() ? image.transform[i].parameters.size() : 0);
        write_big_endian_varint(io, (nb_params << 4) + id);
        for (int j=0; j<nb_params; j++) write_big_endian_varint(io, image.transform[i].parameters[j]);
    }

    nb_channels = image.channel.size();

    int responsive_offsets[5] = {-1, -1, -1, -1, -1}; //   LQIP, 1/16 1/8 1/4 1/2

    // encode channel data
    for (int i=0; i<nb_channels; i++) {
        if (! image.channel[i].w || ! image.channel[i].h ) continue; // skip empty channels
        int predictor = 0;
        if (options.predictor.size() > i) predictor = options.predictor[i]; else if (options.predictor.size() > 0) predictor = options.predictor.back(); else predictor = 0;
//        if (predictor < 0) predictor = find_best_predictor(image.channel[i]);

        int j=i;
        Tree tree;
        size_t header_pos;

        if (!options.compress) {
            if (!fuif_encode_channels<BlobIO, RacOut<BlobIO>, FinalPropertySymbolCoder<FUIFBitChancePass2, RacOut<BlobIO>, MAX_BIT_DEPTH>, false, false >(io, tree, options, predictor, i, j, image, header_pos)) return false;
            continue;
        }

        // do several channels at a time (keep going until we hit a new downscale truncation point)
        for (int s=1; s<5; s++) if (j > image.downscales[s] && j < image.downscales[s+1]) j = image.downscales[s+1];

        // needed for interleaved (which we don't use), and maybe a good idea in any case: only clump same-dimension channels
        for (int k=i+1; k<=j; k++) if (image.channel[i].w != image.channel[k].w || image.channel[i].h != image.channel[k].h) { j=k-1; break; }

        if (options.max_group > 0 && j > i + options.max_group - 1) j = i + options.max_group - 1;

        DummyIO dummyio;
        if (!fuif_encode_channels<DummyIO, RacDummy<DummyIO>, PropertySymbolCoder<FUIFBitChancePass1, RacDummy<DummyIO>, MAX_BIT_DEPTH>, true, true >(dummyio, tree, options, predictor, i, j, image, header_pos)) return false;
        size_t before=io.ftell();
        if (!fuif_encode_channels<BlobIO, RacOut<BlobIO>, FinalPropertySymbolCoder<FUIFBitChancePass2, RacOut<BlobIO>, MAX_BIT_DEPTH>, false, true >(io, tree, options, predictor, i, j, image, header_pos)) return false;
        size_t after=io.ftell();
        float bits = (after-header_pos)*8.0;
        float pixels = 0.0;
        float ubits = 0.0;
        for (int k=i; k<=j; k++) {
            float chpixels = image.channel[k].w*image.channel[k].h;
            float uncompressed_bpp = maniac::util::ilog2(image.channel[k].maxval-image.channel[k].minval)+1;
            pixels += chpixels;
            if (image.channel[k].maxval > image.channel[k].minval)
                ubits += chpixels*uncompressed_bpp;
        }
        if (ubits > 0.0) ubits += 16; // rac flush might add 2 bytes
        float bpp=bits/pixels;
        float ubpp=ubits/pixels;

        v_printf(4,"Encoded channel %i-%i (%ix%i %s, range %i..%i), %i+%i bytes [%i-%i] (%f bpp; uncompressed estimate: %f bpp; %.2f%% reduction)\n", i,j, image.channel[i].w, image.channel[i].h, ch_describe(image,i), image.channel[i].minval, image.channel[i].maxval, after-header_pos, header_pos-before, before,after,
                bpp, ubpp, 100.0-100.0*bpp/ubpp);

        if ( bits >= ubits ) {
            io.fseek(before,SEEK_SET);
            if (!fuif_encode_channels<BlobIO, RacOut<BlobIO>, FinalPropertySymbolCoder<FUIFBitChancePass2, RacOut<BlobIO>, MAX_BIT_DEPTH>, false, false >(io, tree, options, predictor, i, j, image, header_pos)) return false;
            after=io.ftell();
            float bpp=(after-header_pos)*8.0/pixels;
            v_printf(4,"Rolled back. Encoded channel %i-%i UNCOMPRESSED (%ix%i %s, range %i..%i), %i+%i bytes (%f bpp)\n", i, j, image.channel[i].w, image.channel[i].h, ch_describe(image,i), image.channel[i].minval, image.channel[i].maxval, after-header_pos, header_pos-before, bpp);
        }
        for (int s=0; s<5; s++) {
            if (image.downscales[s] >= i && image.downscales[s] <= j) responsive_offsets[s] = after;
        }
        i=j;
    }

    int relative_offset = 0;
    for (int s=0; s<5; s++) {
        v_printf(3,"Responsive truncation point for size 1/%i after channel %i, at post-header position %i\n",responsive_sizes[s],image.downscales[s],responsive_offsets[s]);
        if (responsive_offsets[s] < 0) responsive_offsets[s] = io.ftell();
        int offset = responsive_offsets[s] - relative_offset;
        write_big_endian_varint(realio, (offset+TRUNCATION_OFFSET_RESOLUTION-1)/TRUNCATION_OFFSET_RESOLUTION);
        relative_offset = responsive_offsets[s];
    }

    if (options.debug) options.heatmap.recompute_minmax();

    io.fseek(0,SEEK_SET);
    int c;
    while ( (c=io.get_c()) != io.EOS ) realio.fputc(c); // TODO: copy the memory buffer more efficiently
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
cmpb $0x0, 0xa8(%rsi)
je 0x1190e
xorl %r14d, %r14d
jmp 0x1225f
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r14
cmpl $0x2, 0x38(%rsi)
movq (%rdi), %rsi
leaq 0x14c50(%rip), %rax     # 0x26575
leaq 0x14c4e(%rip), %rdi     # 0x2657a
cmovlq %rax, %rdi
callq 0x3330
movslq 0x68(%r15), %rbx
leaq 0x30(%rbx), %rsi
movl $0x1, %r12d
movq %r14, %rdi
movl $0x1, %edx
callq 0x122c2
movl 0x60(%r15), %eax
cmpl $0x2, %eax
jl 0x11972
movl $0x1, %r12d
movl $0x1, %ecx
incl %r12d
leal 0x1(,%rcx,2), %ecx
cmpl %eax, %ecx
jl 0x11964
leal 0x26(%r12), %esi
movq %r14, %rdi
movl $0x1, %edx
callq 0x122c2
movslq 0x30(%r15), %rsi
decq %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x122c2
movslq 0x34(%r15), %rsi
decq %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x122c2
movl 0x38(%r15), %esi
cmpl $0x2, %esi
jl 0x11a3e
movq %rbx, %rbp
addl $-0x2, %esi
movq %r14, %rdi
movl $0x1, %edx
callq 0x122c2
movslq 0x3c(%r15), %rsi
decq %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x122c2
movq 0x48(%r15), %rax
cmpq 0x40(%r15), %rax
je 0x11a20
movq 0x40(%r15), %rax
cmpq %rax, 0x48(%r15)
je 0x11a2a
xorl %ebx, %ebx
movslq (%rax,%rbx,4), %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x122c2
incq %rbx
movq 0x40(%r15), %rax
movq 0x48(%r15), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
ja 0x119f6
jmp 0x11a2a
movq (%r14), %rsi
xorl %edi, %edi
callq 0x33a0
movslq 0x58(%r15), %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x122c2
movq %rbp, %rbx
movslq 0x70(%r15), %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x122c2
movq %r13, 0x18(%rsp)
movslq 0x10(%r13), %rsi
movq %r14, 0xb8(%rsp)
movq %r14, %rdi
movl $0x1, %edx
callq 0x122c2
movl 0x30(%r15), %ebp
movl 0x34(%r15), %r13d
movl 0x70(%r15), %edi
movl %ebx, %esi
callq 0x5f9c
movq %rax, %r14
movl 0x70(%r15), %edi
callq 0x6085
movq %rax, %r10
leaq 0x14ae9(%rip), %rsi     # 0x2657f
movl $0x2, %edi
movl %ebx, %edx
movl %r12d, %ecx
movl %ebp, %r8d
movl %r13d, %r9d
xorl %eax, %eax
pushq %r10
pushq %r14
callq 0x1d0d6
addq $0x10, %rsp
pxor %xmm0, %xmm0
movdqa %xmm0, 0x50(%rsp)
movdqa %xmm0, 0x40(%rsp)
movl $0xffffffff, 0x60(%rsp) # imm = 0xFFFFFFFF
testl %ebx, %ebx
jle 0x1224d
movq 0x20(%r15), %rbx
subq 0x18(%r15), %rbx
shrq $0x5, %rbx
movslq %ebx, %rsi
leaq 0x40(%rsp), %rdi
movl $0x1, %edx
callq 0x12307
testl %ebx, %ebx
jle 0x11b95
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
xorl %r12d, %r12d
leaq 0x40(%rsp), %r14
movq %rbx, (%rsp)
movq 0x18(%r15), %rcx
movq %r12, %r13
shlq $0x5, %r13
movl (%rcx,%r13), %eax
movl $0x0, %ebp
cmpl $0xa, %eax
ja 0x11b44
movl $0x7d8, %edx            # imm = 0x7D8
btl %eax, %edx
movl $0x0, %ebp
jae 0x11b44
addq %r13, %rcx
movq 0x10(%rcx), %rbp
subq 0x8(%rcx), %rbp
shrq $0x2, %rbp
movl %ebp, %ecx
shll $0x4, %ecx
addl %eax, %ecx
movslq %ecx, %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x12307
testl %ebp, %ebp
jle 0x11b85
movl %ebp, %ebp
xorl %ebx, %ebx
movq 0x18(%r15), %rax
movq 0x8(%rax,%r13), %rax
movslq (%rax,%rbx,4), %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x12307
incq %rbx
cmpq %rbx, %rbp
jne 0x11b63
incq %r12
movq (%rsp), %rbx
cmpq %rbx, %r12
jne 0x11b0d
movq 0x8(%r15), %rcx
subq (%r15), %rcx
shrq $0x6, %rcx
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0xc0(%rsp)
movl $0xffffffff, 0xd0(%rsp) # imm = 0xFFFFFFFF
testl %ecx, %ecx
setle %r14b
jle 0x12170
xorl %r12d, %r12d
movq 0x18(%rsp), %rbp
movq %rcx, 0xb0(%rsp)
movslq %r12d, %rbx
movq (%r15), %rax
movq %rbx, %r13
shlq $0x6, %r13
cmpl $0x0, 0x18(%rax,%r13)
je 0x12160
addq %r13, %rax
cmpl $0x0, 0x1c(%rax)
je 0x12160
movq 0x28(%rbp), %rcx
movq 0x30(%rbp), %rax
movq %rax, %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
cmpq %rbx, %rdx
jbe 0x11c17
leaq (%rcx,%rbx,4), %rax
jmp 0x11c24
cmpq %rcx, %rax
je 0x11d21
addq $-0x4, %rax
movl (%rax), %eax
movl %eax, (%rsp)
pxor %xmm0, %xmm0
movdqa %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movl $0x8, %edi
callq 0x32b0
movq %rax, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x30(%rsp)
movq $0xffff, (%rax)         # imm = 0xFFFF
movq %rcx, 0x28(%rsp)
cmpb $0x1, 0x1c(%rbp)
jne 0x11ce6
movl %r12d, %esi
movl $0x26, %ecx
movl %r12d, %eax
cmpl -0x4(%r15,%rcx,4), %eax
jle 0x11c89
movl (%r15,%rcx,4), %edx
cmpl %edx, %eax
cmovlel %edx, %eax
incq %rcx
cmpq $0x2a, %rcx
jne 0x11c79
movq %rsi, 0xe8(%rsp)
movq (%r15), %rdx
leaq (%rdx,%r13), %rcx
cmpl %r12d, %eax
movl %r12d, %esi
cmovgl %eax, %esi
movslq %esi, %rsi
subq %rsi, %rbx
leaq (%rdx,%r13), %rsi
addq $0x5c, %rsi
xorl %edx, %edx
movl %r14d, 0xc(%rsp)
cmpq %rdx, %rbx
je 0x11d32
movl 0x18(%rcx), %edi
cmpl -0x4(%rsi), %edi
jne 0x11d2d
movl 0x1c(%rcx), %edi
decq %rdx
leaq 0x40(%rsi), %r8
cmpl (%rsi), %edi
movq %r8, %rsi
je 0x11cbf
notl %edx
addl %r12d, %edx
movl %edx, %eax
jmp 0x11d32
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbp, %rdx
movl (%rsp), %ecx
movl %r12d, %r8d
movl %r12d, %r9d
leaq 0x10(%rsp), %rax
pushq %rax
pushq %r15
callq 0x12347
addq $0x10, %rsp
testb %al, %al
movl $0x1, %ebx
movl $0xf, %eax
cmovnel %eax, %ebx
jmp 0x1212b
movl $0x0, (%rsp)
jmp 0x11c29
movl %r12d, %eax
subl %edx, %eax
movl 0x20(%rbp), %ecx
leal (%rcx,%r12), %edx
cmpl %edx, %eax
leal -0x1(%rcx,%r12), %r14d
cmovll %eax, %r14d
testl %ecx, %ecx
cmovlel %eax, %r14d
movl $0xffffffff, 0xa4(%rsp) # imm = 0xFFFFFFFF
leaq 0xa4(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbp, %rdx
movl (%rsp), %ecx
movl %r12d, %r8d
movl %r14d, %r9d
leaq 0x10(%rsp), %rax
pushq %rax
pushq %r15
callq 0x1293f
addq $0x10, %rsp
movl $0x1, %ebx
testb %al, %al
je 0x12120
movslq 0x58(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbp, %rdx
movl (%rsp), %ecx
movl %r12d, %r8d
movl %r14d, %r9d
leaq 0x10(%rsp), %rax
pushq %rax
pushq %r15
callq 0x13174
addq $0x10, %rsp
testb %al, %al
je 0x12120
movq 0x58(%rsp), %rax
movq %rax, 0xa8(%rsp)
cltq
movq 0x10(%rsp), %rcx
movq %rax, 0x70(%rsp)
movq %rcx, 0x78(%rsp)
subq %rcx, %rax
movq %rax, 0x80(%rsp)
movq %rax, %xmm1
punpckldq 0x145c2(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x145ca(%rip), %xmm1    # 0x263d0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x14626(%rip), %xmm0    # 0x26440
xorps %xmm4, %xmm4
xorpd %xmm1, %xmm1
cmpl %r14d, %r12d
jg 0x11e87
movq (%r15), %rax
addq %r13, %rax
addq $0x22, %rax
movl %r14d, %ecx
subl %r12d, %ecx
incl %ecx
movl -0x6(%rax), %edx
imull -0xa(%rax), %edx
movswl (%rax), %edi
movswl -0x2(%rax), %r8d
movl %edi, %esi
subl %r8d, %esi
bsrl %esi, %esi
xorl $-0x20, %esi
addl $0x21, %esi
movss 0x14603(%rip), %xmm3    # 0x26460
cmpw %r8w, %di
je 0x11e6a
xorps %xmm3, %xmm3
cvtsi2ss %esi, %xmm3
xorps %xmm2, %xmm2
cvtsi2ss %edx, %xmm2
jle 0x11e7b
mulss %xmm2, %xmm3
addss %xmm3, %xmm1
addss %xmm2, %xmm4
addq $0x40, %rax
decl %ecx
jne 0x11e38
xorps %xmm2, %xmm2
cvtsd2ss %xmm0, %xmm2
movaps %xmm1, %xmm0
addss 0x145cb(%rip), %xmm0    # 0x26464
xorps %xmm3, %xmm3
cmpltss %xmm1, %xmm3
andps %xmm3, %xmm0
andnps %xmm1, %xmm3
orps %xmm0, %xmm3
movss %xmm2, 0x94(%rsp)
divss %xmm4, %xmm2
movss %xmm2, 0x98(%rsp)
movaps %xmm3, 0x100(%rsp)
movaps %xmm4, 0xf0(%rsp)
divss %xmm4, %xmm3
movaps %xmm3, 0x110(%rsp)
movq (%r15), %rbp
movl 0x18(%rbp,%r13), %eax
movl %eax, 0xa0(%rsp)
movl 0x1c(%rbp,%r13), %eax
movl %eax, 0x9c(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x11370
movq %rax, 0xe0(%rsp)
movswl 0x20(%rbp,%r13), %eax
movq %rax, 0xd8(%rsp)
movswl 0x22(%rbp,%r13), %ebp
movq 0x88(%rsp), %r10
movq 0x78(%rsp), %r11
subq %r10, %r11
xorps %xmm0, %xmm0
cvtss2sd 0x98(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x110(%rsp), %xmm1
movaps %xmm0, %xmm3
movsd 0x144f7(%rip), %xmm2    # 0x26448
mulsd %xmm2, %xmm3
divsd %xmm1, %xmm3
subsd %xmm3, %xmm2
subq $0x8, %rsp
movl $0x4, %edi
leaq 0x14642(%rip), %rsi     # 0x265af
movl %r12d, %edx
movl %r14d, %ecx
movl 0xa8(%rsp), %r8d
movl 0xa4(%rsp), %r9d
movb $0x3, %al
pushq 0x78(%rsp)
pushq %r10
pushq %r11
pushq 0xa0(%rsp)
pushq %rbp
pushq 0x108(%rsp)
pushq 0x118(%rsp)
callq 0x1d0d6
addq $0x40, %rsp
movq 0x18(%rsp), %rbp
movss 0x94(%rsp), %xmm0
ucomiss 0x100(%rsp), %xmm0
jb 0x120e9
movq 0x88(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbp, %rdx
movl (%rsp), %ecx
movl %r12d, %r8d
movl %r14d, %r9d
leaq 0x10(%rsp), %rax
pushq %rax
pushq %r15
callq 0x12347
addq $0x10, %rsp
testb %al, %al
je 0x12120
movq 0x58(%rsp), %rax
movq %rax, 0xa8(%rsp)
cltq
movq 0x10(%rsp), %rbx
subq %rbx, %rax
movq %rax, (%rsp)
movq %rax, %xmm0
punpckldq 0x14394(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1439c(%rip), %xmm0    # 0x263d0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x143f8(%rip), %xmm1    # 0x26440
xorps %xmm0, %xmm0
cvtss2sd 0xf0(%rsp), %xmm0
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x70(%rsp)
movq (%r15), %rbp
movl 0x18(%rbp,%r13), %eax
movl %eax, 0x80(%rsp)
movl 0x1c(%rbp,%r13), %eax
movl %eax, 0x78(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x11370
movq %rax, %r10
movswl 0x20(%rbp,%r13), %r11d
movswl 0x22(%rbp,%r13), %r13d
movq 0x18(%rsp), %rbp
subq 0x88(%rsp), %rbx
xorps %xmm0, %xmm0
cvtss2sd 0x70(%rsp), %xmm0
subq $0x8, %rsp
movl $0x4, %edi
leaq 0x14571(%rip), %rsi     # 0x2662e
movl %r12d, %edx
movl %r14d, %ecx
movl 0x88(%rsp), %r8d
movl 0x80(%rsp), %r9d
movb $0x1, %al
pushq %rbx
pushq 0x10(%rsp)
pushq %r13
pushq %r11
pushq %r10
callq 0x1d0d6
addq $0x30, %rsp
xorl %eax, %eax
movq 0xe8(%rsp), %rdx
movq 0xa8(%rsp), %rsi
movl 0x90(%r15,%rax,4), %ecx
cmpl %edx, %ecx
jl 0x12113
cmpl %r14d, %ecx
jg 0x12113
movl %esi, 0xc0(%rsp,%rax,4)
incq %rax
cmpq $0x5, %rax
jne 0x120fb
xorl %ebx, %ebx
jmp 0x12123
movl %r12d, %r14d
movl %r14d, %r12d
movl 0xc(%rsp), %r14d
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x12142
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
cmpl $0xf, %ebx
je 0x12158
testl %ebx, %ebx
movq 0xb0(%rsp), %rcx
je 0x12160
jmp 0x12250
movq 0xb0(%rsp), %rcx
incl %r12d
cmpl %ecx, %r12d
setge %r14b
jl 0x11bd4
movl %r14d, 0xc(%rsp)
leaq 0x14204(%rip), %rbx     # 0x26380
leaq 0x1450b(%rip), %r14     # 0x2668e
xorl %r13d, %r13d
xorl %ebp, %ebp
movl (%r13,%rbx), %edx
movl 0x90(%r15,%r13), %ecx
movl 0xc0(%rsp,%r13), %r12d
movl $0x3, %edi
movq %r14, %rsi
movl %r12d, %r8d
xorl %eax, %eax
callq 0x1d0d6
testl %r12d, %r12d
jns 0x121c0
movl 0x58(%rsp), %eax
movl %eax, 0xc0(%rsp,%r13)
movl 0xc0(%rsp,%r13), %r12d
movl %r12d, %eax
subl %ebp, %eax
movslq %eax, %rsi
movq 0xb8(%rsp), %rdi
movl $0x1, %edx
callq 0x122c2
addq $0x4, %r13
movl %r12d, %ebp
cmpq $0x14, %r13
jne 0x12188
movq 0x18(%rsp), %rdi
cmpb $0x0, 0x24(%rdi)
je 0x12203
addq $0x40, %rdi
callq 0x13bb0
movq $0x0, 0x58(%rsp)
movq 0xb8(%rsp), %rbx
movl 0xc(%rsp), %r14d
movq 0x58(%rsp), %rax
cmpq 0x50(%rsp), %rax
jae 0x12239
movq 0x40(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x58(%rsp)
movzbl (%rcx,%rax), %edi
jmp 0x1223d
movl 0x60(%rsp), %edi
cmpl 0x60(%rsp), %edi
je 0x12250
movq (%rbx), %rsi
callq 0x33a0
jmp 0x12219
movb $0x1, %r14b
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x1225f
callq 0x33b0
andb $0x1, %r14b
movl %r14d, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x12284
jmp 0x122a8
jmp 0x122a8
jmp 0x12284
jmp 0x12284
jmp 0x12284
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x122ab
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0x122ab
jmp 0x122a8
jmp 0x122a8
jmp 0x122a8
jmp 0x122a8
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x122ba
callq 0x33b0
movq %rbx, %rdi
callq 0x35a0