// File: /workspace/github_c_makefile_star2_O3/skeeto[P]enchive/src/sha256.c
// Function: sha256_final
void sha256_final(SHA256_CTX *ctx, uint8_t hash[])
{
	uint32_t i;

	i = ctx->datalen;

	/* Pad whatever data is left in the buffer. */
	if (ctx->datalen < 56) {
		ctx->data[i++] = 0x80;
		while (i < 56)
			ctx->data[i++] = 0x00;
	}
	else {
		ctx->data[i++] = 0x80;
		while (i < 64)
			ctx->data[i++] = 0x00;
		sha256_transform(ctx, ctx->data);
		memset(ctx->data, 0, 56);
	}

	/* Append to the padding the total message's length in bits and transform. */
	ctx->bitlen += ctx->datalen * 8;
	ctx->data[63] = ctx->bitlen;
	ctx->data[62] = ctx->bitlen >> 8;
	ctx->data[61] = ctx->bitlen >> 16;
	ctx->data[60] = ctx->bitlen >> 24;
	ctx->data[59] = ctx->bitlen >> 32;
	ctx->data[58] = ctx->bitlen >> 40;
	ctx->data[57] = ctx->bitlen >> 48;
	ctx->data[56] = ctx->bitlen >> 56;
	sha256_transform(ctx, ctx->data);

	/* Since this implementation uses little endian byte ordering and SHA uses big endian, */
	/* reverse all the bytes when copying the final state to the output hash. */
	for (i = 0; i < 4; ++i) {
		hash[i]      = (ctx->state[0] >> (24 - i * 8)) & 0x000000ff;
		hash[i + 4]  = (ctx->state[1] >> (24 - i * 8)) & 0x000000ff;
		hash[i + 8]  = (ctx->state[2] >> (24 - i * 8)) & 0x000000ff;
		hash[i + 12] = (ctx->state[3] >> (24 - i * 8)) & 0x000000ff;
		hash[i + 16] = (ctx->state[4] >> (24 - i * 8)) & 0x000000ff;
		hash[i + 20] = (ctx->state[5] >> (24 - i * 8)) & 0x000000ff;
		hash[i + 24] = (ctx->state[6] >> (24 - i * 8)) & 0x000000ff;
		hash[i + 28] = (ctx->state[7] >> (24 - i * 8)) & 0x000000ff;
	}
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %rbp
movl 0x40(%rdi), %eax
movb $-0x80, (%rdi,%rax)
cmpq $0x37, %rax
ja 0x70cd
cmpl $0x37, %eax
je 0x710d
leaq (%rax,%rbp), %rdi
incq %rdi
movl $0x37, %edx
subl %eax, %edx
xorl %esi, %esi
callq 0x2160
jmp 0x710d
leal 0x1(%rax), %ecx
cmpl $0x3f, %ecx
ja 0x70eb
movl %ecx, %edi
addq %rbp, %rdi
movl $0x3e, %edx
subl %eax, %edx
incq %rdx
xorl %esi, %esi
callq 0x2160
movq %rbp, %rdi
movq %rbp, %rsi
callq 0x6d80
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbp)
movups %xmm0, 0x10(%rbp)
movups %xmm0, (%rbp)
movq $0x0, 0x30(%rbp)
movl 0x40(%rbp), %eax
shll $0x3, %eax
addq 0x48(%rbp), %rax
movq %rax, 0x48(%rbp)
movb %al, 0x3f(%rbp)
movb %ah, 0x3e(%rbp)
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x3d(%rbp)
movl %eax, %ecx
shrl $0x18, %ecx
movb %cl, 0x3c(%rbp)
movq %rax, %rcx
shrq $0x20, %rcx
movb %cl, 0x3b(%rbp)
movq %rax, %rcx
shrq $0x28, %rcx
movb %cl, 0x3a(%rbp)
movq %rax, %rcx
shrq $0x30, %rcx
movb %cl, 0x39(%rbp)
shrq $0x38, %rax
movb %al, 0x38(%rbp)
movq %rbp, %rdi
movq %rbp, %rsi
callq 0x6d80
movl $0x18, %ecx
movq $-0x4, %rax
movl 0x50(%rbp), %edx
shrl %cl, %edx
movb %dl, 0x4(%rbx,%rax)
movl 0x54(%rbp), %edx
shrl %cl, %edx
movb %dl, 0x8(%rbx,%rax)
movl 0x58(%rbp), %edx
shrl %cl, %edx
movb %dl, 0xc(%rbx,%rax)
movl 0x5c(%rbp), %edx
shrl %cl, %edx
movb %dl, 0x10(%rbx,%rax)
movl 0x60(%rbp), %edx
shrl %cl, %edx
movb %dl, 0x14(%rbx,%rax)
movl 0x64(%rbp), %edx
shrl %cl, %edx
movb %dl, 0x18(%rbx,%rax)
movl 0x68(%rbp), %edx
shrl %cl, %edx
movb %dl, 0x1c(%rbx,%rax)
movl 0x6c(%rbp), %edx
shrl %cl, %edx
movb %dl, 0x20(%rbx,%rax)
addl $-0x8, %ecx
incq %rax
jne 0x716d
addq $0x8, %rsp
popq %rbx
popq %rbp
retq