#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 *);
char getenv_bool(const char *v, char *y) {
  char *x = getenv(v);
  if (!x)
    return 0;
  if (strcasecmp(x, "0") == 0 || strcasecmp(x, "n") == 0 ||
      strcasecmp(x, "false") == 0) {
    *y = 0;
  } else {
    *y = 1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<getenv_bool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1151 <getenv_bool+0x31>
movb   $0x0,-0x1(%rbp)
jmp    11b6 <getenv_bool+0x96>
mov    -0x20(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     119f <getenv_bool+0x7f>
mov    -0x20(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     119f <getenv_bool+0x7f>
mov    -0x20(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11ab <getenv_bool+0x8b>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11b2 <getenv_bool+0x92>
mov    -0x18(%rbp),%rax
movb   $0x1,(%rax)
movb   $0x1,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getenv_bool>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1030 <getenv@plt>
test   %rax,%rax
je     1173 <getenv_bool+0x53>
mov    %rax,%rbx
lea    0xec5(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1177 <getenv_bool+0x57>
lea    0xeb3(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1177 <getenv_bool+0x57>
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
setne  %al
jmp    1179 <getenv_bool+0x59>
xor    %eax,%eax
jmp    117e <getenv_bool+0x5e>
xor    %eax,%eax
mov    %al,(%r14)
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [2 x i8] c"n\00"
@.str.2 = [6 x i8] c"false\00"
define signext i8 @getenv_bool(i8* %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i8* @getenv(i8* %7)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i8 0, i8* %3
br label %29
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = call i64 @strcasecmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %12
%17 = load i8*, i8** %6
%18 = call i64 @strcasecmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i8*, i8** %6
%22 = call i64 @strcasecmp(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20, %16, %12
%25 = load i8*, i8** %5
store i8 0, i8* %25
br label %28
26: ; preds = %20
%27 = load i8*, i8** %5
store i8 1, i8* %27
br label %28
28: ; preds = %26, %24
store i8 1, i8* %3
br label %29
29: ; preds = %28, %11
%30 = load i8, i8* %3
ret i8 %30
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@.str.1 = [2 x i8] c"n\00"
@.str.2 = [6 x i8] c"false\00"
define signext i8 @getenv_bool(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = tail call i8* @getenv(i8* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = tail call i64 @strcasecmp(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %5
%9 = tail call i64 @strcasecmp(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = tail call i64 @strcasecmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
%14 = zext i1 %13 to i8
br label %15
15: ; preds = %11, %5, %8
%16 = phi i8 [ 0, %8 ], [ 0, %5 ], [ %14, %11 ]
store i8 %16, i8* %1
br label %17
17: ; preds = %2, %15
%18 = phi i8 [ 1, %15 ], [ 0, %2 ]
ret i8 %18
}