#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 *, ...);
void dump_hex(const unsigned char *data, int size) {
  int i;
  for (i = 0; i < size; i++) {
    if (i == 0) {
    } else if ((i & 15) == 0) {
      printf("\n");
    } else if ((i & 3) == 0) {
      printf(" ");
    } else if ((i & 15) == 15) {
    }
    printf("%02X", data[i]);
  }
  if ((i & 15) != 1) {
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<dump_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d0 <dump_hex+0xc0>
cmpl   $0x0,-0x10(%rbp)
jne    1141 <dump_hex+0x31>
jmp    11a8 <dump_hex+0x98>
mov    -0x10(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    1163 <dump_hex+0x53>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a3 <dump_hex+0x93>
mov    -0x10(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
jne    1185 <dump_hex+0x75>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119e <dump_hex+0x8e>
mov    -0x10(%rbp),%eax
and    $0xf,%eax
cmp    $0xf,%eax
jne    1199 <dump_hex+0x89>
jmp    1199 <dump_hex+0x89>
jmp    119e <dump_hex+0x8e>
jmp    11a3 <dump_hex+0x93>
jmp    11a8 <dump_hex+0x98>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <dump_hex+0x16>
mov    -0x10(%rbp),%eax
and    $0xf,%eax
cmp    $0x1,%eax
je     11ed <dump_hex+0xdd>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_hex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    11a6 <dump_hex+0x86>
mov    %esi,%ebp
mov    %rdi,%r15
movzbl (%rdi),%esi
lea    0xec6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%ebp
je     119b <dump_hex+0x7b>
mov    %ebp,%ebp
mov    $0x1,%ebx
lea    0xeac(%rip),%r14
jmp    1182 <dump_hex+0x62>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
movzbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1193 <dump_hex+0x73>
test   $0xf,%bl
je     1160 <dump_hex+0x40>
test   $0x3,%bl
jne    116a <dump_hex+0x4a>
mov    $0x20,%edi
jmp    1165 <dump_hex+0x45>
and    $0xf,%ebp
cmp    $0x1,%ebp
jne    11a6 <dump_hex+0x86>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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