// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/htslib/cram/cram_decode.c
// Function: cram_decode_TD
int cram_decode_TD(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;

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

    /* Decode */
    cp += safe_itf8_get(cp, endp, &blk_size);
    if (!blk_size) {
	h->nTL = 0;
	h->TL = NULL;
	cram_free_block(b);
	return cp - op;
    }

    if (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
    h->nTL = nTL;
    if (!(h->TL = calloc(h->nTL, sizeof(unsigned char *)))) {
        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;
    
    return sz;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r12
andl $0x0, 0xc(%rsp)
xorl %edi, %edi
xorl %esi, %esi
callq 0x4db76
movq %rax, %r14
pushq $-0x1
popq %rax
testq %r14, %r14
je 0x66740
leaq 0xc(%rsp), %r13
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x6674f
movl %eax, %r15d
movl (%r13), %r13d
testq %r13, %r13
je 0x665ee
testl %r13d, %r13d
js 0x6672c
movl %r15d, %eax
addq %r12, %rax
subq %rax, %rbp
cmpq %r13, %rbp
jl 0x6672c
movq %rax, %rbp
movl $0x400, %r15d           # imm = 0x400
movq 0x28(%r14), %rax
movq 0x30(%r14), %rdi
leaq (%rdi,%r13), %rcx
cmpq %rcx, %rax
ja 0x66607
movq %rax, %xmm0
punpckldq 0x14a77(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x14a7f(%rip), %xmm0    # 0x7b020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x19233(%rip), %xmm1    # 0x7f7e8
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x20b0b(%rip), %xmm1    # 0x870d0
cvttsd2si %xmm1, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %r15, %rsi
movq %rsi, 0x28(%r14)
movq 0x20(%r14), %rdi
callq 0x6c80
movq %rax, 0x20(%r14)
jmp 0x6657b
andl $0x0, 0x58(%rbx)
andq $0x0, 0x60(%rbx)
movq %r14, %rdi
callq 0x4e18f
movl %r15d, %eax
jmp 0x66740
addq 0x20(%r14), %rdi
movq %rbp, %r15
movq %rbp, %rsi
movq %r13, %rdx
callq 0x6570
movq 0x30(%r14), %rbp
addq %r13, %rbp
movq %rbp, 0x30(%r14)
addl %r13d, %r15d
movq 0x20(%r14), %r13
cmpb $0x0, -0x1(%r13,%rbp)
je 0x666ce
movq %r15, 0x10(%rsp)
movl $0x400, %r15d           # imm = 0x400
movq 0x28(%r14), %rax
leaq 0x1(%rbp), %rcx
cmpq %rcx, %rax
ja 0x666b7
movq %rax, %xmm0
punpckldq 0x149b4(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x149bc(%rip), %xmm0    # 0x7b020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x19170(%rip), %xmm1    # 0x7f7e8
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
subsd 0x20a44(%rip), %xmm1    # 0x870d0
cvttsd2si %xmm1, %rsi
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %r15, %rsi
movq %rsi, 0x28(%r14)
movq %r13, %rdi
callq 0x6c80
movq %rax, %r13
movq %rax, 0x20(%r14)
movq 0x30(%r14), %rbp
jmp 0x66642
movq %rcx, 0x30(%r14)
movb $0x0, (%r13,%rbp)
movq 0x20(%r14), %r13
movq 0x30(%r14), %rbp
movq 0x10(%rsp), %r15
subl %r12d, %r15d
xorl %eax, %eax
xorl %ecx, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rbp
jbe 0x666ed
cmpb $0x0, (%r13,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x666dd
incl %eax
jmp 0x666d5
movl %eax, 0x58(%rbx)
movl %eax, %edi
pushq $0x8
popq %rsi
callq 0x6470
movq %rax, 0x60(%rbx)
testq %rax, %rax
je 0x6672c
xorl %eax, %eax
xorl %ecx, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rbp
jbe 0x66739
leaq (%rcx,%r13), %rdx
movq 0x60(%rbx), %rsi
movq %rdx, (%rsi,%rax,8)
cmpb $0x0, (%r13,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x6671b
incq %rax
jmp 0x66707
movq %r14, %rdi
callq 0x4e18f
pushq $-0x1
popq %rax
jmp 0x66740
movq %r14, 0x50(%rbx)
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq