#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__ ARRAY_SIZE(char const *const *);
int atoi(char const *);
int /*<<< orphan*/ strcasecmp(char const *, char const *const);
int arg_to_bool(const char *s) {
  static const char *const on[] = {"on", "yes", "true"};
  int n = atoi(s);
  if (n)
    return 1;
  for (n = 0; n < (int)ARRAY_SIZE(on); n++)
    if (!strcasecmp(s, on[n]))
      return 1;
  return 0;
}


x86 assembly (clang, -O0):
<arg_to_bool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     115e <arg_to_bool+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    11cc <arg_to_bool+0x9c>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    0x2c8e(%rip),%rdi
call   1050 <ARRAY_SIZE@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11c5 <arg_to_bool+0x95>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rcx
lea    0x2c6c(%rip),%rax
mov    (%rax,%rcx,8),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11b2 <arg_to_bool+0x82>
movl   $0x1,-0x4(%rbp)
jmp    11cc <arg_to_bool+0x9c>
jmp    11b7 <arg_to_bool+0x87>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <arg_to_bool+0x35>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_to_bool>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
call   1040 <atoi@plt>
mov    $0x1,%r14d
test   %eax,%eax
jne    1199 <arg_to_bool+0x69>
lea    0x2caf(%rip),%r15
mov    %r15,%rdi
call   1050 <ARRAY_SIZE@plt>
test   %eax,%eax
jle    1196 <arg_to_bool+0x66>
xor    %ebp,%ebp
mov    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx),%rsi
mov    %r12,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     1199 <arg_to_bool+0x69>
add    $0x1,%rbp
mov    %r15,%rdi
call   1050 <ARRAY_SIZE@plt>
cltq
add    $0x8,%rbx
cmp    %rax,%rbp
jl     1170 <arg_to_bool+0x40>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@arg_to_bool.on = internal constant [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0)]
@.str = [3 x i8] c"on\00"
@.str.1 = [4 x i8] c"yes\00"
@.str.2 = [5 x i8] c"true\00"
define i32 @arg_to_bool(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @atoi(i8* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 1, i32* %2
br label %30
10: ; preds = %1
store i32 0, i32* %4
br label %11
11: ; preds = %26, %10
%12 = load i32, i32* %4
%13 = call i64 @ARRAY_SIZE(i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @arg_to_bool.on, i64 0, i64 0))
%14 = trunc i64 %13 to i32
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %29
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [3 x i8*], [3 x i8*]* @arg_to_bool.on, i64 0, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 @strcasecmp(i8* %17, i8* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %16
store i32 1, i32* %2
br label %30
25: ; preds = %16
br label %26
26: ; preds = %25
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %11
29: ; preds = %11
store i32 0, i32* %2
br label %30
30: ; preds = %29, %24, %9
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@arg_to_bool.on = internal constant [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0)]
@.str = [3 x i8] c"on\00"
@.str.1 = [4 x i8] c"yes\00"
@.str.2 = [5 x i8] c"true\00"
define i32 @arg_to_bool(i8* nocapture %0) {
%2 = tail call i32 @atoi(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %20
4: ; preds = %1
%5 = tail call i64 @ARRAY_SIZE(i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @arg_to_bool.on, i64 0, i64 0))
%6 = trunc i64 %5 to i32
%7 = icmp sgt i32 %6, 0
br i1 %7, label %13, label %20
8: ; preds = %13
%9 = tail call i64 @ARRAY_SIZE(i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @arg_to_bool.on, i64 0, i64 0))
%10 = shl i64 %9, 32
%11 = ashr exact i64 %10, 32
%12 = icmp slt i64 %19, %11
br i1 %12, label %13, label %20
13: ; preds = %4, %8
%14 = phi i64 [ %19, %8 ], [ 0, %4 ]
%15 = getelementptr inbounds [3 x i8*], [3 x i8*]* @arg_to_bool.on, i64 0, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i32 @strcasecmp(i8* %0, i8* %16)
%18 = icmp eq i32 %17, 0
%19 = add nuw nsw i64 %14, 1
br i1 %18, label %20, label %8
20: ; preds = %13, %8, %4, %1
%21 = phi i32 [ 1, %1 ], [ 0, %4 ], [ 1, %13 ], [ 0, %8 ]
ret i32 %21
}