#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 *, ...);
void print_hex_string(char *buf, int len) {
  int i;
  if (len == 0) {
    printf("<empty string>");
    return;
  }
  for (i = 0; i < len; i++) {
    printf("%02x ", *((unsigned char *)buf + i));
    if ((i & 0xf) == 15)
      printf("\n");
  }
  if ((i & 0xf))
    printf("\n");
}


x86 assembly (clang, -O0):
<print_hex_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    113c <print_hex_string+0x2c>
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b6 <print_hex_string+0xa6>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1199 <print_hex_string+0x89>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
and    $0xf,%eax
cmp    $0xf,%eax
jne    1186 <print_hex_string+0x76>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118b <print_hex_string+0x7b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1143 <print_hex_string+0x33>
mov    -0x10(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
je     11b6 <print_hex_string+0xa6>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex_string>:
test   %esi,%esi
je     117c <print_hex_string+0x5c>
jle    11a2 <print_hex_string+0x82>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
mov    %esi,%ebp
lea    0xed2(%rip),%r15
xor    %ebx,%ebx
jmp    1159 <print_hex_string+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     118a <print_hex_string+0x6a>
movzbl (%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
not    %eax
test   $0xf,%al
jne    1150 <print_hex_string+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1150 <print_hex_string+0x30>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
jmp    1040 <printf@plt>
test   $0xf,%r14b
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
je     11a2 <print_hex_string+0x82>
mov    $0xa,%edi
jmp    1030 <putchar@plt>
ret

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

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