// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x490, %rsp            # imm = 0x490
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movabsq $0x1fffffffe0, %rax     # imm = 0x1FFFFFFFE0
cmpq %rax, 0x10(%rbp)
ja 0x15c59
jmp 0x15c78
leaq 0xaca0(%rip), %rdi      # 0x20900
leaq 0xacbc(%rip), %rsi      # 0x20923
movl $0x28b, %edx            # imm = 0x28B
leaq 0xaccc(%rip), %rcx      # 0x2093f
callq 0x3240
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x3c0(%rbp), %rcx
leaq -0x420(%rbp), %r8
leaq -0x420(%rbp), %r9
addq $0x40, %r9
leaq -0x100(%rbp), %rdi
callq 0x15890
leaq -0x1d0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
movl $0xd0, %edx
callq 0x32c0
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x3c0(%rbp), %rcx
leaq -0x1d0(%rbp), %rdi
callq 0x15a40
movq $0x0, -0x428(%rbp)
movq -0x428(%rbp), %rax
shlq $0x5, %rax
cmpq 0x10(%rbp), %rax
jae 0x15ee3
leaq -0x42c(%rbp), %rdi
movq -0x428(%rbp), %rax
addq $0x1, %rax
movl %eax, %esi
callq 0x15f70
leaq -0x2a0(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
movl $0xd0, %edx
callq 0x32c0
leaq -0x42c(%rbp), %rsi
leaq -0x3c0(%rbp), %rcx
leaq -0x2a0(%rbp), %rdi
movl $0x4, %edx
callq 0x15a40
leaq -0x450(%rbp), %rdi
leaq -0x3c0(%rbp), %rdx
leaq -0x420(%rbp), %rcx
leaq -0x2a0(%rbp), %rsi
callq 0x15af0
movq -0x450(%rbp), %rax
movq %rax, -0x470(%rbp)
movq -0x448(%rbp), %rax
movq %rax, -0x468(%rbp)
movq -0x440(%rbp), %rax
movq %rax, -0x460(%rbp)
movq -0x438(%rbp), %rax
movq %rax, -0x458(%rbp)
movq $0x2, -0x478(%rbp)
movq -0x478(%rbp), %rax
cmpq -0x28(%rbp), %rax
ja 0x15e79
leaq -0x2a0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
movl $0xd0, %edx
callq 0x32c0
leaq -0x450(%rbp), %rsi
leaq -0x3c0(%rbp), %rcx
leaq -0x2a0(%rbp), %rdi
movl $0x20, %edx
callq 0x15a40
leaq -0x450(%rbp), %rdi
leaq -0x3c0(%rbp), %rdx
leaq -0x420(%rbp), %rcx
leaq -0x2a0(%rbp), %rsi
callq 0x15af0
movl $0x0, -0x47c(%rbp)
cmpl $0x20, -0x47c(%rbp)
jge 0x15e60
movslq -0x47c(%rbp), %rax
movzbl -0x450(%rbp,%rax), %edx
movslq -0x47c(%rbp), %rax
movzbl -0x470(%rbp,%rax), %ecx
xorl %edx, %ecx
movb %cl, -0x470(%rbp,%rax)
movl -0x47c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x47c(%rbp)
jmp 0x15e1f
jmp 0x15e62
movq -0x478(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x478(%rbp)
jmp 0x15dac
movq 0x10(%rbp), %rax
movq -0x428(%rbp), %rcx
shlq $0x5, %rcx
subq %rcx, %rax
movq %rax, -0x488(%rbp)
cmpq $0x20, -0x488(%rbp)
jbe 0x15ea7
movq $0x20, -0x488(%rbp)
movq -0x30(%rbp), %rdi
movq -0x428(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
leaq -0x470(%rbp), %rsi
movq -0x488(%rbp), %rdx
callq 0x32c0
movq -0x428(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x428(%rbp)
jmp 0x15ce3
leaq -0x100(%rbp), %rdi
movl $0xd0, %esi
callq 0x156d0
leaq -0x1d0(%rbp), %rdi
movl $0xd0, %esi
callq 0x156d0
leaq -0x2a0(%rbp), %rdi
movl $0xd0, %esi
callq 0x156d0
leaq -0x3c0(%rbp), %rdi
movl $0x120, %esi            # imm = 0x120
callq 0x156d0
leaq -0x420(%rbp), %rdi
movl $0x60, %esi
callq 0x156d0
leaq -0x450(%rbp), %rdi
movl $0x20, %esi
callq 0x156d0
leaq -0x470(%rbp), %rdi
movl $0x20, %esi
callq 0x156d0
addq $0x490, %rsp            # imm = 0x490
popq %rbp
retq
nopw %cs:(%rax,%rax)