// File: /workspace/github_c_makefile_star2_O0/Seclabs-htc[P]slip39/trezor-crypto/sha2.c
// Function: sha1_Final
void sha1_Final(SHA1_CTX* context, sha2_byte digest[]) {
	unsigned int	usedspace;

	/* If no digest buffer is passed, we don't bother doing this: */
	if (digest != (sha2_byte*)0) {
		usedspace = (context->bitcount >> 3) % SHA1_BLOCK_LENGTH;
		/* Begin padding with a 1 bit: */
		((uint8_t*)context->buffer)[usedspace++] = 0x80;

		if (usedspace > SHA1_SHORT_BLOCK_LENGTH) {
			memzero(((uint8_t*)context->buffer) + usedspace, SHA1_BLOCK_LENGTH - usedspace);

#if BYTE_ORDER == LITTLE_ENDIAN
			/* Convert TO host byte order */
			for (int j = 0; j < 16; j++) {
				REVERSE32(context->buffer[j],context->buffer[j]);
			}
#endif
			/* Do second-to-last transform: */
			sha1_Transform(context->state, context->buffer, context->state);

			/* And prepare the last transform: */
			usedspace = 0;
		}
		/* Set-up for the last transform: */
		memzero(((uint8_t*)context->buffer) + usedspace, SHA1_SHORT_BLOCK_LENGTH - usedspace);

#if BYTE_ORDER == LITTLE_ENDIAN
		/* Convert TO host byte order */
		for (int j = 0; j < 14; j++) {
			REVERSE32(context->buffer[j],context->buffer[j]);
		}
#endif
		/* Set the bit count: */
		context->buffer[14] = context->bitcount >> 32;
		context->buffer[15] = context->bitcount & 0xffffffff;

		/* Final transform: */
		sha1_Transform(context->state, context->buffer, context->state);

#if BYTE_ORDER == LITTLE_ENDIAN
		/* Convert FROM host byte order */
		for (int j = 0; j < 5; j++) {
			REVERSE32(context->state[j],context->state[j]);
		}
#endif
		MEMCPY_BCOPY(digest, context->state, SHA1_DIGEST_LENGTH);
	}

	/* Clean up state data: */
	memzero(context, sizeof(SHA1_CTX));
	usedspace = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x95a8
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x3, %rax
andq $0x3f, %rax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movl %ecx, %ecx
movb $-0x80, 0x20(%rax,%rcx)
cmpl $0x38, -0x14(%rbp)
jbe 0x9454
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
movl -0x14(%rbp), %eax
addq %rax, %rdi
movl $0x40, %eax
subl -0x14(%rbp), %eax
movl %eax, %eax
movl %eax, %esi
callq 0x81c0
movl $0x0, -0x18(%rbp)
cmpl $0x10, -0x18(%rbp)
jge 0x9438
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl 0x20(%rax,%rcx,4), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
shrl $0x10, %eax
movl -0x1c(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movabsq $0xff00ff00, %rcx       # imm = 0xFF00FF00
andq %rcx, %rax
shrq $0x8, %rax
movl -0x1c(%rbp), %ecx
andq $0xff00ff, %rcx         # imm = 0xFF00FF
shlq $0x8, %rcx
orq %rcx, %rax
movl %eax, %edx
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, 0x20(%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x93d4
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x20, %rsi
movq -0x8(%rbp), %rdx
callq 0x8c50
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
movl -0x14(%rbp), %eax
addq %rax, %rdi
movl $0x38, %eax
subl -0x14(%rbp), %eax
movl %eax, %eax
movl %eax, %esi
callq 0x81c0
movl $0x0, -0x20(%rbp)
cmpl $0xe, -0x20(%rbp)
jge 0x94de
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl 0x20(%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
shrl $0x10, %eax
movl -0x24(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movabsq $0xff00ff00, %rcx       # imm = 0xFF00FF00
andq %rcx, %rax
shrq $0x8, %rax
movl -0x24(%rbp), %ecx
andq $0xff00ff, %rcx         # imm = 0xFF00FF
shlq $0x8, %rcx
orq %rcx, %rax
movl %eax, %edx
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl %edx, 0x20(%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x947a
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x8(%rbp), %rcx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq 0x18(%rcx), %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x5c(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x20, %rsi
movq -0x8(%rbp), %rdx
callq 0x8c50
movl $0x0, -0x28(%rbp)
cmpl $0x5, -0x28(%rbp)
jge 0x958c
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
shrl $0x10, %eax
movl -0x2c(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movabsq $0xff00ff00, %rcx       # imm = 0xFF00FF00
andq %rcx, %rax
shrq $0x8, %rax
movl -0x2c(%rbp), %ecx
andq $0xff00ff, %rcx         # imm = 0xFF00FF
shlq $0x8, %rcx
orq %rcx, %rax
movl %eax, %edx
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x952a
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movl 0x10(%rcx), %ecx
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movl $0x60, %esi
callq 0x81c0
movl $0x0, -0x14(%rbp)
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)