// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x20(%rsp)
movq %r8, 0x10(%rsp)
movq %rcx, %r12
movq %rdx, %rbp
movq %rsi, %r15
movq %rdi, %r14
movq 0xf0(%rdi), %r13
leaq 0x7(%r13), %rdi
sarq $0x3, %rdi
callq 0x2160
testq %rax, %rax
je 0x72b1
movq %rax, %rbx
leaq 0x18(%r14), %rdi
testb $0x7, 0x10(%r14)
movq %rdi, 0x18(%rsp)
je 0x72bb
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x2070
testl %eax, %eax
js 0x73a2
movb 0x148(%r14), %dl
movb %dl, 0xe(%rsp)
movq 0x10(%r14), %rax
testq %r12, %r12
je 0x7292
movzbl (%r15,%rbp), %esi
movl %eax, %ecx
andb $0x7, %cl
movl %esi, %edi
shrb %cl, %dil
orb %dl, %dil
movb %dil, 0xe(%rsp)
movb $0x8, %dl
subb %cl, %dl
movl %edx, %ecx
shll %cl, %esi
movb %sil, 0xf(%rsp)
andl $0x7, %eax
addq %r12, %rax
movq %rax, %rdx
shrq $0x3, %rdx
andl $0x7, %eax
leaq 0xe(%rsp), %rsi
movq 0x18(%rsp), %rdi
movq %rax, %rcx
jmp 0x72c4
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x73cc
movq %r15, %rsi
movq %rbp, %rdx
movq %r12, %rcx
movq 0x10(%rsp), %r8
movq %rbx, %r9
callq 0x2140
testl %eax, %eax
js 0x73a2
movq (%r14), %rax
movq 0xf0(%r14), %r12
movq %rax, 0x8(%r14)
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2070
testl %eax, %eax
js 0x73a2
sarq $0x3, %r13
andl $0x7, %r12d
testb $0x7, 0x10(%r14)
je 0x737d
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2070
testl %eax, %eax
js 0x73a2
movb 0x148(%r14), %dl
movb %dl, 0xe(%rsp)
movq 0x10(%r14), %rax
testq %r12, %r12
je 0x7358
movzbl (%rbx,%r13), %esi
movl %eax, %ecx
andb $0x7, %cl
movl %esi, %edi
sarb %cl, %dil
orb %dl, %dil
movb %dil, 0xe(%rsp)
movb $0x8, %dl
subb %cl, %dl
movl %edx, %ecx
shll %cl, %esi
movb %sil, 0xf(%rsp)
andl $0x7, %eax
addq %r12, %rax
movl %eax, %edx
shrl $0x3, %edx
andl $0x7, %eax
leaq 0xe(%rsp), %rsi
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movq 0x10(%rsp), %r8
movq %rbx, %r9
jmp 0x7395
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %r9
callq 0x2140
testl %eax, %eax
js 0x73a2
xorl %ebp, %ebp
jmp 0x73a7
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0xf0(%r14), %rdx
addq $0x7, %rdx
sarq $0x3, %rdx
movq 0x4d4b(%rip), %rax      # 0xc108
movq %rbx, %rdi
xorl %esi, %esi
callq *%rax
movq %rbx, %rdi
callq 0x2040
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)