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

/* Variables and functions */
int /*<<< orphan*/ SHA512_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA512_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA512_Update(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ strcpy(unsigned char *, unsigned char *);
int strlen(unsigned char *);
void generate_hash(unsigned char *hash, unsigned char *salt,
                   unsigned char *password, int salt_length) {
  SHA512_CTX c;
  unsigned char buffer[salt_length + strlen(password) + 1];
  strcpy(buffer, password);
  memcpy(buffer + strlen(password), salt, salt_length);
  SHA512_Init(&c);
  SHA512_Update(&c, buffer, strlen(password) + salt_length);
  SHA512_Final(hash, &c);
}


x86 assembly (clang, -O0):
<generate_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%ecx
mov    %eax,%edx
mov    %ecx,%eax
mov    %edx,%ecx
lea    0x1(%rax,%rcx,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <memcpy@plt>
lea    -0x20(%rbp),%rdi
call   1080 <SHA512_Init@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
add    -0x1c(%rbp),%edx
lea    -0x20(%rbp),%rdi
call   1050 <SHA512_Update@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <SHA512_Final@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_hash>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r13d
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,-0x30(%rbp)
mov    %rdx,%rdi
call   1040 <strlen@plt>
mov    %rsp,%r14
add    %r13d,%eax
add    $0x1,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
call   1060 <memcpy@plt>
lea    -0x34(%rbp),%r12
mov    %r12,%rdi
call   1080 <SHA512_Init@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %eax,%r13d
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1050 <SHA512_Update@plt>
mov    -0x30(%rbp),%rdi
mov    %r12,%rsi
call   1070 <SHA512_Final@plt>
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @generate_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 i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%12 = load i32, i32* %8
%13 = load i8*, i8** %7
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %12, %14
%16 = add nsw i32 %15, 1
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %10
%19 = alloca i8, i64 %17
store i64 %17, i64* %11
%20 = load i8*, i8** %7
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i8*, i8** %7
%23 = call i32 @strlen(i8* %22)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %19, i64 %24
%26 = load i8*, i8** %6
%27 = load i32, i32* %8
%28 = call i32 @memcpy(i8* %25, i8* %26, i32 %27)
%29 = call i32 @SHA512_Init(i32* %9)
%30 = load i8*, i8** %7
%31 = call i32 @strlen(i8* %30)
%32 = load i32, i32* %8
%33 = add nsw i32 %31, %32
%34 = call i32 @SHA512_Update(i32* %9, i8* %19, i32 %33)
%35 = load i8*, i8** %5
%36 = call i32 @SHA512_Final(i8* %35, i32* %9)
%37 = load i8*, i8** %10
ret void
}

LLVM IR (-O2):
define void @generate_hash(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = tail call i32 @strlen(i8* %2)
%8 = add i32 %3, 1
%9 = add i32 %8, %7
%10 = zext i32 %9 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = call i32 @strcpy(i8* %12, i8* %2)
%14 = call i32 @strlen(i8* %2)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = call i32 @memcpy(i8* %16, i8* %1, i32 %3)
%18 = call i32 @SHA512_Init(i32* %5)
%19 = call i32 @strlen(i8* %2)
%20 = add nsw i32 %19, %3
%21 = call i32 @SHA512_Update(i32* %5, i8* %12, i32 %20)
%22 = call i32 @SHA512_Final(i8* %0, i32* %5)
ret void
}