// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x38, 0x40(%rax)
jae 0xa748
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movl %ecx, %ecx
movb $-0x80, (%rax,%rcx)
cmpl $0x38, -0x14(%rbp)
jae 0xa746
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movl %ecx, %ecx
movb $0x0, (%rax,%rcx)
jmp 0xa729
jmp 0xa797
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movl %ecx, %ecx
movb $-0x80, (%rax,%rcx)
cmpl $0x40, -0x14(%rbp)
jae 0xa77a
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movl %ecx, %ecx
movb $0x0, (%rax,%rcx)
jmp 0xa75d
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0xa270
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x2160
movq -0x8(%rbp), %rax
movl 0x40(%rax), %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x8(%rbp), %rax
addq 0x48(%rax), %rcx
movq %rcx, 0x48(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x3f(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
shrq $0x8, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x3e(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
shrq $0x10, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x3d(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
shrq $0x18, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x3c(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
shrq $0x20, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x3b(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
shrq $0x28, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x3a(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
shrq $0x30, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x39(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
shrq $0x38, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0xa270
movl $0x0, -0x14(%rbp)
cmpl $0x4, -0x14(%rbp)
jae 0xa9dc
movq -0x8(%rbp), %rax
movl 0x50(%rax), %eax
movl -0x14(%rbp), %edx
shll $0x3, %edx
movl $0x18, %ecx
subl %edx, %ecx
shrl %cl, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl 0x54(%rax), %eax
movl -0x14(%rbp), %edx
shll $0x3, %edx
movl $0x18, %ecx
subl %edx, %ecx
shrl %cl, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x4, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl 0x58(%rax), %eax
movl -0x14(%rbp), %edx
shll $0x3, %edx
movl $0x18, %ecx
subl %edx, %ecx
shrl %cl, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x8, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl 0x5c(%rax), %eax
movl -0x14(%rbp), %edx
shll $0x3, %edx
movl $0x18, %ecx
subl %edx, %ecx
shrl %cl, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0xc, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl 0x60(%rax), %eax
movl -0x14(%rbp), %edx
shll $0x3, %edx
movl $0x18, %ecx
subl %edx, %ecx
shrl %cl, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x10, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl 0x64(%rax), %eax
movl -0x14(%rbp), %edx
shll $0x3, %edx
movl $0x18, %ecx
subl %edx, %ecx
shrl %cl, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x14, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl 0x68(%rax), %eax
movl -0x14(%rbp), %edx
shll $0x3, %edx
movl $0x18, %ecx
subl %edx, %ecx
shrl %cl, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x18, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl 0x6c(%rax), %eax
movl -0x14(%rbp), %edx
shll $0x3, %edx
movl $0x18, %ecx
subl %edx, %ecx
shrl %cl, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1c, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xa869
addq $0x20, %rsp
popq %rbp
retq