#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(int);
char *mongo_util_md5_hex(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int strlen(char *);
char *mongo_authenticate_hash_user_password(char *username, char *password) {
  char *salted;
  int length;
  char *hash;
  length = strlen(username) + 7 + strlen(password) + 1;
  salted = malloc(length);
  snprintf(salted, length, "%s:mongo:%s", username, password);
  hash = mongo_util_md5_hex(salted, length - 1);
  free(salted);
  return hash;
}


x86 assembly (clang, -O0):
<mongo_authenticate_hash_user_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x7,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe59(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
call   1070 <mongo_util_md5_hex@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mongo_authenticate_hash_user_password>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%r12d
add    $0x7,%r12d
add    %eax,%ebx
add    $0x8,%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
lea    0xe75(%rip),%rdx
mov    %rax,%rdi
mov    %ebx,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1050 <snprintf@plt>
mov    %rbp,%rdi
mov    %r12d,%esi
call   1070 <mongo_util_md5_hex@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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