#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(unsigned char);
int /*<<< orphan*/ printf(char *, unsigned char);
int /*<<< orphan*/ putchar(char);
char *PrintString(char *str, unsigned int len) {
  while (len-- > 0) {
    if (isprint((unsigned char)*str)) {
      putchar(*str);
    } else {
      printf("(%02x)", *(unsigned char *)str);
    }
    str++;
  }
  return str;
}


x86 assembly (clang, -O0):
<PrintString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jbe    119e <PrintString+0x6e>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     117a <PrintString+0x4a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    118d <PrintString+0x5d>
mov    -0x8(%rbp),%rax
lea    0xe7b(%rip),%rdi
movzbl (%rax),%esi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    113f <PrintString+0xf>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrintString>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
test   %esi,%esi
je     1180 <PrintString+0x50>
mov    %esi,%ebp
lea    0xebc(%rip),%r14
jmp    1163 <PrintString+0x33>
cs nopw 0x0(%rax,%rax,1)
movzbl %cl,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
test   %ebp,%ebp
je     1180 <PrintString+0x50>
add    $0xffffffff,%ebp
movzbl (%rbx),%edi
call   1050 <isprint@plt>
movzbl (%rbx),%ecx
test   %rax,%rax
je     1150 <PrintString+0x20>
movsbl %cl,%edi
call   1030 <putchar@plt>
jmp    115b <PrintString+0x2b>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"(%02x)\00"
define i8* @PrintString(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
br label %5
5: ; preds = %22, %2
%6 = load i32, i32* %4
%7 = add i32 %6, -1
store i32 %7, i32* %4
%8 = icmp ugt i32 %6, 0
br i1 %8, label %9, label %25
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = call i64 @isprint(i8 zeroext %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = call i32 @putchar(i8 signext %16)
br label %22
18: ; preds = %9
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %20)
br label %22
22: ; preds = %18, %14
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
br label %5
25: ; preds = %5
%26 = load i8*, i8** %3
ret i8* %26
}

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