// File: /workspace/github_c_makefile_star2_O1/rb-de0[P]hashverifier-for-monacoin/Lyra2RE/blake.c
// Function: blake64_close
static void
blake64_close(sph_blake_big_context *sc,
	unsigned ub, unsigned n, void *dst, size_t out_size_w64)
{
	union {
		unsigned char buf[128];
		sph_u64 dummy;
	} u;
	size_t ptr, k;
	unsigned bit_len;
	unsigned z;
	sph_u64 th, tl;
	unsigned char *out;

	ptr = sc->ptr;
	bit_len = ((unsigned)ptr << 3) + n;
	z = 0x80 >> n;
	u.buf[ptr] = ((ub & -z) | z) & 0xFF;
	tl = sc->T0 + bit_len;
	th = sc->T1;
	if (ptr == 0 && n == 0) {
		sc->T0 = SPH_C64(0xFFFFFFFFFFFFFC00);
		sc->T1 = SPH_C64(0xFFFFFFFFFFFFFFFF);
	} else if (sc->T0 == 0) {
		sc->T0 = SPH_C64(0xFFFFFFFFFFFFFC00) + bit_len;
		sc->T1 = SPH_T64(sc->T1 - 1);
	} else {
		sc->T0 -= 1024 - bit_len;
	}
	if (bit_len <= 894) {
		memset(u.buf + ptr + 1, 0, 111 - ptr);
		if (out_size_w64 == 8)
			u.buf[111] |= 1;
		sph_enc64be_aligned(u.buf + 112, th);
		sph_enc64be_aligned(u.buf + 120, tl);
		blake64(sc, u.buf + ptr, 128 - ptr);
	} else {
		memset(u.buf + ptr + 1, 0, 127 - ptr);
		blake64(sc, u.buf + ptr, 128 - ptr);
		sc->T0 = SPH_C64(0xFFFFFFFFFFFFFC00);
		sc->T1 = SPH_C64(0xFFFFFFFFFFFFFFFF);
		memset(u.buf, 0, 112);
		if (out_size_w64 == 8)
			u.buf[111] = 1;
		sph_enc64be_aligned(u.buf + 112, th);
		sph_enc64be_aligned(u.buf + 120, tl);
		blake64(sc, u.buf, 128);
	}
	out = dst;
	for (k = 0; k < out_size_w64; k ++)
		sph_enc64be(out + (k << 3), sc->H[k]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r8, %rbx
movq %rcx, %r14
movl %edx, %ecx
movq %rdi, %r15
movq 0x80(%rdi), %r12
leal (%rcx,%r12,8), %eax
movl $0x80, %edx
shrl %cl, %edx
movl %edx, %edi
negl %edi
andl %esi, %edi
orl %edx, %edi
movb %dil, -0xc0(%rbp,%r12)
movq 0xe8(%r15), %r13
movq 0xf0(%r15), %rsi
testq %r12, %r12
setne %dl
testl %ecx, %ecx
setne %cl
orb %dl, %cl
movq %rsi, -0x38(%rbp)
jne 0x11c33
movq $-0x400, 0xe8(%r15) # imm = 0xFC00
movq $-0x1, 0xf0(%r15)
jmp 0x11c67
testq %r13, %r13
je 0x11c4e
movl $0x400, %ecx            # imm = 0x400
subl %eax, %ecx
movq %r13, %rdx
subq %rcx, %rdx
movq %rdx, 0xe8(%r15)
jmp 0x11c67
leaq -0x400(%rax), %rcx
movq %rcx, 0xe8(%r15)
leaq -0x1(%rsi), %rcx
movq %rcx, 0xf0(%r15)
addq %rax, %r13
leaq (%r12,%rbp), %rcx
addq $-0xc0, %rcx
leaq (%r12,%rbp), %rdi
addq $-0xbf, %rdi
cmpl $0x37e, %eax            # imm = 0x37E
movq %rcx, -0x30(%rbp)
ja 0x11cca
movl $0x6f, %edx
subq %r12, %rdx
xorl %esi, %esi
callq 0x1080
cmpq $0x8, %rbx
jne 0x11ca4
orb $0x1, -0x51(%rbp)
movq -0x38(%rbp), %rax
bswapq %rax
bswapq %r13
movq %rax, -0x50(%rbp)
movq %r13, -0x48(%rbp)
movl $0x80, %edx
subq %r12, %rdx
movq %r15, %rdi
movq -0x30(%rbp), %rsi
jmp 0x11d59
movl $0x7f, %edx
subq %r12, %rdx
xorl %esi, %esi
callq 0x1080
movl $0x80, %edx
subq %r12, %rdx
movq %r15, %rdi
movq -0x30(%rbp), %rsi
callq 0xe9bb
movq $-0x400, 0xe8(%r15) # imm = 0xFC00
movq $-0x1, 0xf0(%r15)
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
movaps %xmm0, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
cmpq $0x8, %rbx
jne 0x11d38
movb $0x1, -0x51(%rbp)
movq -0x38(%rbp), %rax
bswapq %rax
leaq -0xc0(%rbp), %rsi
movq %rax, 0x70(%rsi)
bswapq %r13
movq %r13, 0x78(%rsi)
movl $0x80, %edx
movq %r15, %rdi
callq 0xe9bb
testq %rbx, %rbx
je 0x11d7c
xorl %eax, %eax
movq 0x88(%r15,%rax,8), %rcx
bswapq %rcx
movq %rcx, (%r14,%rax,8)
incq %rax
cmpq %rax, %rbx
jne 0x11d65
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq