#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 /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void print_hex(uint8_t *data, uint32_t len) {
  uint32_t ctr;
  char *sep;
  if (len > 64)
    len = 64;
  for (ctr = 0; ctr < len; ctr++) {
    sep = (((ctr & 7) == 0) && ctr) ? "\n" : "";
    fprintf(stderr, "%s%02x ", sep, data[ctr]);
  }
  fprintf(stderr, "\n\n");
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x40,-0xc(%rbp)
jle    1130 <print_hex+0x20>
movl   $0x40,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b1 <print_hex+0xa1>
mov    -0x10(%rbp),%ecx
and    $0x7,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jne    1161 <print_hex+0x51>
cmpl   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%dl
lea    0xe9f(%rip),%rax
lea    0xe97(%rip),%rcx
test   $0x1,%dl
cmovne %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1137 <print_hex+0x27>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1183 <print_hex+0x73>
mov    %rdi,%r15
cmp    $0x40,%esi
mov    $0x40,%r13d
cmovb  %esi,%r13d
lea    0xed4(%rip),%rbx
mov    0x2ea3(%rip),%rbp
lea    0xebc(%rip),%r14
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
test   $0x7,%r12b
mov    %rbx,%rdx
lea    0xeab(%rip),%rax
cmove  %rax,%rdx
test   %r12,%r12
cmove  %rbx,%rdx
mov    0x0(%rbp),%edi
mov    (%r15,%r12,4),%ecx
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r13
jne    1150 <print_hex+0x40>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.2 = [8 x i8] c"%s%02x \00"
@.str.3 = [3 x i8] c"\0A\0A\00"
define void @print_hex(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 64
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 64, i32* %4
br label %10
10: ; preds = %9, %2
store i32 0, i32* %5
br label %11
11: ; preds = %34, %10
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %37
15: ; preds = %11
%16 = load i32, i32* %5
%17 = and i32 %16, 7
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br label %22
22: ; preds = %19, %15
%23 = phi i1 [ false, %15 ], [ %21, %19 ]
%24 = zext i1 %23 to i64
%25 = select i1 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0)
store i8* %25, i8** %6
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %6
%28 = load i32*, i32** %3
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %27, i32 %32)
br label %34
34: ; preds = %22
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %11
37: ; preds = %11
%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))
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.2 = [8 x i8] c"%s%02x \00"
@.str.3 = [3 x i8] c"\0A\0A\00"
define void @print_hex(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %21
4: ; preds = %2
%5 = icmp ult i32 %1, 64
%6 = select i1 %5, i32 %1, i32 64
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %4, %8
%9 = phi i64 [ 0, %4 ], [ %19, %8 ]
%10 = and i64 %9, 7
%11 = icmp eq i64 %10, 0
%12 = icmp ne i64 %9, 0
%13 = and i1 %12, %11
%14 = select i1 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0)
%15 = load i32, i32* @stderr
%16 = getelementptr inbounds i32, i32* %0, i64 %9
%17 = load i32, i32* %16
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %14, i32 %17)
%19 = add nuw nsw i64 %9, 1
%20 = icmp eq i64 %19, %7
br i1 %20, label %21, label %8
21: ; preds = %8, %2
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
ret void
}