// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %rax
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r15
xorl %edi, %edi
xorl %esi, %esi
callq 0x325ef
movq %rax, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x1c9be
movq %rbp, %rcx
subq %r15, %rcx
cmpq $0x4, %rcx
jg 0x1c746
xorl %eax, %eax
cmpq %rbp, %r15
jae 0x1c771
movzbl (%r15), %edx
shrl $0x4, %edx
leaq 0x37fc9(%rip), %rsi     # 0x54700
movslq (%rsi,%rdx,4), %rdx
movl $0x0, %r12d
cmpq %rdx, %rcx
jl 0x1c774
movzbl (%r15), %eax
movl $0x1, %r12d
testb %al, %al
jns 0x1c774
movzbl 0x1(%r15), %ecx
cmpb $-0x41, %al
ja 0x1c92e
andl $0x3f, %eax
shll $0x8, %eax
orl %ecx, %eax
movl $0x2, %r12d
jmp 0x1c774
xorl %r12d, %r12d
testl %eax, %eax
je 0x1c90f
js 0x1c9b1
movl %r12d, %ecx
addq %r15, %rcx
subq %rcx, %rbp
movl %eax, %r13d
cmpq %r13, %rbp
jl 0x1c9b1
movq %rcx, (%rsp)
movq 0x28(%r14), %rax
movq 0x30(%r14), %rdi
leaq (%rdi,%r13), %rcx
cmpq %rcx, %rax
ja 0x1c823
movl $0x400, %r12d           # imm = 0x400
movq %rax, %xmm0
punpckldq 0x36171(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x36179(%rip), %xmm0    # 0x52940
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x3722d(%rip), %xmm1    # 0x53a08
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x3611d(%rip), %xmm1    # 0x52908
cvttsd2si %xmm1, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %r12, %rsi
movq %rsi, 0x28(%r14)
movq 0x20(%r14), %rdi
callq 0x48d0
movq %rax, 0x20(%r14)
movq 0x28(%r14), %rax
movq 0x30(%r14), %rdi
leaq (%rdi,%r13), %rcx
cmpq %rcx, %rax
jbe 0x1c7b2
addq 0x20(%r14), %rdi
movq (%rsp), %rsi
movq %r13, %rdx
callq 0x4420
movq 0x30(%r14), %rax
addq %r13, %rax
movq %rax, 0x30(%r14)
movq 0x20(%r14), %rcx
cmpb $0x0, -0x1(%rcx,%rax)
je 0x1c8e1
movq 0x28(%r14), %rax
movq 0x30(%r14), %rcx
leaq 0x1(%rcx), %rdx
cmpq %rdx, %rax
ja 0x1c8d5
movl $0x400, %r12d           # imm = 0x400
movq %rax, %xmm0
punpckldq 0x360bf(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x360c7(%rip), %xmm0    # 0x52940
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x3717b(%rip), %xmm1    # 0x53a08
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x3606b(%rip), %xmm1    # 0x52908
cvttsd2si %xmm1, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %r12, %rsi
movq %rsi, 0x28(%r14)
movq 0x20(%r14), %rdi
callq 0x48d0
movq %rax, 0x20(%r14)
movq 0x28(%r14), %rax
movq 0x30(%r14), %rcx
leaq 0x1(%rcx), %rdx
cmpq %rdx, %rax
jbe 0x1c864
movq 0x20(%r14), %rax
movq %rdx, 0x30(%r14)
movb $0x0, (%rax,%rcx)
movq 0x20(%r14), %rbp
movq 0x30(%r14), %r12
testq %r12, %r12
je 0x1c953
xorl %ecx, %ecx
xorl %eax, %eax
movslq %ecx, %rdx
addq %rbp, %rdx
incl %ecx
cmpb $0x0, (%rdx)
leaq 0x1(%rdx), %rdx
jne 0x1c8f8
incl %eax
movslq %ecx, %rdx
cmpq %rdx, %r12
ja 0x1c8f2
jmp 0x1c955
movl $0x0, 0x58(%rbx)
movq $0x0, 0x60(%rbx)
movq %r14, %rdi
callq 0x32ea8
movl %r12d, %eax
jmp 0x1c9be
cmpb $-0x21, %al
ja 0x1c9cd
shll $0x8, %ecx
movzbl 0x2(%r15), %edx
andl $0x1f, %eax
shll $0x10, %eax
orl %ecx, %eax
orl %edx, %eax
movl $0x3, %r12d
jmp 0x1c774
xorl %eax, %eax
movl %eax, 0x58(%rbx)
movl %eax, %edi
movl $0x8, %esi
callq 0x4360
movq %rax, 0x60(%rbx)
testq %rax, %rax
je 0x1c9b1
movq (%rsp), %rdi
addl %r13d, %edi
testq %r12, %r12
je 0x1c9a6
xorl %eax, %eax
xorl %edx, %edx
xorl %ecx, %ecx
addq %rbp, %rdx
movq 0x60(%rbx), %rsi
movq %rdx, (%rsi,%rax,8)
movslq %ecx, %rdx
addq %rbp, %rdx
incl %ecx
cmpb $0x0, (%rdx)
leaq 0x1(%rdx), %rdx
jne 0x1c990
incq %rax
movslq %ecx, %rdx
cmpq %rdx, %r12
ja 0x1c97f
subl %r15d, %edi
movq %r14, 0x50(%rbx)
movl %edi, %eax
jmp 0x1c9be
movq %r14, %rdi
callq 0x32ea8
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $-0x11, %al
ja 0x1c9f8
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, %r12d
jmp 0x1c774
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, %r12d
jmp 0x1c774