// File: /workspace/github_cpp_makefile_star2_O1/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 0x4d40b
movq (%rcx,%rax,8), %r13
jmp 0x4d44e
movq (%rdi), %rcx
movslq 0x20(%rcx), %rcx
testq %rcx, %rcx
jle 0x4d44b
movq 0x10(%rdi), %rdx
xorl %edi, %edi
movq (%rdx,%rdi,8), %r10
testq %r10, %r10
je 0x4d43b
cmpl $0x4, 0x8(%r10)
jne 0x4d43b
cmpl %eax, 0xc(%r10)
jne 0x4d43b
xorl %r9d, %r9d
movq %r10, %r13
jmp 0x4d43e
movb $0x1, %r9b
testb %r9b, %r9b
je 0x4d44e
incq %rdi
cmpq %rdi, %rcx
jne 0x4d41d
xorl %r13d, %r13d
testq %r13, %r13
je 0x4d4b9
movslq 0x1c(%r13), %r9
movslq 0x14(%r13), %r11
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %r11d, %r9d
jge 0x4d62e
movq 0x20(%r13), %rdi
leaq (%rdi,%r9), %r15
movq 0x28(%r14), %r10
movq 0x30(%r14), %rdx
movb 0x30(%rsi), %al
movq %r11, %rcx
subq %r9, %rcx
subq %rdx, %r10
cmpq %r10, %rcx
jae 0x4d4c5
addq 0x20(%r14), %rdx
cmpl %r11d, %r9d
je 0x4d4a9
movb (%r15), %sil
cmpb %al, %sil
je 0x4d4a9
incq %r15
movb %sil, (%rdx)
incq %rdx
decq %rcx
jne 0x4d493
subq 0x20(%r14), %rdx
movq %rdx, 0x30(%r14)
movq %r15, %rbp
jmp 0x4d613
xorl %eax, %eax
cmpl (%r8), %eax
sbbl %eax, %eax
jmp 0x4d62e
movq %r15, %rbp
cmpl %r11d, %r9d
je 0x4d4e3
addq %r11, %rdi
movq %r15, %rbp
cmpb %al, (%rbp)
je 0x4d4e3
incq %rbp
decq %rcx
jne 0x4d4d3
movq %rdi, %rbp
movq %r8, (%rsp)
movq %rbp, %r12
subq %r15, %r12
movq 0x28(%r14), %rax
movq 0x30(%r14), %rdi
leaq (%rdi,%r12), %rcx
cmpq %rcx, %rax
ja 0x4d574
movl $0x400, %ebx            # imm = 0x400
movq %rax, %xmm0
punpckldq 0x5420(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x5428(%rip), %xmm0     # 0x52940
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x64dc(%rip), %xmm1     # 0x53a08
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x53cc(%rip), %xmm1     # 0x52908
cvttsd2si %xmm1, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %rbx, %rsi
movq %rsi, 0x28(%r14)
movq 0x20(%r14), %rdi
callq 0x48d0
movq %rax, 0x20(%r14)
movq 0x28(%r14), %rax
movq 0x30(%r14), %rdi
leaq (%rdi,%r12), %rcx
cmpq %rcx, %rax
jbe 0x4d503
addq 0x20(%r14), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x4420
movq 0x30(%r14), %rcx
addq %r12, %rcx
movq %rcx, 0x30(%r14)
movq 0x28(%r14), %rax
addq %r12, %rcx
cmpq %rcx, %rax
ja 0x4d60f
movl $0x400, %ebx            # imm = 0x400
movq %rax, %xmm0
punpckldq 0x5384(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x538c(%rip), %xmm0     # 0x52940
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x6440(%rip), %xmm1     # 0x53a08
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x5330(%rip), %xmm1     # 0x52908
cvttsd2si %xmm1, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %rbx, %rsi
movq %rsi, 0x28(%r14)
movq 0x20(%r14), %rdi
callq 0x48d0
movq %rax, 0x20(%r14)
movq 0x28(%r14), %rax
movq 0x30(%r14), %rcx
addq %r12, %rcx
cmpq %rcx, %rax
jbe 0x4d59f
movq (%rsp), %r8
movl 0x20(%r13), %eax
movl 0x1c(%r13), %ecx
addl %eax, %ecx
movl %ebp, %edx
subl %ecx, %edx
movl %edx, (%r8)
subl %eax, %ebp
incl %ebp
movl %ebp, 0x1c(%r13)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq