#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*/ printf(char *, ...);
int print_hex_data(const char *buffer, const int len) {
  int last_byte = len - 1;
  if (len < 0) {
    return (-1);
  }
  int i = 0;
  for (i = 0; i < len; i++) {
    if ((i % 14) == 0) {
      printf("\n\t\t\t");
    }
    printf("%02X", 0xFF & (unsigned int)buffer[i]);
    if (i < last_byte) {
      printf(":");
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<print_hex_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    113e <print_hex_data+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <print_hex_data+0xbe>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c7 <print_hex_data+0xb7>
mov    -0x1c(%rbp),%eax
mov    $0xe,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117a <print_hex_data+0x6a>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11b4 <print_hex_data+0xa4>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b9 <print_hex_data+0xa9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114c <print_hex_data+0x3c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex_data>:
test   %esi,%esi
js     11bd <print_hex_data+0x9d>
je     11c3 <print_hex_data+0xa3>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
lea    -0x1(%rsi),%eax
mov    %eax,%r13d
mov    %esi,%ebx
mov    $0x92492493,%ebp
lea    0xeb5(%rip),%r15
xor    %r14d,%r14d
jmp    1169 <print_hex_data+0x49>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r14
cmp    %r14,%rbx
je     11ac <print_hex_data+0x8c>
mov    %r14d,%eax
shr    %eax
imul   %rbp,%rax
shr    $0x22,%rax
imul   $0xfffffff2,%eax,%eax
add    %r14d,%eax
jne    118c <print_hex_data+0x6c>
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r12,%r14,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r13,%r14
jae    1160 <print_hex_data+0x40>
mov    $0x3a,%edi
call   1030 <putchar@plt>
jmp    1160 <print_hex_data+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%eax
ret
xor    %eax,%eax
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"\0A\09\09\09\00"
@.str.1 = [5 x i8] c"%02X\00"
define i32 @print_hex_data(i8* nocapture %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = icmp slt i32 %1, 0
br i1 %4, label %28, label %5
5: ; preds = %2
%6 = icmp eq i32 %1, 0
br i1 %6, label %28, label %7
7: ; preds = %5
%8 = zext i32 %3 to i64
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %7, %25
%11 = phi i64 [ 0, %7 ], [ %26, %25 ]
%12 = trunc i64 %11 to i32
%13 = urem i32 %12, 14
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
%18 = getelementptr inbounds i8, i8* %0, i64 %11
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = icmp ult i64 %11, %8
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = tail call i32 @putchar(i32 58)
br label %25
25: ; preds = %17, %23
%26 = add nuw nsw i64 %11, 1
%27 = icmp eq i64 %26, %9
br i1 %27, label %28, label %10
28: ; preds = %25, %5, %2
%29 = phi i32 [ -1, %2 ], [ 0, %5 ], [ 0, %25 ]
ret i32 %29
}