// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x64(%rax), %esi
callq 0xe1ab0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xebc7a
movq -0x30(%rbp), %rax
movl (%rax), %edx
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0xebdf8
movq -0x48(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jl 0xebc96
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xebdf8
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movslq 0x1c(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xebd64
movq -0x30(%rbp), %rax
movl (%rax), %eax
movq -0x48(%rbp), %rcx
movl 0x14(%rcx), %ecx
movq -0x48(%rbp), %rdx
subl 0x1c(%rdx), %ecx
cmpl %ecx, %eax
jge 0xebcdb
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
jmp 0xebcec
movq -0x48(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x48(%rbp), %rcx
subl 0x1c(%rcx), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cltq
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movb (%rax), %al
movb %al, -0x39(%rbp)
movsbl %al, %eax
movq -0x18(%rbp), %rcx
movsbl 0x60(%rcx), %ecx
cmpl %ecx, %eax
je 0xebd46
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x50(%rbp)
cmpq $0x0, %rax
jge 0xebd24
jmp 0xebd46
movb -0x39(%rbp), %cl
movq -0x28(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
movb %cl, (%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xebcf5
movsbl -0x39(%rbp), %eax
movq -0x18(%rbp), %rcx
movsbl 0x60(%rcx), %ecx
cmpl %ecx, %eax
je 0xebd62
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xebdf8
jmp 0xebdb3
jmp 0xebd66
movq -0x38(%rbp), %rax
movb (%rax), %al
movb %al, -0x39(%rbp)
movsbl %al, %eax
movq -0x18(%rbp), %rcx
movsbl 0x60(%rcx), %ecx
cmpl %ecx, %eax
je 0xebdb1
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
movq 0x20(%rcx), %rcx
subq %rcx, %rax
movq -0x48(%rbp), %rcx
movslq 0x14(%rcx), %rcx
cmpq %rcx, %rax
jl 0xebda3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xebdf8
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xebd66
jmp 0xebdb3
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x48(%rbp), %rdx
movslq 0x1c(%rdx), %rdx
addq %rdx, %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
movq 0x20(%rcx), %rcx
subq %rcx, %rax
addq $0x1, %rax
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)