// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/cram_encode.c
// Function: cram_allocate_block
static int cram_allocate_block(cram_codec *codec, cram_slice *s, int ds_id) {
    if (!codec)
        return 0;

    switch(codec->codec) {
    // Codecs which are hard-coded to use the CORE block
    case E_GOLOMB:
    case E_HUFFMAN:
    case E_BETA:
    case E_SUBEXP:
    case E_GOLOMB_RICE:
    case E_GAMMA:
        codec->out = s->block[0];
        break;

    // Codecs which don't use external blocks
    case E_CONST_BYTE:
    case E_CONST_INT:
       codec->out = NULL;
       break;

    // Codecs that emit directly to external blocks
    case E_EXTERNAL:
    case E_VARINT_UNSIGNED:
    case E_VARINT_SIGNED:
        if (!(s->block[ds_id] = cram_new_block(EXTERNAL, ds_id)))
            return -1;
        codec->u.external.content_id = ds_id;
        codec->out = s->block[ds_id];
        break;

    case E_BYTE_ARRAY_STOP: // Why no sub-codec?
        if (!(s->block[ds_id] = cram_new_block(EXTERNAL, ds_id)))
            return -1;
        codec->u.byte_array_stop.content_id = ds_id;
        codec->out = s->block[ds_id];
        break;


    // Codecs that contain sub-codecs which may in turn emit to external blocks
    case E_BYTE_ARRAY_LEN: {
        cram_codec *bal = codec->u.e_byte_array_len.len_codec;
        if (cram_allocate_block(bal, s, bal->u.external.content_id))
            return -1;
        bal = codec->u.e_byte_array_len.val_codec;
        if (cram_allocate_block(bal, s, bal->u.external.content_id))
            return -1;

        break;
    }

    case E_XRLE:
        if (cram_allocate_block(codec->u.e_xrle.len_codec, s, ds_id))
                                //ds_id == DS_QS ? DS_QS_len : ds_id))
            return -1;
        if (cram_allocate_block(codec->u.e_xrle.lit_codec, s, ds_id))
            return -1;

        break;

    case E_XPACK:
        if (cram_allocate_block(codec->u.e_xpack.sub_codec, s, ds_id))
            return -1;
        codec->out = cram_new_block(0, 0); // ephemeral
        if (!codec->out)
            return -1;

        break;

    case E_XDELTA:
        if (cram_allocate_block(codec->u.e_xdelta.sub_codec, s, ds_id))
            return -1;
        codec->out = cram_new_block(0, 0); // ephemeral
        if (!codec->out)
            return -1;

        break;

    default:
        break;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x64f66
movl $0x0, -0x4(%rbp)
jmp 0x651c3
movq -0x10(%rbp), %rax
movl (%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x34, %eax
ja 0x651ba
movq -0x30(%rbp), %rax
leaq 0x8ed00(%rip), %rcx     # 0xf3c88
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x651bc
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
jmp 0x651bc
movl -0x1c(%rbp), %esi
movl $0x4, %edi
callq 0x6ede0
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
cmpq $0x0, %rax
jne 0x64fe9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x651c3
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x60(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x651bc
movl -0x1c(%rbp), %esi
movl $0x4, %edi
callq 0x6ede0
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
cmpq $0x0, %rax
jne 0x6503f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x651c3
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x64(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x651bc
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rax
movl 0x60(%rax), %edx
callq 0x64f40
cmpl $0x0, %eax
je 0x65097
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x651c3
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rax
movl 0x60(%rax), %edx
callq 0x64f40
cmpl $0x0, %eax
je 0x650cb
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x651c3
jmp 0x651bc
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x64f40
cmpl $0x0, %eax
je 0x650f5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x651c3
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x64f40
cmpl $0x0, %eax
je 0x6511d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x651c3
jmp 0x651bc
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x64f40
cmpl $0x0, %eax
je 0x65144
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x651c3
xorl %esi, %esi
movl %esi, %edi
callq 0x6ede0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x6516c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x651c3
jmp 0x651bc
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x64f40
cmpl $0x0, %eax
je 0x65190
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x651c3
xorl %esi, %esi
movl %esi, %edi
callq 0x6ede0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x651b8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x651c3
jmp 0x651bc
jmp 0x651bc
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)