#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 */
char *malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
char *sprint_md5_hash(int *hashval) {
  int x = 0;
  char *out = NULL;
  out = malloc(35);
  memset(out, 0x00, 35);
  strcpy(out, "$1$");
  for (x = 0; x < 4; x++) {
    sprintf(out + (x * 8) + 3, "%08x", hashval[x]);
  }
  out[32] = 0;
  return out;
}


x86 assembly (clang, -O0):
<sprint_md5_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x23,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x23,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jge    11d2 <sprint_md5_hash+0x92>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rdi
add    $0x3,%rdi
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe45(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1190 <sprint_md5_hash+0x50>
mov    -0x18(%rbp),%rax
movb   $0x0,0x20(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sprint_md5_hash>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x23,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x23,%edx
call   1040 <memset@plt>
lea    0xe95(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0x3(%rbx),%rdi
mov    (%r14),%edx
lea    0xe83(%rip),%r15
mov    %r15,%rsi
call   1060 <sprintf@plt>
lea    0xb(%rbx),%rdi
mov    0x4(%r14),%edx
mov    %r15,%rsi
call   1060 <sprintf@plt>
lea    0x13(%rbx),%rdi
mov    0x8(%r14),%edx
mov    %r15,%rsi
call   1060 <sprintf@plt>
lea    0x1b(%rbx),%rdi
mov    0xc(%r14),%edx
mov    %r15,%rsi
call   1060 <sprintf@plt>
movb   $0x0,0x20(%rbx)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"$1$\00"
@.str.1 = [5 x i8] c"%08x\00"
define i8* @sprint_md5_hash(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
store i32* %0, i32** %2
store i32 0, i32* %3
store i8* null, i8** %4
%5 = call i8* @malloc(i32 35)
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = call i32 @memset(i8* %6, i32 0, i32 35)
%8 = load i8*, i8** %4
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %10
10: ; preds = %26, %1
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = load i8*, i8** %4
%15 = load i32, i32* %3
%16 = mul nsw i32 %15, 8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 3
%20 = load i32*, i32** %2
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %13
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %10
29: ; preds = %10
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 32
store i8 0, i8* %31
%32 = load i8*, i8** %4
ret i8* %32
}

LLVM IR (-O2):
@.str = [4 x i8] c"$1$\00"
@.str.1 = [5 x i8] c"%08x\00"
define i8* @sprint_md5_hash(i32* nocapture %0) {
%2 = tail call dereferenceable_or_null(35) i8* @malloc(i32 35)
%3 = tail call i32 @memset(i8* %2, i32 0, i32 35)
%4 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds i8, i8* %2, i64 3
%6 = load i32, i32* %0
%7 = tail call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds i8, i8* %2, i64 11
%9 = getelementptr inbounds i32, i32* %0, i64 1
%10 = load i32, i32* %9
%11 = tail call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds i8, i8* %2, i64 19
%13 = getelementptr inbounds i32, i32* %0, i64 2
%14 = load i32, i32* %13
%15 = tail call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds i8, i8* %2, i64 27
%17 = getelementptr inbounds i32, i32* %0, i64 3
%18 = load i32, i32* %17
%19 = tail call i32 @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds i8, i8* %2, i64 32
store i8 0, i8* %20
ret i8* %2
}