#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 *, char const);
int /*<<< orphan*/ putchar(char const);
int printesc(const char *string) {
  const char *p;
  for (p = string; *p; p++) {
    switch (*p) {
    case '$':
    case '"':
    case '\\':
    case '`':
      putchar('\\');
      putchar(*p);
      break;
    default:
      if ((unsigned char)*p < 32 || (unsigned char)*p > 127) {
        printf("\\%03o", *p);
        continue;
      }
      putchar(*p);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<printesc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1201 <printesc+0xe1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x22,%eax
je     118c <printesc+0x6c>
jmp    1159 <printesc+0x39>
mov    -0x14(%rbp),%eax
sub    $0x24,%eax
je     118c <printesc+0x6c>
jmp    116a <printesc+0x4a>
mov    -0x14(%rbp),%eax
sub    $0x5c,%eax
je     118c <printesc+0x6c>
jmp    117b <printesc+0x5b>
mov    -0x14(%rbp),%eax
sub    $0x60,%eax
jne    11a7 <printesc+0x87>
jmp    118c <printesc+0x6c>
mov    $0x5c,%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    11eb <printesc+0xcb>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jl     11c7 <printesc+0xa7>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7f,%eax
jle    11df <printesc+0xbf>
mov    -0x10(%rbp),%rax
lea    0xe2e(%rip),%rdi
movsbl (%rax),%esi
call   1040 <printf@plt>
jmp    11f0 <printesc+0xd0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    11f0 <printesc+0xd0>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <printesc+0x14>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printesc>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     119e <printesc+0x7e>
mov    %rdi,%rbx
add    $0x1,%rbx
lea    0xec7(%rip),%r14
movabs $0x4400000000000005,%r15
jmp    1160 <printesc+0x40>
mov    %esi,%edi
nopw   0x0(%rax,%rax,1)
call   1030 <putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     119e <printesc+0x7e>
movsbl %al,%esi
lea    -0x22(%rsi),%ecx
cmp    $0x3e,%ecx
ja     1190 <printesc+0x70>
bt     %rcx,%r15
jae    1190 <printesc+0x70>
mov    $0x5c,%edi
call   1030 <putchar@plt>
movsbl -0x1(%rbx),%edi
jmp    1150 <printesc+0x30>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x1f,%al
jg     1145 <printesc+0x25>
mov    %r14,%rdi
call   1040 <printf@plt>
jmp    1155 <printesc+0x35>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"\\%03o\00"
define i32 @printesc(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
store i8* %4, i8** %3
br label %5
5: ; preds = %37, %1
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %40
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %18 [
i32 36, label %13
i32 34, label %13
i32 92, label %13
i32 96, label %13
]
13: ; preds = %9, %9, %9, %9
%14 = call i32 @putchar(i8 signext 92)
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = call i32 @putchar(i8 signext %16)
br label %36
18: ; preds = %9
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = icmp slt i32 %21, 32
br i1 %22, label %28, label %23
23: ; preds = %18
%24 = load i8*, i8** %3
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = icmp sgt i32 %26, 127
br i1 %27, label %28, label %32
28: ; preds = %23, %18
%29 = load i8*, i8** %3
%30 = load i8, i8* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %30)
br label %37
32: ; preds = %23
%33 = load i8*, i8** %3
%34 = load i8, i8* %33
%35 = call i32 @putchar(i8 signext %34)
br label %36
36: ; preds = %32, %13
br label %37
37: ; preds = %36, %28
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %3
br label %5
40: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"\\%03o\00"
define i32 @printesc(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %22, label %4
4: ; preds = %1, %18
%5 = phi i8 [ %20, %18 ], [ %2, %1 ]
%6 = phi i8* [ %19, %18 ], [ %0, %1 ]
%7 = sext i8 %5 to i32
switch i32 %7, label %12 [
i32 36, label %8
i32 34, label %8
i32 92, label %8
i32 96, label %8
]
8: ; preds = %4, %4, %4, %4
%9 = tail call i32 @putchar(i8 signext 92)
%10 = load i8, i8* %6
%11 = tail call i32 @putchar(i8 signext %10)
br label %18
12: ; preds = %4
%13 = icmp slt i8 %5, 32
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %5)
br label %18
16: ; preds = %12
%17 = tail call i32 @putchar(i8 signext %5)
br label %18
18: ; preds = %8, %16, %14
%19 = getelementptr inbounds i8, i8* %6, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %4
22: ; preds = %18, %1
ret i32 0
}