// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/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 0x27b0e
movq %rax, %r14
pushq $-0x1
popq %rax
testq %r14, %r14
je 0x16050
leaq 0xc(%rsp), %r13
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x1605f
movl %eax, %r15d
movl (%r13), %r13d
testq %r13, %r13
je 0x15efe
testl %r13d, %r13d
js 0x1603c
movl %r15d, %eax
addq %r12, %rax
subq %rax, %rbp
cmpq %r13, %rbp
jl 0x1603c
movq %rax, %rbp
movl $0x400, %r15d           # imm = 0x400
movq 0x28(%r14), %rax
movq 0x30(%r14), %rdi
leaq (%rdi,%r13), %rcx
cmpq %rcx, %rax
ja 0x15f17
movq %rax, %xmm0
punpckldq 0x2dae7(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2daef(%rip), %xmm0    # 0x439a0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x2eb1b(%rip), %xmm1    # 0x449e0
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x2da43(%rip), %xmm1    # 0x43918
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 0x48c0
movq %rax, 0x20(%r14)
jmp 0x15e8b
andl $0x0, 0x58(%rbx)
andq $0x0, 0x60(%rbx)
movq %r14, %rdi
callq 0x28127
movl %r15d, %eax
jmp 0x16050
addq 0x20(%r14), %rdi
movq %rbp, %r15
movq %rbp, %rsi
movq %r13, %rdx
callq 0x4420
movq 0x30(%r14), %rbp
addq %r13, %rbp
movq %rbp, 0x30(%r14)
addl %r13d, %r15d
movq 0x20(%r14), %r13
cmpb $0x0, -0x1(%r13,%rbp)
je 0x15fde
movq %r15, 0x10(%rsp)
movl $0x400, %r15d           # imm = 0x400
movq 0x28(%r14), %rax
leaq 0x1(%rbp), %rcx
cmpq %rcx, %rax
ja 0x15fc7
movq %rax, %xmm0
punpckldq 0x2da24(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2da2c(%rip), %xmm0    # 0x439a0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x2ea58(%rip), %xmm1    # 0x449e0
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
subsd 0x2d97c(%rip), %xmm1    # 0x43918
cvttsd2si %xmm1, %rsi
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %r15, %rsi
movq %rsi, 0x28(%r14)
movq %r13, %rdi
callq 0x48c0
movq %rax, %r13
movq %rax, 0x20(%r14)
movq 0x30(%r14), %rbp
jmp 0x15f52
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 0x15ffd
cmpb $0x0, (%r13,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x15fed
incl %eax
jmp 0x15fe5
movl %eax, 0x58(%rbx)
movl %eax, %edi
pushq $0x8
popq %rsi
callq 0x4370
movq %rax, 0x60(%rbx)
testq %rax, %rax
je 0x1603c
xorl %eax, %eax
xorl %ecx, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rbp
jbe 0x16049
leaq (%rcx,%r13), %rdx
movq 0x60(%rbx), %rsi
movq %rdx, (%rsi,%rax,8)
cmpb $0x0, (%r13,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x1602b
incq %rax
jmp 0x16017
movq %r14, %rdi
callq 0x28127
pushq $-0x1
popq %rax
jmp 0x16050
movq %r14, 0x50(%rbx)
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq