// File: karel-brinda[P]ococo/ext/htslib/cram/cram_decode.c
// Function: cram_decode_aux_1_0
static int cram_decode_aux_1_0(cram_container *c, cram_slice *s,
			       cram_block *blk, cram_record *cr) {
    int i, r = 0, out_sz = 1;
    unsigned char ntags;
	    
    if (!c->comp_hdr->codecs[DS_TC]) return -1;
    r |= c->comp_hdr->codecs[DS_TC]->decode(s, c->comp_hdr->codecs[DS_TC], blk,
					    (char *)&ntags, &out_sz);
    cr->ntags = ntags;

    //printf("TC=%d\n", cr->ntags);
    cr->aux_size = 0;
    cr->aux = BLOCK_SIZE(s->aux_blk);

    for (i = 0; i < cr->ntags; i++) {
	int32_t id, out_sz = 1;
	unsigned char tag_data[3];
	cram_map *m;

	//printf("Tag %d/%d\n", i+1, cr->ntags);
	if (!c->comp_hdr->codecs[DS_TN]) return -1;
	r |= c->comp_hdr->codecs[DS_TN]->decode(s, c->comp_hdr->codecs[DS_TN],
						blk, (char *)&id, &out_sz);
	if (out_sz == 3) {
	    tag_data[0] = ((char *)&id)[0];
	    tag_data[1] = ((char *)&id)[1];
	    tag_data[2] = ((char *)&id)[2];
	} else {
	    tag_data[0] = (id>>16) & 0xff;
	    tag_data[1] = (id>>8)  & 0xff;
	    tag_data[2] = id       & 0xff;
	} 

	m = map_find(c->comp_hdr->tag_encoding_map, tag_data, id);
	if (!m)
	    return -1;
	BLOCK_APPEND(s->aux_blk, (char *)tag_data, 3);

	if (!m->codec) return -1;
	r |= m->codec->decode(s, m->codec, blk, (char *)s->aux_blk, &out_sz);

	cr->aux_size += out_sz + 3;
    }
    
    return r;
}

// 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)
movl $0x0, -0x30(%rbp)
movl $0x1, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
cmpq $0x0, 0x3e0(%rax)
jne 0x29944
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x29c51
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x3e0(%rax), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq 0x40(%rcx), %rcx
movq 0x3e0(%rcx), %rsi
movq -0x20(%rbp), %rdx
leaq -0x35(%rbp), %rcx
leaq -0x34(%rbp), %r8
callq *%rax
orl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movzbl -0x35(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x30(%rax), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x3c(%rax)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jge 0x29c4b
movl $0x1, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
cmpq $0x0, 0x3b8(%rax)
jne 0x299e8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x29c51
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x3b8(%rax), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq 0x40(%rcx), %rcx
movq 0x3b8(%rcx), %rsi
movq -0x20(%rbp), %rdx
leaq -0x3c(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq *%rax
orl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
cmpl $0x3, -0x40(%rbp)
jne 0x29a3c
movb -0x3c(%rbp), %al
movb %al, -0x43(%rbp)
movb -0x3b(%rbp), %al
movb %al, -0x42(%rbp)
movb -0x3a(%rbp), %al
movb %al, -0x41(%rbp)
jmp 0x29a63
movl -0x3c(%rbp), %eax
sarl $0x10, %eax
andl $0xff, %eax
movb %al, -0x43(%rbp)
movl -0x3c(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, -0x42(%rbp)
movl -0x3c(%rbp), %eax
andl $0xff, %eax
movb %al, -0x41(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
addq $0x180, %rdi            # imm = 0x180
leaq -0x43(%rbp), %rsi
movl -0x3c(%rbp), %edx
callq 0x2f530
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x29a95
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x29c51
jmp 0x29a97
jmp 0x29a99
jmp 0x29a9b
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x88(%rcx), %rcx
movq 0x30(%rcx), %rcx
addq $0x3, %rcx
cmpq %rcx, %rax
ja 0x29ba0
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rax
cmpq $0x0, 0x28(%rax)
je 0x29b1d
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x28(%rax), %xmm0
movaps 0x50ff1(%rip), %xmm1    # 0x7aae0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x50ff5(%rip), %xmm1    # 0x7aaf0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x51fc6(%rip), %xmm1    # 0x7bad8
mulsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x29b2c
movsd 0x51fab(%rip), %xmm0    # 0x7bad0
movsd %xmm0, -0x58(%rbp)
jmp 0x29b2c
movsd -0x58(%rbp), %xmm0
movsd 0x50f87(%rip), %xmm2    # 0x7aac0
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rax
cvttsd2si %xmm0, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
andq %rdx, %rax
orq %rax, %rcx
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x28(%rax), %rsi
callq 0x4990
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq %rcx, 0x20(%rax)
jmp 0x29a9b
jmp 0x29ba2
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x88(%rcx), %rcx
movq 0x30(%rcx), %rcx
movw -0x43(%rbp), %dx
movw %dx, (%rax,%rcx)
movb -0x41(%rbp), %dl
movb %dl, 0x2(%rax,%rcx)
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x30(%rax), %rcx
addq $0x3, %rcx
movq %rcx, 0x30(%rax)
movq -0x50(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x29bfa
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x29c51
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rcx
movq 0x10(%rcx), %rsi
movq -0x20(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq 0x88(%rcx), %rcx
leaq -0x40(%rbp), %r8
callq *%rax
orl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x40(%rbp), %ecx
addl $0x3, %ecx
movq -0x28(%rbp), %rax
addl 0x40(%rax), %ecx
movl %ecx, 0x40(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x299b3
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)