#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 *);
int /*<<< orphan*/ putchar(char);
void print_quoted(char *str) {
  char first_quote = 0, q;
  char *c;
  for (c = str; *c; c++) {
    switch (*c) {
    case '\'':
    case '"':
      first_quote = *c;
      break;
    case ' ':
    case '\t':
      first_quote = *c;
      continue;
    default:
      continue;
    }
    break;
  }
  if (!first_quote) {
    printf("%s", str);
    return;
  }
  if (first_quote == '"')
    q = '\'';
  else
    q = '"';
  putchar(q);
  for (c = str; *c; c++) {
    if (*c == q) {
      putchar(q);
      q ^= '"' ^ '\'';
      putchar(q);
    }
    putchar(*c);
  }
  putchar(q);
}


x86 assembly (clang, -O0):
<print_quoted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a9 <print_quoted+0x89>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0xfffffff7,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x1e,%eax
ja     118e <print_quoted+0x6e>
mov    -0x20(%rbp),%rax
lea    0xe97(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x9(%rbp)
jmp    1193 <print_quoted+0x73>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x9(%rbp)
jmp    1198 <print_quoted+0x78>
jmp    1198 <print_quoted+0x78>
jmp    11a9 <print_quoted+0x89>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <print_quoted+0x18>
cmpb   $0x0,-0x9(%rbp)
jne    11c8 <print_quoted+0xa8>
mov    -0x8(%rbp),%rsi
lea    0xebe(%rip),%rdi
call   1040 <printf@plt>
jmp    1255 <print_quoted+0x135>
movsbl -0x9(%rbp),%eax
cmp    $0x22,%eax
jne    11de <print_quoted+0xbe>
movb   $0x27,-0xa(%rbp)
jmp    11e2 <print_quoted+0xc2>
movb   $0x22,-0xa(%rbp)
movsbl -0xa(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     124c <print_quoted+0x12c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
movsbl -0xa(%rbp),%ecx
cmp    %ecx,%eax
jne    122f <print_quoted+0x10f>
movsbl -0xa(%rbp),%edi
call   1030 <putchar@plt>
movsbl -0xa(%rbp),%eax
xor    $0x5,%eax
mov    %al,-0xa(%rbp)
movsbl -0xa(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11f3 <print_quoted+0xd3>
movsbl -0xa(%rbp),%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_quoted>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
mov    (%rdi),%bl
test   %bl,%bl
je     116e <print_quoted+0x4e>
lea    0x1(%rbp),%rax
xor    %edx,%edx
lea    0xec6(%rip),%rsi
jmp    114f <print_quoted+0x2f>
nopl   0x0(%rax)
mov    %ebx,%edx
movzbl (%rax),%ebx
add    $0x1,%rax
mov    %edx,%ecx
test   %bl,%bl
je     1165 <print_quoted+0x45>
movsbl %bl,%ecx
add    $0xfffffff7,%ecx
cmp    $0x1e,%ecx
ja     1142 <print_quoted+0x22>
movslq (%rsi,%rcx,4),%rdi
add    %rsi,%rdi
mov    %ebx,%ecx
jmp    *%rdi
cmp    $0x22,%cl
je     1181 <print_quoted+0x61>
test   %cl,%cl
jne    1186 <print_quoted+0x66>
lea    0xf07(%rip),%rdi
mov    %rbp,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>
mov    $0x27,%r14b
jmp    1189 <print_quoted+0x69>
mov    $0x22,%r14b
movzbl %r14b,%edi
call   1030 <putchar@plt>
mov    0x0(%rbp),%bl
test   %bl,%bl
je     11d7 <print_quoted+0xb7>
add    $0x1,%rbp
jmp    11b4 <print_quoted+0x94>
nop
movsbl %bl,%edi
call   1030 <putchar@plt>
movzbl 0x0(%rbp),%ebx
add    $0x1,%rbp
test   %bl,%bl
je     11d7 <print_quoted+0xb7>
cmp    %r14b,%bl
jne    11a0 <print_quoted+0x80>
movsbl %bl,%edi
call   1030 <putchar@plt>
mov    %ebx,%r14d
xor    $0x5,%r14b
movsbl %r14b,%edi
call   1030 <putchar@plt>
movzbl -0x1(%rbp),%ebx
jmp    11a0 <print_quoted+0x80>
movsbl %r14b,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define void @print_quoted(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8*
store i8* %0, i8** %2
store i8 0, i8* %3
%6 = load i8*, i8** %2
store i8* %6, i8** %5
br label %7
7: ; preds = %23, %1
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %26
11: ; preds = %7
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
switch i32 %14, label %21 [
i32 39, label %15
i32 34, label %15
i32 32, label %18
i32 9, label %18
]
15: ; preds = %11, %11
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
store i8 %17, i8* %3
br label %22
18: ; preds = %11, %11
%19 = load i8*, i8** %5
%20 = load i8, i8* %19
store i8 %20, i8* %3
br label %23
21: ; preds = %11
br label %23
22: ; preds = %15
br label %26
23: ; preds = %21, %18
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %5
br label %7
26: ; preds = %22, %7
%27 = load i8, i8* %3
%28 = icmp ne i8 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i8*, i8** %2
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %30)
br label %72
32: ; preds = %26
%33 = load i8, i8* %3
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 34
br i1 %35, label %36, label %37
36: ; preds = %32
store i8 39, i8* %4
br label %38
37: ; preds = %32
store i8 34, i8* %4
br label %38
38: ; preds = %37, %36
%39 = load i8, i8* %4
%40 = call i32 @putchar(i8 signext %39)
%41 = load i8*, i8** %2
store i8* %41, i8** %5
br label %42
42: ; preds = %66, %38
%43 = load i8*, i8** %5
%44 = load i8, i8* %43
%45 = icmp ne i8 %44, 0
br i1 %45, label %46, label %69
46: ; preds = %42
%47 = load i8*, i8** %5
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = load i8, i8* %4
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %49, %51
br i1 %52, label %53, label %62
53: ; preds = %46
%54 = load i8, i8* %4
%55 = call i32 @putchar(i8 signext %54)
%56 = load i8, i8* %4
%57 = sext i8 %56 to i32
%58 = xor i32 %57, 5
%59 = trunc i32 %58 to i8
store i8 %59, i8* %4
%60 = load i8, i8* %4
%61 = call i32 @putchar(i8 signext %60)
br label %62
62: ; preds = %53, %46
%63 = load i8*, i8** %5
%64 = load i8, i8* %63
%65 = call i32 @putchar(i8 signext %64)
br label %66
66: ; preds = %62
%67 = load i8*, i8** %5
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %5
br label %42
69: ; preds = %42
%70 = load i8, i8* %4
%71 = call i32 @putchar(i8 signext %70)
br label %72
72: ; preds = %69, %29
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define void @print_quoted(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %17, label %4
4: ; preds = %1, %10
%5 = phi i8 [ %13, %10 ], [ %2, %1 ]
%6 = phi i8* [ %12, %10 ], [ %0, %1 ]
%7 = phi i8 [ %11, %10 ], [ 0, %1 ]
%8 = sext i8 %5 to i32
switch i32 %8, label %10 [
i32 39, label %15
i32 34, label %15
i32 32, label %9
i32 9, label %9
]
9: ; preds = %4, %4
br label %10
10: ; preds = %4, %9
%11 = phi i8 [ %7, %4 ], [ %5, %9 ]
%12 = getelementptr inbounds i8, i8* %6, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %4
15: ; preds = %10, %4, %4
%16 = phi i8 [ %11, %10 ], [ %5, %4 ], [ %5, %4 ]
switch i8 %16, label %19 [
i8 0, label %17
i8 34, label %20
]
17: ; preds = %1, %15
%18 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %45
19: ; preds = %15
br label %20
20: ; preds = %15, %19
%21 = phi i8 [ 34, %19 ], [ 39, %15 ]
%22 = tail call i32 @putchar(i8 signext %21)
%23 = load i8, i8* %0
%24 = icmp eq i8 %23, 0
br i1 %24, label %42, label %25
25: ; preds = %20, %35
%26 = phi i8 [ %40, %35 ], [ %23, %20 ]
%27 = phi i8* [ %39, %35 ], [ %0, %20 ]
%28 = phi i8 [ %37, %35 ], [ %21, %20 ]
%29 = icmp eq i8 %26, %28
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = tail call i32 @putchar(i8 signext %26)
%32 = xor i8 %26, 5
%33 = tail call i32 @putchar(i8 signext %32)
%34 = load i8, i8* %27
br label %35
35: ; preds = %30, %25
%36 = phi i8 [ %34, %30 ], [ %26, %25 ]
%37 = phi i8 [ %32, %30 ], [ %28, %25 ]
%38 = tail call i32 @putchar(i8 signext %36)
%39 = getelementptr inbounds i8, i8* %27, i64 1
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 0
br i1 %41, label %42, label %25
42: ; preds = %35, %20
%43 = phi i8 [ %21, %20 ], [ %37, %35 ]
%44 = tail call i32 @putchar(i8 signext %43)
br label %45
45: ; preds = %42, %17
ret void
}