// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, %r12
movq %rsi, (%rsp)
movl $0x0, 0xc(%rsp)
xorl %edi, %edi
xorl %esi, %esi
callq 0x4c675
movq %rax, %r15
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r15, %r15
je 0x37146
cmpq $0x0, 0x50(%r14)
jne 0x370b6
cmpq $0x0, 0x60(%r14)
je 0x370ec
leaq 0x620a3(%rip), %rsi     # 0x99160
leaq 0x620ab(%rip), %rdx     # 0x9916f
xorl %ebp, %ebp
movl $0x3, %edi
xorl %eax, %eax
callq 0x13de5
movq 0x50(%r14), %rdi
callq 0x4ceb6
movq 0x60(%r14), %rdi
callq 0x45c0
movq %rbp, 0x50(%r14)
movq %rbp, 0x60(%r14)
movq %rsp, %rdi
leaq 0xc(%rsp), %rdx
movq %rbx, %rsi
callq *0x89a8(%r12)
movq %rax, %rbp
testl %ebp, %ebp
je 0x37130
js 0x37121
cmpl $0x0, 0xc(%rsp)
jne 0x37121
movq (%rsp), %r12
subq %r12, %rbx
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
cmpq %rbp, %rbx
jge 0x37155
movq %r15, %rdi
callq 0x4ceb6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x37146
movl $0x0, 0x58(%r14)
movq %r15, %rdi
callq 0x4ceb6
movl (%rsp), %eax
subl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, 0x10(%rsp)
movq 0x28(%r15), %rax
movq 0x30(%r15), %r13
movq %r13, %rbx
addq %rbp, %rbx
cmpq %rbx, %rax
ja 0x371a5
leaq 0x320(%rax), %rcx
shrq $0x2, %rcx
addq %rcx, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %rbx, %rax
cmovaq %rax, %rbx
movq 0x20(%r15), %rdi
movq %rbx, %rsi
callq 0x4840
testq %rax, %rax
je 0x37121
movq %rbx, 0x28(%r15)
movq %rax, 0x20(%r15)
movq 0x30(%r15), %r13
testq %rbp, %rbp
je 0x371c7
addq 0x20(%r15), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x43c0
movq 0x30(%r15), %r13
addq %rbp, %r13
movq %r13, 0x30(%r15)
addq (%rsp), %rbp
movq %rbp, (%rsp)
movq 0x20(%r15), %rbx
cmpb $0x0, -0x1(%rbx,%r13)
je 0x3723b
leaq 0x1(%r13), %r12
movq 0x28(%r15), %rax
cmpq %r12, %rax
ja 0x3722a
leaq 0x320(%rax), %rcx
shrq $0x2, %rcx
addq %rcx, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %r12, %rax
cmovaq %rax, %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4840
testq %rax, %rax
je 0x37121
movq %rax, %rbx
movq %r12, 0x28(%r15)
movq %rax, 0x20(%r15)
movq 0x30(%r15), %r13
leaq 0x1(%r13), %r12
movq %r12, 0x30(%r15)
movb $0x0, (%rbx,%r13)
movq 0x20(%r15), %rbx
movq 0x30(%r15), %r13
testq %r13, %r13
je 0x372ad
xorl %eax, %eax
xorl %ecx, %ecx
movslq %eax, %rdx
addq %rbx, %rdx
incl %eax
cmpb $0x0, (%rdx)
leaq 0x1(%rdx), %rdx
jne 0x3724a
incl %ecx
movslq %eax, %rdx
cmpq %rdx, %r13
ja 0x37244
movl %ecx, %edi
movl $0x8, %esi
callq 0x4300
movq %rax, 0x60(%r14)
testq %rax, %rax
je 0x37121
xorl %r12d, %r12d
testq %r13, %r13
je 0x372c9
xorl %ecx, %ecx
xorl %eax, %eax
addq %rbx, %rcx
movq 0x60(%r14), %rdx
movq %rcx, (%rdx,%r12,8)
movslq %eax, %rcx
addq %rbx, %rcx
incl %eax
cmpb $0x0, (%rcx)
leaq 0x1(%rcx), %rcx
jne 0x37295
incq %r12
movslq %eax, %rcx
cmpq %rcx, %r13
ja 0x37284
jmp 0x372c9
xorl %r12d, %r12d
movl $0x8, %esi
xorl %edi, %edi
callq 0x4300
movq %rax, 0x60(%r14)
testq %rax, %rax
je 0x37121
subl 0x10(%rsp), %ebp
movq %r15, 0x50(%r14)
movl %r12d, 0x58(%r14)
movl %ebp, %eax
jmp 0x37146