#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ printf(char *, size_t);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
const char *MD5Key2String(const unsigned char *s, size_t s_len, char *buf,
                          size_t size) {
  size_t i, n;
  char output1[34], *ptr;
  unsigned char digest[16];
  if (s_len != 16) {
    printf("s_len(%d) != 16\n", s_len);
    assert(0);
  }
  if (size < 32) {
    printf("size(%d) < 32\n", size);
    assert(0);
  }
  memcpy(digest, s, 16);
  for (i = 0; i < 16; i++) {
    sprintf(&(output1[2 * i]), "%02x", (unsigned char)digest[i]);
    sprintf(&(output1[2 * i + 1]), "%02x", (unsigned char)(digest[i] << 4));
  }
  ptr = buf;
  size--;
  n = size > 32 ? 32 : size;
  for (i = 0; i < n; i++)
    *ptr++ = output1[i];
  *ptr = '\0';
  return (buf);
}


x86 assembly (clang, -O0):
<MD5Key2String>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x10,-0x10(%rbp)
je     117d <MD5Key2String+0x3d>
mov    -0x10(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <assert@plt>
cmpq   $0x20,-0x20(%rbp)
jae    119f <MD5Key2String+0x5f>
mov    -0x20(%rbp),%rsi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <assert@plt>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
movq   $0x0,-0x28(%rbp)
cmpq   $0x10,-0x28(%rbp)
jae    1227 <MD5Key2String+0xe7>
mov    -0x28(%rbp),%rax
shl    $0x1,%rax
lea    -0x60(%rbp),%rdi
add    %rax,%rdi
mov    -0x28(%rbp),%rax
lea    0xe42(%rip),%rsi
movzbl -0x80(%rbp,%rax,1),%edx
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rax
shl    $0x1,%rax
add    $0x1,%rax
lea    -0x60(%rbp),%rdi
add    %rax,%rdi
mov    -0x28(%rbp),%rax
movzbl -0x80(%rbp,%rax,1),%eax
shl    $0x4,%eax
lea    0xe12(%rip),%rsi
movzbl %al,%edx
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11b9 <MD5Key2String+0x79>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x20,-0x20(%rbp)
jbe    1257 <MD5Key2String+0x117>
mov    $0x20,%eax
mov    %rax,-0x88(%rbp)
jmp    1262 <MD5Key2String+0x122>
mov    -0x20(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    12ad <MD5Key2String+0x16d>
mov    -0x28(%rbp),%rax
mov    -0x60(%rbp,%rax,1),%cl
mov    -0x68(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x68(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1275 <MD5Key2String+0x135>
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MD5Key2String>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rdi,%r15
cmp    $0x10,%rsi
je     116f <MD5Key2String+0x2f>
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <assert@plt>
cmp    $0x1f,%r12
ja     118b <MD5Key2String+0x4b>
lea    0xe95(%rip),%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <assert@plt>
mov    %rsp,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0x10(%rsp),%r13
xor    %ebx,%ebx
lea    0xe77(%rip),%r15
nopl   0x0(%rax)
movzbl (%rsp,%rbx,1),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1060 <sprintf@plt>
lea    0x1(%r13),%rdi
movzbl (%rsp,%rbx,1),%eax
shl    $0x4,%al
movzbl %al,%edx
mov    %r15,%rsi
call   1060 <sprintf@plt>
add    $0x1,%rbx
add    $0x2,%r13
cmp    $0x10,%rbx
jne    11b0 <MD5Key2String+0x70>
add    $0xffffffffffffffff,%r12
cmp    $0x20,%r12
mov    $0x20,%ebx
cmovb  %r12,%rbx
mov    %r14,%rax
test   %rbx,%rbx
je     1212 <MD5Key2String+0xd2>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
add    %r14,%rbx
mov    %rbx,%rax
movb   $0x0,(%rax)
mov    %r14,%rax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"s_len(%d) != 16\0A\00"
@.str.1 = [15 x i8] c"size(%d) < 32\0A\00"
@.str.2 = [5 x i8] c"%02x\00"
define i8* @MD5Key2String(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca [34 x i8]
%12 = alloca i8*
%13 = alloca [16 x i8]
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%14 = load i64, i64* %6
%15 = icmp ne i64 %14, 16
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i64, i64* %6
%18 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %17)
%19 = call i32 @assert(i32 0)
br label %20
20: ; preds = %16, %4
%21 = load i64, i64* %8
%22 = icmp ult i64 %21, 32
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i64, i64* %8
%25 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i64 %24)
%26 = call i32 @assert(i32 0)
br label %27
27: ; preds = %23, %20
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%29 = load i8*, i8** %5
%30 = call i32 @memcpy(i8* %28, i8* %29, i32 16)
store i64 0, i64* %9
br label %31
31: ; preds = %53, %27
%32 = load i64, i64* %9
%33 = icmp ult i64 %32, 16
br i1 %33, label %34, label %56
34: ; preds = %31
%35 = load i64, i64* %9
%36 = mul i64 2, %35
%37 = getelementptr inbounds [34 x i8], [34 x i8]* %11, i64 0, i64 %36
%38 = load i64, i64* %9
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %40)
%42 = load i64, i64* %9
%43 = mul i64 2, %42
%44 = add i64 %43, 1
%45 = getelementptr inbounds [34 x i8], [34 x i8]* %11, i64 0, i64 %44
%46 = load i64, i64* %9
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = shl i32 %49, 4
%51 = trunc i32 %50 to i8
%52 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %51)
br label %53
53: ; preds = %34
%54 = load i64, i64* %9
%55 = add i64 %54, 1
store i64 %55, i64* %9
br label %31
56: ; preds = %31
%57 = load i8*, i8** %7
store i8* %57, i8** %12
%58 = load i64, i64* %8
%59 = add i64 %58, -1
store i64 %59, i64* %8
%60 = load i64, i64* %8
%61 = icmp ugt i64 %60, 32
br i1 %61, label %62, label %63
62: ; preds = %56
br label %65
63: ; preds = %56
%64 = load i64, i64* %8
br label %65
65: ; preds = %63, %62
%66 = phi i64 [ 32, %62 ], [ %64, %63 ]
store i64 %66, i64* %10
store i64 0, i64* %9
br label %67
67: ; preds = %77, %65
%68 = load i64, i64* %9
%69 = load i64, i64* %10
%70 = icmp ult i64 %68, %69
br i1 %70, label %71, label %80
71: ; preds = %67
%72 = load i64, i64* %9
%73 = getelementptr inbounds [34 x i8], [34 x i8]* %11, i64 0, i64 %72
%74 = load i8, i8* %73
%75 = load i8*, i8** %12
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %12
store i8 %74, i8* %75
br label %77
77: ; preds = %71
%78 = load i64, i64* %9
%79 = add i64 %78, 1
store i64 %79, i64* %9
br label %67
80: ; preds = %67
%81 = load i8*, i8** %12
store i8 0, i8* %81
%82 = load i8*, i8** %7
ret i8* %82
}

