// File: /workspace/github_cpp_makefile_star2_O2/Infinidat[P]slimfastq/recs.cpp
// Function: RecSave::save(unsigned char const*, unsigned char const*, unsigned char const*, unsigned char const*)
void RecSave::save(const UCHAR* buf, const UCHAR* end, const UCHAR* prev_buf, const UCHAR* prev_end) {

    rarely_if(not m_last.initilized) {
        imap = 0;
        save_first_line(buf, end);
        map_space(buf, imap);
        bzero(ctype[0], sizeof(ctype[0])); // clear cache
        bzero(ctype[1], sizeof(ctype[1])); // clear cache
        return;
    }
    bool pmap = imap;
    imap = imap ? 0 : 1;
    map_space(buf, imap);

    rarely_if (smap[imap].len != smap[pmap].len or
               memcmp(smap[imap].str, smap[pmap].str, smap[imap].len)) {
        // Too bad, new kind of header
        // must push to extension file

        x_file->put(g_record_count - m_last.index);
        m_last.index = g_record_count;
        x_file->put_str(buf, end-buf);
        bzero(ctype[imap], sizeof(ctype[imap])); // clear cache

        stats.new_n ++ ;
        stats.new_l += end-buf;
        return;
    }

    UINT64 map = 0;
    for (int i = 0; i < smap[imap].len; i ++)
        if ( smap[imap].wln[i] != smap[pmap].wln[i] or
             memcmp(buf + smap[imap].off[i], prev_buf + smap[pmap].off[i], smap[imap].wln[i]))
            DO_SET(map, i);

    put_num (0, map);           // mapping of changes. (zero could have meant copy prev)

    for (int i = 0; i < smap[0].len; i++) {
        if (IS_SET(map, i)) {

            // int i = BFIRST(map)-1;
            // DO_CLR(map, i);
            const UCHAR* b = buf + smap[imap].off[i];
            // const UCHAR* p = prev_buf + smap[pmap].off[i];
            UINT64 bnum;

            UCHAR type = numberwang(b, smap[imap].wln[i], bnum, ctype[pmap][i]);
            if  ( type == ST_STR) {
                put_type(i+1, type);
                put_str (i+1, b, smap[imap].wln[i]);
                stats.str_n ++ ;
                stats.str_l += smap[imap].wln[i];
                ctype[imap][i] = 0; // NAN
                continue;
            }
            // HERE: this is a number
            UINT64 pnum = ctype[pmap][i] ? cnumb[pmap][i] : 0;
            UINT64 gap ;

            ctype[imap][i] = (type < ST_STR or type >= ST_DGT_Z) ? 1 : 2;
            cnumb[imap][i] = bnum;

            if (bnum < pnum) {
                gap  = pnum - bnum;
                type ++ ;
            }
            else
                gap  = bnum - pnum;

            put_type(i+1, type);
            put_num (i+1, gap);

            //     if (is_number(b, smap[imap].wln[i], bnum) and
            //         is_number(p, smap[pmap].wln[i], pnum)) {
            //         if (bnum > pnum) {
            //             put_type(i+1, ST_DGT);
            //             put_num (i+1, bnum - pnum);
            //         }
            //         else {
            //             put_type(i+1, ST_DLT);
            //             put_num (i+1, pnum - bnum);
            //         }
            //     }
            //     else {
            //         put_type(i+1, ST_STR);
            //         put_str (i+1, b, smap[imap].wln[i]);
            //         stats.str_n ++ ;
            //         stats.str_l += smap[imap].wln[i];
            //     }
        }
        else {
            ctype[imap][i] = ctype[pmap][i];
            cnumb[imap][i] = cnumb[pmap][i];
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x10(%rsp)
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
cmpb $0x0, 0xc7d08(%rdi)
je 0x6615
movzbl 0xc8660(%rbx), %r12d
movl %r12d, %eax
xorb $0x1, %al
movb %al, 0xc8660(%rbx)
movzbl %al, %edx
movq %rbx, %rdi
movq %r14, 0x18(%rsp)
movq %r14, %rsi
callq 0x60a2
movzbl 0xc8660(%rbx), %eax
imulq $0x24c, %rax, %rax      # imm = 0x24C
movzbl 0xc7f79(%rbx,%rax), %r13d
imulq $0x24c, %r12, %rcx      # imm = 0x24C
cmpb 0xc7f79(%rbx,%rcx), %r13b
jne 0x656d
leaq (%rbx,%rax), %rbp
addq $0xc7d30, %rbp          # imm = 0xC7D30
leaq (%rbx,%rcx), %r14
addq $0xc7d30, %r14          # imm = 0xC7D30
movl $0x208, %esi            # imm = 0x208
leaq (%rsi,%rbp), %rdi
addq %r14, %rsi
movq %r13, %rdx
callq 0x2200
testl %eax, %eax
jne 0x656d
movq %r12, 0x8(%rsp)
leaq 0xc7d30(%rbx), %rax
movq %rax, 0x28(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
cmpq %r12, %r13
je 0x6256
movslq 0x104(%rbp,%r12,4), %rdx
cmpl 0x104(%r14,%r12,4), %edx
jne 0x624d
movslq (%rbp,%r12,4), %rdi
addq 0x18(%rsp), %rdi
movslq (%r14,%r12,4), %rsi
addq 0x10(%rsp), %rsi
callq 0x2200
testl %eax, %eax
je 0x6251
btsq %r12, %r15
incq %r12
jmp 0x621a
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x5e3e
leaq 0xc81c8(%rbx), %r14
leaq 0xc8250(%rbx), %rax
movq 0x8(%rsp), %rdx
imulq $0x41, %rdx, %rcx
addq %r14, %rcx
movq %rcx, 0x10(%rsp)
imulq $0x208, %rdx, %rcx      # imm = 0x208
movq %rax, 0x8(%rsp)
addq %rax, %rcx
movq %rcx, 0x20(%rsp)
movq %r15, 0x30(%rsp)
movzbl 0xc7f79(%rbx), %eax
cmpq %rax, %rbp
jae 0x6606
btq %rbp, %r15
jae 0x632e
movzbl 0xc8660(%rbx), %eax
imulq $0x24c, %rax, %rcx      # imm = 0x24C
addq 0x28(%rsp), %rcx
movslq (%rcx,%rbp,4), %rdx
movq 0x18(%rsp), %rsi
leaq (%rsi,%rdx), %r12
movslq 0x104(%rcx,%rbp,4), %rdi
movq 0x10(%rsp), %rcx
movb (%rbp,%rcx), %cl
movb (%rsi,%rdx), %sil
xorl %r9d, %r9d
cmpb $0x30, %sil
je 0x6558
movl %r9d, %r8d
xorl %edx, %edx
cmpb $0x2, %cl
je 0x636e
cmpq %rdi, %r8
jge 0x6373
movzbl (%r12,%r8), %r10d
leal -0x30(%r10), %r11d
cmpl $0x9, %r11d
ja 0x6387
imulq $0xa, %rdx, %r11
addq %r11, %r10
addq $-0x30, %r10
incq %r8
cmpq %rdx, %r10
movq %r10, %rdx
jae 0x62fa
jmp 0x63b7
movq 0x10(%rsp), %rax
movb (%rbp,%rax), %al
movzbl 0xc8660(%rbx), %ecx
imulq $0x41, %rcx, %rcx
addq %r14, %rcx
movb %al, (%rbp,%rcx)
movq 0x20(%rsp), %rax
movq (%rax,%rbp,8), %rax
movzbl 0xc8660(%rbx), %ecx
imulq $0x208, %rcx, %rcx      # imm = 0x208
addq 0x8(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
jmp 0x6550
xorl %r8d, %r8d
jmp 0x63ae
cmpb $0x30, %sil
movl $0x0, %esi
pushq $0xb
popq %rdi
cmovel %edi, %esi
jmp 0x64d2
movl %r10d, %edx
orl $0x20, %edx
addl $-0x67, %edx
cmpl $-0x6, %edx
jb 0x63b7
xorl %r9d, %r9d
cmpb $0x30, %sil
sete %r9b
cmpb $0x61, %r10b
movl $0x0, %r8d
adcb $0x1, %r8b
cmpl $0x10, %edi
jle 0x644d
leal 0x1(%rbp), %eax
movzbl %al, %r13d
movq %rbx, %rdi
movl %r13d, %esi
pushq $0x2
popq %rdx
callq 0x5e6e
movzbl 0xc8660(%rbx), %eax
imulq $0x24c, %rax, %rax      # imm = 0x24C
movq %r14, %r15
movq 0x28(%rsp), %r14
addq %r14, %rax
movl 0x104(%rax,%rbp,4), %ecx
movq %rbx, %rdi
movl %r13d, %esi
movq %r12, %rdx
callq 0x5dd4
movzbl 0xc8660(%rbx), %eax
imulq $0x24c, %rax, %rcx      # imm = 0x24C
addq %r14, %rcx
movq %r15, %r14
movq 0x30(%rsp), %r15
movq 0xc7d1c(%rbx), %xmm0
movd 0x104(%rcx,%rbp,4), %xmm1
movdqa 0x3af4(%rip), %xmm2     # 0x9f20
punpckldq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
paddd %xmm0, %xmm2
movq %xmm2, 0xc7d1c(%rbx)
imulq $0x41, %rax, %rax
addq %r14, %rax
movb $0x0, (%rbp,%rax)
jmp 0x6550
movl %r9d, %r9d
xorl %edx, %edx
cmpq %rdi, %r9
jge 0x64b4
movzbl (%r12,%r9), %r10d
leal -0x30(%r10), %r11d
cmpl $0xa, %r11d
jb 0x64a5
leal -0x61(%r10), %r11d
cmpb $0x5, %r11b
ja 0x6483
cmpb $0x2, %r8b
je 0x63b7
addl $-0x57, %r10d
movb $0x1, %r8b
jmp 0x64a2
leal -0x47(%r10), %r11d
cmpb $-0x6, %r11b
jb 0x63b7
cmpb $0x1, %r8b
je 0x63b7
addl $-0x37, %r10d
movb $0x2, %r8b
movl %r10d, %r11d
shlq $0x4, %rdx
movslq %r11d, %r10
addq %r10, %rdx
incq %r9
jmp 0x6452
cmpb $0x30, %sil
sete %dil
cmpb $0x2, %r8b
sete %sil
addb %dil, %dil
shlb $0x2, %sil
orb %dil, %sil
addb $0x3, %sil
testb %cl, %cl
je 0x64e1
movq 0x20(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
jmp 0x64e3
xorl %ecx, %ecx
movq %rdx, %rdi
subq %rcx, %rdi
movl %esi, %r8d
adcb $0x0, %r8b
negq %rdi
movq %rdx, %r12
subq %rcx, %r12
cmovbq %rdi, %r12
addb $-0xb, %sil
cmpb $-0x9, %sil
movb $0x2, %cl
sbbb $0x0, %cl
imulq $0x41, %rax, %rax
addq %r14, %rax
movb %cl, (%rbp,%rax)
movzbl 0xc8660(%rbx), %eax
imulq $0x208, %rax, %rax      # imm = 0x208
addq 0x8(%rsp), %rax
movq %rdx, (%rax,%rbp,8)
leal 0x1(%rbp), %eax
movzbl %r8b, %edx
movzbl %al, %r13d
movq %rbx, %rdi
movl %r13d, %esi
callq 0x5e6e
movq %rbx, %rdi
movl %r13d, %esi
movq %r12, %rdx
callq 0x5e3e
incq %rbp
jmp 0x629d
cmpb $0x30, 0x1(%r12)
pushq $0x1
popq %r9
jne 0x62f5
jmp 0x63b7
movq 0xc8670(%rbx), %rdi
leaq 0x8c55(%rip), %r14      # 0xf1d0
movq (%r14), %rsi
subq 0xc7d10(%rbx), %rsi
callq 0x85be
movq (%r14), %rax
movq %rax, 0xc7d10(%rbx)
movq 0xc8670(%rbx), %rdi
movq 0x18(%rsp), %rsi
subq %rsi, %r15
movq %r15, %rdx
callq 0x87ee
movzbl 0xc8660(%rbx), %eax
imulq $0x41, %rax, %rax
xorps %xmm0, %xmm0
movups %xmm0, 0xc81f8(%rbx,%rax)
movups %xmm0, 0xc81e8(%rbx,%rax)
movups %xmm0, 0xc81d8(%rbx,%rax)
movups %xmm0, 0xc81c8(%rbx,%rax)
movb $0x0, 0xc8208(%rbx,%rax)
movq 0xc7d24(%rbx), %xmm0
movd %r15d, %xmm1
movdqa 0x392a(%rip), %xmm2     # 0x9f20
punpckldq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
paddd %xmm0, %xmm2
movq %xmm2, 0xc7d24(%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, 0xc8660(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x5d92
movzbl 0xc8660(%rbx), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x60a2
addq $0xc81c8, %rbx          # imm = 0xC81C8
movl $0x82, %edx
movq %rbx, %rdi
xorl %esi, %esi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2130