#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*/ byte_to_hex(char const, char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ stdout;
void print_hex(const char *buf, int size) {
  int i = 0U;
  char out[2];
  for (i = 0U; i < size; i++) {
    byte_to_hex(buf[i], &out[0]);
    printf("%c", out[0]);
    printf("%c", out[1]);
  }
  fflush(stdout);
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119e <print_hex+0x6e>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
lea    -0x12(%rbp),%rsi
movsbl %al,%edi
call   1050 <byte_to_hex@plt>
lea    0xe89(%rip),%rdi
movsbl -0x12(%rbp),%esi
call   1030 <printf@plt>
lea    0xe79(%rip),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114d <print_hex+0x1d>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    1190 <print_hex+0x60>
mov    %rdi,%r15
mov    %esi,%r12d
xor    %ebx,%ebx
lea    0xe(%rsp),%r14
lea    0xeab(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r15,%rbx,1),%edi
mov    %r14,%rsi
call   1050 <byte_to_hex@plt>
movsbl 0xe(%rsp),%esi
mov    %r13,%rdi
call   1030 <printf@plt>
movsbl 0xf(%rsp),%esi
mov    %r13,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <print_hex+0x30>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@stdout = global i32 0
define void @print_hex(i8* nocapture %0, i32 %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %20
6: ; preds = %2
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ 0, %6 ], [ %18, %9 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = call i32 @byte_to_hex(i8 signext %12, i8* %4)
%14 = load i8, i8* %4
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %14)
%16 = load i8, i8* %7
%17 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %16)
%18 = add nuw nsw i64 %10, 1
%19 = icmp eq i64 %18, %8
br i1 %19, label %20, label %9
20: ; preds = %9, %2
%21 = load i32, i32* @stdout
%22 = call i32 @fflush(i32 %21)
ret void
}