// File: Infinidat[P]slimfastq/recs.cpp
// Function: RecLoad::load_pre5(unsigned char*, unsigned char const*)
size_t RecLoad::load_pre5(UCHAR* buf, const UCHAR* prev) {

    UINT64 map = get_num(0);

    UCHAR* b = buf;
    for (int i = 0; i < smap[0].len; i++) {
        // if (IS_SET(last_map, i)) {
         if (IS_SET(map, i)) {

             UCHAR type = get_type(i+1);
             switch (type) {

             case ST_DGT:
             case ST_DLT: {
                      // compatibility - let it open old fi
                 long long pval;
                 bool expect_num = is_number(prev + smap[0].off[i], smap[0].wln[i], pval);
                 assert(expect_num);
                 long long gap = get_num(i+1);
                 long long val = type == ST_DGT ? pval + gap : pval - gap ;
                 // if (UINT64(val) > 0xffffffff00000000) {
                 //     fprintf(stderr, "big val: 0x%llx gap=0x%llx %s pval=0x%llx\n",
                 //             val, gap, (type == ST_DGT ? "GAP" : "PAG"), pval);
                 //     // debug point
                 // }

                 b += sprintf((char*)b, "%lld", val);
             } break;

             case ST_STR: {
                 b = get_str(i+1, b);
             } break;

             default:
                 croak("REC: bad type value %d", type);
             }
         }
         else {
            // b = (UCHAR*)mempcpy(b, prev + smap[0].off[i], smap[0].wln[i]);
            // mempcpy is not compatible with Mac OS, must do it the hard way ..
            UINT32 count = smap[0].wln[i] ;
            memcpy(b, prev + smap[0].off[i], count );
            b += count;
        }
        *b ++ = smap[0].str[i];
    }
    return b-buf-1;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq 0x70(%rsp), %rdi
movq %rdi, 0x18(%rsp)
xorl %esi, %esi
callq 0xaac0
movq %rax, 0x58(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
movq 0x18(%rsp), %rcx
movl 0x4c(%rsp), %eax
movzbl 0xc7f79(%rcx), %ecx
cmpl %ecx, %eax
jge 0xc331
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq 0x10(%rsp), %rcx
andq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
je 0xc2b0
movq 0x18(%rsp), %rdi
movl 0x4c(%rsp), %eax
incl %eax
movzbl %al, %esi
callq 0xaa80
movb %al, 0x4b(%rsp)
movzbl 0x4b(%rsp), %eax
movl %eax, 0xc(%rsp)
subl $0x2, %eax
jb 0xc1a7
jmp 0xc195
movl 0xc(%rsp), %eax
subl $0x2, %eax
je 0xc27b
jmp 0xc29b
movq 0x18(%rsp), %rax
movq 0x60(%rsp), %rdi
movslq 0x4c(%rsp), %rcx
movslq 0xc7d30(%rax,%rcx,4), %rcx
addq %rcx, %rdi
movslq 0x4c(%rsp), %rcx
movl 0xc7e34(%rax,%rcx,4), %esi
leaq 0x40(%rsp), %rdx
callq 0xc350
andb $0x1, %al
movb %al, 0x3f(%rsp)
testb $0x1, 0x3f(%rsp)
je 0xc1e6
jmp 0xc205
leaq 0x4f3c(%rip), %rdi      # 0x11129
leaq 0x4e78(%rip), %rsi      # 0x1106c
movl $0x1e0, %edx            # imm = 0x1E0
leaq 0x4f34(%rip), %rcx      # 0x11134
callq 0x21b0
movq 0x18(%rsp), %rdi
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movzbl %al, %esi
callq 0xaac0
movq %rax, 0x30(%rsp)
movzbl 0x4b(%rsp), %eax
cmpl $0x0, %eax
jne 0xc238
movq 0x40(%rsp), %rax
addq 0x30(%rsp), %rax
movq %rax, (%rsp)
jmp 0xc246
movq 0x40(%rsp), %rax
subq 0x30(%rsp), %rax
movq %rax, (%rsp)
movq (%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rdi
movq 0x28(%rsp), %rdx
leaq 0x4991(%rip), %rsi      # 0x10bf1
movb $0x0, %al
callq 0x20b0
movl %eax, %ecx
movq 0x50(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0xc2ae
movq 0x18(%rsp), %rdi
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movq 0x50(%rsp), %rdx
movzbl %al, %esi
callq 0xab00
movq %rax, 0x50(%rsp)
jmp 0xc2ae
movzbl 0x4b(%rsp), %esi
leaq 0x4e6b(%rip), %rdi      # 0x11112
movb $0x0, %al
callq 0x3450
jmp 0xc2fd
movq 0x18(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movl 0xc7e34(%rax,%rcx,4), %ecx
movl %ecx, 0x24(%rsp)
movq 0x50(%rsp), %rdi
movq 0x60(%rsp), %rsi
movslq 0x4c(%rsp), %rcx
movslq 0xc7d30(%rax,%rcx,4), %rax
addq %rax, %rsi
movl 0x24(%rsp), %eax
movl %eax, %edx
callq 0x2220
movl 0x24(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
movq 0x18(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movb 0xc7f38(%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x50(%rsp)
movb %cl, (%rax)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0xc12b
movq 0x50(%rsp), %rax
movq 0x68(%rsp), %rcx
subq %rcx, %rax
subq $0x1, %rax
addq $0x78, %rsp
retq
nopw (%rax,%rax)