// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_codecs.c
// Function: cram_byte_array_stop_decode_char
static int cram_byte_array_stop_decode_char(cram_slice *slice, cram_codec *c,
                                            cram_block *in, char *out,
                                            int *out_size) {
    char *cp, ch;
    cram_block *b = NULL;

    b = cram_get_block_by_id(slice, c->u.byte_array_stop.content_id);
    if (!b)
        return *out_size?-1:0;

    if (b->idx >= b->uncomp_size)
        return -1;

    cp = (char *)b->data + b->idx;
    if (out) {
       // memccpy equivalent but without copying the terminating byte
        ssize_t term = MIN(*out_size, b->uncomp_size - b->idx);
        while ((ch = *cp) != (char)c->u.byte_array_stop.stop) {
            if (term-- < 0)
                break;
            *out++ = ch;
            cp++;
        }

        // Attempted overrun on input or output
        if (ch != (char)c->u.byte_array_stop.stop)
            return -1;
    } else {
        // Consume input, but produce no output
        while ((ch = *cp) != (char)c->u.byte_array_stop.stop) {
            if (cp - (char *)b->data >= b->uncomp_size)
                return -1;
            cp++;
        }
    }

    *out_size = cp - (char *)(b->data + b->idx);
    b->idx = cp - (char *)b->data + 1;

    return 0;
}

// Assembly:
pushq %rbx
movl 0x64(%rsi), %eax
cmpq $0x100, %rax            # imm = 0x100
setae %r9b
movq 0x18(%rdi), %rdx
testq %rdx, %rdx
sete %r10b
orb %r9b, %r10b
jne 0x94d18
movq (%rdx,%rax,8), %rdx
jmp 0x94d8e
testq %rdx, %rdx
je 0x94d4e
movl $0x828cbfbf, %r9d       # imm = 0x828CBFBF
imulq %rax, %r9
shrq $0x27, %r9
imull $0xfb, %r9d, %r9d
movl %eax, %r10d
subl %r9d, %r10d
shll $0x3, %r10d
movq 0x800(%rdx,%r10), %rdx
testq %rdx, %rdx
je 0x94d4e
cmpl %eax, 0xc(%rdx)
je 0x94d8e
movq (%rdi), %rdx
movslq 0x28(%rdx), %r9
testq %r9, %r9
jle 0x94d8c
movq 0x10(%rdi), %rdi
xorl %r10d, %r10d
movq (%rdi,%r10,8), %r11
testq %r11, %r11
je 0x94d7e
cmpl $0x4, 0x8(%r11)
jne 0x94d7e
cmpl %eax, 0xc(%r11)
jne 0x94d7e
xorl %ebx, %ebx
movq %r11, %rdx
jmp 0x94d80
movb $0x1, %bl
testb %bl, %bl
je 0x94d8e
incq %r10
cmpq %r10, %r9
jne 0x94d61
xorl %edx, %edx
testq %rdx, %rdx
je 0x94e02
movslq 0x1c(%rdx), %r10
movslq 0x14(%rdx), %r9
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %r10d, %r9d
jle 0x94e43
movq 0x20(%rdx), %r11
leaq (%r11,%r10), %rdi
testq %rcx, %rcx
je 0x94e0b
movl (%r8), %r11d
subl %r10d, %r9d
cmpl %r9d, %r11d
cmovll %r11d, %r9d
movb (%rdi), %r10b
cmpb 0x60(%rsi), %r10b
sete %r11b
je 0x94dfb
testl %r9d, %r9d
js 0x94dfb
movl %r9d, %r9d
movb %r10b, (%rcx)
movb 0x1(%rdi), %r10b
incq %rdi
cmpb 0x60(%rsi), %r10b
sete %r11b
je 0x94dfb
leaq -0x1(%r9), %rbx
incq %rcx
testq %r9, %r9
movq %rbx, %r9
jg 0x94dd8
testb %r11b, %r11b
jne 0x94e2b
jmp 0x94e43
xorl %eax, %eax
cmpl (%r8), %eax
sbbl %eax, %eax
jmp 0x94e43
movb 0x60(%rsi), %cl
cmpb %cl, (%rdi)
je 0x94e2b
cmpq %r9, %r10
jge 0x94e43
leaq 0x1(%r10), %rsi
cmpb %cl, 0x1(%r11,%r10)
movq %rsi, %r10
jne 0x94e12
addq %rsi, %r11
movq %r11, %rdi
movl 0x20(%rdx), %eax
movl 0x1c(%rdx), %ecx
addl %eax, %ecx
movl %edi, %esi
subl %ecx, %esi
movl %esi, (%r8)
subl %eax, %edi
incl %edi
movl %edi, 0x1c(%rdx)
xorl %eax, %eax
popq %rbx
retq