// File: /workspace/github_c_makefile_star2_O2/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
leaq (%r12,%rbp), %r8
addq $-0xc0, %r8
movb %dil, (%r8)
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 0x104a7
movq $-0x400, 0xe8(%r15) # imm = 0xFC00
orq $-0x1, 0xf0(%r15)
jmp 0x104db
testq %r13, %r13
je 0x104c2
movl $0x400, %ecx            # imm = 0x400
subl %eax, %ecx
movq %r13, %rdx
subq %rcx, %rdx
movq %rdx, 0xe8(%r15)
jmp 0x104db
leaq -0x400(%rax), %rcx
movq %rcx, 0xe8(%r15)
leaq -0x1(%rsi), %rcx
movq %rcx, 0xf0(%r15)
addq %rax, %r13
leaq 0x1(%r8), %rdi
cmpl $0x37e, %eax            # imm = 0x37E
movq %r8, -0x30(%rbp)
ja 0x1052a
pushq $0x6f
popq %rdx
subq %r12, %rdx
xorl %esi, %esi
callq 0x1080
cmpq $0x8, %rbx
jne 0x10504
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 0x105b4
pushq $0x7f
popq %rdx
subq %r12, %rdx
xorl %esi, %esi
callq 0x1080
movl $0x80, %edx
subq %r12, %rdx
movq %r15, %rdi
movq -0x30(%rbp), %rsi
callq 0xd323
movq $-0x400, 0xe8(%r15) # imm = 0xFC00
orq $-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 0x10593
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 0xd323
xorl %eax, %eax
cmpq %rax, %rbx
je 0x105d4
movq 0x88(%r15,%rax,8), %rcx
bswapq %rcx
movq %rcx, (%r14,%rax,8)
incq %rax
jmp 0x105bb
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq