#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*/ free(char *);
int /*<<< orphan*/ get_env_util(char **, char *);
int /*<<< orphan*/ *getenv(char *);
int strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int get_error_envvar(void) {
  char *error_envvar = NULL;
  if (getenv("CLARMOR_EXIT_ON_OVERFLOW") == NULL) {
    return 0;
  } else {
    int ret_val;
    if (!get_env_util(&error_envvar, "CLARMOR_EXIT_ON_OVERFLOW")) {
      if (error_envvar != NULL) {
        ret_val = strtol(error_envvar, NULL, 0);
        free(error_envvar);
      } else
        ret_val = -1;
    } else
      ret_val = -1;
    if (ret_val > 1)
      ret_val = 1;
    return ret_val;
  }
}


x86 assembly (clang, -O0):
<get_error_envvar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
lea    0xea9(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    1172 <get_error_envvar+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <get_error_envvar+0xa0>
lea    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1050 <get_env_util@plt>
cmp    $0x0,%eax
jne    11c2 <get_error_envvar+0x82>
cmpq   $0x0,-0x10(%rbp)
je     11b6 <get_error_envvar+0x76>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
jmp    11bd <get_error_envvar+0x7d>
movl   $0xffffffff,-0x14(%rbp)
jmp    11c9 <get_error_envvar+0x89>
movl   $0xffffffff,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    11da <get_error_envvar+0x9a>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_error_envvar>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0xeab(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11a7 <get_error_envvar+0x67>
lea    0xe9a(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1050 <get_env_util@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
jne    11a9 <get_error_envvar+0x69>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     11a9 <get_error_envvar+0x69>
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    $0x1,%eax
test   %ebx,%ebx
jg     11a9 <get_error_envvar+0x69>
mov    %ebx,%eax
jmp    11a9 <get_error_envvar+0x69>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [25 x i8] c"CLARMOR_EXIT_ON_OVERFLOW\00"
define i32 @get_error_envvar() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%3 = tail call i32* @getenv(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %18, label %5
5: ; preds = %0
%6 = call i32 @get_env_util(i8** %1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = load i8*, i8** %1
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = call i32 @strtol(i8* nocapture %9, i32* null, i32 0)
%13 = load i8*, i8** %1
%14 = call i32 @free(i8* %13)
%15 = icmp slt i32 %12, 1
br i1 %15, label %16, label %18
16: ; preds = %5, %8, %11
%17 = phi i32 [ %12, %11 ], [ -1, %8 ], [ -1, %5 ]
br label %18
18: ; preds = %16, %11, %0
%19 = phi i32 [ 0, %0 ], [ %17, %16 ], [ 1, %11 ]
ret i32 %19
}