// File: /workspace/github_c_makefile_star2_O0/maandree[P]libkeccak/hmac/libkeccak_hmac_digest.c
// Function: libkeccak_hmac_digest
int
libkeccak_hmac_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);
	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_digest(&state->sponge, msg, msglen, bits, suffix, tmp) < 0)
			goto fail;
		goto stage_2;
	}

	if (libkeccak_hmac_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_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_update(state, NULL, 0) < 0)
		goto fail;

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

	if (libkeccak_hmac_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_digest(&state->sponge, leftover, newlen >> 3, newlen & 7, suffix, tmp) < 0)
		goto fail;

stage_3:
	my_explicit_bzero(tmp, (size_t)((state->sponge.n + 7) >> 3) * sizeof(char));
	free(tmp);
	return 0;
fail:
	my_explicit_bzero(tmp, (size_t)((state->sponge.n + 7) >> 3) * sizeof(char));
	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
sarq $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 0x8b2e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8dd3
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
andq $0x7, %rax
cmpq $0x0, %rax
jne 0x8b70
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 0x2190
cmpl $0x0, %eax
jge 0x8b6b
jmp 0x8da3
jmp 0x8c33
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x2070
cmpl $0x0, %eax
jge 0x8b8b
jmp 0x8da3
movq -0x10(%rbp), %rax
movb 0x148(%rax), %al
movb %al, -0x52(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x8bea
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 0x2190
cmpl $0x0, %eax
jge 0x8c31
jmp 0x8da3
jmp 0x8c33
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 0x2070
cmpl $0x0, %eax
jge 0x8c6f
jmp 0x8da3
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
andq $0x7, %rax
cmpq $0x0, %rax
jne 0x8cb1
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 0x2190
cmpl $0x0, %eax
jge 0x8cac
jmp 0x8da3
jmp 0x8d71
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x2070
cmpl $0x0, %eax
jge 0x8ccc
jmp 0x8da3
movq -0x10(%rbp), %rax
movb 0x148(%rax), %al
movb %al, -0x52(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x8d2b
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
movsbl (%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
movsbl (%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 0x2190
cmpl $0x0, %eax
jge 0x8d6f
jmp 0x8da3
jmp 0x8d71
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0xf0(%rax), %rsi
addq $0x7, %rsi
sarq $0x3, %rsi
shlq $0x0, %rsi
callq 0x8de0
movq -0x50(%rbp), %rdi
callq 0x2040
movl $0x0, -0x4(%rbp)
jmp 0x8dd3
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0xf0(%rax), %rsi
addq $0x7, %rsi
sarq $0x3, %rsi
shlq $0x0, %rsi
callq 0x8de0
movq -0x50(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)