#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ digest;

/* Variables and functions */
int /*<<< orphan*/ SHA256(unsigned char const *, int, unsigned char *);
int /*<<< orphan*/ memcpy(char *, unsigned char *, int);
int strlen(char const *);
void key_from_password(const char *a_password, char *a_key) {
  unsigned char digest[256 / 8] = {0};
  int i;
  SHA256((const unsigned char *)a_password, strlen(a_password), digest);
  for (i = 0; i < 40872; i++) {
    SHA256(digest, 32, digest);
  }
  memcpy(a_key, digest, sizeof(digest));
}


x86 assembly (clang, -O0):
<key_from_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
lea    -0x30(%rbp),%rdx
call   1030 <SHA256@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x9fa8,-0x34(%rbp)
jge    11b4 <key_from_password+0x74>
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rdx
mov    $0x20,%esi
call   1030 <SHA256@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1187 <key_from_password+0x47>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1060 <memcpy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<key_from_password>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
call   1040 <strlen@plt>
mov    %rsp,%rbx
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1030 <SHA256@plt>
mov    $0x9fa8,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x20,%esi
mov    %rbx,%rdx
call   1030 <SHA256@plt>
add    $0xffffffff,%ebp
jne    1170 <key_from_password+0x40>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x20,%edx
call   1050 <memcpy@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @key_from_password(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [32 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = bitcast [32 x i8]* %5 to i8*
%8 = load i8*, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%12 = call i32 @SHA256(i8* %8, i32 %10, i8* %11)
store i32 0, i32* %6
br label %13
13: ; preds = %20, %2
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 40872
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%19 = call i32 @SHA256(i8* %17, i32 32, i8* %18)
br label %20
20: ; preds = %16
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %13
23: ; preds = %13
%24 = load i8*, i8** %4
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%26 = call i32 @memcpy(i8* %24, i8* %25, i32 32)
ret void
}

LLVM IR (-O2):
define void @key_from_password(i8* %0, i8* %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %0)
%6 = call i32 @SHA256(i8* %0, i32 %5, i8* %4)
br label %7
7: ; preds = %2, %7
%8 = phi i32 [ 0, %2 ], [ %10, %7 ]
%9 = call i32 @SHA256(i8* %4, i32 32, i8* %4)
%10 = add nuw nsw i32 %8, 1
%11 = icmp eq i32 %10, 40872
br i1 %11, label %12, label %7
12: ; preds = %7
%13 = call i32 @memcpy(i8* %1, i8* %4, i32 32)
ret void
}