#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*/ free(char *);
char *malloc(size_t);
int md5_hash(char *, size_t, char *);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
int md5_encrypt(const char *passwd, const char *salt, size_t salt_len,
                char *buf) {
  size_t passwd_len = strlen(passwd);
  char *crypt_buf = malloc(passwd_len + salt_len);
  int ret;
  if (!crypt_buf)
    return 0;
  strcpy(crypt_buf, passwd);
  memcpy(crypt_buf + passwd_len, salt, salt_len);
  ret = md5_hash(crypt_buf, passwd_len + salt_len, buf);
  free(crypt_buf);
  return ret;
}


x86 assembly (clang, -O0):
<md5_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
add    -0x20(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11ad <md5_encrypt+0x4d>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <md5_encrypt+0x96>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
add    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1080 <md5_hash@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<md5_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
call   1050 <strlen@plt>
mov    %rax,%rbp
lea    (%rax,%r15,1),%r13
mov    %r13,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11cd <md5_encrypt+0x6d>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
add    %rbx,%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1060 <memcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    (%rsp),%rdx
call   1080 <md5_hash@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    11cf <md5_encrypt+0x6f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @md5_encrypt(i8* %0, i8* %1, i64 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
%13 = load i8*, i8** %6
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %10
%15 = load i64, i64* %10
%16 = load i64, i64* %8
%17 = add i64 %15, %16
%18 = call i8* @malloc(i64 %17)
store i8* %18, i8** %11
%19 = load i8*, i8** %11
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %4
store i32 0, i32* %5
br label %41
22: ; preds = %4
%23 = load i8*, i8** %11
%24 = load i8*, i8** %6
%25 = call i32 @strcpy(i8* %23, i8* %24)
%26 = load i8*, i8** %11
%27 = load i64, i64* %10
%28 = getelementptr inbounds i8, i8* %26, i64 %27
%29 = load i8*, i8** %7
%30 = load i64, i64* %8
%31 = call i32 @memcpy(i8* %28, i8* %29, i64 %30)
%32 = load i8*, i8** %11
%33 = load i64, i64* %10
%34 = load i64, i64* %8
%35 = add i64 %33, %34
%36 = load i8*, i8** %9
%37 = call i32 @md5_hash(i8* %32, i64 %35, i8* %36)
store i32 %37, i32* %12
%38 = load i8*, i8** %11
%39 = call i32 @free(i8* %38)
%40 = load i32, i32* %12
store i32 %40, i32* %5
br label %41
41: ; preds = %22, %21
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
define i32 @md5_encrypt(i8* %0, i8* %1, i64 %2, i8* %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = add i64 %5, %2
%7 = tail call i8* @malloc(i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %15, label %9
9: ; preds = %4
%10 = tail call i32 @strcpy(i8* %7, i8* %0)
%11 = getelementptr inbounds i8, i8* %7, i64 %5
%12 = tail call i32 @memcpy(i8* %11, i8* %1, i64 %2)
%13 = tail call i32 @md5_hash(i8* %7, i64 %6, i8* %3)
%14 = tail call i32 @free(i8* %7)
br label %15
15: ; preds = %4, %9
%16 = phi i32 [ %13, %9 ], [ 0, %4 ]
ret i32 %16
}