#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 */
char *getenv(char const *);
scalar_t__ strcasecmp(char *, char *);
int get_env_flag(const char *var_name, int default_val) {
  char *val;
  if (var_name == NULL)
    return 0;
  val = getenv(var_name);
  if (val == NULL)
    return default_val;
  if (strcasecmp(val, "1") == 0 || strcasecmp(val, "y") == 0 ||
      strcasecmp(val, "on") == 0 || strcasecmp(val, "yes") == 0) {
    return 1;
  } else if (strcasecmp(val, "0") == 0 || strcasecmp(val, "n") == 0 ||
             strcasecmp(val, "off") == 0 || strcasecmp(val, "no") == 0) {
    return 0;
  } else {
    ((void)1);
    return default_val;
  }
}


x86 assembly (clang, -O0):
<get_env_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1146 <get_env_flag+0x26>
movl   $0x0,-0x4(%rbp)
jmp    1257 <get_env_flag+0x137>
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1169 <get_env_flag+0x49>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1257 <get_env_flag+0x137>
mov    -0x20(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     11d1 <get_env_flag+0xb1>
mov    -0x20(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     11d1 <get_env_flag+0xb1>
mov    -0x20(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     11d1 <get_env_flag+0xb1>
mov    -0x20(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11dd <get_env_flag+0xbd>
movl   $0x1,-0x4(%rbp)
jmp    1257 <get_env_flag+0x137>
mov    -0x20(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     1245 <get_env_flag+0x125>
mov    -0x20(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     1245 <get_env_flag+0x125>
mov    -0x20(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     1245 <get_env_flag+0x125>
mov    -0x20(%rbp),%rdi
lea    0xddb(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1251 <get_env_flag+0x131>
movl   $0x0,-0x4(%rbp)
jmp    1257 <get_env_flag+0x137>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_env_flag>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     11fc <get_env_flag+0xdc>
mov    %esi,%r14d
call   1030 <getenv@plt>
test   %rax,%rax
je     11f7 <get_env_flag+0xd7>
mov    %rax,%rbx
lea    0xeb8(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcasecmp@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11fe <get_env_flag+0xde>
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     11fe <get_env_flag+0xde>
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     11fe <get_env_flag+0xde>
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     11fe <get_env_flag+0xde>
lea    0xe66(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     11fc <get_env_flag+0xdc>
lea    0xe4c(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     11fc <get_env_flag+0xdc>
lea    0xe40(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
mov    $0x0,%ebp
test   %rax,%rax
je     11fe <get_env_flag+0xde>
lea    0xe2b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
cmove  %ecx,%r14d
mov    %r14d,%ebp
jmp    11fe <get_env_flag+0xde>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"y\00"
@.str.2 = [3 x i8] c"on\00"
@.str.3 = [4 x i8] c"yes\00"
@.str.4 = [2 x i8] c"0\00"
@.str.5 = [2 x i8] c"n\00"
@.str.6 = [4 x i8] c"off\00"
@.str.7 = [3 x i8] c"no\00"
define i32 @get_env_flag(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 0, i32* %3
br label %53
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i8* @getenv(i8* %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = load i32, i32* %5
store i32 %16, i32* %3
br label %53
17: ; preds = %10
%18 = load i8*, i8** %6
%19 = call i64 @strcasecmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %33, label %21
21: ; preds = %17
%22 = load i8*, i8** %6
%23 = call i64 @strcasecmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %21
%26 = load i8*, i8** %6
%27 = call i64 @strcasecmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = call i64 @strcasecmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29, %25, %21, %17
store i32 1, i32* %3
br label %53
34: ; preds = %29
%35 = load i8*, i8** %6
%36 = call i64 @strcasecmp(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %50, label %38
38: ; preds = %34
%39 = load i8*, i8** %6
%40 = call i64 @strcasecmp(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %50, label %42
42: ; preds = %38
%43 = load i8*, i8** %6
%44 = call i64 @strcasecmp(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %42
%47 = load i8*, i8** %6
%48 = call i64 @strcasecmp(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %46, %42, %38, %34
store i32 0, i32* %3
br label %53
51: ; preds = %46
%52 = load i32, i32* %5
store i32 %52, i32* %3
br label %53
53: ; preds = %51, %50, %33, %15, %9
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"y\00"
@.str.2 = [3 x i8] c"on\00"
@.str.3 = [4 x i8] c"yes\00"
@.str.4 = [2 x i8] c"0\00"
@.str.5 = [2 x i8] c"n\00"
@.str.6 = [4 x i8] c"off\00"
@.str.7 = [3 x i8] c"no\00"
define i32 @get_env_flag(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %32, label %4
4: ; preds = %2
%5 = tail call i8* @getenv(i8* %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %32, label %7
7: ; preds = %4
%8 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %32, label %10
10: ; preds = %7
%11 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %32, label %13
13: ; preds = %10
%14 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %32, label %16
16: ; preds = %13
%17 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %32, label %19
19: ; preds = %16
%20 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %32, label %22
22: ; preds = %19
%23 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %22
%26 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = tail call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
%31 = select i1 %30, i32 0, i32 %1
br label %32
32: ; preds = %28, %19, %22, %25, %7, %10, %13, %16, %4, %2
%33 = phi i32 [ 0, %2 ], [ %1, %4 ], [ 1, %16 ], [ 1, %13 ], [ 1, %10 ], [ 1, %7 ], [ 0, %25 ], [ 0, %22 ], [ 0, %19 ], [ %31, %28 ]
ret i32 %33
}