// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/cram/cram_decode.c
// Function: cram_decode_TD
int cram_decode_TD(cram_fd *fd, char *cp, const char *endp,
                   cram_block_compression_hdr *h) {
    char *op = cp;
    unsigned char *dat;
    cram_block *b;
    int32_t blk_size = 0;
    int nTL, i, sz, err = 0;

    if (!(b = cram_new_block(0, 0)))
        return -1;

    if (h->TD_blk || h->TL) {
        hts_log_warning("More than one TD block found in compression header");
        cram_free_block(h->TD_blk);
        free(h->TL);
        h->TD_blk = NULL;
        h->TL = NULL;
    }

    /* Decode */
    blk_size = fd->vv.varint_get32(&cp, endp, &err);
    if (!blk_size) {
        h->nTL = 0;
        cram_free_block(b);
        return cp - op;
    }

    if (err || blk_size < 0 || endp - cp < blk_size) {
        cram_free_block(b);
        return -1;
    }

    BLOCK_APPEND(b, cp, blk_size);
    cp += blk_size;
    sz = cp - op;
    // Force nul termination if missing
    if (BLOCK_DATA(b)[BLOCK_SIZE(b)-1])
        BLOCK_APPEND_CHAR(b, '\0');

    /* Set up TL lookup table */
    dat = BLOCK_DATA(b);

    // Count
    for (nTL = i = 0; i < BLOCK_SIZE(b); i++) {
        nTL++;
        while (dat[i])
            i++;
    }

    // Copy
    if (!(h->TL = calloc(nTL, sizeof(*h->TL)))) {
        cram_free_block(b);
        return -1;
    }
    for (nTL = i = 0; i < BLOCK_SIZE(b); i++) {
        h->TL[nTL++] = &dat[i];
        while (dat[i])
            i++;
    }
    h->TD_blk = b;
    h->nTL = nTL;

    return sz;

 block_err:
    cram_free_block(b);
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %r15
movq %rsi, 0x8(%rsp)
andl $0x0, 0x14(%rsp)
xorl %edi, %edi
xorl %esi, %esi
callq 0x3f426
pushq $-0x1
popq %rbp
testq %rax, %rax
je 0x2cf15
movq %rax, %r14
cmpq $0x0, 0x50(%rbx)
jne 0x2ce26
cmpq $0x0, 0x60(%rbx)
je 0x2ce5a
leaq 0x4e2a3(%rip), %rsi     # 0x7b0d0
leaq 0x4e2ab(%rip), %rdx     # 0x7b0df
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x110c6
movq 0x50(%rbx), %rdi
callq 0x3f8fc
movq 0x60(%rbx), %rdi
callq 0x45c0
andq $0x0, 0x50(%rbx)
andq $0x0, 0x60(%rbx)
leaq 0x8(%rsp), %rdi
leaq 0x14(%rsp), %rdx
movq %r13, %rsi
callq *0x89a8(%r15)
movq %rax, %r15
testl %r15d, %r15d
je 0x2cf02
js 0x2cef8
cmpl $0x0, 0x14(%rsp)
jne 0x2cef8
movq 0x8(%rsp), %rsi
subq %rsi, %r13
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
cmpq %r15, %r13
jl 0x2cef8
movq %r14, %rdi
movq %r15, %rdx
callq 0x2cf7b
testl %eax, %eax
js 0x2cef8
addq 0x8(%rsp), %r15
movq %r15, 0x8(%rsp)
movq 0x20(%r14), %r13
movq 0x30(%r14), %rbp
cmpb $0x0, -0x1(%r13,%rbp)
je 0x2ced9
movq %r14, %rdi
xorl %esi, %esi
callq 0x2cfc7
testl %eax, %eax
pushq $-0x1
popq %rbp
js 0x2cef8
movq 0x20(%r14), %r13
movq 0x30(%r14), %rbp
subl %r12d, %r15d
xorl %eax, %eax
xorl %ecx, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rbp
jbe 0x2cf26
cmpb $0x0, (%r13,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x2cee8
incl %eax
jmp 0x2cee0
movq %r14, %rdi
callq 0x3f8fc
jmp 0x2cf15
andl $0x0, 0x58(%rbx)
movq %r14, %rdi
callq 0x3f8fc
movl 0x8(%rsp), %ebp
subl %r12d, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
pushq $0x8
popq %rsi
callq 0x4300
movq %rax, 0x60(%rbx)
testq %rax, %rax
je 0x2cf6e
xorl %eax, %eax
xorl %ecx, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rbp
jbe 0x2cf62
leaq (%rcx,%r13), %rdx
movq 0x60(%rbx), %rsi
movq %rdx, (%rsi,%rax,8)
cmpb $0x0, (%r13,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x2cf51
incq %rax
jmp 0x2cf3d
movq %r14, 0x50(%rbx)
movl %eax, 0x58(%rbx)
movl %r15d, %ebp
jmp 0x2cf15
movq %r14, %rdi
callq 0x3f8fc
pushq $-0x1
popq %rbp
jmp 0x2cf15