#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*/ EXIT_FAILURE;
long LONG_MAX;
long LONG_MIN;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *);
int /*<<< orphan*/ stderr;
long strtol(char const *, char **, int);
long extract_long(const char *longstr, const char *var) {
  char *endptr;
  long l;
  l = strtol(longstr, &endptr, 10);
  if (l == LONG_MIN || l == LONG_MAX || endptr == longstr) {
    {
      fprintf(stderr, "invalid %s %s\n", var, longstr);
      exit(EXIT_FAILURE);
    };
  }
  return l;
}


x86 assembly (clang, -O0):
<extract_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e87(%rip),%rcx
cmp    (%rcx),%rax
je     118c <extract_long+0x5c>
mov    -0x20(%rbp),%rax
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%rax
je     118c <extract_long+0x5c>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11b7 <extract_long+0x87>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe5c(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_long>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%rax
je     116d <extract_long+0x3d>
mov    0x2e76(%rip),%rcx
cmp    (%rcx),%rax
je     116d <extract_long+0x3d>
cmp    %rbx,(%rsp)
je     116d <extract_long+0x3d>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <fprintf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@stderr = global i32 0
@.str = [15 x i8] c"invalid %s %s\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @extract_long(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i64 @strtol(i8* %7, i8** %5, i32 10)
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = load i64, i64* @LONG_MIN
%11 = icmp eq i64 %9, %10
br i1 %11, label %20, label %12
12: ; preds = %2
%13 = load i64, i64* %6
%14 = load i64, i64* @LONG_MAX
%15 = icmp eq i64 %13, %14
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = load i8*, i8** %3
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %27
20: ; preds = %16, %12, %2
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %4
%23 = load i8*, i8** %3
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %16
%28 = load i64, i64* %6
ret i64 %28
}

LLVM IR (-O2):
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@stderr = global i32 0
@.str = [15 x i8] c"invalid %s %s\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @extract_long(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%6 = load i64, i64* @LONG_MIN
%7 = icmp eq i64 %5, %6
%8 = load i64, i64* @LONG_MAX
%9 = icmp eq i64 %5, %8
%10 = select i1 %7, i1 true, i1 %9
%11 = load i8*, i8** %3
%12 = icmp eq i8* %11, %0
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
ret i64 %5
}