#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 */
char *index(char const *, char);
int /*<<< orphan*/ out1fmt(char *, ...);
scalar_t__ strcspn(char const *, char *);
scalar_t__ strlen(char const *);
void print_quoted(const char *p) {
  const char *q;
  if (strcspn(p, "|&;<>()$`\\\"' \t\n*?[]#~=%") == strlen(p)) {
    out1fmt("%s", p);
    return;
  }
  while (*p) {
    if (*p == '\'') {
      out1fmt("\\'");
      p++;
      continue;
    }
    q = index(p, '\'');
    if (!q) {
      out1fmt("'%s'", p);
      return;
    }
    out1fmt("'%.*s'", (int)(q - p), p);
    p = q;
  }
}


x86 assembly (clang, -O0):
<print_quoted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <strcspn@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
jne    1190 <print_quoted+0x50>
mov    -0x8(%rbp),%rsi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <out1fmt@plt>
jmp    1231 <print_quoted+0xf1>
jmp    1195 <print_quoted+0x55>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1231 <print_quoted+0xf1>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    11d1 <print_quoted+0x91>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <out1fmt@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1195 <print_quoted+0x55>
mov    -0x8(%rbp),%rdi
mov    $0x27,%esi
call   1050 <index@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1205 <print_quoted+0xc5>
mov    -0x8(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <out1fmt@plt>
jmp    1231 <print_quoted+0xf1>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <out1fmt@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1195 <print_quoted+0x55>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_quoted>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
lea    0xeae(%rip),%rsi
call   1060 <strcspn@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
cmp    %rax,%rbx
jne    1170 <print_quoted+0x30>
lea    0xeaa(%rip),%rdi
jmp    11da <print_quoted+0x9a>
lea    0xea4(%rip),%r14
lea    0xea5(%rip),%r15
jmp    118e <print_quoted+0x4e>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <out1fmt@plt>
add    $0x1,%r12
movzbl (%r12),%eax
cmp    $0x27,%al
je     1180 <print_quoted+0x40>
test   %al,%al
je     11c7 <print_quoted+0x87>
mov    %r12,%rdi
mov    $0x27,%esi
call   1050 <index@plt>
test   %rax,%rax
je     11d3 <print_quoted+0x93>
mov    %rax,%rbx
mov    %ebx,%esi
sub    %r12d,%esi
mov    %r15,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <out1fmt@plt>
mov    %rbx,%r12
jmp    118e <print_quoted+0x4e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe44(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <out1fmt@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"|&;<>()$`\\\22' \09\0A*?[]#~=%\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"\\'\00"
@.str.3 = [5 x i8] c"'%s'\00"
@.str.4 = [7 x i8] c"'%.*s'\00"
define void @print_quoted(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @strcspn(i8* %4, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
%8 = icmp eq i64 %5, %7
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 (i8*, ...) @out1fmt(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %44
12: ; preds = %1
br label %13
13: ; preds = %34, %22, %12
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %44
17: ; preds = %13
%18 = load i8*, i8** %2
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 39
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = call i32 (i8*, ...) @out1fmt(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %2
br label %13
26: ; preds = %17
%27 = load i8*, i8** %2
%28 = call i8* @index(i8* %27, i8 signext 39)
store i8* %28, i8** %3
%29 = load i8*, i8** %3
%30 = icmp ne i8* %29, null
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = load i8*, i8** %2
%33 = call i32 (i8*, ...) @out1fmt(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %32)
br label %44
34: ; preds = %26
%35 = load i8*, i8** %3
%36 = load i8*, i8** %2
%37 = ptrtoint i8* %35 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
%40 = trunc i64 %39 to i32
%41 = load i8*, i8** %2
%42 = call i32 (i8*, ...) @out1fmt(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %40, i8* %41)
%43 = load i8*, i8** %3
store i8* %43, i8** %2
br label %13
44: ; preds = %9, %31, %13
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"|&;<>()$`\\\22' \09\0A*?[]#~=%\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"\\'\00"
@.str.3 = [5 x i8] c"'%s'\00"
@.str.4 = [7 x i8] c"'%.*s'\00"
define void @print_quoted(i8* %0) {
%2 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = icmp eq i64 %2, %3
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 (i8*, ...) @out1fmt(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %26
7: ; preds = %1, %13
%8 = phi i8* [ %14, %13 ], [ %0, %1 ]
%9 = load i8, i8* %8
switch i8 %9, label %15 [
i8 0, label %26
i8 39, label %10
]
10: ; preds = %7
%11 = tail call i32 (i8*, ...) @out1fmt(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds i8, i8* %8, i64 1
br label %13
13: ; preds = %10, %20
%14 = phi i8* [ %12, %10 ], [ %16, %20 ]
br label %7
15: ; preds = %7
%16 = tail call i8* @index(i8* %8, i8 signext 39)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 (i8*, ...) @out1fmt(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %8)
br label %26
20: ; preds = %15
%21 = ptrtoint i8* %16 to i64
%22 = ptrtoint i8* %8 to i64
%23 = sub i64 %21, %22
%24 = trunc i64 %23 to i32
%25 = tail call i32 (i8*, ...) @out1fmt(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %24, i8* %8)
br label %13
26: ; preds = %7, %18, %5
ret void
}