#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__ isspace(char const);
int readboolvalue(char const *str) {
  char d;
  while (isspace(*str))
    ++str;
  if (!*str)
    return -1;
  d = *str++;
  while (isspace(*str))
    ++str;
  if (*str)
    return -1;
  if (d == '0')
    return 0;
  else if (d == '1')
    return 1;
  else
    return -1;
}


x86 assembly (clang, -O0):
<readboolvalue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     1143 <readboolvalue+0x33>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    111c <readboolvalue+0xc>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    115c <readboolvalue+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <readboolvalue+0xd9>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     1197 <readboolvalue+0x87>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1170 <readboolvalue+0x60>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b0 <readboolvalue+0xa0>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <readboolvalue+0xd9>
movsbl -0x11(%rbp),%eax
cmp    $0x30,%eax
jne    11c9 <readboolvalue+0xb9>
movl   $0x0,-0x4(%rbp)
jmp    11e9 <readboolvalue+0xd9>
movsbl -0x11(%rbp),%eax
cmp    $0x31,%eax
jne    11e2 <readboolvalue+0xd2>
movl   $0x1,-0x4(%rbp)
jmp    11e9 <readboolvalue+0xd9>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readboolvalue>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1030 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1120 <readboolvalue+0x10>
mov    -0x1(%rbx),%r14b
mov    $0xffffffff,%ebp
test   %r14b,%r14b
je     116e <readboolvalue+0x5e>
nop
movsbl (%rbx),%edi
call   1030 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1140 <readboolvalue+0x30>
cmpb   $0x0,-0x1(%rbx)
jne    116e <readboolvalue+0x5e>
xor    %eax,%eax
cmp    $0x31,%r14b
sete   %al
add    %eax,%eax
add    $0xffffffff,%eax
xor    %ebp,%ebp
cmp    $0x30,%r14b
cmovne %eax,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @readboolvalue(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %3
br label %5
5: ; preds = %10, %1
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = call i64 @isspace(i8 signext %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %3
br label %5
13: ; preds = %5
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %13
store i32 -1, i32* %2
br label %46
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
%21 = load i8, i8* %19
store i8 %21, i8* %4
br label %22
22: ; preds = %27, %18
%23 = load i8*, i8** %3
%24 = load i8, i8* %23
%25 = call i64 @isspace(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
br label %22
30: ; preds = %22
%31 = load i8*, i8** %3
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 -1, i32* %2
br label %46
35: ; preds = %30
%36 = load i8, i8* %4
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 48
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 0, i32* %2
br label %46
40: ; preds = %35
%41 = load i8, i8* %4
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 49
br i1 %43, label %44, label %45
44: ; preds = %40
store i32 1, i32* %2
br label %46
45: ; preds = %40
store i32 -1, i32* %2
br label %46
46: ; preds = %45, %44, %39, %34, %17
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
define i32 @readboolvalue(i8* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %7, %2 ]
%4 = load i8, i8* %3
%5 = tail call i64 @isspace(i8 signext %4)
%6 = icmp eq i64 %5, 0
%7 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %6, label %8, label %2
8: ; preds = %2
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %25, label %11
11: ; preds = %8, %11
%12 = phi i8* [ %13, %11 ], [ %3, %8 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = tail call i64 @isspace(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %11
17: ; preds = %11
%18 = load i8, i8* %13
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = icmp eq i8 %9, 49
%22 = select i1 %21, i32 1, i32 -1
%23 = icmp eq i8 %9, 48
%24 = select i1 %23, i32 0, i32 %22
br label %25
25: ; preds = %20, %17, %8
%26 = phi i32 [ -1, %8 ], [ -1, %17 ], [ %24, %20 ]
ret i32 %26
}