// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_codecs.c
// Function: cram_byte_array_stop_decode_block
int cram_byte_array_stop_decode_block(cram_slice *slice, cram_codec *c,
                                      cram_block *in, char *out_,
                                      int *out_size) {
    cram_block *b;
    cram_block *out = (cram_block *)out_;
    unsigned char *cp, *cp_end;
    unsigned char stop;

    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 = b->data + b->idx;
    cp_end = b->data + b->uncomp_size;

    // STOP byte is hard-coded as zero by our name tokeniser decoder
    // implementation, so we may ignore what was requested.
    stop = b->orig_method == TOK3 ? 0 : c->u.byte_array_stop.stop;

    if (cp_end - cp < out->alloc - out->byte) {
        unsigned char *out_cp = BLOCK_END(out);
        while (cp != cp_end && *cp != stop)
            *out_cp++ = *cp++;
        BLOCK_SIZE(out) = out_cp - BLOCK_DATA(out);
    } else {
        unsigned char *cp_start;
        for (cp_start = cp; cp != cp_end && *cp != stop; cp++)
            ;
        BLOCK_APPEND(out, cp_start, cp - cp_start);
        BLOCK_GROW(out, cp - cp_start);
    }

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

    return 0;

 block_err:
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x64(%rsi), %eax
cmpq $0x100, %rax            # imm = 0x100
setae %dl
movq 0x18(%rdi), %r10
testq %r10, %r10
sete %r9b
orb %dl, %r9b
jne 0x9497e
movq (%r10,%rax,8), %rbx
jmp 0x949f4
testq %r10, %r10
je 0x949b2
movl $0x828cbfbf, %edx       # imm = 0x828CBFBF
imulq %rax, %rdx
shrq $0x27, %rdx
imull $0xfb, %edx, %edx
movl %eax, %r9d
subl %edx, %r9d
shll $0x3, %r9d
movq 0x800(%r10,%r9), %rbx
testq %rbx, %rbx
je 0x949b2
cmpl %eax, 0xc(%rbx)
je 0x949f4
movq (%rdi), %rdx
movslq 0x28(%rdx), %r11
testq %r11, %r11
jle 0x949f2
movq 0x10(%rdi), %rdx
xorl %edi, %edi
movq (%rdx,%rdi,8), %r10
testq %r10, %r10
je 0x949e2
cmpl $0x4, 0x8(%r10)
jne 0x949e2
cmpl %eax, 0xc(%r10)
jne 0x949e2
xorl %r9d, %r9d
movq %r10, %rbx
jmp 0x949e5
movb $0x1, %r9b
testb %r9b, %r9b
je 0x949f4
incq %rdi
cmpq %rdi, %r11
jne 0x949c4
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x94a6c
movslq 0x1c(%rbx), %r9
movslq 0x14(%rbx), %r10
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl %r10d, %r9d
jge 0x94b75
movq 0x20(%rbx), %rdi
xorl %eax, %eax
cmpl $0x8, 0x4(%rbx)
je 0x94a1f
movzbl 0x60(%rsi), %eax
leaq (%rdi,%r9), %r14
movq %r10, %r11
subq %r9, %r11
movq 0x28(%rcx), %rdx
movq 0x30(%rcx), %r12
movq %rdx, %rsi
subq %r12, %rsi
cmpq %rsi, %r11
jae 0x94a78
addq 0x20(%rcx), %r12
cmpl %r10d, %r9d
je 0x94a5c
movzbl (%r14), %edx
cmpl %edx, %eax
je 0x94a5c
incq %r14
movb %dl, (%r12)
incq %r12
decq %r11
jne 0x94a45
subq 0x20(%rcx), %r12
movq %r12, 0x30(%rcx)
movq %r14, %r15
jmp 0x94b59
xorl %ebp, %ebp
cmpl (%r8), %ebp
sbbl %ebp, %ebp
jmp 0x94b75
movq %r14, %r15
cmpl %r10d, %r9d
je 0x94a99
addq %r10, %rdi
movq %r14, %r15
movzbl (%r15), %esi
cmpl %esi, %eax
je 0x94a99
incq %r15
decq %r11
jne 0x94a86
movq %rdi, %r15
movq %r8, 0x8(%rsp)
movq %r15, %r13
subq %r14, %r13
addq %r13, %r12
cmpq %r12, %rdx
ja 0x94aee
leaq 0x320(%rdx), %rax
shrq $0x2, %rax
addq %rdx, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %r12, %rax
cmovaq %rax, %r12
movq 0x20(%rcx), %rdi
movq %r12, %rsi
movq %rcx, 0x10(%rsp)
callq 0x4840
testq %rax, %rax
je 0x94b75
movq 0x10(%rsp), %rcx
movq %r12, 0x28(%rcx)
movq %rax, 0x20(%rcx)
cmpq %r14, %r15
je 0x94b10
movq 0x20(%rcx), %rdi
addq 0x30(%rcx), %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rcx, %r14
callq 0x43c0
movq %r14, %rcx
addq %r13, 0x30(%r14)
addq 0x30(%rcx), %r13
movq 0x28(%rcx), %rax
cmpq %r13, %rax
ja 0x94b54
leaq 0x320(%rax), %rdx
shrq $0x2, %rdx
addq %rdx, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %r13, %rax
cmovaq %rax, %r13
movq 0x20(%rcx), %rdi
movq %r13, %rsi
movq %rcx, %r14
callq 0x4840
testq %rax, %rax
je 0x94b75
movq %r13, 0x28(%r14)
movq %rax, 0x20(%r14)
movq 0x8(%rsp), %r8
movl 0x20(%rbx), %eax
movl 0x1c(%rbx), %ecx
addl %eax, %ecx
movl %r15d, %edx
subl %ecx, %edx
movl %edx, (%r8)
subl %eax, %r15d
incl %r15d
movl %r15d, 0x1c(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq