#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;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void hexprint(uint16_t length, uint8_t *buffer) {
  char hexstring[255];
  char *hexpointer = hexstring;
  for (int i = 0; i < length; i++) {
    sprintf(hexpointer, "%02X ", buffer[i]);
    hexpointer += 3;
  }
  printf("%s\n", hexstring);
}


x86 assembly (clang, -O0):
<hexprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
movl   $0x0,-0x11c(%rbp)
mov    -0x11c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a0 <hexprint+0x80>
mov    -0x118(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x11c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe8b(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x118(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x118(%rbp)
mov    -0x11c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x11c(%rbp)
jmp    114a <hexprint+0x2a>
lea    -0x110(%rbp),%rsi
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexprint>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
test   %edi,%edi
jle    116c <hexprint+0x4c>
mov    %rsi,%r14
mov    %rsp,%r13
mov    %edi,%r12d
xor    %ebx,%ebx
lea    0xeba(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
add    $0x3,%r13
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <hexprint+0x30>
lea    0xe93(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%02X \00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @hexprint(i32 %0, i32* nocapture %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = zext i32 %0 to i64
br label %10
8: ; preds = %10, %2
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
ret void
10: ; preds = %6, %10
%11 = phi i64 [ 0, %6 ], [ %17, %10 ]
%12 = phi i8* [ %4, %6 ], [ %16, %10 ]
%13 = getelementptr inbounds i32, i32* %1, i64 %11
%14 = load i32, i32* %13
%15 = call i32 @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds i8, i8* %12, i64 3
%17 = add nuw nsw i64 %11, 1
%18 = icmp eq i64 %17, %7
br i1 %18, label %8, label %10
}