#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*/ putchar(char);
int /*<<< orphan*/ stderr;
unsigned long strlen(unsigned char *);
void print_hex(unsigned char *prefix, unsigned char *str, int len) {
  unsigned long i, j, preflen = 0;
  if (prefix) {
    fprintf(stderr, "%s", prefix);
    preflen = strlen(prefix);
  }
  for (i = 0; i < len; i++) {
    fprintf(stderr, "%02x", str[i]);
    if (((i % (4 * 4)) == ((4 * 4) - 1)) && ((i + 1) != len)) {
    } else if ((i % 4) == (4 - 1))
      putchar(' ');
  }
  putchar('\n');
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     117e <print_hex+0x4e>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jae    121d <print_hex+0xed>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0xf,%rax
jne    11e6 <print_hex+0xb6>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
je     11e6 <print_hex+0xb6>
jmp    1207 <print_hex+0xd7>
mov    -0x20(%rbp),%rax
and    $0x3,%rax
cmp    $0x3,%rax
jne    1202 <print_hex+0xd2>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1207 <print_hex+0xd7>
jmp    120c <print_hex+0xdc>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1186 <print_hex+0x56>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x30,%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    %edx,%ebp
mov    %rsi,%r15
test   %rdi,%rdi
je     114f <print_hex+0x2f>
mov    %rdi,%rdx
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    0xeb8(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %ebp,%ebp
je     11cb <print_hex+0xab>
movslq %ebp,%rbp
cmp    $0x2,%rbp
mov    $0x1,%r13d
cmovae %rbp,%r13
add    $0xffffffffffffffff,%rbp
lea    0xe94(%rip),%r14
xor    %r12d,%r12d
jmp    1185 <print_hex+0x65>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %r12,%r13
je     11cb <print_hex+0xab>
mov    %r12,%rbx
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
movzbl (%r15,%r12,1),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%eax
not    %eax
test   $0xf,%al
sete   %al
add    $0x1,%r12
cmp    %rbx,%rbp
setne  %cl
test   %cl,%al
jne    1180 <print_hex+0x60>
and    $0x3,%ebx
cmp    $0x3,%ebx
jne    1180 <print_hex+0x60>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1180 <print_hex+0x60>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c"%02x\00"
define void @print_hex(i8* %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %8, label %5
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %5, %3
%9 = sext i32 %2 to i64
%10 = icmp eq i32 %2, 0
br i1 %10, label %32, label %11
11: ; preds = %8
%12 = call i64 @llvm.umax.i64(i64 %9, i64 1)
br label %13
13: ; preds = %11, %30
%14 = phi i64 [ %22, %30 ], [ 0, %11 ]
%15 = load i32, i32* @stderr
%16 = getelementptr inbounds i8, i8* %1, i64 %14
%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 i64 %14, 15
%21 = icmp ne i64 %20, 15
%22 = add nuw i64 %14, 1
%23 = icmp eq i64 %22, %9
%24 = or i1 %21, %23
%25 = and i64 %14, 3
%26 = icmp eq i64 %25, 3
%27 = select i1 %24, i1 %26, i1 false
br i1 %27, label %28, label %30
28: ; preds = %13
%29 = tail call i32 @putchar(i8 signext 32)
br label %30
30: ; preds = %13, %28
%31 = icmp eq i64 %22, %12
br i1 %31, label %32, label %13
32: ; preds = %30, %8
%33 = tail call i32 @putchar(i8 signext 10)
ret void
}