// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/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_;
    char *cp, *out_cp, *cp_end;
    char stop;

    b = cram_get_block_by_id(slice, c->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;
    cp_end = (char *)b->data + b->uncomp_size;
    out_cp = (char *)BLOCK_END(out);

    stop = c->byte_array_stop.stop;
    if (cp_end - cp < out->alloc - out->byte) {
	while (cp != cp_end && *cp != stop)
	    *out_cp++ = *cp++;
	BLOCK_SIZE(out) = out_cp - (char *)BLOCK_DATA(out);
    } else {
	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 - (char *)(b->data + b->idx);
    b->idx = cp - (char *)b->data + 1;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %rbx
movq %rcx, %r15
movq %rsi, %r13
movl 0x34(%rsi), %esi
callq 0x3bc37
testq %rax, %rax
je 0x3e8d7
movq %rax, %r14
movslq 0x1c(%rax), %r8
movslq 0x14(%rax), %rcx
cmpl %ecx, %r8d
jge 0x3e8e2
movq 0x20(%r14), %rbp
leaq (%r8,%rbp), %r12
addq %rcx, %rbp
movq 0x20(%r15), %rdi
movq 0x28(%r15), %rax
movq 0x30(%r15), %rdx
movb 0x30(%r13), %sil
subq %r8, %rcx
movq %rax, %r8
subq %rdx, %r8
cmpq %r8, %rcx
jae 0x3e8ea
addq %rdx, %rdi
movq %rdi, %rax
negq %rax
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x3e909
movb (%r12,%rdx), %r8b
cmpb %sil, %r8b
je 0x3e903
movb %r8b, (%rdi,%rdx)
decq %rax
incq %rdx
jmp 0x3e8bd
xorl %eax, %eax
cmpl (%rbx), %eax
sbbl %eax, %eax
jmp 0x3ea47
pushq $-0x1
popq %rax
jmp 0x3ea47
movq %r12, %r8
movq %rbx, (%rsp)
testq %rcx, %rcx
je 0x3e91c
cmpb %sil, (%r8)
je 0x3e919
incq %r8
decq %rcx
jmp 0x3e8f1
addq %rdx, %r12
movq %r12, %rbp
addq 0x20(%r15), %rax
negq %rax
movq %rax, 0x30(%r15)
jmp 0x3ea2d
movq %r8, %rbp
movq %rbp, %r13
subq %r12, %r13
movl $0x400, %ebx            # imm = 0x400
leaq (%rdx,%r13), %rcx
cmpq %rcx, %rax
ja 0x3e999
movq %rax, %xmm0
punpckldq 0x5053(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x505b(%rip), %xmm0     # 0x439a0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x6087(%rip), %xmm1     # 0x449e0
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
subsd 0x4fab(%rip), %xmm1     # 0x43918
cvttsd2si %xmm1, %rsi
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %rbx, %rsi
movq %rsi, 0x28(%r15)
callq 0x48c0
movq %rax, %rdi
movq %rax, 0x20(%r15)
movq 0x28(%r15), %rax
movq 0x30(%r15), %rdx
jmp 0x3e927
addq %rdx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x4420
movq 0x30(%r15), %rcx
addq %r13, %rcx
movq %rcx, 0x30(%r15)
movl $0x400, %ebx            # imm = 0x400
movq 0x28(%r15), %rax
addq %r13, %rcx
cmpq %rcx, %rax
ja 0x3ea29
movq %rax, %xmm0
punpckldq 0x4fc0(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x4fc8(%rip), %xmm0     # 0x439a0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x5ff4(%rip), %xmm1     # 0x449e0
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x4f1c(%rip), %xmm1     # 0x43918
cvttsd2si %xmm1, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %rbx, %rsi
movq %rsi, 0x28(%r15)
movq 0x20(%r15), %rdi
callq 0x48c0
movq %rax, 0x20(%r15)
movq 0x30(%r15), %rcx
jmp 0x3e9b7
movq (%rsp), %rbx
movl 0x20(%r14), %eax
movl 0x1c(%r14), %ecx
addl %eax, %ecx
movl %ebp, %edx
subl %ecx, %edx
movl %edx, (%rbx)
subl %eax, %ebp
incl %ebp
movl %ebp, 0x1c(%r14)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq