#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 */
scalar_t__ ERANGE;
int /*<<< orphan*/ Log(char *, char const *, char const *);
scalar_t__ errno;
char *getenv(char const *);
long strtol(char const *, char **, int /*<<< orphan*/);
long GetLongSetting(const char *name, long def) {
  const char *value = getenv(name);
  if (value == NULL || value[0] == 0) {
    return def;
  }
  char *endptr = NULL;
  errno = 0;
  long number = strtol(value, &endptr, 0);
  if (errno == ERANGE) {
    Log("Ignoring out-of-range value of %s: %s", name, value);
    return def;
  }
  if ((endptr != NULL && *endptr != 0)) {
    Log("Ignoring non-numeric value of %s: %s", name, value);
    return def;
  }
  return number;
}


x86 assembly (clang, -O0):
<GetLongSetting>:
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 <GetLongSetting+0x38>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1175 <GetLongSetting+0x45>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121d <GetLongSetting+0xed>
movq   $0x0,-0x28(%rbp)
mov    0x2e54(%rip),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%rax
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%rax
jne    11d9 <GetLongSetting+0xa9>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe39(%rip),%rdi
call   1050 <Log@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121d <GetLongSetting+0xed>
cmpq   $0x0,-0x28(%rbp)
je     1215 <GetLongSetting+0xe5>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1215 <GetLongSetting+0xe5>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe23(%rip),%rdi
call   1050 <Log@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121d <GetLongSetting+0xed>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetLongSetting>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <getenv@plt>
test   %rax,%rax
je     11b3 <GetLongSetting+0x83>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     11b3 <GetLongSetting+0x83>
movq   $0x0,(%rsp)
mov    0x2e79(%rip),%r12
movq   $0x0,(%r12)
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    (%r12),%rcx
mov    0x2e69(%rip),%rdx
cmp    (%rdx),%rcx
jne    118d <GetLongSetting+0x5d>
lea    0xe75(%rip),%rdi
jmp    11a2 <GetLongSetting+0x72>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     11b0 <GetLongSetting+0x80>
cmpb   $0x0,(%rcx)
je     11b0 <GetLongSetting+0x80>
lea    0xe84(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <Log@plt>
mov    %r14,%rax
mov    %rax,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@.str = [38 x i8] c"Ignoring out-of-range value of %s: %s\00"
@.str.1 = [37 x i8] c"Ignoring non-numeric value of %s: %s\00"
define i64 @GetLongSetting(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 eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13, %2
%20 = load i64, i64* %5
store i64 %20, i64* %3
br label %47
21: ; preds = %13
store i8* null, i8** %7
store i64 0, i64* @errno
%22 = load i8*, i8** %6
%23 = call i64 @strtol(i8* %22, i8** %7, i32 0)
store i64 %23, i64* %8
%24 = load i64, i64* @errno
%25 = load i64, i64* @ERANGE
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = load i8*, i8** %6
%30 = call i32 @Log(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %29)
%31 = load i64, i64* %5
store i64 %31, i64* %3
br label %47
32: ; preds = %21
%33 = load i8*, i8** %7
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %45
35: ; preds = %32
%36 = load i8*, i8** %7
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = load i8*, i8** %4
%42 = load i8*, i8** %6
%43 = call i32 @Log(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %41, i8* %42)
%44 = load i64, i64* %5
store i64 %44, i64* %3
br label %47
45: ; preds = %35, %32
%46 = load i64, i64* %8
store i64 %46, i64* %3
br label %47
47: ; preds = %45, %40, %27, %19
%48 = load i64, i64* %3
ret i64 %48
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@.str = [38 x i8] c"Ignoring out-of-range value of %s: %s\00"
@.str.1 = [37 x i8] c"Ignoring non-numeric value of %s: %s\00"
define i64 @GetLongSetting(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = tail call i8* @getenv(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %26, label %6
6: ; preds = %2
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 0
br i1 %8, label %26, label %9
9: ; preds = %6
%10 = bitcast i8** %3 to i8*
store i8* null, i8** %3
store i64 0, i64* @errno
%11 = call i64 @strtol(i8* %4, i8** %3, i32 0)
%12 = load i64, i64* @errno
%13 = load i64, i64* @ERANGE
%14 = icmp eq i64 %12, %13
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = icmp eq i8* %16, null
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = load i8, i8* %16
%20 = icmp eq i8 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18, %9
%22 = phi i8* [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), %9 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), %18 ]
%23 = tail call i32 @Log(i8* %22, i8* %0, i8* %4)
br label %24
24: ; preds = %21, %15, %18
%25 = phi i64 [ %11, %18 ], [ %11, %15 ], [ %1, %21 ]
br label %26
26: ; preds = %2, %6, %24
%27 = phi i64 [ %25, %24 ], [ %1, %6 ], [ %1, %2 ]
ret i64 %27
}