#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*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getenv(char *);
int /*<<< orphan*/ stderr;
unsigned long strtoul(char *, char **, int);
unsigned long int get_long_from_env(char *name, unsigned long int fallback) {
  char *str;
  char *endptr;
  unsigned long int res;
  str = getenv(name);
  if (!str || *str == '\0')
    return fallback;
  res = strtoul(str, &endptr, 10);
  if (endptr == str) {
    fprintf(stderr, "error parsing env parameter '%s'\n", name);
    return fallback;
  }
  return res;
}


x86 assembly (clang, -O0):
<get_long_from_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1168 <get_long_from_env+0x38>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1175 <get_long_from_env+0x45>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c7 <get_long_from_env+0x97>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    11bf <get_long_from_env+0x8f>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe53(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c7 <get_long_from_env+0x97>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_long_from_env>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <getenv@plt>
test   %rax,%rax
je     1187 <get_long_from_env+0x57>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     1187 <get_long_from_env+0x57>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1050 <strtoul@plt>
cmp    %rbx,0x8(%rsp)
je     116f <get_long_from_env+0x3f>
mov    %rax,%r14
jmp    1187 <get_long_from_env+0x57>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
mov    %r15,%rdx
call   1040 <fprintf@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"error parsing env parameter '%s'\0A\00"
define i64 @get_long_from_env(i8* %0, i64 %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = load i8*, i8** %4
%10 = call i8* @getenv(i8* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13, %2
%19 = load i64, i64* %5
store i64 %19, i64* %3
br label %33
20: ; preds = %13
%21 = load i8*, i8** %6
%22 = call i64 @strtoul(i8* %21, i8** %7, i32 10)
store i64 %22, i64* %8
%23 = load i8*, i8** %7
%24 = load i8*, i8** %6
%25 = icmp eq i8* %23, %24
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %4
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = load i64, i64* %5
store i64 %30, i64* %3
br label %33
31: ; preds = %20
%32 = load i64, i64* %8
store i64 %32, i64* %3
br label %33
33: ; preds = %31, %26, %18
%34 = load i64, i64* %3
ret i64 %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"error parsing env parameter '%s'\0A\00"
define i64 @get_long_from_env(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i8* @getenv(i8* %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %17, label %7
7: ; preds = %2
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %7
%11 = call i64 @strtoul(i8* %5, i8** %3, i32 10)
%12 = load i8*, i8** %3
%13 = icmp eq i8* %12, %5
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %10, %2, %7, %14
%18 = phi i64 [ %1, %14 ], [ %1, %7 ], [ %1, %2 ], [ %11, %10 ]
ret i64 %18
}