#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 *, size_t const);
int /*<<< orphan*/ puts(char const *);
void print_hex(const char *message, const unsigned char *x, const size_t len) {
  puts(message);
  for (size_t i = 0; i < len; i++) {
    if ((i != 0) && (i % 16 == 0)) {
      puts("");
    }
    printf("%02x ", x[i]);
  }
  printf("     %zu (octets)\n\n", len);
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a7 <print_hex+0x87>
cmpq   $0x0,-0x20(%rbp)
je     117c <print_hex+0x5c>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    117c <print_hex+0x5c>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,%esi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1145 <print_hex+0x25>
mov    -0x18(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
call   1040 <puts@plt>
test   %r12,%r12
je     1191 <print_hex+0x61>
xor    %ebx,%ebx
lea    0xeaf(%rip),%r15
jmp    1176 <print_hex+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
je     1191 <print_hex+0x61>
test   %rbx,%rbx
je     1160 <print_hex+0x30>
mov    %ebx,%eax
and    $0xf,%eax
test   %rax,%rax
jne    1160 <print_hex+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1160 <print_hex+0x30>
lea    0xe6e(%rip),%rdi
mov    %r12,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <printf@plt>

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

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