// File: /workspace/github_c_makefile_star2_O3/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 %r14
pushq %rbx
movl 0x64(%rsi), %eax
cmpq $0x100, %rax            # imm = 0x100
setb %r9b
movq 0x18(%rdi), %rdx
testq %rdx, %rdx
setne %r10b
testb %r10b, %r9b
je 0x923cc
movq (%rdx,%rax,8), %rdx
testq %rdx, %rdx
jne 0x9240a
jmp 0x924b9
testq %rdx, %rdx
je 0x92486
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 0x92486
cmpl %eax, 0xc(%rdx)
jne 0x92486
movslq 0x1c(%rdx), %r9
movslq 0x14(%rdx), %r11
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %r9d, %r11d
jle 0x924f7
movq 0x20(%rdx), %r10
leaq (%r10,%r9), %rdi
testq %rcx, %rcx
je 0x924c2
movl (%r8), %r10d
subl %r9d, %r11d
cmpl %r11d, %r10d
cmovll %r10d, %r11d
movb (%rdi), %r10b
cmpb 0x60(%rsi), %r10b
sete %r9b
je 0x92477
testl %r11d, %r11d
js 0x92477
movl %r11d, %r11d
xorl %ebx, %ebx
movb %r10b, (%rcx,%rbx)
movb 0x1(%rdi,%rbx), %r10b
leaq 0x1(%rbx), %r14
cmpb 0x60(%rsi), %r10b
sete %r9b
je 0x92474
cmpq %rbx, %r11
movq %r14, %rbx
jne 0x92455
addq %r14, %rdi
testb %r9b, %r9b
je 0x924f7
movq 0x20(%rdx), %r10
movslq 0x1c(%rdx), %r9
jmp 0x924e2
movq (%rdi), %rdx
movslq 0x28(%rdx), %r9
testq %r9, %r9
jle 0x924b9
movq 0x10(%rdi), %rdi
xorl %r10d, %r10d
movq (%rdi,%r10,8), %rdx
testq %rdx, %rdx
je 0x924b1
cmpl $0x4, 0x8(%rdx)
jne 0x924b1
cmpl %eax, 0xc(%rdx)
je 0x9240a
incq %r10
cmpq %r10, %r9
jne 0x92499
xorl %eax, %eax
cmpl (%r8), %eax
sbbl %eax, %eax
jmp 0x924f7
movb 0x60(%rsi), %cl
cmpb %cl, (%rdi)
je 0x924e2
movq %r9, %rsi
cmpq %r11, %rsi
jge 0x924f7
leaq 0x1(%rsi), %rdi
cmpb %cl, 0x1(%r10,%rsi)
movq %rdi, %rsi
jne 0x924cc
addq %r10, %rdi
addl %r10d, %r9d
movl %edi, %eax
subl %r9d, %eax
movl %eax, (%r8)
subl %r10d, %edi
incl %edi
movl %edi, 0x1c(%rdx)
xorl %eax, %eax
popq %rbx
popq %r14
retq