#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 *, unsigned char, char);
int /*<<< orphan*/ puts(char *);
void hex_print(char *s, int len) {
  puts("Hex Print:");
  for (int i = 0; i < len; ++i) {
    printf("%02x%c", (unsigned char)s[i],
           " \n"[(i && (i % 8 == 0)) || i == len - 1]);
  }
}


x86 assembly (clang, -O0):
<hex_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c6 <hex_print+0xa6>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     117f <hex_print+0x5f>
mov    -0x10(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    $0x1,%al
cmp    $0x0,%edx
mov    %al,-0x12(%rbp)
je     1190 <hex_print+0x70>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x11(%rbp),%dl
mov    -0x12(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rcx
lea    0xe66(%rip),%rdi
lea    0xe66(%rip),%rax
movzbl %dl,%esi
movsbl (%rax,%rcx,1),%edx
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1142 <hex_print+0x22>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
test   %r14d,%r14d
jle    1193 <hex_print+0x73>
lea    -0x1(%r14),%r12d
mov    %r14d,%r13d
xor    %ebx,%ebx
lea    0xec0(%rip),%rbp
lea    0xeb2(%rip),%r14
nopl   0x0(%rax)
movzbl (%r15,%rbx,1),%esi
test   %rbx,%rbx
setne  %al
test   $0x7,%bl
sete   %cl
and    %al,%cl
cmp    %rbx,%r12
sete   %al
or     %cl,%al
movzbl %al,%eax
movsbl (%rax,%rbp,1),%edx
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1160 <hex_print+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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