// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %rdi, %r15
xorl %edi, %edi
xorl %esi, %esi
callq 0x31a6d
movq %rax, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x1c777
movq %r12, %rax
subq %r15, %rax
cmpq $0x5, %rax
jge 0x1c4a6
xorl %ebp, %ebp
cmpq %r12, %r15
jae 0x1c6e8
movzbl (%r15), %edx
movl %edx, %ecx
shrl $0x4, %ecx
leaq 0x363c8(%rip), %rsi     # 0x52860
movslq (%rsi,%rcx,4), %rcx
cmpq %rcx, %rax
jge 0x1c4a9
jmp 0x1c6e8
movb (%r15), %dl
movzbl %dl, %eax
movl $0x1, %ebp
testb %al, %al
jns 0x1c543
movzbl 0x1(%r15), %ecx
cmpb $-0x41, %dl
ja 0x1c4d2
andl $0x3f, %eax
shll $0x8, %eax
orl %ecx, %eax
movl $0x2, %ebp
jmp 0x1c543
cmpb $-0x21, %dl
ja 0x1c4f0
shll $0x8, %ecx
movzbl 0x2(%r15), %edx
andl $0x1f, %eax
shll $0x10, %eax
orl %ecx, %eax
orl %edx, %eax
movl $0x3, %ebp
jmp 0x1c543
cmpb $-0x11, %dl
ja 0x1c518
shll $0x10, %ecx
movzbl 0x2(%r15), %edx
shll $0x8, %edx
movzbl 0x3(%r15), %esi
andl $0xf, %eax
shll $0x18, %eax
orl %ecx, %eax
orl %edx, %eax
orl %esi, %eax
movl $0x4, %ebp
jmp 0x1c543
shll $0x1c, %eax
shll $0x14, %ecx
orl %eax, %ecx
movzbl 0x2(%r15), %eax
shll $0xc, %eax
orl %ecx, %eax
movzbl 0x3(%r15), %ecx
shll $0x4, %ecx
orl %eax, %ecx
movzbl 0x4(%r15), %eax
andl $0xf, %eax
orl %ecx, %eax
movl $0x5, %ebp
testl %eax, %eax
je 0x1c6e8
js 0x1c76a
movl %ebp, %ebp
addq %r15, %rbp
subq %rbp, %r12
movl %eax, %r13d
cmpq %r13, %r12
jl 0x1c76a
movq 0x20(%r14), %rax
movq 0x28(%r14), %rcx
movq 0x30(%r14), %rdx
leaq (%rdx,%r13), %rsi
cmpq %rsi, %rcx
ja 0x1c5f0
movl $0x400, %r12d           # imm = 0x400
movq %rcx, %xmm0
punpckldq 0x343f3(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x343fb(%rip), %xmm0    # 0x50990
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x354b7(%rip), %xmm1    # 0x51a60
cvttsd2si %xmm1, %rdx
movq %rdx, %rdi
sarq $0x3f, %rdi
subsd 0x3434b(%rip), %xmm1    # 0x50908
cvttsd2si %xmm1, %rsi
andq %rdi, %rsi
orq %rdx, %rsi
testq %rcx, %rcx
cmoveq %r12, %rsi
movq %rsi, 0x28(%r14)
movq %rax, %rdi
callq 0x48d0
movq %rax, 0x20(%r14)
movq 0x28(%r14), %rcx
movq 0x30(%r14), %rdx
leaq (%rdx,%r13), %rsi
cmpq %rsi, %rcx
jbe 0x1c580
addq %rdx, %rax
movq %rax, %rdi
movq %rbp, 0x8(%rsp)
movq %rbp, %rsi
movq %r13, %rdx
callq 0x4420
movq 0x30(%r14), %rbp
addq %r13, %rbp
movq %rbp, 0x30(%r14)
movq 0x20(%r14), %r12
cmpb $0x0, -0x1(%r12,%rbp)
je 0x1c6c2
movq %r15, 0x10(%rsp)
movq 0x28(%r14), %rax
leaq 0x1(%rbp), %rcx
cmpq %rcx, %rax
ja 0x1c6ac
movl $0x400, %r15d           # imm = 0x400
movq %rax, %xmm0
punpckldq 0x3433a(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x34342(%rip), %xmm0    # 0x50990
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x353fe(%rip), %xmm1    # 0x51a60
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
subsd 0x34292(%rip), %xmm1    # 0x50908
cvttsd2si %xmm1, %rsi
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %r15, %rsi
movq %rsi, 0x28(%r14)
movq %r12, %rdi
callq 0x48d0
movq %rax, %r12
movq %rax, 0x20(%r14)
movq 0x28(%r14), %rax
movq 0x30(%r14), %rbp
leaq 0x1(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x1c639
movq %rcx, 0x30(%r14)
movb $0x0, (%r12,%rbp)
movq 0x20(%r14), %r12
movq 0x30(%r14), %rbp
movq 0x10(%rsp), %r15
testq %rbp, %rbp
je 0x1c703
xorl %ecx, %ecx
xorl %eax, %eax
movslq %ecx, %rdx
addq %r12, %rdx
incl %ecx
cmpb $0x0, (%rdx)
leaq 0x1(%rdx), %rdx
jne 0x1c6d1
incl %eax
movslq %ecx, %rdx
cmpq %rdx, %rbp
ja 0x1c6cb
jmp 0x1c705
movl $0x0, 0x58(%rbx)
movq $0x0, 0x60(%rbx)
movq %r14, %rdi
callq 0x321b4
movl %ebp, %eax
jmp 0x1c777
xorl %eax, %eax
movl %eax, 0x58(%rbx)
movl %eax, %edi
movl $0x8, %esi
callq 0x4360
movq %rax, 0x60(%rbx)
testq %rax, %rax
je 0x1c76a
movq 0x8(%rsp), %rax
addl %r13d, %eax
movq %rax, 0x8(%rsp)
testq %rbp, %rbp
je 0x1c75c
xorl %eax, %eax
xorl %edx, %edx
xorl %ecx, %ecx
addq %r12, %rdx
movq 0x60(%rbx), %rsi
movq %rdx, (%rsi,%rax,8)
movslq %ecx, %rdx
addq %r12, %rdx
incl %ecx
cmpb $0x0, (%rdx)
leaq 0x1(%rdx), %rdx
jne 0x1c746
incq %rax
movslq %ecx, %rdx
cmpq %rdx, %rbp
ja 0x1c735
movq 0x8(%rsp), %rax
subl %r15d, %eax
movq %r14, 0x50(%rbx)
jmp 0x1c777
movq %r14, %rdi
callq 0x321b4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq