void generate_master_key(char *passwd, char *key) {
  unsigned char salt[16];
  if (!(RAND_bytes(salt, sizeof(salt)))) {
    printf("ERROR: call to RAND_bytes() failed\n");
    exit(1);
  }
  PKCS5_PBKDF2_HMAC_SHA1(passwd, strlen(passwd), (unsigned char *)salt,
                         strlen(salt), 1000, 16, key);
}


x86 assembly (clang, -O0):
<generate_master_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x10,%esi
mov    $0x0,%al
call   1040 <RAND_bytes@plt>
cmp    $0x0,%eax
jne    1191 <generate_master_key+0x41>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    $0x3e8,%r8d
mov    $0x10,%r9d
mov    %rax,(%rsp)
mov    $0x0,%al
call   1060 <PKCS5_PBKDF2_HMAC_SHA1@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_master_key>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
xor    %eax,%eax
call   1050 <RAND_bytes@plt>
test   %eax,%eax
je     11bd <generate_master_key+0x6d>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
lea    0x10(%rsp),%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r14,(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rax,%rcx
mov    $0x3e8,%r8d
mov    $0x10,%r9d
xor    %eax,%eax
call   1060 <PKCS5_PBKDF2_HMAC_SHA1@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe3c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"ERROR: call to RAND_bytes() failed\0A\00"
define void @generate_master_key(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [16 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%7 = call i32 (i8*, i64, ...) bitcast (i32 (...)* @RAND_bytes to i32 (i8*, i64, ...)*)(i8* %6, i64 16)
%8 = icmp ne i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
unreachable
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = load i8*, i8** %3
%14 = call i64 @strlen(i8* %13)
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%17 = call i64 @strlen(i8* %16)
%18 = load i8*, i8** %4
%19 = call i32 (i8*, i64, i8*, i64, i32, i32, i8*, ...) bitcast (i32 (...)* @PKCS5_PBKDF2_HMAC_SHA1 to i32 (i8*, i64, i8*, i64, i32, i32, i8*, ...)*)(i8* %12, i64 %14, i8* %15, i64 %17, i32 1000, i32 16, i8* %18)
ret void
}

LLVM IR (-O2):
@str = [35 x i8] c"ERROR: call to RAND_bytes() failed\00"
define void @generate_master_key(i8* %0, i8* %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = call i32 (i8*, i64, ...) bitcast (i32 (...)* @RAND_bytes to i32 (i8*, i64, ...)*)(i8* %4, i64 16)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
unreachable
9: ; preds = %2
%10 = call i64 @strlen(i8* dereferenceable(1) %0)
%11 = call i64 @strlen(i8* %4)
%12 = call i32 (i8*, i64, i8*, i64, i32, i32, i8*, ...) bitcast (i32 (...)* @PKCS5_PBKDF2_HMAC_SHA1 to i32 (i8*, i64, i8*, i64, i32, i32, i8*, ...)*)(i8* %0, i64 %10, i8* %4, i64 %11, i32 1000, i32 16, i8* %1)
ret void
}