#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;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void print_hex(void *in, int start, int end) {
  uint8_t *array = (uint8_t *)in;
  int i;
  printf("\n[0000] ");
  for (i = start; i < end; i++) {
    if (i > 0 && i % 8 == 0) {
      printf("\n[%04x] ", i);
    }
    uint8_t foo = array[i];
    printf("%02x ", foo);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11a6 <print_hex+0x96>
cmpl   $0x0,-0x1c(%rbp)
jle    1179 <print_hex+0x69>
mov    -0x1c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1179 <print_hex+0x69>
mov    -0x1c(%rbp),%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113e <print_hex+0x2e>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %ebp,%ebx
jge    1190 <print_hex+0x70>
movslq %ebx,%rbx
lea    0xebe(%rip),%r15
lea    0xec0(%rip),%r12
jmp    1176 <print_hex+0x56>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%rbx,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %ebx,%ebp
je     1190 <print_hex+0x70>
test   %rbx,%rbx
jle    1160 <print_hex+0x40>
mov    %ebx,%eax
and    $0x7,%eax
jne    1160 <print_hex+0x40>
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <print_hex+0x40>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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