#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*/ snprintf(char *, int, char *, unsigned char);
char *bb_to_ascii(unsigned char *block, size_t len, char *out) {
  int i;
  char *o_out = out;
  for (i = 0; i < len; i++) {
    snprintf(out, 3, "%.2hhx", block[i]);
    out += 2;
  }
  return o_out;
}


x86 assembly (clang, -O0):
<bb_to_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    117c <bb_to_ascii+0x6c>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    $0x3,%esi
lea    0xea7(%rip),%rdx
movzbl (%rax,%rcx,1),%ecx
call   1030 <snprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1133 <bb_to_ascii+0x23>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bb_to_ascii>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
test   %rsi,%rsi
je     1162 <bb_to_ascii+0x52>
mov    %rsi,%r13
mov    %rdi,%r15
xor    %ebp,%ebp
lea    0xece(%rip),%r12
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r15,%rbp,1),%ecx
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %r12,%rdx
call   1030 <snprintf@plt>
add    $0x2,%rbx
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1140 <bb_to_ascii+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%.2hhx\00"
define i8* @bb_to_ascii(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
store i8* %9, i8** %8
store i32 0, i32* %7
br label %10
10: ; preds = %25, %3
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = load i64, i64* %5
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %28
15: ; preds = %10
%16 = load i8*, i8** %6
%17 = load i8*, i8** %4
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = call i32 @snprintf(i8* %16, i32 3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %21)
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 2
store i8* %24, i8** %6
br label %25
25: ; preds = %15
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %10
28: ; preds = %10
%29 = load i8*, i8** %8
ret i8* %29
}

LLVM IR (-O2):
@.str = [7 x i8] c"%.2hhx\00"
define i8* @bb_to_ascii(i8* nocapture %0, i64 %1, i8* returned %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %14, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %12, %5 ], [ 0, %3 ]
%7 = phi i8* [ %11, %5 ], [ %2, %3 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %6
%9 = load i8, i8* %8
%10 = tail call i32 @snprintf(i8* %7, i32 3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %9)
%11 = getelementptr inbounds i8, i8* %7, i64 2
%12 = add nuw i64 %6, 1
%13 = icmp eq i64 %12, %1
br i1 %13, label %14, label %5
14: ; preds = %5, %3
ret i8* %2
}