// File: /workspace/github_c_makefile_star2_O0/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
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
shll $0x3, %eax
addl -0x10(%rbp), %eax
movl %eax, -0xb4(%rbp)
movl -0x10(%rbp), %ecx
movl $0x80, %eax
sarl %cl, %eax
movl %eax, -0xb8(%rbp)
movl -0xc(%rbp), %eax
xorl %ecx, %ecx
subl -0xb8(%rbp), %ecx
andl %ecx, %eax
orl -0xb8(%rbp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0xa8(%rbp), %rax
movb %cl, -0xa0(%rbp,%rax)
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rax
movl -0xb4(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0xc8(%rbp)
movq -0x8(%rbp), %rax
movq 0xf0(%rax), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0xa8(%rbp)
jne 0x278c7
cmpl $0x0, -0x10(%rbp)
jne 0x278c7
movq -0x8(%rbp), %rax
movq $-0x400, 0xe8(%rax) # imm = 0xFC00
movq -0x8(%rbp), %rax
movq $-0x1, 0xf0(%rax)
jmp 0x27935
movq -0x8(%rbp), %rax
cmpq $0x0, 0xe8(%rax)
jne 0x2790f
movl -0xb4(%rbp), %eax
movl %eax, %ecx
addq $-0x400, %rcx           # imm = 0xFC00
movq -0x8(%rbp), %rax
movq %rcx, 0xe8(%rax)
movq -0x8(%rbp), %rax
movq 0xf0(%rax), %rcx
subq $0x1, %rcx
andq $-0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xf0(%rax)
jmp 0x27933
movl $0x400, %eax            # imm = 0x400
subl -0xb4(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0xe8(%rax)
jmp 0x27935
cmpl $0x37e, -0xb4(%rbp)     # imm = 0x37E
ja 0x279d1
leaq -0xa0(%rbp), %rdi
addq -0xa8(%rbp), %rdi
addq $0x1, %rdi
movl $0x6f, %edx
subq -0xa8(%rbp), %rdx
xorl %esi, %esi
callq 0x1060
cmpq $0x8, -0x20(%rbp)
jne 0x2797b
movzbl -0x31(%rbp), %eax
orl $0x1, %eax
movb %al, -0x31(%rbp)
leaq -0xa0(%rbp), %rdi
addq $0x70, %rdi
movq -0xc0(%rbp), %rsi
callq 0x27cc0
leaq -0xa0(%rbp), %rdi
addq $0x78, %rdi
movq -0xc8(%rbp), %rsi
callq 0x27cc0
movq -0x8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
addq -0xa8(%rbp), %rsi
movl $0x80, %edx
subq -0xa8(%rbp), %rdx
callq 0x1c600
jmp 0x27a98
leaq -0xa0(%rbp), %rdi
addq -0xa8(%rbp), %rdi
addq $0x1, %rdi
movl $0x7f, %edx
subq -0xa8(%rbp), %rdx
xorl %esi, %esi
callq 0x1060
movq -0x8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
addq -0xa8(%rbp), %rsi
movl $0x80, %edx
subq -0xa8(%rbp), %rdx
callq 0x1c600
movq -0x8(%rbp), %rax
movq $-0x400, 0xe8(%rax) # imm = 0xFC00
movq -0x8(%rbp), %rax
movq $-0x1, 0xf0(%rax)
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
movl $0x70, %edx
callq 0x1060
cmpq $0x8, -0x20(%rbp)
jne 0x27a55
movb $0x1, -0x31(%rbp)
leaq -0xa0(%rbp), %rdi
addq $0x70, %rdi
movq -0xc0(%rbp), %rsi
callq 0x27cc0
leaq -0xa0(%rbp), %rdi
addq $0x78, %rdi
movq -0xc8(%rbp), %rsi
callq 0x27cc0
movq -0x8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
movl $0x80, %edx
callq 0x1c600
movq -0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq $0x0, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x27afc
movq -0xd0(%rbp), %rdi
movq -0xb0(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movq -0xb0(%rbp), %rcx
movq 0x88(%rax,%rcx,8), %rsi
callq 0x27cf0
movq -0xb0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb0(%rbp)
jmp 0x27aae
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)