// File: /workspace/github_c_makefile_star2_O0/maandree[P]libkeccak/hmac/libkeccak_hmac_fast_digest.c
// Function: libkeccak_hmac_fast_digest
int
libkeccak_hmac_fast_digest(struct libkeccak_hmac_state *restrict state, const void *restrict msg_, size_t msglen,
                           size_t bits, const char *restrict suffix, void *restrict hashsum)
{
	const unsigned char *restrict msg = msg_;
	size_t hashsize = (size_t)state->sponge.n >> 3;
	unsigned char *tmp = malloc((size_t)((state->sponge.n + 7) >> 3) * sizeof(char));
	unsigned char leftover[2];
	size_t newlen;

	if (!tmp)
		return -1;

	if (!(state->key_length & 7)) {
		if (libkeccak_fast_digest(&state->sponge, msg, msglen, bits, suffix, tmp) < 0)
			goto fail;
		goto stage_2;
	}

	if (libkeccak_hmac_fast_update(state, msg, msglen) < 0)
		goto fail;
	leftover[0] = state->leftover;
	if (bits) {
		leftover[0] |= (unsigned char)(msg[msglen] >> (state->key_length & 7));
		leftover[1] = (unsigned char)(msg[msglen] << (8 - (state->key_length & 7)));
	}
	newlen = (state->key_length & 7) + bits;
	if (libkeccak_fast_digest(&state->sponge, leftover, newlen >> 3, newlen & 7, suffix, tmp) < 0)
		goto fail;

stage_2:
	bits = state->sponge.n & 7;
	state->key_ipad = state->key_opad;
	if (libkeccak_hmac_fast_update(state, NULL, 0) < 0)
		goto fail;

	if (!(state->key_length & 7)) {
		if (libkeccak_fast_digest(&state->sponge, tmp, hashsize, bits, suffix, hashsum) < 0)
			goto fail;
		goto stage_3;
	}

	if (libkeccak_hmac_fast_update(state, tmp, hashsize) < 0)
		goto fail;
	leftover[0] = state->leftover;
	if (bits) {
		leftover[0] |= (unsigned char)(tmp[hashsize] >> (state->key_length & 7));
		leftover[1] = (unsigned char)(tmp[hashsize] << (8 - (state->key_length & 7)));
	}
	newlen = (state->key_length & 7) + bits;
	if (libkeccak_fast_digest(&state->sponge, leftover, newlen >> 3, newlen & 7, suffix, tmp) < 0)
		goto fail;

stage_3:
	free(tmp);
	return 0;
fail:
	free(tmp);
	return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0xf0(%rax), %rax
shrq $0x3, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0xf0(%rax), %rdi
addq $0x7, %rdi
sarq $0x3, %rdi
shlq $0x0, %rdi
callq 0x21c0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x8f5e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x91c3
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
andq $0x7, %rax
cmpq $0x0, %rax
jne 0x8fa0
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x50(%rbp), %r9
callq 0x2050
cmpl $0x0, %eax
jge 0x8f9b
jmp 0x91b3
jmp 0x9063
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x2030
cmpl $0x0, %eax
jge 0x8fbb
jmp 0x91b3
movq -0x10(%rbp), %rax
movb 0x148(%rax), %al
movb %al, -0x52(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x901a
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
andq $0x7, %rcx
sarl %cl, %eax
movzbl %al, %ecx
movzbl -0x52(%rbp), %eax
orl %ecx, %eax
movb %al, -0x52(%rbp)
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rdx
andq $0x7, %rdx
movl $0x8, %ecx
subq %rdx, %rcx
shll %cl, %eax
movb %al, -0x51(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
andq $0x7, %rax
addq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
leaq -0x52(%rbp), %rsi
movq -0x60(%rbp), %rdx
shrq $0x3, %rdx
movq -0x60(%rbp), %rcx
andq $0x7, %rcx
movq -0x30(%rbp), %r8
movq -0x50(%rbp), %r9
callq 0x2050
cmpl $0x0, %eax
jge 0x9061
jmp 0x91b3
jmp 0x9063
movq -0x10(%rbp), %rax
movq 0xf0(%rax), %rax
andq $0x7, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x2030
cmpl $0x0, %eax
jge 0x909f
jmp 0x91b3
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
andq $0x7, %rax
cmpq $0x0, %rax
jne 0x90e1
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r9
callq 0x2050
cmpl $0x0, %eax
jge 0x90dc
jmp 0x91b3
jmp 0x91a1
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x2030
cmpl $0x0, %eax
jge 0x90fc
jmp 0x91b3
movq -0x10(%rbp), %rax
movb 0x148(%rax), %al
movb %al, -0x52(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x915b
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
andq $0x7, %rcx
sarl %cl, %eax
movzbl %al, %ecx
movzbl -0x52(%rbp), %eax
orl %ecx, %eax
movb %al, -0x52(%rbp)
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rdx
andq $0x7, %rdx
movl $0x8, %ecx
subq %rdx, %rcx
shll %cl, %eax
movb %al, -0x51(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
andq $0x7, %rax
addq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
leaq -0x52(%rbp), %rsi
movq -0x60(%rbp), %rdx
shrq $0x3, %rdx
movq -0x60(%rbp), %rcx
andq $0x7, %rcx
movq -0x30(%rbp), %r8
movq -0x50(%rbp), %r9
callq 0x2050
cmpl $0x0, %eax
jge 0x919f
jmp 0x91b3
jmp 0x91a1
movq -0x50(%rbp), %rdi
callq 0x2040
movl $0x0, -0x4(%rbp)
jmp 0x91c3
movq -0x50(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)