#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);
int strlen(char *);
void print_hex(char *s, int len) {
  if (len == 0)
    return;
  int i = 0;
  if (len < 0)
    i = strlen(s);
  while (i < len) {
    printf("%02x ", (unsigned char)s[i]);
    i++;
  }
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    113e <print_hex+0x1e>
jmp    1192 <print_hex+0x72>
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    115b <print_hex+0x3b>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
jmp    1160 <print_hex+0x40>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1192 <print_hex+0x72>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xe85(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1160 <print_hex+0x40>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1176 <print_hex+0x56>
mov    %esi,%r12d
mov    %rdi,%r14
xor    %eax,%eax
test   %esi,%esi
js     113f <print_hex+0x1f>
cmp    %r12d,%eax
jl     114c <print_hex+0x2c>
jmp    1176 <print_hex+0x56>
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %r12d,%eax
jge    1176 <print_hex+0x56>
movslq %eax,%rcx
add    %rcx,%r14
sub    %eax,%r12d
xor    %ebx,%ebx
lea    0xea2(%rip),%r15
xchg   %ax,%ax
movzbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %ebx,%r12d
jne    1160 <print_hex+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%02x \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
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
br label %29
9: ; preds = %2
store i32 0, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %5
br label %15
15: ; preds = %12, %9
br label %16
16: ; preds = %20, %15
%17 = load i32, i32* %5
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %25)
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %16
29: ; preds = %8, %16
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%02x \00"
define void @print_hex(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %21, label %4
4: ; preds = %2
%5 = icmp slt i32 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @strlen(i8* %0)
br label %8
8: ; preds = %6, %4
%9 = phi i32 [ %7, %6 ], [ 0, %4 ]
%10 = icmp slt i32 %9, %1
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = sext i32 %9 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ %12, %11 ], [ %18, %13 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %16)
%18 = add nsw i64 %14, 1
%19 = trunc i64 %18 to i32
%20 = icmp eq i32 %19, %1
br i1 %20, label %21, label %13
21: ; preds = %13, %8, %2
ret void
}