#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*/ EXIT_FAILURE;
int LONG_MAX;
int LONG_MIN;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int strtol(char const *, int /*<<< orphan*/ *, int);
int get_arg_signed(const char *arg, const char *name) {
  int n;
  errno = 0;
  n = strtol(arg, NULL, 10);
  if (errno == ERANGE && (n == LONG_MAX || n == LONG_MIN)) {
    fprintf(stderr, "Invalid argument <%s>\n", name);
    exit(EXIT_FAILURE);
  }
  return n;
}


x86 assembly (clang, -O0):
<get_arg_signed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e79(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%rax
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%rax
jne    11c8 <get_arg_signed+0x98>
mov    -0x14(%rbp),%eax
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%eax
je     11a1 <get_arg_signed+0x71>
mov    -0x14(%rbp),%eax
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%eax
jne    11c8 <get_arg_signed+0x98>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4b(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_arg_signed>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e82(%rip),%rbx
movq   $0x0,(%rbx)
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    (%rbx),%rcx
mov    0x2e85(%rip),%rdx
cmp    (%rdx),%rcx
jne    1176 <get_arg_signed+0x46>
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%eax
je     117e <get_arg_signed+0x4e>
mov    0x2e76(%rip),%rcx
cmp    (%rcx),%eax
je     117e <get_arg_signed+0x4e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
mov    %r14,%rdx
call   1030 <fprintf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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

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