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


x86 assembly (clang, -O0):
<print_c_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_c_hex_string+0x2c>
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e6 <print_c_hex_string+0xd6>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c9 <print_c_hex_string+0xb9>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    117f <print_c_hex_string+0x6f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1199 <print_c_hex_string+0x89>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
and    $0xf,%eax
cmp    $0xf,%eax
jne    11b6 <print_c_hex_string+0xa6>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bb <print_c_hex_string+0xab>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1143 <print_c_hex_string+0x33>
mov    -0x10(%rbp),%eax
and    $0xf,%eax
cmp    $0x1,%eax
je     11e6 <print_c_hex_string+0xd6>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_c_hex_string>:
test   %esi,%esi
je     1194 <print_c_hex_string+0x74>
jle    11be <print_c_hex_string+0x9e>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
lea    -0x1(%rsi),%r12d
mov    %rsi,(%rsp)
mov    %esi,%ebx
lea    0xec6(%rip),%r13
lea    0xec7(%rip),%rbp
xor    %r14d,%r14d
jmp    1169 <print_c_hex_string+0x49>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r14
cmp    %r14,%rbx
je     11a2 <print_c_hex_string+0x82>
cmp    %r12,%r14
movzbl (%r15,%r14,1),%esi
mov    %rbp,%rdi
cmovb  %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%eax
not    %eax
test   $0xf,%al
jne    1160 <print_c_hex_string+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1160 <print_c_hex_string+0x40>
lea    0xe65(%rip),%rdi
xor    %eax,%eax
jmp    1040 <printf@plt>
mov    (%rsp),%rax
and    $0xf,%eax
cmp    $0x1,%eax
lea    0x8(%rsp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jne    11be <print_c_hex_string+0x9e>
ret
mov    $0xa,%edi
jmp    1030 <putchar@plt>

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

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