// File: /workspace/github_cpp_makefile_star2_O3/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 %rcx, %r14
movl 0x34(%rsi), %eax
cmpq $0x400, %rax            # imm = 0x400
setb %dl
movq 0x18(%rdi), %rcx
testq %rcx, %rcx
setne %r9b
testb %r9b, %dl
je 0x4c39d
movq (%rcx,%rax,8), %r13
testq %r13, %r13
je 0x4c3d1
movslq 0x1c(%r13), %r9
movslq 0x14(%r13), %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %edi, %r9d
jge 0x4c542
movq 0x20(%r13), %rax
leaq (%rax,%r9), %r15
addq %rdi, %rax
movq 0x28(%r14), %rdx
movq 0x30(%r14), %rcx
movb 0x30(%rsi), %sil
subq %r9, %rdi
movq %rdx, %r9
subq %rcx, %r9
cmpq %r9, %rdi
jae 0x4c3dd
addq 0x20(%r14), %rcx
movb (%r15), %dl
cmpb %sil, %dl
je 0x4c390
incq %r15
movb %dl, (%rcx)
incq %rcx
decq %rdi
jne 0x4c378
movq %rax, %r15
subq 0x20(%r14), %rcx
movq %rcx, 0x30(%r14)
jmp 0x4c524
movq (%rdi), %rcx
movslq 0x20(%rcx), %rcx
testq %rcx, %rcx
jle 0x4c3d1
movq 0x10(%rdi), %rdx
xorl %edi, %edi
movq (%rdx,%rdi,8), %r13
testq %r13, %r13
je 0x4c3c9
cmpl $0x4, 0x8(%r13)
jne 0x4c3c9
cmpl %eax, 0xc(%r13)
je 0x4c339
incq %rdi
cmpq %rdi, %rcx
jne 0x4c3af
xorl %eax, %eax
cmpl (%r8), %eax
sbbl %eax, %eax
jmp 0x4c542
movq %r15, %rbp
movq %r8, (%rsp)
cmpb %sil, (%rbp)
je 0x4c3f5
incq %rbp
decq %rdi
jne 0x4c3e4
movq %rax, %rbp
movq %rbp, %r12
subq %r15, %r12
leaq (%rcx,%r12), %rsi
movq 0x20(%r14), %rax
cmpq %rsi, %rdx
ja 0x4c47d
movl $0x400, %ebx            # imm = 0x400
movq %rdx, %xmm0
punpckldq 0x4566(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x456e(%rip), %xmm0     # 0x50990
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x562a(%rip), %xmm1     # 0x51a60
cvttsd2si %xmm1, %rcx
movq %rcx, %rdi
sarq $0x3f, %rdi
subsd 0x44be(%rip), %xmm1     # 0x50908
cvttsd2si %xmm1, %rsi
andq %rdi, %rsi
orq %rcx, %rsi
testq %rdx, %rdx
cmoveq %rbx, %rsi
movq %rsi, 0x28(%r14)
movq %rax, %rdi
callq 0x48d0
movq %rax, 0x20(%r14)
movq 0x28(%r14), %rdx
movq 0x30(%r14), %rcx
leaq (%rcx,%r12), %rsi
cmpq %rsi, %rdx
jbe 0x4c40d
addq %rcx, %rax
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x4420
movq 0x30(%r14), %rax
addq %r12, %rax
movq %rax, 0x30(%r14)
movq 0x28(%r14), %rcx
addq %r12, %rax
cmpq %rax, %rcx
ja 0x4c51d
movq 0x20(%r14), %rax
movl $0x400, %ebx            # imm = 0x400
movq %rcx, %xmm0
punpckldq 0x44c5(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x44cd(%rip), %xmm0     # 0x50990
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x5589(%rip), %xmm1     # 0x51a60
cvttsd2si %xmm1, %rdx
movq %rdx, %rdi
sarq $0x3f, %rdi
subsd 0x441d(%rip), %xmm1     # 0x50908
cvttsd2si %xmm1, %rsi
andq %rdi, %rsi
orq %rdx, %rsi
testq %rcx, %rcx
cmoveq %rbx, %rsi
movq %rsi, 0x28(%r14)
movq %rax, %rdi
callq 0x48d0
movq %rax, 0x20(%r14)
movq 0x28(%r14), %rcx
movq 0x30(%r14), %rdx
addq %r12, %rdx
cmpq %rdx, %rcx
jbe 0x4c4ae
movq %rbp, %r15
movq (%rsp), %r8
movl 0x20(%r13), %eax
movl 0x1c(%r13), %ecx
addl %eax, %ecx
movl %r15d, %edx
subl %ecx, %edx
movl %edx, (%r8)
subl %eax, %r15d
incl %r15d
movl %r15d, 0x1c(%r13)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq