#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*/ perror(char *);
int strtol(char *, char **, int);
int string_to_int_with_check(char *number) {
  char *endptr, *str = number;
  int val;
  errno = 0;
  val = strtol(str, &endptr, 10);
  if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) ||
      (errno != 0 && val == 0) || (endptr == str)) {
    perror("Wrong argument.");
    exit(EXIT_FAILURE);
  }
  return val;
}


x86 assembly (clang, -O0):
<string_to_int_with_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e7d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%rax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
jne    11a5 <string_to_int_with_check+0x75>
mov    -0x1c(%rbp),%eax
mov    0x2e45(%rip),%rcx
cmp    (%rcx),%eax
je     11ce <string_to_int_with_check+0x9e>
mov    -0x1c(%rbp),%eax
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%eax
je     11ce <string_to_int_with_check+0x9e>
mov    0x2e1c(%rip),%rax
cmpq   $0x0,(%rax)
je     11c0 <string_to_int_with_check+0x90>
cmpl   $0x0,-0x1c(%rbp)
je     11ce <string_to_int_with_check+0x9e>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11e8 <string_to_int_with_check+0xb8>
lea    0xe2b(%rip),%rdi
call   1040 <perror@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_int_with_check>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e8a(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    (%r14),%rcx
mov    0x2e84(%rip),%rdx
cmp    (%rdx),%rcx
jne    1177 <string_to_int_with_check+0x47>
mov    0x2e68(%rip),%rdx
cmp    (%rdx),%eax
je     1194 <string_to_int_with_check+0x64>
mov    0x2e75(%rip),%rdx
cmp    (%rdx),%eax
je     1194 <string_to_int_with_check+0x64>
test   %rcx,%rcx
setne  %cl
test   %eax,%eax
sete   %dl
test   %dl,%cl
jne    1194 <string_to_int_with_check+0x64>
cmp    %rbx,(%rsp)
je     1194 <string_to_int_with_check+0x64>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe65(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e19(%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
@.str = [16 x i8] c"Wrong argument.\00"
@EXIT_FAILURE = global i32 0
define i32 @string_to_int_with_check(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %4
store i64 0, i64* @errno
%7 = load i8*, i8** %4
%8 = call i32 @strtol(i8* %7, i8** %3, i32 10)
store i32 %8, i32* %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @ERANGE
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %1
%13 = load i32, i32* %5
%14 = load i32, i32* @LONG_MAX
%15 = icmp eq i32 %13, %14
br i1 %15, label %30, label %16
16: ; preds = %12
%17 = load i32, i32* %5
%18 = load i32, i32* @LONG_MIN
%19 = icmp eq i32 %17, %18
br i1 %19, label %30, label %20
20: ; preds = %16, %1
%21 = load i64, i64* @errno
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %23, %20
%27 = load i8*, i8** %3
%28 = load i8*, i8** %4
%29 = icmp eq i8* %27, %28
br i1 %29, label %30, label %34
30: ; preds = %26, %23, %16, %12
%31 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %26
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i32 0
@LONG_MIN = global i32 0
@.str = [16 x i8] c"Wrong argument.\00"
@EXIT_FAILURE = global i32 0
define i32 @string_to_int_with_check(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i64 0, i64* @errno
%4 = call i32 @strtol(i8* %0, i8** %2, i32 10)
%5 = load i64, i64* @errno
%6 = load i64, i64* @ERANGE
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i32, i32* @LONG_MAX
%10 = icmp eq i32 %4, %9
%11 = load i32, i32* @LONG_MIN
%12 = icmp eq i32 %4, %11
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %21, label %14
14: ; preds = %8, %1
%15 = icmp ne i64 %5, 0
%16 = icmp eq i32 %4, 0
%17 = select i1 %15, i1 %16, i1 false
%18 = load i8*, i8** %2
%19 = icmp eq i8* %18, %0
%20 = select i1 %17, i1 true, i1 %19
br i1 %20, label %21, label %25
21: ; preds = %14, %8
%22 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %14
ret i32 %4
}