#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*/ itoa(unsigned char, char *, int);
char *rpad(char *, char *, int, int /*<<< orphan*/);
char *write(char *, char);
char *hex_bytes(char *out, char *in, int size) {
  char buf[3];
  for (int i = 0; i < size; i++) {
    unsigned char value = in[i];
    itoa(value, buf, 16);
    out = rpad(out, buf, 2, '0');
    out = write(out, ' ');
  }
  return out;
}


x86 assembly (clang, -O0):
<hex_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b3 <hex_bytes+0x83>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
lea    -0x17(%rbp),%rsi
mov    $0x10,%edx
movzbl %al,%edi
call   1050 <itoa@plt>
mov    -0x8(%rbp),%rdi
lea    -0x17(%rbp),%rsi
mov    $0x2,%edx
mov    $0x30,%ecx
call   1040 <rpad@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1030 <write@plt>
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114a <hex_bytes+0x1a>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_bytes>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r13
test   %edx,%edx
jle    11a0 <hex_bytes+0x70>
mov    %rsi,%r14
mov    %edx,%r12d
xor    %ebx,%ebx
lea    0xd(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%edi
mov    %r15,%rsi
mov    $0x10,%edx
call   1050 <itoa@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
mov    $0x30,%ecx
call   1040 <rpad@plt>
mov    %rax,%rdi
mov    $0x20,%esi
call   1030 <write@plt>
mov    %rax,%r13
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <hex_bytes+0x30>
mov    %r13,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @hex_bytes(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [3 x i8]
%8 = alloca i32
%9 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %8
br label %10
10: ; preds = %28, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %31
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
store i8 %19, i8* %9
%20 = load i8, i8* %9
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%22 = call i32 @itoa(i8 zeroext %20, i8* %21, i32 16)
%23 = load i8*, i8** %4
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%25 = call i8* @rpad(i8* %23, i8* %24, i32 2, i32 48)
store i8* %25, i8** %4
%26 = load i8*, i8** %4
%27 = call i8* @write(i8* %26, i8 signext 32)
store i8* %27, i8** %4
br label %28
28: ; preds = %14
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %10
31: ; preds = %10
%32 = load i8*, i8** %4
ret i8* %32
}

LLVM IR (-O2):
define i8* @hex_bytes(i8* %0, i8* nocapture %1, i32 %2) {
%4 = alloca [3 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %11
9: ; preds = %11, %3
%10 = phi i8* [ %0, %3 ], [ %18, %11 ]
ret i8* %10
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %19, %11 ]
%13 = phi i8* [ %0, %7 ], [ %18, %11 ]
%14 = getelementptr inbounds i8, i8* %1, i64 %12
%15 = load i8, i8* %14
%16 = call i32 @itoa(i8 zeroext %15, i8* %5, i32 16)
%17 = call i8* @rpad(i8* %13, i8* %5, i32 2, i32 48)
%18 = call i8* @write(i8* %17, i8 signext 32)
%19 = add nuw nsw i64 %12, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %9, label %11
}