// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x54(%rbp)
xorl %esi, %esi
movl %esi, %edi
callq 0x6ede0
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x4ed7d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4efe5
movq -0x28(%rbp), %rax
cmpq $0x0, 0x50(%rax)
jne 0x4ed93
movq -0x28(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x4eddf
movl $0x3, %edi
leaq 0xa491c(%rip), %rsi     # 0xf36bb
leaq 0xa4924(%rip), %rdx     # 0xf36ca
movb $0x0, %al
callq 0x1b030
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x6f940
movq -0x28(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x45a0
movq -0x28(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x10(%rbp), %rax
movq 0x89a8(%rax), %rax
movq -0x20(%rbp), %rsi
leaq -0x18(%rbp), %rdi
leaq -0x54(%rbp), %rdx
callq *%rax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x4ee28
movq -0x28(%rbp), %rax
movl $0x0, 0x58(%rax)
movq -0x40(%rbp), %rdi
callq 0x6f940
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x4(%rbp)
jmp 0x4efe5
cmpl $0x0, -0x54(%rbp)
jne 0x4ee48
cmpl $0x0, -0x44(%rbp)
jl 0x4ee48
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movslq -0x44(%rbp), %rcx
cmpq %rcx, %rax
jge 0x4ee5d
movq -0x40(%rbp), %rdi
callq 0x6f940
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4efe5
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x44(%rbp), %rdx
callq 0x4eff0
cmpl $0x0, %eax
jge 0x4ee78
jmp 0x4efd5
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x30(%rcx), %rcx
subq $0x1, %rcx
cmpb $0x0, (%rax,%rcx)
je 0x4eec8
movq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x4f070
cmpl $0x0, %eax
jge 0x4eec6
jmp 0x4efd5
jmp 0x4eec8
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x48(%rbp)
movslq -0x4c(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jae 0x4ef1f
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movslq -0x4c(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x4ef12
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x4eef9
jmp 0x4ef14
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x4eee2
movslq -0x48(%rbp), %rdi
movl $0x8, %esi
callq 0x42f0
movq -0x28(%rbp), %rcx
movq %rax, 0x60(%rcx)
cmpq $0x0, %rax
jne 0x4ef50
movq -0x40(%rbp), %rdi
callq 0x6f940
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4efe5
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x48(%rbp)
movslq -0x4c(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jae 0x4efb7
movq -0x38(%rbp), %rdx
movslq -0x4c(%rbp), %rax
addq %rax, %rdx
movq -0x28(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x48(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x48(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movslq -0x4c(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x4efaa
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x4ef91
jmp 0x4efac
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x4ef5e
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x50(%rax)
movl -0x48(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x58(%rax)
movl -0x50(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4efe5
movq -0x40(%rbp), %rdi
callq 0x6f940
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop