#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*/ *MD5(unsigned char const *, int /*<<< orphan*/,
                        unsigned char *);
int MD5_DIGEST_LENGTH;
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ strlen(char const *);
int str2md5str(char *buf, unsigned int buf_size, const char *str) {
  if (buf_size < (MD5_DIGEST_LENGTH * 2 + 1))
    return 1;
  unsigned char md5digest[MD5_DIGEST_LENGTH];
  if (MD5((const unsigned char *)str, strlen(str), md5digest) == NULL)
    return 1;
  char *p = buf;
  for (int i = 0; i < MD5_DIGEST_LENGTH; i++) {
    sprintf(p, "%02x", md5digest[i]);
    p += 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<str2md5str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e93(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jae    1169 <str2md5str+0x39>
movl   $0x1,-0x4(%rbp)
jmp    123e <str2md5str+0x10e>
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rdx
mov    %eax,%esi
call   1040 <MD5@plt>
cmp    $0x0,%rax
jne    11d2 <str2md5str+0xa2>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1237 <str2md5str+0x107>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%eax
jge    1229 <str2md5str+0xf9>
mov    -0x50(%rbp),%rax
mov    -0x40(%rbp),%rdi
movslq -0x44(%rbp),%rcx
lea    0xdfa(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1050 <sprintf@plt>
mov    -0x40(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11e1 <str2md5str+0xb1>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2md5str>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    0x2e98(%rip),%r13
mov    0x0(%r13),%edx
lea    (%rdx,%rdx,1),%ecx
add    $0x1,%ecx
mov    $0x1,%eax
cmp    %esi,%ecx
ja     11e1 <str2md5str+0xb1>
mov    %rdi,%rbx
mov    %rsp,%r15
mov    %rsp,%r14
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
sub    %rdx,%r14
mov    %r14,%rsp
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %r12,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1040 <MD5@plt>
test   %rax,%rax
je     11d9 <str2md5str+0xa9>
cmpl   $0x0,0x0(%r13)
jle    11d5 <str2md5str+0xa5>
mov    %r15,-0x30(%rbp)
lea    0xe5e(%rip),%r12
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r14,%r15,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <sprintf@plt>
add    $0x2,%rbx
add    $0x1,%r15
movslq 0x0(%r13),%rax
cmp    %rax,%r15
jl     11b0 <str2md5str+0x80>
mov    -0x30(%rbp),%r15
xor    %eax,%eax
jmp    11de <str2md5str+0xae>
mov    $0x1,%eax
mov    %r15,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MD5_DIGEST_LENGTH = global i32 0
@.str = [5 x i8] c"%02x\00"
define i32 @str2md5str(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%13 = load i32, i32* %6
%14 = load i32, i32* @MD5_DIGEST_LENGTH
%15 = mul nsw i32 %14, 2
%16 = add nsw i32 %15, 1
%17 = icmp ult i32 %13, %16
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 1, i32* %4
br label %51
19: ; preds = %3
%20 = load i32, i32* @MD5_DIGEST_LENGTH
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %8
%23 = alloca i8, i64 %21
store i64 %21, i64* %9
%24 = load i8*, i8** %7
%25 = load i8*, i8** %7
%26 = call i32 @strlen(i8* %25)
%27 = call i32* @MD5(i8* %24, i32 %26, i8* %23)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %19
store i32 1, i32* %4
store i32 1, i32* %10
br label %49
30: ; preds = %19
%31 = load i8*, i8** %5
store i8* %31, i8** %11
store i32 0, i32* %12
br label %32
32: ; preds = %45, %30
%33 = load i32, i32* %12
%34 = load i32, i32* @MD5_DIGEST_LENGTH
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %48
36: ; preds = %32
%37 = load i8*, i8** %11
%38 = load i32, i32* %12
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %23, i64 %39
%41 = load i8, i8* %40
%42 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %41)
%43 = load i8*, i8** %11
%44 = getelementptr inbounds i8, i8* %43, i64 2
store i8* %44, i8** %11
br label %45
45: ; preds = %36
%46 = load i32, i32* %12
%47 = add nsw i32 %46, 1
store i32 %47, i32* %12
br label %32
48: ; preds = %32
store i32 0, i32* %4
store i32 1, i32* %10
br label %49
49: ; preds = %48, %29
%50 = load i8*, i8** %8
br label %51
51: ; preds = %49, %18
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
@MD5_DIGEST_LENGTH = global i32 0
@.str = [5 x i8] c"%02x\00"
define i32 @str2md5str(i8* nocapture writeonly %0, i32 %1, i8* %2) {
%4 = load i32, i32* @MD5_DIGEST_LENGTH
%5 = shl nsw i32 %4, 1
%6 = or i32 %5, 1
%7 = icmp ugt i32 %6, %1
br i1 %7, label %31, label %8
8: ; preds = %3
%9 = zext i32 %4 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = tail call i32 @strlen(i8* %2)
%13 = call i32* @MD5(i8* %2, i32 %12, i8* %11)
%14 = icmp eq i32* %13, null
br i1 %14, label %29, label %15
15: ; preds = %8
%16 = load i32, i32* @MD5_DIGEST_LENGTH
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %15, %18
%19 = phi i64 [ %25, %18 ], [ 0, %15 ]
%20 = phi i8* [ %24, %18 ], [ %0, %15 ]
%21 = getelementptr inbounds i8, i8* %11, i64 %19
%22 = load i8, i8* %21
%23 = call i32 @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %22)
%24 = getelementptr inbounds i8, i8* %20, i64 2
%25 = add nuw nsw i64 %19, 1
%26 = load i32, i32* @MD5_DIGEST_LENGTH
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %18, label %29
29: ; preds = %18, %15, %8
%30 = phi i32 [ 1, %8 ], [ 0, %15 ], [ 0, %18 ]
br label %31
31: ; preds = %3, %29
%32 = phi i32 [ %30, %29 ], [ 1, %3 ]
ret i32 %32
}