// File: /workspace/github_c_makefile_star2_O1/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 0xef1f
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 0xea56
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 0xe79a
testq %r13, %r13
je 0xee91
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 0xe79a
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
leaq 0x60(%rsp), %rcx
callq 0xebe9
movaps 0x40(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
movaps %xmm1, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
cmpq $0x2, %r14
jb 0xee4f
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 0xe79a
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
leaq 0x60(%rsp), %rcx
callq 0xebe9
xorl %eax, %eax
movb 0x40(%rsp,%rax), %cl
xorb %cl, 0x20(%rsp,%rax)
incq %rax
cmpq $0x20, %rax
jne 0xee36
incq %rbx
cmpq %r14, %rbx
jbe 0xedf9
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 0xed8f
leaq 0x9740(%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 0x461a(%rip), %rdi      # 0x13540
leaq 0x4636(%rip), %rsi      # 0x13563
leaq 0x464b(%rip), %rcx      # 0x1357f
movl $0x28b, %edx            # imm = 0x28B
callq 0x3200