#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(uint8_t *data, size_t count) {
  size_t row_count = 8;
  for (size_t byte = 0; byte < count; ++byte) {
    if (byte % row_count == 0) {
      if (byte != 0)
        printf("\n");
      printf("0x%08x:", byte / row_count);
    }
    printf("  0x%02x", data[byte]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x8,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11b4 <print_hex+0xa4>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
jne    118a <print_hex+0x7a>
cmpq   $0x0,-0x20(%rbp)
je     116d <print_hex+0x5d>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %rax,%rsi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1130 <print_hex+0x20>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     115b <print_hex+0x3b>
mov    %rsi,%r13
mov    %rdi,%r14
lea    0xec5(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%esi
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%r13
jne    116e <print_hex+0x4e>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>
mov    $0x1,%ebx
lea    0xe86(%rip),%r15
lea    0xe87(%rip),%r12
jmp    11a7 <print_hex+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%rbx,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
je     115b <print_hex+0x3b>
test   $0x7,%bl
jne    1190 <print_hex+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rsi
shr    $0x3,%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1190 <print_hex+0x70>

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

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