// File: /workspace/github_c_makefile_star2_O1/rb-de0[P]hashverifier-for-monacoin/Lyra2RE/blake.c
// Function: blake32_close
static void
blake32_close(sph_blake_small_context *sc,
	unsigned ub, unsigned n, void *dst, size_t out_size_w32)
{
	union {
		unsigned char buf[64];
		sph_u32 dummy;
	} u;
	size_t ptr, k;
	unsigned bit_len;
	unsigned z;
	sph_u32 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_C32(0xFFFFFE00);
		sc->T1 = SPH_C32(0xFFFFFFFF);
	} else if (sc->T0 == 0) {
		sc->T0 = SPH_C32(0xFFFFFE00) + bit_len;
		sc->T1 = SPH_T32(sc->T1 - 1);
	} else {
		sc->T0 -= 512 - bit_len;
	}
	if (bit_len <= 446) {
		memset(u.buf + ptr + 1, 0, 55 - ptr);
		if (out_size_w32 == 8)
			u.buf[55] |= 1;
		sph_enc32be_aligned(u.buf + 56, th);
		sph_enc32be_aligned(u.buf + 60, tl);
		blake32(sc, u.buf + ptr, 64 - ptr);
	} else {
		memset(u.buf + ptr + 1, 0, 63 - ptr);
		blake32(sc, u.buf + ptr, 64 - ptr);
		sc->T0 = SPH_C32(0xFFFFFE00);
		sc->T1 = SPH_C32(0xFFFFFFFF);
		memset(u.buf, 0, 56);
		if (out_size_w32 == 8)
			u.buf[55] = 1;
		sph_enc32be_aligned(u.buf + 56, th);
		sph_enc32be_aligned(u.buf + 60, tl);
		blake32(sc, u.buf, 64);
	}
	out = dst;
	for (k = 0; k < out_size_w32; k ++)
		sph_enc32be(out + (k << 2), sc->H[k]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %rbx
movq %rcx, %r14
movl %edx, %ecx
movq %rdi, %r15
movq 0x40(%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, -0x80(%rbp,%r12)
movl 0x78(%r15), %r13d
movl 0x7c(%r15), %esi
testq %r12, %r12
setne %dl
testl %ecx, %ecx
setne %cl
orb %dl, %cl
movq %rsi, -0x38(%rbp)
jne 0xe784
movq $-0x200, 0x78(%r15)     # imm = 0xFE00
jmp 0xe7a3
leal -0x200(%rax), %ecx
testl %r13d, %r13d
je 0xe798
addl %r13d, %ecx
movl %ecx, 0x78(%r15)
jmp 0xe7a3
movl %ecx, 0x78(%r15)
leal -0x1(%rsi), %ecx
movl %ecx, 0x7c(%r15)
addl %eax, %r13d
leaq (%r12,%rbp), %rcx
addq $-0x80, %rcx
leaq (%r12,%rbp), %rdi
addq $-0x7f, %rdi
cmpl $0x1be, %eax            # imm = 0x1BE
movq %rcx, -0x30(%rbp)
ja 0xe7fb
movl $0x37, %edx
subq %r12, %rdx
xorl %esi, %esi
callq 0x1080
cmpq $0x8, %rbx
jne 0xe7da
orb $0x1, -0x49(%rbp)
movq -0x38(%rbp), %rax
bswapl %eax
movl %eax, -0x48(%rbp)
bswapl %r13d
movl %r13d, -0x44(%rbp)
movl $0x40, %edx
subq %r12, %rdx
movq %r15, %rdi
movq -0x30(%rbp), %rsi
jmp 0xe863
movl $0x3f, %edx
subq %r12, %rdx
xorl %esi, %esi
callq 0x1080
movl $0x40, %edx
subq %r12, %rdx
movq %r15, %rdi
movq -0x30(%rbp), %rsi
callq 0xc160
movq $-0x200, 0x78(%r15)     # imm = 0xFE00
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movq $0x0, -0x50(%rbp)
cmpq $0x8, %rbx
jne 0xe847
movb $0x1, -0x49(%rbp)
movq -0x38(%rbp), %rax
bswapl %eax
leaq -0x80(%rbp), %rsi
movl %eax, 0x38(%rsi)
bswapl %r13d
movl %r13d, 0x3c(%rsi)
movl $0x40, %edx
movq %r15, %rdi
callq 0xc160
testq %rbx, %rbx
je 0xe882
xorl %eax, %eax
movl 0x48(%r15,%rax,4), %ecx
bswapl %ecx
movl %ecx, (%r14,%rax,4)
incq %rax
cmpq %rax, %rbx
jne 0xe86f
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq