#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(int);
scalar_t__ strcmp(char const *, char *);
size_t strlen(char const *);
scalar_t__ strncmp(char *, char *, size_t);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char toupper(char const);
int arg_convertbool(const char *str) {
  char buff[1024];
  size_t i, n;
  if (str == NULL)
    return -1;
  while (isspace((int)*str))
    str++;
  if (strcmp(str, "") == 0)
    return -1;
  n = strlen(str);
  strncpy(buff, str, 1024);
  for (i = 0; i < n; i++)
    buff[i] = toupper(str[i]);
  if (strncmp(buff, "FALSE", n) == 0)
    return 0;
  if (strncmp(buff, "NO", n) == 0)
    return 0;
  if (strncmp(buff, "OFF", n) == 0 && n > 1)
    return 0;
  if (strncmp(buff, "TRUE", n) == 0)
    return 1;
  if (strncmp(buff, "YES", n) == 0)
    return 1;
  if (strncmp(buff, "ON", n) == 0 && n > 1)
    return 1;
  return -1;
}


x86 assembly (clang, -O0):
<arg_convertbool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1186 <arg_convertbool+0x26>
movl   $0xffffffff,-0x4(%rbp)
jmp    139a <arg_convertbool+0x23a>
jmp    118b <arg_convertbool+0x2b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1070 <isspace@plt>
cmp    $0x0,%rax
je     11b2 <arg_convertbool+0x52>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    118b <arg_convertbool+0x2b>
mov    -0x10(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11d8 <arg_convertbool+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    139a <arg_convertbool+0x23a>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
movq   $0x0,-0x418(%rbp)
mov    -0x418(%rbp),%rax
cmp    -0x420(%rbp),%rax
jae    1257 <arg_convertbool+0xf7>
mov    -0x10(%rbp),%rax
mov    -0x418(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <toupper@plt>
mov    %al,%cl
mov    -0x418(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x418(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
jmp    1208 <arg_convertbool+0xa8>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rdx
lea    0xd94(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1287 <arg_convertbool+0x127>
movl   $0x0,-0x4(%rbp)
jmp    139a <arg_convertbool+0x23a>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rdx
lea    0xd6a(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12b7 <arg_convertbool+0x157>
movl   $0x0,-0x4(%rbp)
jmp    139a <arg_convertbool+0x23a>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rdx
lea    0xd3d(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12f5 <arg_convertbool+0x195>
cmpq   $0x1,-0x420(%rbp)
01
jbe    12f5 <arg_convertbool+0x195>
movl   $0x0,-0x4(%rbp)
jmp    139a <arg_convertbool+0x23a>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rdx
lea    0xd03(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1325 <arg_convertbool+0x1c5>
movl   $0x1,-0x4(%rbp)
jmp    139a <arg_convertbool+0x23a>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rdx
lea    0xcd8(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1355 <arg_convertbool+0x1f5>
movl   $0x1,-0x4(%rbp)
jmp    139a <arg_convertbool+0x23a>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rdx
lea    0xcac(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1393 <arg_convertbool+0x233>
cmpq   $0x1,-0x420(%rbp)
01
jbe    1393 <arg_convertbool+0x233>
movl   $0x1,-0x4(%rbp)
jmp    139a <arg_convertbool+0x23a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_convertbool>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     12a8 <arg_convertbool+0x148>
mov    %rdi,%rbp
add    $0xffffffffffffffff,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl 0x1(%rbp),%edi
add    $0x1,%rbp
call   1070 <isspace@plt>
test   %rax,%rax
jne    1190 <arg_convertbool+0x30>
lea    0xe5c(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12a8 <arg_convertbool+0x148>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
test   %r15,%r15
je     11f6 <arg_convertbool+0x96>
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl 0x0(%rbp,%rbx,1),%edi
call   1050 <toupper@plt>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11e0 <arg_convertbool+0x80>
lea    0xe03(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
call   1040 <strncmp@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     12a8 <arg_convertbool+0x148>
lea    0xdeb(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
call   1040 <strncmp@plt>
test   %rax,%rax
je     12a8 <arg_convertbool+0x148>
lea    0xdd7(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1248 <arg_convertbool+0xe8>
cmp    $0x1,%r15
ja     12a8 <arg_convertbool+0x148>
lea    0xdbe(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
call   1040 <strncmp@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     12a8 <arg_convertbool+0x148>
lea    0xda6(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
call   1040 <strncmp@plt>
test   %rax,%rax
je     12a8 <arg_convertbool+0x148>
cmp    $0x2,%r15
setae  %bl
lea    0xd8c(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
call   1040 <strncmp@plt>
test   %rax,%rax
sete   %al
and    %bl,%al
movzbl %al,%eax
lea    (%rax,%rax,1),%r14d
add    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [6 x i8] c"FALSE\00"
@.str.2 = [3 x i8] c"NO\00"
@.str.3 = [4 x i8] c"OFF\00"
@.str.4 = [5 x i8] c"TRUE\00"
@.str.5 = [4 x i8] c"YES\00"
@.str.6 = [3 x i8] c"ON\00"
define i32 @arg_convertbool(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %89
10: ; preds = %1
br label %11
11: ; preds = %17, %10
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = call i64 @isspace(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
br label %11
20: ; preds = %11
%21 = load i8*, i8** %3
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 -1, i32* %2
br label %89
25: ; preds = %20
%26 = load i8*, i8** %3
%27 = call i64 @strlen(i8* %26)
store i64 %27, i64* %6
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%29 = load i8*, i8** %3
%30 = call i32 @strncpy(i8* %28, i8* %29, i32 1024)
store i64 0, i64* %5
br label %31
31: ; preds = %43, %25
%32 = load i64, i64* %5
%33 = load i64, i64* %6
%34 = icmp ult i64 %32, %33
br i1 %34, label %35, label %46
35: ; preds = %31
%36 = load i8*, i8** %3
%37 = load i64, i64* %5
%38 = getelementptr inbounds i8, i8* %36, i64 %37
%39 = load i8, i8* %38
%40 = call signext i8 @toupper(i8 signext %39)
%41 = load i64, i64* %5
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %41
store i8 %40, i8* %42
br label %43
43: ; preds = %35
%44 = load i64, i64* %5
%45 = add i64 %44, 1
store i64 %45, i64* %5
br label %31
46: ; preds = %31
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%48 = load i64, i64* %6
%49 = call i64 @strncmp(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %46
store i32 0, i32* %2
br label %89
52: ; preds = %46
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%54 = load i64, i64* %6
%55 = call i64 @strncmp(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %52
store i32 0, i32* %2
br label %89
58: ; preds = %52
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%60 = load i64, i64* %6
%61 = call i64 @strncmp(i8* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %58
%64 = load i64, i64* %6
%65 = icmp ugt i64 %64, 1
br i1 %65, label %66, label %67
66: ; preds = %63
store i32 0, i32* %2
br label %89
67: ; preds = %63, %58
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%69 = load i64, i64* %6
%70 = call i64 @strncmp(i8* %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %69)
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %67
store i32 1, i32* %2
br label %89
73: ; preds = %67
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%75 = load i64, i64* %6
%76 = call i64 @strncmp(i8* %74, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i64 %75)
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %73
store i32 1, i32* %2
br label %89
79: ; preds = %73
%80 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%81 = load i64, i64* %6
%82 = call i64 @strncmp(i8* %80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64 %81)
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %88
84: ; preds = %79
%85 = load i64, i64* %6
%86 = icmp ugt i64 %85, 1
br i1 %86, label %87, label %88
87: ; preds = %84
store i32 1, i32* %2
br label %89
88: ; preds = %84, %79
store i32 -1, i32* %2
br label %89
89: ; preds = %88, %87, %78, %72, %66, %57, %51, %24, %9
%90 = load i32, i32* %2
ret i32 %90
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [6 x i8] c"FALSE\00"
@.str.2 = [3 x i8] c"NO\00"
@.str.3 = [4 x i8] c"OFF\00"
@.str.4 = [5 x i8] c"TRUE\00"
@.str.5 = [4 x i8] c"YES\00"
@.str.6 = [3 x i8] c"ON\00"
define i32 @arg_convertbool(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %49, label %5
5: ; preds = %1, %5
%6 = phi i8* [ %11, %5 ], [ %0, %1 ]
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = tail call i64 @isspace(i32 %8)
%10 = icmp eq i64 %9, 0
%11 = getelementptr inbounds i8, i8* %6, i64 1
br i1 %10, label %12, label %5
12: ; preds = %5
%13 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %49, label %15
15: ; preds = %12
%16 = tail call i64 @strlen(i8* %6)
%17 = call i32 @strncpy(i8* %3, i8* %6, i32 1024)
%18 = icmp eq i64 %16, 0
br i1 %18, label %27, label %19
19: ; preds = %15, %19
%20 = phi i64 [ %25, %19 ], [ 0, %15 ]
%21 = getelementptr inbounds i8, i8* %6, i64 %20
%22 = load i8, i8* %21
%23 = call signext i8 @toupper(i8 signext %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %20
store i8 %23, i8* %24
%25 = add nuw i64 %20, 1
%26 = icmp eq i64 %25, %16
br i1 %26, label %27, label %19
27: ; preds = %19, %15
%28 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %16)
%29 = icmp eq i64 %28, 0
br i1 %29, label %49, label %30
30: ; preds = %27
%31 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 %16)
%32 = icmp eq i64 %31, 0
br i1 %32, label %49, label %33
33: ; preds = %30
%34 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %16)
%35 = icmp eq i64 %34, 0
%36 = icmp ugt i64 %16, 1
%37 = select i1 %35, i1 %36, i1 false
br i1 %37, label %49, label %38
38: ; preds = %33
%39 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %16)
%40 = icmp eq i64 %39, 0
br i1 %40, label %49, label %41
41: ; preds = %38
%42 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i64 %16)
%43 = icmp eq i64 %42, 0
br i1 %43, label %49, label %44
44: ; preds = %41
%45 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64 %16)
%46 = icmp eq i64 %45, 0
%47 = select i1 %46, i1 %36, i1 false
%48 = select i1 %47, i32 1, i32 -1
br label %49
49: ; preds = %44, %41, %38, %33, %30, %27, %12, %1
%50 = phi i32 [ -1, %1 ], [ -1, %12 ], [ 0, %27 ], [ 0, %30 ], [ 0, %33 ], [ 1, %38 ], [ 1, %41 ], [ %48, %44 ]
ret i32 %50
}