#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcasecmp(char const *, char *);
int /*<<< orphan*/ strcmp(char const *, char *);
int cast_to_boolean(const char *key, const char *val, int *out) {
  if (!strcasecmp(val, "y") || !strcasecmp(val, "yes") ||
      !strcasecmp(val, "true") || !strcmp(val, "1"))
    *out = 1;
  else if (!strcasecmp(val, "n") || !strcasecmp(val, "no") ||
           !strcasecmp(val, "false") || !strcmp(val, "0"))
    *out = 0;
  else {
    fprintf(stderr,
            "Error: key \"%s\" (\"%s\") did not cast "
            "properly to boolean\n",
            key, val);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cast_to_boolean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
je     11a8 <cast_to_boolean+0x78>
mov    -0x18(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
je     11a8 <cast_to_boolean+0x78>
mov    -0x18(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
je     11a8 <cast_to_boolean+0x78>
mov    -0x18(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11b7 <cast_to_boolean+0x87>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
jmp    1258 <cast_to_boolean+0x128>
mov    -0x18(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
je     121b <cast_to_boolean+0xeb>
mov    -0x18(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
je     121b <cast_to_boolean+0xeb>
mov    -0x18(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
je     121b <cast_to_boolean+0xeb>
mov    -0x18(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    122a <cast_to_boolean+0xfa>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
jmp    1253 <cast_to_boolean+0x123>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdd8(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125f <cast_to_boolean+0x12f>
jmp    1258 <cast_to_boolean+0x128>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cast_to_boolean>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xeb9(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
mov    $0x1,%ebp
test   %eax,%eax
je     120d <cast_to_boolean+0xdd>
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     120d <cast_to_boolean+0xdd>
lea    0xe8c(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     120d <cast_to_boolean+0xdd>
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     120d <cast_to_boolean+0xdd>
lea    0xe69(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     120d <cast_to_boolean+0xdd>
lea    0xe56(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     120d <cast_to_boolean+0xdd>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     120d <cast_to_boolean+0xdd>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     120d <cast_to_boolean+0xdd>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1212 <cast_to_boolean+0xe2>
mov    %ebp,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"y\00"
@.str.1 = [4 x i8] c"yes\00"
@.str.2 = [5 x i8] c"true\00"
@.str.3 = [2 x i8] c"1\00"
@.str.4 = [2 x i8] c"n\00"
@.str.5 = [3 x i8] c"no\00"
@.str.6 = [6 x i8] c"false\00"
@.str.7 = [2 x i8] c"0\00"
@stderr = global i32 0
@.str.8 = [57 x i8] c"Error: key \22%s\22 (\22%s\22) did not cast properly to boolean\0A\00"
define i32 @cast_to_boolean(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%8 = load i8*, i8** %6
%9 = call i32 @strcasecmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = call i32 @strcasecmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = call i32 @strcasecmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = call i32 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19, %15, %11, %3
%24 = load i32*, i32** %7
store i32 1, i32* %24
br label %49
25: ; preds = %19
%26 = load i8*, i8** %6
%27 = call i32 @strcasecmp(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %41
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = call i32 @strcasecmp(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %29
%34 = load i8*, i8** %6
%35 = call i32 @strcasecmp(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i8*, i8** %6
%39 = call i32 @strcmp(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%40 = icmp ne i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %37, %33, %29, %25
%42 = load i32*, i32** %7
store i32 0, i32* %42
br label %48
43: ; preds = %37
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %5
%46 = load i8*, i8** %6
%47 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.8, i64 0, i64 0), i8* %45, i8* %46)
store i32 -1, i32* %4
br label %50
48: ; preds = %41
br label %49
49: ; preds = %48, %23
store i32 0, i32* %4
br label %50
50: ; preds = %49, %43
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@.str = [2 x i8] c"y\00"
@.str.1 = [4 x i8] c"yes\00"
@.str.2 = [5 x i8] c"true\00"
@.str.3 = [2 x i8] c"1\00"
@.str.4 = [2 x i8] c"n\00"
@.str.5 = [3 x i8] c"no\00"
@.str.6 = [6 x i8] c"false\00"
@.str.7 = [2 x i8] c"0\00"
@stderr = global i32 0
@.str.8 = [57 x i8] c"Error: key \22%s\22 (\22%s\22) did not cast properly to boolean\0A\00"
define i32 @cast_to_boolean(i8* %0, i8* %1, i32* nocapture writeonly %2) {
%4 = tail call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %30, label %6
6: ; preds = %3
%7 = tail call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %30, label %9
9: ; preds = %6
%10 = tail call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %30, label %12
12: ; preds = %9
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %30, label %15
15: ; preds = %12
%16 = tail call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %30, label %18
18: ; preds = %15
%19 = tail call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %18
%22 = tail call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %21
%25 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.8, i64 0, i64 0), i8* %0, i8* %1)
br label %32
30: ; preds = %15, %18, %21, %24, %3, %6, %9, %12
%31 = phi i32 [ 1, %12 ], [ 1, %9 ], [ 1, %6 ], [ 1, %3 ], [ 0, %24 ], [ 0, %21 ], [ 0, %18 ], [ 0, %15 ]
store i32 %31, i32* %2
br label %32
32: ; preds = %30, %27
%33 = phi i32 [ -1, %27 ], [ 0, %30 ]
ret i32 %33
}