// File: /workspace/github_c_makefile_star2_O3/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
setb %dl
movq 0x18(%rdi), %r10
testq %r10, %r10
setne %r9b
testb %r9b, %dl
je 0x91ff0
movq (%r10,%rax,8), %r14
testq %r14, %r14
jne 0x92031
jmp 0x920e8
testq %r10, %r10
je 0x920b4
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), %r14
testq %r14, %r14
je 0x920b4
cmpl %eax, 0xc(%r14)
jne 0x920b4
movslq 0x1c(%r14), %rdi
movslq 0x14(%r14), %r10
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl %r10d, %edi
jge 0x9220e
movq 0x20(%r14), %rax
xorl %r11d, %r11d
cmpl $0x8, 0x4(%r14)
je 0x9205a
movzbl 0x60(%rsi), %r11d
leaq (%rax,%rdi), %r13
addq %r10, %rax
movq %r10, %rdx
subq %rdi, %rdx
movq 0x28(%rcx), %rsi
movq 0x30(%rcx), %r15
movq %rsi, %r9
subq %r15, %r9
cmpq %r9, %rdx
jae 0x920f4
movq 0x20(%rcx), %rsi
addq %rsi, %r15
cmpl %r10d, %edi
je 0x920a5
movzbl (%r13), %esi
cmpl %esi, %r11d
je 0x920a1
incq %r13
movb %sil, (%r15)
incq %r15
decq %rdx
jne 0x92086
movq %rax, %r13
movq 0x20(%rcx), %rsi
subq %rsi, %r15
movq %r15, 0x30(%rcx)
movq %r13, %r12
jmp 0x921f0
movq (%rdi), %rdx
movslq 0x28(%rdx), %r9
testq %r9, %r9
jle 0x920e8
movq 0x10(%rdi), %rdx
xorl %edi, %edi
movq (%rdx,%rdi,8), %r14
testq %r14, %r14
je 0x920e0
cmpl $0x4, 0x8(%r14)
jne 0x920e0
cmpl %eax, 0xc(%r14)
je 0x92031
incq %rdi
cmpq %rdi, %r9
jne 0x920c6
xorl %ebp, %ebp
cmpl (%r8), %ebp
sbbl %ebp, %ebp
jmp 0x9220e
movq %r13, %r12
cmpl %r10d, %edi
je 0x92114
movq %r13, %r12
movzbl (%r12), %edi
cmpl %edi, %r11d
je 0x92114
incq %r12
decq %rdx
jne 0x920ff
movq %rax, %r12
movq %r8, 0x8(%rsp)
movq %r12, %rax
subq %r13, %rax
movq %rax, 0x10(%rsp)
leaq (%rax,%r15), %rbx
cmpq %rbx, %rsi
jbe 0x92132
movq %rsi, %rbx
jmp 0x92174
leaq 0x320(%rsi), %rax
shrq $0x2, %rax
addq %rsi, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %rbx, %rax
cmovaq %rax, %rbx
movq 0x20(%rcx), %rdi
movq %rbx, %rsi
movq %rcx, %r15
callq 0x4840
testq %rax, %rax
je 0x9220e
movq %rbx, 0x28(%r15)
movq %rax, 0x20(%r15)
movq %r15, %rcx
movq 0x30(%r15), %r15
cmpq %r13, %r12
je 0x921a7
addq 0x20(%rcx), %r15
movq %r15, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %r13
movq %r13, %rdx
movq %rcx, %rbx
callq 0x43c0
movq %rbx, %rcx
movq 0x30(%rbx), %r15
addq %r13, %r15
movq %r15, 0x30(%rbx)
movq 0x28(%rbx), %rbx
jmp 0x921ac
movq 0x10(%rsp), %r13
addq %r13, %r15
cmpq %r15, %rbx
ja 0x921eb
leaq 0x320(%rbx), %rax
shrq $0x2, %rax
addq %rbx, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %r15, %rax
cmovaq %rax, %r15
movq 0x20(%rcx), %rdi
movq %r15, %rsi
movq %rcx, %rbx
callq 0x4840
testq %rax, %rax
je 0x9220e
movq %r15, 0x28(%rbx)
movq %rax, 0x20(%rbx)
movq 0x8(%rsp), %r8
movl 0x20(%r14), %eax
movl 0x1c(%r14), %ecx
addl %eax, %ecx
movl %r12d, %edx
subl %ecx, %edx
movl %edx, (%r8)
subl %eax, %r12d
incl %r12d
movl %r12d, 0x1c(%r14)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq