// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/liball/../libcperciva/alg/sha256.c
// Function: PBKDF2_SHA256
void
PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt,
    size_t saltlen, uint64_t c, uint8_t * buf, size_t dkLen)
{
	HMAC_SHA256_CTX Phctx, PShctx, hctx;
	uint32_t tmp32[72];
	uint8_t tmp8[96];
	size_t i;
	uint8_t ivec[4];
	uint8_t U[32];
	uint8_t T[32];
	uint64_t j;
	int k;
	size_t clen;

#if SIZE_MAX >= (32 * UINT32_MAX)
	/* Sanity-check. */
	assert(dkLen <= 32 * (size_t)(UINT32_MAX));
#endif

	/* Compute HMAC state after processing P. */
	HMAC_SHA256_Init_internal(&Phctx, passwd, passwdlen,
	    tmp32, &tmp8[0], &tmp8[64]);

	/* Compute HMAC state after processing P and S. */
	memcpy(&PShctx, &Phctx, sizeof(HMAC_SHA256_CTX));
	HMAC_SHA256_Update_internal(&PShctx, salt, saltlen, tmp32);

	/* Iterate through the blocks. */
	for (i = 0; i * 32 < dkLen; i++) {
		/* Generate INT(i + 1). */
		be32enc(ivec, (uint32_t)(i + 1));

		/* Compute U_1 = PRF(P, S || INT(i)). */
		memcpy(&hctx, &PShctx, sizeof(HMAC_SHA256_CTX));
		HMAC_SHA256_Update_internal(&hctx, ivec, 4, tmp32);
		HMAC_SHA256_Final_internal(U, &hctx, tmp32, tmp8);

		/* T_i = U_1 ... */
		memcpy(T, U, 32);

		for (j = 2; j <= c; j++) {
			/* Compute U_j. */
			memcpy(&hctx, &Phctx, sizeof(HMAC_SHA256_CTX));
			HMAC_SHA256_Update_internal(&hctx, U, 32, tmp32);
			HMAC_SHA256_Final_internal(U, &hctx, tmp32, tmp8);

			/* ... xor U_j ... */
			for (k = 0; k < 32; k++)
				T[k] ^= U[k];
		}

		/* Copy as many bytes as necessary into buf. */
		clen = dkLen - i * 32;
		if (clen > 32)
			clen = 32;
		memcpy(&buf[i * 32], T, clen);
	}

	/* Clean the stack. */
	insecure_memzero(&Phctx, sizeof(HMAC_SHA256_CTX));
	insecure_memzero(&PShctx, sizeof(HMAC_SHA256_CTX));
	insecure_memzero(&hctx, sizeof(HMAC_SHA256_CTX));
	insecure_memzero(tmp32, sizeof(uint32_t) * 72);
	insecure_memzero(tmp8, 96);
	insecure_memzero(U, 32);
	insecure_memzero(T, 32);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movq %r9, 0x10(%rsp)
movq 0x490(%rsp), %r13
movabsq $0x1fffffffe1, %rax     # imm = 0x1FFFFFFFE1
cmpq %rax, %r13
jae 0xedae
movq %r8, %r14
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %rdx
movq %rdi, %rsi
leaq 0xa0(%rsp), %r9
leaq 0x190(%rsp), %r12
leaq 0x260(%rsp), %rcx
leaq 0x60(%rsp), %r8
movq %r12, %rdi
callq 0xe8dd
leaq 0xc0(%rsp), %rbp
movl $0xd0, %edx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x3280
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
leaq 0x260(%rsp), %rcx
callq 0xe621
testq %r13, %r13
je 0xed20
xorl %ebp, %ebp
leaq 0x388(%rsp), %r15
leaq 0x260(%rsp), %r12
leaq 0x40(%rsp), %r13
xorl %eax, %eax
incq %rax
movq %rax, 0x18(%rsp)
bswapl %eax
movl %eax, 0xc(%rsp)
movl $0xd0, %edx
movq %r15, %rdi
leaq 0xc0(%rsp), %rsi
callq 0x3280
movl $0x4, %edx
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
movq %r12, %rcx
callq 0xe621
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
leaq 0x60(%rsp), %rcx
callq 0xea70
movaps 0x40(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
movaps %xmm1, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
cmpq $0x2, %r14
jb 0xecde
movl $0x2, %ebx
movl $0xd0, %edx
movq %r15, %rdi
leaq 0x190(%rsp), %rsi
callq 0x3280
movl $0x20, %edx
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rcx
callq 0xe621
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
leaq 0x60(%rsp), %rcx
callq 0xea70
xorl %eax, %eax
movaps 0x20(%rsp,%rax), %xmm0
xorps 0x40(%rsp,%rax), %xmm0
movaps %xmm0, 0x20(%rsp,%rax)
addq $0x10, %rax
cmpq $0x20, %rax
jne 0xecbd
incq %rbx
cmpq %r14, %rbx
jbe 0xec80
movq 0x490(%rsp), %rbx
movq %rbx, %rdx
subq %rbp, %rdx
cmpq $0x20, %rdx
movl $0x20, %eax
cmovaeq %rax, %rdx
addq 0x10(%rsp), %rbp
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x3280
movq 0x18(%rsp), %rax
movq %rax, %rbp
shlq $0x5, %rbp
cmpq %rbx, %rbp
jb 0xec16
leaq 0x98b1(%rip), %rbx      # 0x185d8
movq (%rbx), %rax
leaq 0x190(%rsp), %rdi
movl $0xd0, %esi
callq *%rax
movq (%rbx), %rax
leaq 0xc0(%rsp), %rdi
movl $0xd0, %esi
callq *%rax
movq (%rbx), %rax
leaq 0x388(%rsp), %rdi
movl $0xd0, %esi
callq *%rax
movq (%rbx), %rax
leaq 0x260(%rsp), %rdi
movl $0x120, %esi            # imm = 0x120
callq *%rax
movq (%rbx), %rax
leaq 0x60(%rsp), %rdi
movl $0x60, %esi
callq *%rax
movq (%rbx), %rax
leaq 0x40(%rsp), %rdi
movl $0x20, %esi
callq *%rax
movq (%rbx), %rax
leaq 0x20(%rsp), %rdi
movl $0x20, %esi
callq *%rax
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x461b(%rip), %rdi      # 0x133d0
leaq 0x4637(%rip), %rsi      # 0x133f3
leaq 0x464c(%rip), %rcx      # 0x1340f
movl $0x28b, %edx            # imm = 0x28B
callq 0x3200