#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 *);
int getpid();
char *malloc(int);
char *mongo_util_md5_hex(char *, int);
int snprintf(char *, int, char *, int, char *, char *);
int strlen(char *);
char *mongo_server_create_hashed_password(char *username, char *password) {
  int salt_length, length;
  char *hash, *salt;
  salt_length = strlen(password) + strlen(username) + 10 + 1;
  salt = malloc(salt_length);
  length = snprintf(salt, salt_length, "%d%s%s", getpid(), password, username);
  hash = mongo_util_md5_hex(salt, length);
  free(salt);
  return hash;
}


x86 assembly (clang, -O0):
<mongo_server_create_hashed_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
add    $0xa,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    %eax,%ecx
mov    -0x10(%rbp),%r8
mov    -0x8(%rbp),%r9
lea    0xe32(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1080 <mongo_util_md5_hex@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mongo_server_create_hashed_password>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%ebp
add    $0xb,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe63(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1060 <snprintf@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <mongo_util_md5_hex@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d%s%s\00"
define i8* @mongo_server_create_hashed_password(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %10, %12
%14 = add nsw i32 %13, 10
%15 = add nsw i32 %14, 1
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = load i32, i32* %5
%20 = call i32 (...) @getpid()
%21 = load i8*, i8** %4
%22 = load i8*, i8** %3
%23 = call i32 @snprintf(i8* %18, i32 %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %20, i8* %21, i8* %22)
store i32 %23, i32* %6
%24 = load i8*, i8** %8
%25 = load i32, i32* %6
%26 = call i8* @mongo_util_md5_hex(i8* %24, i32 %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %8
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %7
ret i8* %29
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d%s%s\00"
define i8* @mongo_server_create_hashed_password(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i32 @strlen(i8* %0)
%5 = add i32 %3, 11
%6 = add i32 %5, %4
%7 = tail call i8* @malloc(i32 %6)
%8 = tail call i32 (...) @getpid()
%9 = tail call i32 @snprintf(i8* %7, i32 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %1, i8* %0)
%10 = tail call i8* @mongo_util_md5_hex(i8* %7, i32 %9)
%11 = tail call i32 @free(i8* %7)
ret i8* %10
}