#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*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ PKCS5_PBKDF2_HMAC_SHA1(char *, int /*<<< orphan*/,
                                          unsigned char *, int /*<<< orphan*/,
                                          int, int, unsigned char *);
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strlen(char *);
uint8_t *generatePMK(const char *pass, char *salt) {
  unsigned char digest[32];
  uint8_t *pmk;
  pmk = (uint8_t *)malloc(32);
  if (pmk == NULL) {
    perror("can't allocate memory");
    exit(1);
  }
  PKCS5_PBKDF2_HMAC_SHA1((char *)pass, strlen((char *)pass),
                         (unsigned char *)salt, strlen(salt), 4096, 32, digest);
  memcpy(pmk, digest, 32);
  return (pmk);
}


x86 assembly (clang, -O0):
<generatePMK>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    119f <generatePMK+0x3f>
lea    0xe70(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    %eax,%ecx
lea    -0x30(%rbp),%rax
mov    $0x1000,%r8d
mov    $0x20,%r9d
mov    %rax,(%rsp)
call   1060 <PKCS5_PBKDF2_HMAC_SHA1@plt>
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generatePMK>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x20,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11da <generatePMK+0x7a>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x10(%rsp),%r12
mov    %r12,(%rsp)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    %eax,%ecx
mov    $0x1000,%r8d
mov    $0x20,%r9d
call   1060 <PKCS5_PBKDF2_HMAC_SHA1@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"can't allocate memory\00"
define i32* @generatePMK(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 = call i64 @malloc(i32 32)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = load i8*, i8** %4
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%22 = call i32 @PKCS5_PBKDF2_HMAC_SHA1(i8* %15, i32 %17, i8* %18, i32 %20, i32 4096, i32 32, i8* %21)
%23 = load i32*, i32** %6
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%25 = call i32 @memcpy(i32* %23, i8* %24, i32 32)
%26 = load i32*, i32** %6
ret i32* %26
}

LLVM IR (-O2):
@.str = [22 x i8] c"can't allocate memory\00"
define i32* @generatePMK(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 i64 @malloc(i32 32)
%6 = inttoptr i64 %5 to i32*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = tail call i32 @strlen(i8* %0)
%13 = tail call i32 @strlen(i8* %1)
%14 = call i32 @PKCS5_PBKDF2_HMAC_SHA1(i8* %0, i32 %12, i8* %1, i32 %13, i32 4096, i32 32, i8* %4)
%15 = call i32 @memcpy(i32* %6, i8* %4, i32 32)
ret i32* %6
}