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

/* Variables and functions */
int /*<<< orphan*/ SHA512(unsigned char *, int, unsigned char *);
int SHA512_DIGEST_LENGTH;
int /*<<< orphan*/ base64_encode(unsigned char *, int, char *, int);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
void inner_password_hash(const char *password, const char *salt, char *hash,
                         int hash_len) {
  int pw_len = strlen(password);
  char *combined = (char *)malloc(pw_len + strlen(salt) + 1);
  strcpy(combined, password);
  strcpy(combined + pw_len, salt);
  unsigned char raw_hash[SHA512_DIGEST_LENGTH];
  SHA512((unsigned char *)combined, strlen(combined), raw_hash);
  base64_encode(raw_hash, SHA512_DIGEST_LENGTH, hash, hash_len);
  free(combined);
}


x86 assembly (clang, -O0):
<inner_password_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x4c(%rbp),%ecx
mov    %eax,%edx
mov    %ecx,%eax
mov    %edx,%ecx
lea    0x1(%rax,%rcx,1),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    %eax,%esi
call   1080 <SHA512@plt>
mov    -0x40(%rbp),%rdi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1070 <base64_encode@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inner_password_hash>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,-0x2c(%rbp)
mov    %rdx,-0x38(%rbp)
mov    %rsi,%r12
mov    %rdi,%r13
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    (%r14,%rax,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
movslq %r14d,%rdi
add    %r15,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    0x2e2b(%rip),%r14
mov    (%r14),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1080 <SHA512@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
mov    -0x38(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1070 <base64_encode@plt>
mov    %r15,%rdi
call   1030 <free@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHA512_DIGEST_LENGTH = global i32 0
define void @inner_password_hash(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = load i8*, i8** %6
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %15, %17
%19 = add nsw i32 %18, 1
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %10
%22 = load i8*, i8** %10
%23 = load i8*, i8** %5
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %10
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8*, i8** %6
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = load i32, i32* @SHA512_DIGEST_LENGTH
%32 = zext i32 %31 to i64
%33 = call i8* @llvm.stacksave()
store i8* %33, i8** %11
%34 = alloca i8, i64 %32
store i64 %32, i64* %12
%35 = load i8*, i8** %10
%36 = load i8*, i8** %10
%37 = call i32 @strlen(i8* %36)
%38 = call i32 @SHA512(i8* %35, i32 %37, i8* %34)
%39 = load i32, i32* @SHA512_DIGEST_LENGTH
%40 = load i8*, i8** %7
%41 = load i32, i32* %8
%42 = call i32 @base64_encode(i8* %34, i32 %39, i8* %40, i32 %41)
%43 = load i8*, i8** %10
%44 = call i32 @free(i8* %43)
%45 = load i8*, i8** %11
ret void
}

LLVM IR (-O2):
@SHA512_DIGEST_LENGTH = global i32 0
define void @inner_password_hash(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i32 @strlen(i8* %1)
%7 = add i32 %5, 1
%8 = add i32 %7, %6
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @strcpy(i8* %10, i8* %0)
%12 = sext i32 %5 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = tail call i32 @strcpy(i8* %13, i8* %1)
%15 = load i32, i32* @SHA512_DIGEST_LENGTH
%16 = zext i32 %15 to i64
%17 = alloca i8, i64 %16
%18 = tail call i32 @strlen(i8* %10)
%19 = call i32 @SHA512(i8* %10, i32 %18, i8* %17)
%20 = load i32, i32* @SHA512_DIGEST_LENGTH
%21 = call i32 @base64_encode(i8* %17, i32 %20, i8* %2, i32 %3)
%22 = call i32 @free(i8* %10)
ret void
}