#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 */
scalar_t__ isprint(char const);
int /*<<< orphan*/ isspace(char const);
int /*<<< orphan*/ printf(char *, int);
void print_buffer(const char *buffer, size_t size) {
  size_t i;
  for (i = 0; i != size; ++i) {
    if (buffer[i] == ' ' || (isprint(buffer[i]) && !isspace(buffer[i])))
      printf("%c", (char)buffer[i]);
    else if (buffer[i] == '\n')
      printf("<"
             ""
             "0x%02X"
             ""
             ">\n",
             (int)buffer[i]);
    else
      printf("<"
             ""
             "0x%02X"
             ""
             ">",
             (int)buffer[i]);
  }
}


x86 assembly (clang, -O0):
<print_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1222 <print_buffer+0xf2>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     11a0 <print_buffer+0x70>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     11bd <print_buffer+0x8d>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    11bd <print_buffer+0x8d>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
jmp    120c <print_buffer+0xdc>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11ef <print_buffer+0xbf>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
jmp    1207 <print_buffer+0xd7>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
jmp    120c <print_buffer+0xdc>
jmp    1211 <print_buffer+0xe1>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1148 <print_buffer+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     11c1 <print_buffer+0x91>
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
lea    0xead(%rip),%r15
lea    0xea9(%rip),%r12
lea    0xeac(%rip),%r13
jmp    1184 <print_buffer+0x54>
movzbl (%rbx,%rbp,1),%eax
nopw   0x0(%rax,%rax,1)
movsbl %al,%esi
mov    %r15,%rdi
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
je     11c1 <print_buffer+0x91>
movzbl (%rbx,%rbp,1),%ecx
mov    $0x20,%al
cmp    $0x20,%cl
je     1170 <print_buffer+0x40>
movsbl %cl,%edi
call   1050 <isprint@plt>
test   %rax,%rax
je     11a9 <print_buffer+0x79>
movsbl (%rbx,%rbp,1),%edi
call   1040 <isspace@plt>
test   %eax,%eax
je     1163 <print_buffer+0x33>
movsbl (%rbx,%rbp,1),%esi
cmp    $0xa,%esi
jne    11bc <print_buffer+0x8c>
mov    %r12,%rdi
mov    $0xa,%esi
jmp    1176 <print_buffer+0x46>
mov    %r13,%rdi
jmp    1176 <print_buffer+0x46>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [10 x i8] c"<0x%02X>\0A\00"
@.str.2 = [9 x i8] c"<0x%02X>\00"
define void @print_buffer(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %5
br label %6
6: ; preds = %61, %2
%7 = load i64, i64* %5
%8 = load i64, i64* %4
%9 = icmp ne i64 %7, %8
br i1 %9, label %10, label %64
10: ; preds = %6
%11 = load i8*, i8** %3
%12 = load i64, i64* %5
%13 = getelementptr inbounds i8, i8* %11, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 32
br i1 %16, label %31, label %17
17: ; preds = %10
%18 = load i8*, i8** %3
%19 = load i64, i64* %5
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i8, i8* %20
%22 = call i64 @isprint(i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %17
%25 = load i8*, i8** %3
%26 = load i64, i64* %5
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @isspace(i8 signext %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %38, label %31
31: ; preds = %24, %10
%32 = load i8*, i8** %3
%33 = load i64, i64* %5
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %36)
br label %60
38: ; preds = %24, %17
%39 = load i8*, i8** %3
%40 = load i64, i64* %5
%41 = getelementptr inbounds i8, i8* %39, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 10
br i1 %44, label %45, label %52
45: ; preds = %38
%46 = load i8*, i8** %3
%47 = load i64, i64* %5
%48 = getelementptr inbounds i8, i8* %46, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %50)
br label %59
52: ; preds = %38
%53 = load i8*, i8** %3
%54 = load i64, i64* %5
%55 = getelementptr inbounds i8, i8* %53, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %52, %45
br label %60
60: ; preds = %59, %31
br label %61
61: ; preds = %60
%62 = load i64, i64* %5
%63 = add i64 %62, 1
store i64 %63, i64* %5
br label %6
64: ; preds = %6
ret void
}

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