#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*/ die(char *, unsigned char const *);
scalar_t__ errno;
unsigned char *getenv(unsigned char const *);
scalar_t__ isspace(unsigned char const);
int strtol(unsigned char const *, char **, int);
void parse_int_env(const unsigned char *env_name, int *p_var) {
  const unsigned char *s;
  int i;
  char *eptr = 0;
  if (!(s = getenv(env_name)))
    return;
  for (i = 0; s[i] && isspace(s[i]); ++i) {
  }
  if (!s[i])
    die("invalid value of environment '%s'", env_name);
  errno = 0;
  i = strtol(s, &eptr, 10);
  if (errno != 0 || *eptr)
    die("invalid value of environment '%s'", env_name);
  if (i < 0)
    die("invalid value of environment '%s'", env_name);
  *p_var = i;
}


x86 assembly (clang, -O0):
<parse_int_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1174 <parse_int_env+0x34>
jmp    126c <parse_int_env+0x12c>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     11b0 <parse_int_env+0x70>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11c0 <parse_int_env+0x80>
jmp    11d3 <parse_int_env+0x93>
jmp    11c5 <parse_int_env+0x85>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117b <parse_int_env+0x3b>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    11f5 <parse_int_env+0xb5>
mov    -0x8(%rbp),%rsi
lea    0xe10(%rip),%rdi
call   1060 <die@plt>
mov    0x2de4(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dc1(%rip),%rax
cmpq   $0x0,(%rax)
jne    1239 <parse_int_env+0xf9>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1249 <parse_int_env+0x109>
mov    -0x8(%rbp),%rsi
lea    0xdbc(%rip),%rdi
call   1060 <die@plt>
cmpl   $0x0,-0x1c(%rbp)
jge    1263 <parse_int_env+0x123>
mov    -0x8(%rbp),%rsi
lea    0xda2(%rip),%rdi
call   1060 <die@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int_env>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movq   $0x0,0x8(%rsp)
call   1030 <getenv@plt>
test   %rax,%rax
je     120e <parse_int_env+0xce>
mov    %rax,%r12
mov    (%rax),%al
test   %al,%al
je     11a6 <parse_int_env+0x66>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl %al,%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     119d <parse_int_env+0x5d>
movzbl 0x1(%r12,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1180 <parse_int_env+0x40>
jmp    11a6 <parse_int_env+0x66>
mov    %ebx,%eax
cmpb   $0x0,(%r12,%rax,1)
jne    11b5 <parse_int_env+0x75>
lea    0xe53(%rip),%rdi
mov    %r15,%rsi
call   1060 <die@plt>
mov    0x2e24(%rip),%r13
movq   $0x0,0x0(%r13)
lea    0x8(%rsp),%rsi
mov    %r12,%rdi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%ebx
cmpq   $0x0,0x0(%r13)
jne    11e9 <parse_int_env+0xa9>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     11f8 <parse_int_env+0xb8>
lea    0xe10(%rip),%rdi
mov    %r15,%rsi
call   1060 <die@plt>
test   %ebx,%ebx
jns    120b <parse_int_env+0xcb>
lea    0xdfd(%rip),%rdi
mov    %r15,%rsi
call   1060 <die@plt>
mov    %ebx,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"invalid value of environment '%s'\00"
@errno = global i64 0
define void @parse_int_env(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
store i8* null, i8** %7
%8 = load i8*, i8** %3
%9 = call i8* @getenv(i8* %8)
store i8* %9, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
br label %67
12: ; preds = %2
store i32 0, i32* %6
br label %13
13: ; preds = %32, %12
%14 = load i8*, i8** %5
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %13
%22 = load i8*, i8** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = call i64 @isspace(i8 zeroext %26)
%28 = icmp ne i64 %27, 0
br label %29
29: ; preds = %21, %13
%30 = phi i1 [ false, %13 ], [ %28, %21 ]
br i1 %30, label %31, label %35
31: ; preds = %29
br label %32
32: ; preds = %31
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %13
35: ; preds = %29
%36 = load i8*, i8** %5
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = icmp ne i8 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %35
%43 = load i8*, i8** %3
%44 = call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %42, %35
store i64 0, i64* @errno
%46 = load i8*, i8** %5
%47 = call i32 @strtol(i8* %46, i8** %7, i32 10)
store i32 %47, i32* %6
%48 = load i64, i64* @errno
%49 = icmp ne i64 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %45
%51 = load i8*, i8** %7
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %50, %45
%56 = load i8*, i8** %3
%57 = call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %56)
br label %58
58: ; preds = %55, %50
%59 = load i32, i32* %6
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i8*, i8** %3
%63 = call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %61, %58
%65 = load i32, i32* %6
%66 = load i32*, i32** %4
store i32 %65, i32* %66
br label %67
67: ; preds = %64, %11
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"invalid value of environment '%s'\00"
@errno = global i64 0
define void @parse_int_env(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = tail call i8* @getenv(i8* %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %42, label %7
7: ; preds = %2
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %7, %15
%11 = phi i64 [ %16, %15 ], [ 0, %7 ]
%12 = phi i8 [ %18, %15 ], [ %8, %7 ]
%13 = tail call i64 @isspace(i8 zeroext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %10
%16 = add nuw i64 %11, 1
%17 = getelementptr inbounds i8, i8* %5, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %25, label %10
20: ; preds = %10
%21 = and i64 %11, 4294967295
%22 = getelementptr inbounds i8, i8* %5, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %15, %7, %20
%26 = tail call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %27
27: ; preds = %25, %20
store i64 0, i64* @errno
%28 = call i32 @strtol(i8* %5, i8** %3, i32 10)
%29 = load i64, i64* @errno
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i8*, i8** %3
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %31, %27
%36 = tail call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %37
37: ; preds = %35, %31
%38 = icmp slt i32 %28, 0
br i1 %38, label %39, label %41
39: ; preds = %37
%40 = tail call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %41
41: ; preds = %39, %37
store i32 %28, i32* %1
br label %42
42: ; preds = %2, %41
ret void
}