#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 */
typedef int uint8_t;

/* Variables and functions */
int MD5_DIGEST_LENGTH;
char *malloc(int);
char *saslc__crypto_hash_to_hex(const uint8_t *hash) {
  static const char hex[] = "0123456789abcdef";
  char *r;
  size_t i, j;
  if ((r = malloc(MD5_DIGEST_LENGTH * 2 + 1)) == NULL)
    return NULL;
  for (i = 0; i < MD5_DIGEST_LENGTH; i++) {
    j = i * 2;
    r[j] = hex[(unsigned)hash[i] >> 4];
    r[j + 1] = hex[hash[i] & 0x0F];
  }
  r[MD5_DIGEST_LENGTH * 2] = '\0';
  return r;
}


x86 assembly (clang, -O0):
<saslc__crypto_hash_to_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
shl    $0x1,%edi
add    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    114b <saslc__crypto_hash_to_hex+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    11f4 <saslc__crypto_hash_to_hex+0xe4>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e82(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jae    11d5 <saslc__crypto_hash_to_hex+0xc5>
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
shr    $0x4,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0xe71(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xe4b(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,0x1(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1153 <saslc__crypto_hash_to_hex+0x43>
mov    -0x18(%rbp),%rax
mov    0x2e00(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saslc__crypto_hash_to_hex>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
mov    0x2ebe(%rip),%rax
movslq (%rax),%r15
lea    (%r15,%r15,1),%r14
lea    0x1(%r14),%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     11d2 <saslc__crypto_hash_to_hex+0xc2>
test   %r15d,%r15d
je     11cd <saslc__crypto_hash_to_hex+0xbd>
cmp    $0x1,%r15d
jne    114e <saslc__crypto_hash_to_hex+0x3e>
xor    %ecx,%ecx
jmp    11a5 <saslc__crypto_hash_to_hex+0x95>
mov    %r15,%r8
and    $0xfffffffffffffffe,%r8
xor    %ecx,%ecx
lea    0xea2(%rip),%rsi
xchg   %ax,%ax
mov    (%r12,%rcx,4),%edx
mov    %rdx,%rdi
shr    $0x4,%rdi
movzbl (%rdi,%rsi,1),%ebx
mov    %bl,(%rax,%rcx,2)
and    $0xf,%edx
movzbl (%rdx,%rsi,1),%edx
mov    %dl,0x1(%rax,%rcx,2)
mov    0x4(%r12,%rcx,4),%edx
mov    %rdx,%rdi
shr    $0x4,%rdi
movzbl (%rdi,%rsi,1),%ebx
mov    %bl,0x2(%rax,%rcx,2)
and    $0xf,%edx
movzbl (%rdx,%rsi,1),%edx
mov    %dl,0x3(%rax,%rcx,2)
add    $0x2,%rcx
cmp    %rcx,%r8
jne    1160 <saslc__crypto_hash_to_hex+0x50>
test   $0x1,%r15b
je     11cd <saslc__crypto_hash_to_hex+0xbd>
mov    (%r12,%rcx,4),%edx
mov    %rdx,%rsi
shr    $0x4,%rsi
lea    0xe43(%rip),%rdi
mov    (%rsi,%rdi,1),%bl
mov    %bl,(%rax,%rcx,2)
and    $0xf,%edx
mov    (%rdx,%rdi,1),%dl
mov    %dl,0x1(%rax,%rcx,2)
movb   $0x0,(%rax,%r14,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@saslc__crypto_hash_to_hex.hex = internal unnamed_addr constant [17 x i8] c"0123456789abcdef\00"
@MD5_DIGEST_LENGTH = global i32 0
define noalias i8* @saslc__crypto_hash_to_hex(i32* nocapture %0) {
%2 = load i32, i32* @MD5_DIGEST_LENGTH
%3 = shl nsw i32 %2, 1
%4 = or i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %71, label %7
7: ; preds = %1
%8 = icmp eq i32 %2, 0
br i1 %8, label %68, label %9
9: ; preds = %7
%10 = sext i32 %2 to i64
%11 = and i64 %10, 1
%12 = icmp eq i32 %2, 1
br i1 %12, label %50, label %13
13: ; preds = %9
%14 = and i64 %10, -2
br label %15
15: ; preds = %15, %13
%16 = phi i64 [ 0, %13 ], [ %47, %15 ]
%17 = phi i64 [ 0, %13 ], [ %48, %15 ]
%18 = shl i64 %16, 1
%19 = getelementptr inbounds i32, i32* %0, i64 %16
%20 = load i32, i32* %19
%21 = lshr i32 %20, 4
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [17 x i8], [17 x i8]* @saslc__crypto_hash_to_hex.hex, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = getelementptr inbounds i8, i8* %5, i64 %18
store i8 %24, i8* %25
%26 = and i32 %20, 15
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [17 x i8], [17 x i8]* @saslc__crypto_hash_to_hex.hex, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = or i64 %18, 1
%31 = getelementptr inbounds i8, i8* %5, i64 %30
store i8 %29, i8* %31
%32 = or i64 %16, 1
%33 = shl i64 %32, 1
%34 = getelementptr inbounds i32, i32* %0, i64 %32
%35 = load i32, i32* %34
%36 = lshr i32 %35, 4
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds [17 x i8], [17 x i8]* @saslc__crypto_hash_to_hex.hex, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = getelementptr inbounds i8, i8* %5, i64 %33
store i8 %39, i8* %40
%41 = and i32 %35, 15
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds [17 x i8], [17 x i8]* @saslc__crypto_hash_to_hex.hex, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = or i64 %33, 1
%46 = getelementptr inbounds i8, i8* %5, i64 %45
store i8 %44, i8* %46
%47 = add nuw i64 %16, 2
%48 = add i64 %17, 2
%49 = icmp eq i64 %48, %14
br i1 %49, label %50, label %15
50: ; preds = %15, %9
%51 = phi i64 [ 0, %9 ], [ %47, %15 ]
%52 = icmp eq i64 %11, 0
br i1 %52, label %68, label %53
53: ; preds = %50
%54 = shl i64 %51, 1
%55 = getelementptr inbounds i32, i32* %0, i64 %51
%56 = load i32, i32* %55
%57 = lshr i32 %56, 4
%58 = zext i32 %57 to i64
%59 = getelementptr inbounds [17 x i8], [17 x i8]* @saslc__crypto_hash_to_hex.hex, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = getelementptr inbounds i8, i8* %5, i64 %54
store i8 %60, i8* %61
%62 = and i32 %56, 15
%63 = zext i32 %62 to i64
%64 = getelementptr inbounds [17 x i8], [17 x i8]* @saslc__crypto_hash_to_hex.hex, i64 0, i64 %63
%65 = load i8, i8* %64
%66 = or i64 %54, 1
%67 = getelementptr inbounds i8, i8* %5, i64 %66
store i8 %65, i8* %67
br label %68
68: ; preds = %53, %50, %7
%69 = sext i32 %3 to i64
%70 = getelementptr inbounds i8, i8* %5, i64 %69
store i8 0, i8* %70
br label %71
71: ; preds = %1, %68
ret i8* %5
}