// File: /workspace/github_c_makefile_star2_O2/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
leaq (%r12,%rbp), %r8
addq $-0x80, %r8
movb %dil, (%r8)
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 0xd145
movq $-0x200, 0x78(%r15)     # imm = 0xFE00
jmp 0xd164
leal -0x200(%rax), %ecx
testl %r13d, %r13d
je 0xd159
addl %r13d, %ecx
movl %ecx, 0x78(%r15)
jmp 0xd164
movl %ecx, 0x78(%r15)
leal -0x1(%rsi), %ecx
movl %ecx, 0x7c(%r15)
addl %eax, %r13d
leaq 0x1(%r8), %rdi
cmpl $0x1be, %eax            # imm = 0x1BE
movq %r8, -0x30(%rbp)
ja 0xd1ac
pushq $0x37
popq %rdx
subq %r12, %rdx
xorl %esi, %esi
callq 0x1080
cmpq $0x8, %rbx
jne 0xd18d
orb $0x1, -0x49(%rbp)
movq -0x38(%rbp), %rax
bswapl %eax
movl %eax, -0x48(%rbp)
bswapl %r13d
movl %r13d, -0x44(%rbp)
pushq $0x40
popq %rdx
subq %r12, %rdx
movq %r15, %rdi
movq -0x30(%rbp), %rsi
jmp 0xd20b
pushq $0x3f
popq %rdx
subq %r12, %rdx
xorl %esi, %esi
callq 0x1080
pushq $0x40
popq %rdx
subq %r12, %rdx
movq %r15, %rdi
movq -0x30(%rbp), %rsi
callq 0xab54
movq $-0x200, 0x78(%r15)     # imm = 0xFE00
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
andq $0x0, -0x50(%rbp)
cmpq $0x8, %rbx
jne 0xd1f1
movb $0x1, -0x49(%rbp)
movq -0x38(%rbp), %rax
bswapl %eax
leaq -0x80(%rbp), %rsi
movl %eax, 0x38(%rsi)
bswapl %r13d
movl %r13d, 0x3c(%rsi)
pushq $0x40
popq %rdx
movq %r15, %rdi
callq 0xab54
xorl %eax, %eax
cmpq %rax, %rbx
je 0xd227
movl 0x48(%r15,%rax,4), %ecx
bswapl %ecx
movl %ecx, (%r14,%rax,4)
incq %rax
jmp 0xd212
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq