#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__ isdigit(char const);
scalar_t__ strcasecmp(char const *, char *);
long strtol(char const *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int strtob(const char *str) {
  if (str[0] == '\0') {
    return 0;
  } else if (strcasecmp(str, "true") == 0) {
    return 1;
  } else if (strcasecmp(str, "false") == 0) {
    return 0;
  } else if (isdigit(str[0]) == 0) {
    return -1;
  }
  long int i = strtol(str, NULL, 0);
  if (i < 0 || i > 1) {
    return -1;
  }
  return i;
}


x86 assembly (clang, -O0):
<strtob>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1158 <strtob+0x28>
movl   $0x0,-0x4(%rbp)
jmp    1211 <strtob+0xe1>
mov    -0x10(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    117e <strtob+0x4e>
movl   $0x1,-0x4(%rbp)
jmp    1211 <strtob+0xe1>
mov    -0x10(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11a4 <strtob+0x74>
movl   $0x0,-0x4(%rbp)
jmp    1211 <strtob+0xe1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
jne    11c6 <strtob+0x96>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <strtob+0xe1>
jmp    11cb <strtob+0x9b>
jmp    11d0 <strtob+0xa0>
jmp    11d5 <strtob+0xa5>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jl     11fe <strtob+0xce>
cmpq   $0x1,-0x18(%rbp)
jle    120a <strtob+0xda>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <strtob+0xe1>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtob>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%r14b
xor    %ebp,%ebp
test   %r14b,%r14b
je     119a <strtob+0x6a>
mov    %rdi,%rbx
lea    0xeb8(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     118e <strtob+0x5e>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     119a <strtob+0x6a>
movsbl %r14b,%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     1195 <strtob+0x65>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
cmp    $0x2,%rax
mov    $0xffffffff,%ebp
cmovb  %eax,%ebp
jmp    119a <strtob+0x6a>
mov    $0x1,%ebp
jmp    119a <strtob+0x6a>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"true\00"
@.str.1 = [6 x i8] c"false\00"
define i32 @strtob(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %43
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i64 @strcasecmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 1, i32* %2
br label %43
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = call i64 @strcasecmp(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %2
br label %43
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = call i64 @isdigit(i8 signext %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 -1, i32* %2
br label %43
28: ; preds = %21
br label %29
29: ; preds = %28
br label %30
30: ; preds = %29
br label %31
31: ; preds = %30
%32 = load i8*, i8** %3
%33 = call i64 @strtol(i8* %32, i32* null, i32 0)
store i64 %33, i64* %4
%34 = load i64, i64* %4
%35 = icmp slt i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %31
%37 = load i64, i64* %4
%38 = icmp sgt i64 %37, 1
br i1 %38, label %39, label %40
39: ; preds = %36, %31
store i32 -1, i32* %2
br label %43
40: ; preds = %36
%41 = load i64, i64* %4
%42 = trunc i64 %41 to i32
store i32 %42, i32* %2
br label %43
43: ; preds = %40, %39, %27, %20, %15, %10
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
@.str = [5 x i8] c"true\00"
@.str.1 = [6 x i8] c"false\00"
define i32 @strtob(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = tail call i64 @strcasecmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %18, label %7
7: ; preds = %4
%8 = tail call i64 @strcasecmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %7
%11 = tail call i64 @isdigit(i8 signext %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = tail call i64 @strtol(i8* nocapture %0, i32* null, i32 0)
%15 = icmp ugt i64 %14, 1
%16 = trunc i64 %14 to i32
%17 = select i1 %15, i32 -1, i32 %16
br label %18
18: ; preds = %10, %7, %4, %1, %13
%19 = phi i32 [ %17, %13 ], [ 0, %1 ], [ 1, %4 ], [ 0, %7 ], [ -1, %10 ]
ret i32 %19
}