#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);
int /*<<< orphan*/ printf(char *, unsigned char);
int /*<<< orphan*/ putchar(char);
void safe_print(char *c, int n) {
  int i;
  if (n <= 0)
    return;
  for (i = 0; i < n; i++, c++) {
    if (isprint(*c))
      putchar(*c);
    else
      printf("<%02x>", (unsigned char)(*c));
  }
}


x86 assembly (clang, -O0):
<safe_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     114e <safe_print+0x1e>
jmp    11ba <safe_print+0x8a>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ba <safe_print+0x8a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     1188 <safe_print+0x58>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    119b <safe_print+0x6b>
mov    -0x8(%rbp),%rax
lea    0xe6d(%rip),%rdi
movzbl (%rax),%esi
call   1040 <printf@plt>
jmp    11a0 <safe_print+0x70>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1155 <safe_print+0x25>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_print>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1182 <safe_print+0x52>
mov    %rdi,%r12
mov    %esi,%r15d
xor    %ebx,%ebx
lea    0xeb5(%rip),%r14
jmp    1164 <safe_print+0x34>
nopl   (%rax)
movzbl %cl,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %ebx,%r15d
je     1182 <safe_print+0x52>
movsbl (%r12,%rbx,1),%edi
call   1050 <isprint@plt>
movzbl (%r12,%rbx,1),%ecx
test   %rax,%rax
je     1150 <safe_print+0x20>
movsbl %cl,%edi
call   1030 <putchar@plt>
jmp    115b <safe_print+0x2b>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"<%02x>\00"
define void @safe_print(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %19
4: ; preds = %2, %15
%5 = phi i32 [ %16, %15 ], [ 0, %2 ]
%6 = phi i8* [ %17, %15 ], [ %0, %2 ]
%7 = load i8, i8* %6
%8 = tail call i64 @isprint(i8 signext %7)
%9 = icmp eq i64 %8, 0
%10 = load i8, i8* %6
br i1 %9, label %13, label %11
11: ; preds = %4
%12 = tail call i32 @putchar(i8 signext %10)
br label %15
13: ; preds = %4
%14 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %10)
br label %15
15: ; preds = %11, %13
%16 = add nuw nsw i32 %5, 1
%17 = getelementptr inbounds i8, i8* %6, i64 1
%18 = icmp eq i32 %16, %1
br i1 %18, label %19, label %4
19: ; preds = %15, %2
ret void
}