#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*/ err(int, char *, char const *);
scalar_t__ errno;
char *getenv_string(char const *);
long strtol(char const *, char **, int /*<<< orphan*/);
long getenv_int(const char *var_name) {
  const char *var_value = getenv_string(var_name);
  char *int_end;
  errno = 0;
  long num = strtol(var_value, &int_end, 0);
  if (errno != 0 || *int_end != 0)
    err(1, "Invalid value of integer environment variable: %s", var_value);
  return num;
}


x86 assembly (clang, -O0):
<getenv_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getenv_string@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e90(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e6f(%rip),%rax
cmpq   $0x0,(%rax)
jne    118b <getenv_int+0x5b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a0 <getenv_int+0x70>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xe65(%rip),%rsi
call   1050 <err@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getenv_int>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
call   1030 <getenv_string@plt>
mov    %rax,%rbx
mov    0x2e98(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%r14
cmpq   $0x0,(%r15)
jne    1171 <getenv_int+0x41>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1185 <getenv_int+0x55>
lea    0xe88(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
call   1050 <err@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [50 x i8] c"Invalid value of integer environment variable: %s\00"
define i64 @getenv_int(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @getenv_string(i8* %6)
store i8* %7, i8** %3
store i64 0, i64* @errno
%8 = load i8*, i8** %3
%9 = call i64 @strtol(i8* %8, i8** %4, i32 0)
store i64 %9, i64* %5
%10 = load i64, i64* @errno
%11 = icmp ne i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12, %1
%18 = load i8*, i8** %3
%19 = call i32 @err(i32 1, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %12
%21 = load i64, i64* %5
ret i64 %21
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [50 x i8] c"Invalid value of integer environment variable: %s\00"
define i64 @getenv_int(i8* %0) {
%2 = alloca i8*
%3 = tail call i8* @getenv_string(i8* %0)
%4 = bitcast i8** %2 to i8*
store i64 0, i64* @errno
%5 = call i64 @strtol(i8* %3, i8** %2, i32 0)
%6 = load i64, i64* @errno
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8, %1
%13 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %14
14: ; preds = %12, %8
ret i64 %5
}