LLVM IR (-O2):
@.str = [17 x i8] c"s_len(%d) != 16\0A\00"
@.str.1 = [15 x i8] c"size(%d) < 32\0A\00"
@.str.2 = [5 x i8] c"%02x\00"
define i8* @MD5Key2String(i8* %0, i64 %1, i8* returned writeonly %2, i64 %3) {
%5 = alloca [34 x i8]
%6 = getelementptr inbounds [34 x i8], [34 x i8]* %5, i64 0, i64 0
%7 = alloca [16 x i8]
%8 = getelementptr inbounds [34 x i8], [34 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%10 = icmp eq i64 %1, 16
br i1 %10, label %14, label %11
11: ; preds = %4
%12 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %1)
%13 = tail call i32 @assert(i32 0)
br label %14
14: ; preds = %11, %4
%15 = icmp ult i64 %3, 32
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i64 %3)
%18 = tail call i32 @assert(i32 0)
br label %19
19: ; preds = %16, %14
%20 = call i32 @memcpy(i8* %9, i8* %0, i32 16)
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ 0, %19 ], [ %33, %21 ]
%23 = shl nuw nsw i64 %22, 1
%24 = getelementptr inbounds [34 x i8], [34 x i8]* %5, i64 0, i64 %23
%25 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %22
%26 = load i8, i8* %25
%27 = call i32 @sprintf(i8* %24, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %26)
%28 = or i64 %23, 1
%29 = getelementptr inbounds [34 x i8], [34 x i8]* %5, i64 0, i64 %28
%30 = load i8, i8* %25
%31 = shl i8 %30, 4
%32 = call i32 @sprintf(i8* %29, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %31)
%33 = add nuw nsw i64 %22, 1
%34 = icmp eq i64 %33, 16
br i1 %34, label %35, label %21
35: ; preds = %21
%36 = add i64 %3, -1
%37 = icmp ult i64 %36, 32
%38 = select i1 %37, i64 %36, i64 32
%39 = icmp eq i64 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %35
%41 = getelementptr i8, i8* %2, i64 %38
br label %42
42: ; preds = %40, %35
%43 = phi i8* [ %2, %35 ], [ %41, %40 ]
store i8 0, i8* %43
ret i8* %2
}