#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 *, char);
int /*<<< orphan*/ putchar(char);
void print_escaped(char *s) {
  putchar('"');
  while (s != NULL && *s != '\0') {
    char c = *s;
    if (isprint(c)) {
      putchar(c);
    } else {
      printf("[%i]", c);
    }
    s++;
  }
  putchar('"');
}


x86 assembly (clang, -O0):
<print_escaped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x22,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0xa(%rbp)
je     1166 <print_escaped+0x36>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
test   $0x1,%al
jne    1176 <print_escaped+0x46>
jmp    11c1 <print_escaped+0x91>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     11a0 <print_escaped+0x70>
movsbl -0x9(%rbp),%edi
call   1030 <putchar@plt>
jmp    11b0 <print_escaped+0x80>
lea    0xe59(%rip),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1146 <print_escaped+0x16>
mov    $0x22,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_escaped>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x22,%edi
call   1030 <putchar@plt>
test   %rbx,%rbx
je     118d <print_escaped+0x5d>
mov    (%rbx),%al
test   %al,%al
je     118d <print_escaped+0x5d>
add    $0x1,%rbx
lea    0xea9(%rip),%r14
jmp    1175 <print_escaped+0x45>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     118d <print_escaped+0x5d>
movsbl %al,%ebp
mov    %ebp,%edi
call   1050 <isprint@plt>
test   %rax,%rax
je     1160 <print_escaped+0x30>
mov    %ebp,%edi
call   1030 <putchar@plt>
jmp    116a <print_escaped+0x3a>
mov    $0x22,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"[%i]\00"
define void @print_escaped(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
store i8* %0, i8** %2
%4 = call i32 @putchar(i8 signext 34)
br label %5
5: ; preds = %27, %1
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br label %13
13: ; preds = %8, %5
%14 = phi i1 [ false, %5 ], [ %12, %8 ]
br i1 %14, label %15, label %30
15: ; preds = %13
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
store i8 %17, i8* %3
%18 = load i8, i8* %3
%19 = call i64 @isprint(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i8, i8* %3
%23 = call i32 @putchar(i8 signext %22)
br label %27
24: ; preds = %15
%25 = load i8, i8* %3
%26 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %25)
br label %27
27: ; preds = %24, %21
%28 = load i8*, i8** %2
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %2
br label %5
30: ; preds = %13
%31 = call i32 @putchar(i8 signext 34)
ret void
}

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