#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 */
typedef int /*<<< orphan*/ ON_sym;
typedef int /*<<< orphan*/ OFF_sym;

/* Variables and functions */
int /*<<< orphan*/ assert(char const *);
scalar_t__ errno;
char *getenv(char const *);
scalar_t__ strcasecmp(char *, char *);
long strtol(char *, char **, int);
int get_flagval(const char *envar, const int deflt) {
  long lval = (long)deflt;
  char *str = NULL, *eptr = NULL;
  size_t i = 0;
  static char *ON_sym[] = {"true", "yes", "on"};
  static char *OFF_sym[] = {"false", "no", "off"};
  assert(envar);
  str = getenv(envar);
  if (NULL == str)
    return deflt;
  errno = 0;
  lval = strtol(str, &eptr, 10);
  if (errno)
    return deflt;
  if (eptr && (0 == *eptr))
    return lval;
  for (i = 0; i < sizeof(ON_sym) / sizeof(ON_sym[0]); ++i)
    if (0 == strcasecmp(str, ON_sym[i]))
      return 1;
  for (i = 0; i < sizeof(OFF_sym) / sizeof(OFF_sym[0]); ++i)
    if (0 == strcasecmp(str, OFF_sym[i]))
      return 0;
  return deflt;
}


x86 assembly (clang, -O0):
<get_flagval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movslq -0x14(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    119c <get_flagval+0x5c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12c0 <get_flagval+0x180>
mov    0x2e3d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e19(%rip),%rax
cmpq   $0x0,(%rax)
je     11dc <get_flagval+0x9c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12c0 <get_flagval+0x180>
cmpq   $0x0,-0x30(%rbp)
je     1204 <get_flagval+0xc4>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    1204 <get_flagval+0xc4>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    12c0 <get_flagval+0x180>
movq   $0x0,-0x38(%rbp)
cmpq   $0x3,-0x38(%rbp)
jae    125f <get_flagval+0x11f>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rcx
lea    0x2e2a(%rip),%rax
mov    (%rax,%rcx,8),%rsi
call   1040 <strcasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1249 <get_flagval+0x109>
movl   $0x1,-0x4(%rbp)
jmp    12c0 <get_flagval+0x180>
jmp    124e <get_flagval+0x10e>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    120c <get_flagval+0xcc>
movq   $0x0,-0x38(%rbp)
cmpq   $0x3,-0x38(%rbp)
jae    12ba <get_flagval+0x17a>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rcx
lea    0x2def(%rip),%rax
mov    (%rax,%rcx,8),%rsi
call   1040 <strcasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12a4 <get_flagval+0x164>
movl   $0x0,-0x4(%rbp)
jmp    12c0 <get_flagval+0x180>
jmp    12a9 <get_flagval+0x169>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1267 <get_flagval+0x127>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_flagval>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
movq   $0x0,(%rsp)
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     118e <get_flagval+0x4e>
mov    %rax,%rbx
mov    0x2e6f(%rip),%r15
movq   $0x0,(%r15)
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1060 <strtol@plt>
cmpq   $0x0,(%r15)
je     119e <get_flagval+0x5e>
mov    %r14d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,%rbp
mov    (%rsp),%rax
test   %rax,%rax
je     11af <get_flagval+0x6f>
cmpb   $0x0,(%rax)
je     1191 <get_flagval+0x51>
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1191 <get_flagval+0x51>
lea    0xe36(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1191 <get_flagval+0x51>
lea    0xe26(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1191 <get_flagval+0x51>
lea    0xe15(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1191 <get_flagval+0x51>
lea    0xe05(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1191 <get_flagval+0x51>
lea    0xdf0(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
cmove  %ecx,%r14d
jmp    118e <get_flagval+0x4e>

LLVM IR (-O0):
@get_flagval.ON_sym = internal global [3 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 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 ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0)]
@.str = [5 x i8] c"true\00"
@.str.1 = [4 x i8] c"yes\00"
@.str.2 = [3 x i8] c"on\00"
@get_flagval.OFF_sym = internal global [3 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0)]
@.str.3 = [6 x i8] c"false\00"
@.str.4 = [3 x i8] c"no\00"
@.str.5 = [4 x i8] c"off\00"
@errno = global i64 0
define i32 @get_flagval(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
store i64 %11, i64* %6
store i8* null, i8** %7
store i8* null, i8** %8
store i64 0, i64* %9
%12 = load i8*, i8** %4
%13 = call i32 @assert(i8* %12)
%14 = load i8*, i8** %4
%15 = call i8* @getenv(i8* %14)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = icmp eq i8* null, %16
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = load i32, i32* %5
store i32 %19, i32* %3
br label %72
20: ; preds = %2
store i64 0, i64* @errno
%21 = load i8*, i8** %7
%22 = call i64 @strtol(i8* %21, i8** %8, i32 10)
store i64 %22, i64* %6
%23 = load i64, i64* @errno
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i32, i32* %5
store i32 %26, i32* %3
br label %72
27: ; preds = %20
%28 = load i8*, i8** %8
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load i8*, i8** %8
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 0, %33
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i64, i64* %6
%37 = trunc i64 %36 to i32
store i32 %37, i32* %3
br label %72
38: ; preds = %30, %27
store i64 0, i64* %9
br label %39
39: ; preds = %51, %38
%40 = load i64, i64* %9
%41 = icmp ult i64 %40, 3
br i1 %41, label %42, label %54
42: ; preds = %39
%43 = load i8*, i8** %7
%44 = load i64, i64* %9
%45 = getelementptr inbounds [3 x i8*], [3 x i8*]* @get_flagval.ON_sym, i64 0, i64 %44
%46 = load i8*, i8** %45
%47 = call i64 @strcasecmp(i8* %43, i8* %46)
%48 = icmp eq i64 0, %47
br i1 %48, label %49, label %50
49: ; preds = %42
store i32 1, i32* %3
br label %72
50: ; preds = %42
br label %51
51: ; preds = %50
%52 = load i64, i64* %9
%53 = add i64 %52, 1
store i64 %53, i64* %9
br label %39
54: ; preds = %39
store i64 0, i64* %9
br label %55
55: ; preds = %67, %54
%56 = load i64, i64* %9
%57 = icmp ult i64 %56, 3
br i1 %57, label %58, label %70
58: ; preds = %55
%59 = load i8*, i8** %7
%60 = load i64, i64* %9
%61 = getelementptr inbounds [3 x i8*], [3 x i8*]* @get_flagval.OFF_sym, i64 0, i64 %60
%62 = load i8*, i8** %61
%63 = call i64 @strcasecmp(i8* %59, i8* %62)
%64 = icmp eq i64 0, %63
br i1 %64, label %65, label %66
65: ; preds = %58
store i32 0, i32* %3
br label %72
66: ; preds = %58
br label %67
67: ; preds = %66
%68 = load i64, i64* %9
%69 = add i64 %68, 1
store i64 %69, i64* %9
br label %55
70: ; preds = %55
%71 = load i32, i32* %5
store i32 %71, i32* %3
br label %72
72: ; preds = %70, %65, %49, %35, %25, %18
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str = [5 x i8] c"true\00"
@.str.1 = [4 x i8] c"yes\00"
@.str.2 = [3 x i8] c"on\00"
@.str.3 = [6 x i8] c"false\00"
@.str.4 = [3 x i8] c"no\00"
@.str.5 = [4 x i8] c"off\00"
@errno = global i64 0
define i32 @get_flagval(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = tail call i32 @assert(i8* %0)
%6 = tail call i8* @getenv(i8* %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %39, label %8
8: ; preds = %2
store i64 0, i64* @errno
%9 = call i64 @strtol(i8* %6, i8** %3, i32 10)
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %39
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = icmp eq i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = load i8, i8* %13
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = trunc i64 %9 to i32
br label %39
20: ; preds = %15, %12
%21 = tail call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %39, label %23
23: ; preds = %20
%24 = tail call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %39, label %26
26: ; preds = %23
%27 = tail call i64 @strcasecmp(i8* %6, 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 %39, label %29
29: ; preds = %26
%30 = tail call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %39, label %32
32: ; preds = %29
%33 = tail call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %32
%36 = tail call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
%38 = select i1 %37, i32 0, i32 %1
br label %39
39: ; preds = %35, %20, %23, %26, %29, %32, %8, %2, %18
%40 = phi i32 [ %19, %18 ], [ %1, %2 ], [ %1, %8 ], [ 0, %29 ], [ 0, %32 ], [ 1, %26 ], [ 1, %23 ], [ 1, %20 ], [ %38, %35 ]
ret i32 %40
}