#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void print_hex(const unsigned char *p, int len) {
  int i;
  for (i = 0; i < len; i++) {
    if (i % 16 == 0) {
      fprintf(stderr, "%04x: ", i);
    }
    fprintf(stderr, "%02x", p[i]);
    if (i % 4 == 3) {
      if (i % 16 == 15) {
        fprintf(stderr, "\n");
      } else {
        fprintf(stderr, "  ");
      }
    } else {
      fprintf(stderr, " ");
    }
  }
  if (len % 16) {
    fprintf(stderr, "\n");
  }
}


x86 assembly (clang, -O0):
<print_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    120d <print_hex+0xfd>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1160 <print_hex+0x50>
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xea7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe8b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x3,%edx
jne    11e3 <print_hex+0xd3>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    11c7 <print_hex+0xb7>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11de <print_hex+0xce>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11fa <print_hex+0xea>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11ff <print_hex+0xef>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <print_hex+0x16>
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1238 <print_hex+0x128>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,0x4(%rsp)
test   %esi,%esi
jle    11c9 <print_hex+0xb9>
mov    %rdi,%rbx
mov    0x4(%rsp),%r14d
mov    0x2eaa(%rip),%r15
lea    0xeca(%rip),%rbp
xor    %r13d,%r13d
jmp    116a <print_hex+0x5a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%edi
lea    0xeb5(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%r14
je     11c9 <print_hex+0xb9>
mov    %r13d,%r12d
and    $0xf,%r12d
jne    1187 <print_hex+0x77>
mov    (%r15),%edi
lea    0xe83(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
movzbl (%rbx,%r13,1),%edx
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %r13d,%eax
not    %eax
test   $0x3,%al
jne    1150 <print_hex+0x40>
mov    (%r15),%edi
cmp    $0xf,%r12d
jne    11c0 <print_hex+0xb0>
lea    0xe5a(%rip),%rsi
jmp    115a <print_hex+0x4a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe47(%rip),%rsi
jmp    115a <print_hex+0x4a>
testb  $0xf,0x4(%rsp)
je     11f5 <print_hex+0xe5>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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