// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rax
jae 0x6b4e
cmpq $0x37, %rax
je 0x6b7e
movb $0x0, 0x1(%rbp,%rax)
incq %rax
jmp 0x6b3e
incl %eax
cmpl $0x3f, %eax
ja 0x6b5f
movb $0x0, (%rbp,%rax)
incq %rax
jmp 0x6b50
movq %rbp, %rdi
movq %rbp, %rsi
callq 0x68fc
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbp)
movups %xmm0, 0x10(%rbp)
movups %xmm0, (%rbp)
andq $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 0x68fc
pushq $0x18
popq %rcx
pushq $-0x4
popq %rax
testq %rax, %rax
je 0x6c2d
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
jmp 0x6bd8
addq $0x8, %rsp
popq %rbx
popq %rbp
retq