#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_exitcode_envvar(void) {
  char *exitcode_envvar = NULL;
  int ret_val = 0;
  if (getenv("CLARMOR_ERROR_EXITCODE") != NULL) {
    if (!get_env_util(&exitcode_envvar, "CLARMOR_ERROR_EXITCODE")) {
      if (exitcode_envvar != NULL) {
        ret_val = strtol(exitcode_envvar, NULL, 0);
        free(exitcode_envvar);
      }
    }
  }
  return ret_val;
}


x86 assembly (clang, -O0):
<get_exitcode_envvar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xea2(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11b6 <get_exitcode_envvar+0x76>
lea    -0x8(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1050 <get_env_util@plt>
cmp    $0x0,%eax
jne    11b1 <get_exitcode_envvar+0x71>
cmpq   $0x0,-0x8(%rbp)
je     11ac <get_exitcode_envvar+0x6c>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <free@plt>
jmp    11b1 <get_exitcode_envvar+0x71>
jmp    11b6 <get_exitcode_envvar+0x76>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_exitcode_envvar>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0xeab(%rip),%rdi
call   1030 <getenv@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1195 <get_exitcode_envvar+0x55>
lea    0xe98(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1050 <get_env_util@plt>
test   %eax,%eax
jne    1195 <get_exitcode_envvar+0x55>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1195 <get_exitcode_envvar+0x55>
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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