// File: karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_byte_array_len_decode_init
cram_codec *cram_byte_array_len_decode_init(char *data, int size,
					    enum cram_external_type option,
					    int version) {
    cram_codec *c;
    char *cp   = data;
    char *endp = data + size;
    int32_t encoding = 0;
    int32_t sub_size = -1;

    if (!(c = malloc(sizeof(*c))))
	return NULL;

    c->codec  = E_BYTE_ARRAY_LEN;
    c->decode = cram_byte_array_len_decode;
    c->free   = cram_byte_array_len_decode_free;
    
    cp += safe_itf8_get(cp, endp, &encoding);
    cp += safe_itf8_get(cp, endp, &sub_size);
    if (sub_size < 0 || endp - cp < sub_size)
        goto malformed;
    c->byte_array_len.len_codec = cram_decoder_init(encoding, cp, sub_size,
						    E_INT, version);
    if (c->byte_array_len.len_codec == NULL)
        goto no_codec;
    cp += sub_size;

    sub_size = -1;
    cp += safe_itf8_get(cp, endp, &encoding);
    cp += safe_itf8_get(cp, endp, &sub_size);
    if (sub_size < 0 || endp - cp < sub_size)
        goto malformed;
    c->byte_array_len.val_codec = cram_decoder_init(encoding, cp, sub_size,
						    option, version);
    if (c->byte_array_len.val_codec == NULL)
        goto no_codec;
    cp += sub_size;

    if (cp - data != size)
        goto malformed;

    return c;

 malformed:
    fprintf(stderr, "Malformed byte_array_len header stream\n");
 no_codec:
    free(c);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
movl $0x240, %edi            # imm = 0x240
callq 0x47a0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x72dcb
movq $0x0, -0x8(%rbp)
jmp 0x72f85
movq -0x28(%rbp), %rax
movl $0x4, (%rax)
movq -0x28(%rbp), %rax
leaq -0x1a0(%rip), %rcx      # 0x72c40
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
leaq -0xef(%rip), %rcx       # 0x72d00
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
callq 0x6ded0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x6ded0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x40(%rbp)
jl 0x72e4f
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movslq -0x40(%rbp), %rcx
cmpq %rcx, %rax
jge 0x72e54
jmp 0x72f5c
movl -0x3c(%rbp), %edi
movq -0x30(%rbp), %rsi
movl -0x40(%rbp), %edx
movl -0x1c(%rbp), %r8d
movl $0x1, %ecx
callq 0x72f90
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x72e87
jmp 0x72f74
movl -0x40(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
callq 0x6ded0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x6ded0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x40(%rbp)
jl 0x72efb
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movslq -0x40(%rbp), %rcx
cmpq %rcx, %rax
jge 0x72efd
jmp 0x72f5c
movl -0x3c(%rbp), %edi
movq -0x30(%rbp), %rsi
movl -0x40(%rbp), %edx
movl -0x18(%rbp), %ecx
movl -0x1c(%rbp), %r8d
callq 0x72f90
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x72f2b
jmp 0x72f74
movl -0x40(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movslq -0x14(%rbp), %rcx
cmpq %rcx, %rax
je 0x72f52
jmp 0x72f5c
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x72f85
movq 0x1706d(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
leaq 0xbd1b(%rip), %rsi      # 0x7ec88
movb $0x0, %al
callq 0x4830
movq -0x28(%rbp), %rdi
callq 0x46a0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nop