#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*/ memcpy(unsigned char *, char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int mk_readable(unsigned char *hash, int buflen) {
  char buf[1024];
  int i, j;
  if (buflen < 1024) {
    return 1;
  }
  for (j = 0, i = 0; j < 16; i += 2, j++) {
    sprintf(&buf[i], "%.2X", (unsigned char)hash[j]);
  }
  memset(hash, 0, buflen);
  memcpy(hash, buf, buflen);
  return 0;
}


x86 assembly (clang, -O0):
<mk_readable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x400,-0x14(%rbp)
jge    115b <mk_readable+0x2b>
movl   $0x1,-0x4(%rbp)
jmp    11f3 <mk_readable+0xc3>
movl   $0x0,-0x428(%rbp)
movl   $0x0,-0x424(%rbp)
cmpl   $0x10,-0x428(%rbp)
jge    11cb <mk_readable+0x9b>
movslq -0x424(%rbp),%rax
lea    -0x420(%rbp),%rdi
add    %rax,%rdi
mov    -0x10(%rbp),%rax
movslq -0x428(%rbp),%rcx
lea    0xe61(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1050 <sprintf@plt>
mov    -0x424(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x424(%rbp)
mov    -0x428(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x428(%rbp)
jmp    116f <mk_readable+0x3f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mk_readable>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    $0x1,%ebp
cmp    $0x400,%esi
jl     1288 <mk_readable+0x158>
mov    %esi,%r15d
mov    %rdi,%rbx
movzbl (%rdi),%edx
lea    0xea2(%rip),%rbp
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0x2(%rsp),%rdi
movzbl 0x1(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0x4(%rsp),%rdi
movzbl 0x2(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0x6(%rsp),%rdi
movzbl 0x3(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0x8(%rsp),%rdi
movzbl 0x4(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0xa(%rsp),%rdi
movzbl 0x5(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0xc(%rsp),%rdi
movzbl 0x6(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0xe(%rsp),%rdi
movzbl 0x7(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0x10(%rsp),%rdi
movzbl 0x8(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0x12(%rsp),%rdi
movzbl 0x9(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0x14(%rsp),%rdi
movzbl 0xa(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0x16(%rsp),%rdi
movzbl 0xb(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0x18(%rsp),%rdi
movzbl 0xc(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0x1a(%rsp),%rdi
movzbl 0xd(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0x1c(%rsp),%rdi
movzbl 0xe(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
lea    0x1e(%rsp),%rdi
movzbl 0xf(%rbx),%edx
mov    %rbp,%rsi
call   1050 <sprintf@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1030 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%.2X\00"
define i32 @mk_readable(i8* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %1, 1024
br i1 %5, label %71, label %6
6: ; preds = %2
%7 = load i8, i8* %0
%8 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %7)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 2
%10 = getelementptr inbounds i8, i8* %0, i64 1
%11 = load i8, i8* %10
%12 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %11)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 4
%14 = getelementptr inbounds i8, i8* %0, i64 2
%15 = load i8, i8* %14
%16 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %15)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 6
%18 = getelementptr inbounds i8, i8* %0, i64 3
%19 = load i8, i8* %18
%20 = call i32 @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 8
%22 = getelementptr inbounds i8, i8* %0, i64 4
%23 = load i8, i8* %22
%24 = call i32 @sprintf(i8* %21, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %23)
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 10
%26 = getelementptr inbounds i8, i8* %0, i64 5
%27 = load i8, i8* %26
%28 = call i32 @sprintf(i8* %25, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %27)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 12
%30 = getelementptr inbounds i8, i8* %0, i64 6
%31 = load i8, i8* %30
%32 = call i32 @sprintf(i8* %29, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %31)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 14
%34 = getelementptr inbounds i8, i8* %0, i64 7
%35 = load i8, i8* %34
%36 = call i32 @sprintf(i8* %33, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %35)
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 16
%38 = getelementptr inbounds i8, i8* %0, i64 8
%39 = load i8, i8* %38
%40 = call i32 @sprintf(i8* %37, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %39)
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 18
%42 = getelementptr inbounds i8, i8* %0, i64 9
%43 = load i8, i8* %42
%44 = call i32 @sprintf(i8* %41, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %43)
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 20
%46 = getelementptr inbounds i8, i8* %0, i64 10
%47 = load i8, i8* %46
%48 = call i32 @sprintf(i8* %45, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %47)
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 22
%50 = getelementptr inbounds i8, i8* %0, i64 11
%51 = load i8, i8* %50
%52 = call i32 @sprintf(i8* %49, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %51)
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 24
%54 = getelementptr inbounds i8, i8* %0, i64 12
%55 = load i8, i8* %54
%56 = call i32 @sprintf(i8* %53, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %55)
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 26
%58 = getelementptr inbounds i8, i8* %0, i64 13
%59 = load i8, i8* %58
%60 = call i32 @sprintf(i8* %57, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %59)
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 28
%62 = getelementptr inbounds i8, i8* %0, i64 14
%63 = load i8, i8* %62
%64 = call i32 @sprintf(i8* %61, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %63)
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 30
%66 = getelementptr inbounds i8, i8* %0, i64 15
%67 = load i8, i8* %66
%68 = call i32 @sprintf(i8* %65, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %67)
%69 = tail call i32 @memset(i8* %0, i32 0, i32 %1)
%70 = call i32 @memcpy(i8* %0, i8* %4, i32 %1)
br label %71
71: ; preds = %2, %6
%72 = phi i32 [ 0, %6 ], [ 1, %2 ]
ret i32 %72
}