// File: /workspace/github_c_makefile_star2_O2/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 $0x468, %rsp            # imm = 0x468
movq %r9, 0x10(%rsp)
movabsq $0x1fffffffe1, %rax     # imm = 0x1FFFFFFFE1
cmpq %rax, 0x4a0(%rsp)
jae 0xdd39
movq %r8, %r14
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %rdx
movq %rdi, %rsi
leaq 0xb0(%rsp), %r9
leaq 0x1a0(%rsp), %r13
leaq 0x340(%rsp), %r12
leaq 0x70(%rsp), %r8
movq %r13, %rdi
movq %r12, %rcx
callq 0xd893
leaq 0xd0(%rsp), %rbp
movl $0xd0, %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3290
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0xd5ea
xorl %ecx, %ecx
leaq 0x270(%rsp), %rbp
leaq 0x50(%rsp), %rbx
pushq $0x20
popq %r15
movq %rcx, %rdx
shlq $0x5, %rdx
movq 0x4a0(%rsp), %rax
subq %rdx, %rax
jbe 0xdcae
movq %rdx, 0x18(%rsp)
movq %rax, 0x20(%rsp)
incq %rcx
movq %rcx, 0x28(%rsp)
movl %ecx, %eax
bswapl %eax
movl %eax, 0xc(%rsp)
movl $0xd0, %edx
movq %rbp, %rdi
leaq 0xd0(%rsp), %rsi
callq 0x3290
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x4
popq %rdx
movq %r12, %rcx
callq 0xd5ea
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
leaq 0x70(%rsp), %rcx
callq 0xda18
movaps 0x50(%rsp), %xmm0
movaps 0x60(%rsp), %xmm1
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
pushq $0x2
popq %r13
cmpq %r14, %r13
ja 0xdc83
movl $0xd0, %edx
movq %rbp, %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x3290
movq %rbp, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0xd5ea
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
leaq 0x70(%rsp), %rcx
callq 0xda18
xorl %eax, %eax
cmpq $0x20, %rax
je 0xdc7e
movb 0x50(%rsp,%rax), %cl
xorb %cl, 0x30(%rsp,%rax)
incq %rax
jmp 0xdc6b
incq %r13
jmp 0xdc2b
movq 0x20(%rsp), %rdx
cmpq $0x20, %rdx
cmovaeq %r15, %rdx
movq 0x18(%rsp), %rdi
addq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x3290
movq 0x28(%rsp), %rcx
jmp 0xdba6
leaq 0xa923(%rip), %r14      # 0x185d8
movq (%r14), %rax
leaq 0x1a0(%rsp), %rdi
movl $0xd0, %esi
callq *%rax
movq (%r14), %rax
leaq 0xd0(%rsp), %rdi
movl $0xd0, %esi
callq *%rax
movq (%r14), %rax
leaq 0x270(%rsp), %rdi
movl $0xd0, %esi
callq *%rax
movq (%r14), %rax
leaq 0x340(%rsp), %rdi
movl $0x120, %esi            # imm = 0x120
callq *%rax
movq (%r14), %rax
leaq 0x70(%rsp), %rdi
pushq $0x60
popq %rsi
callq *%rax
movq (%r14), %rax
leaq 0x50(%rsp), %rdi
pushq $0x20
popq %rbx
movq %rbx, %rsi
callq *%rax
movq (%r14), %rax
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq *%rax
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4600(%rip), %rdi      # 0x12340
leaq 0x461c(%rip), %rsi      # 0x12363
leaq 0x4631(%rip), %rcx      # 0x1237f
movl $0x28b, %edx            # imm = 0x28B
callq 0x3210