#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 is_tobequoted(char const);
int is_white(char const);
scalar_t__ strlen(char const *);
needquotes(const char *string) {
  int encapsulation = 0;
  const char *ps = string;
  if (string[0] != '\"') {
    while ((*ps) && (!(encapsulation))) {
      encapsulation = is_white(*ps) + is_tobequoted(*ps);
      ps++;
    }
  } else
    encapsulation = 0;
  if (strlen(string) == 0)
    encapsulation = 1;
  return (encapsulation);
}


x86 assembly (clang, -O0):
<needquotes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
je     11cc <needquotes+0x9c>
jmp    1160 <needquotes+0x30>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1181 <needquotes+0x51>
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1191 <needquotes+0x61>
jmp    11c7 <needquotes+0x97>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1050 <is_white@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <is_tobequoted@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1160 <needquotes+0x30>
jmp    11d3 <needquotes+0xa3>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    11ed <needquotes+0xbd>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<needquotes>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%cl
test   %cl,%cl
je     1172 <needquotes+0x52>
xor    %eax,%eax
cmp    $0x22,%cl
je     1177 <needquotes+0x57>
mov    %rdi,%r14
lea    0x1(%rdi),%rbx
nopl   0x0(%rax,%rax,1)
movsbl %cl,%edi
call   1040 <is_white@plt>
mov    %eax,%ebp
movsbl -0x1(%rbx),%edi
call   1030 <is_tobequoted@plt>
add    %ebp,%eax
movzbl (%rbx),%ecx
test   %cl,%cl
je     1164 <needquotes+0x44>
add    $0x1,%rbx
test   %eax,%eax
je     1140 <needquotes+0x20>
cmpb   $0x0,(%r14)
mov    $0x1,%ecx
cmove  %ecx,%eax
jmp    1177 <needquotes+0x57>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @needquotes(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
store i8* %5, i8** %4
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 34
br i1 %10, label %11, label %34
11: ; preds = %1
br label %12
12: ; preds = %23, %11
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* %3
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br label %21
21: ; preds = %17, %12
%22 = phi i1 [ false, %12 ], [ %20, %17 ]
br i1 %22, label %23, label %33
23: ; preds = %21
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = call i32 @is_white(i8 signext %25)
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = call i32 @is_tobequoted(i8 signext %28)
%30 = add nsw i32 %26, %29
store i32 %30, i32* %3
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
br label %12
33: ; preds = %21
br label %35
34: ; preds = %1
store i32 0, i32* %3
br label %35
35: ; preds = %34, %33
%36 = load i8*, i8** %2
%37 = call i64 @strlen(i8* %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 1, i32* %3
br label %40
40: ; preds = %39, %35
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
define i32 @needquotes(i8* nocapture %0) {
%2 = load i8, i8* %0
switch i8 %2, label %3 [
i8 34, label %20
i8 0, label %19
]
3: ; preds = %1, %3
%4 = phi i8 [ %11, %3 ], [ %2, %1 ]
%5 = phi i8* [ %10, %3 ], [ %0, %1 ]
%6 = tail call i32 @is_white(i8 signext %4)
%7 = load i8, i8* %5
%8 = tail call i32 @is_tobequoted(i8 signext %7)
%9 = add nsw i32 %8, %6
%10 = getelementptr inbounds i8, i8* %5, i64 1
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
%13 = icmp eq i32 %9, 0
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %3, label %15
15: ; preds = %3
%16 = load i8, i8* %0
%17 = icmp eq i8 %16, 0
%18 = select i1 %17, i32 1, i32 %9
br label %20
19: ; preds = %1
br label %20
20: ; preds = %1, %19, %15
%21 = phi i32 [ 0, %1 ], [ %18, %15 ], [ 1, %19 ]
ret i32 %21
}