#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__ EINVAL;
scalar_t__ ERANGE;
int /*<<< orphan*/ LOG_ERR;
long LONG_MAX;
long LONG_MIN;
scalar_t__ errno;
long strtol(char const *, char **, int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char const *);
int atoint(const char *s) {
  char *t;
  long n;
  errno = 0;
  n = strtol(s, &t, 0);
  if ((errno != 0 && n == 0) || s == t ||
      (errno == ERANGE && (n == LONG_MAX || n == LONG_MIN))) {
    if (errno == 0)
      errno = EINVAL;
    syslog(LOG_ERR, "`%s' out of range", s);
    return -1;
  }
  return (int)n;
}


x86 assembly (clang, -O0):
<atoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e95(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e74(%rip),%rax
cmpq   $0x0,(%rax)
je     1169 <atoint+0x49>
cmpq   $0x0,-0x20(%rbp)
je     11b9 <atoint+0x99>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11b9 <atoint+0x99>
mov    0x2e4a(%rip),%rax
mov    (%rax),%rax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%rax
jne    1203 <atoint+0xe3>
mov    -0x20(%rbp),%rax
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
je     11b9 <atoint+0x99>
mov    -0x20(%rbp),%rax
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%rax
jne    1203 <atoint+0xe3>
mov    0x2e08(%rip),%rax
cmpq   $0x0,(%rax)
jne    11de <atoint+0xbe>
mov    0x2def(%rip),%rax
mov    (%rax),%rcx
mov    0x2ded(%rip),%rax
mov    %rcx,(%rax)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe0e(%rip),%rsi
call   1040 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <atoint+0xea>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atoint>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
mov    0x2e95(%rip),%r14
movq   $0x0,(%r14)
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    (%r14),%rcx
test   %rcx,%rcx
setne  %dl
test   %rax,%rax
sete   %bl
test   %bl,%dl
jne    1184 <atoint+0x64>
cmp    %r15,0x8(%rsp)
je     1184 <atoint+0x64>
mov    0x2e79(%rip),%rdx
cmp    (%rdx),%rcx
jne    11b3 <atoint+0x93>
mov    0x2e5d(%rip),%rdx
cmp    (%rdx),%rax
je     1184 <atoint+0x64>
mov    0x2e69(%rip),%rdx
cmp    (%rdx),%rax
jne    11b3 <atoint+0x93>
test   %rcx,%rcx
jne    1196 <atoint+0x76>
mov    0x2e30(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r14)
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
mov    %r15,%rdx
call   1040 <syslog@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@EINVAL = global i64 0
@LOG_ERR = global i32 0
@.str = [18 x i8] c"`%s' out of range\00"
define i32 @atoint(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
store i64 0, i64* @errno
%6 = load i8*, i8** %3
%7 = call i64 @strtol(i8* %6, i8** %4, i32 0)
store i64 %7, i64* %5
%8 = load i64, i64* @errno
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i64, i64* %5
%12 = icmp eq i64 %11, 0
br i1 %12, label %29, label %13
13: ; preds = %10, %1
%14 = load i8*, i8** %3
%15 = load i8*, i8** %4
%16 = icmp eq i8* %14, %15
br i1 %16, label %29, label %17
17: ; preds = %13
%18 = load i64, i64* @errno
%19 = load i64, i64* @ERANGE
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %38
21: ; preds = %17
%22 = load i64, i64* %5
%23 = load i64, i64* @LONG_MAX
%24 = icmp eq i64 %22, %23
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i64, i64* %5
%27 = load i64, i64* @LONG_MIN
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %38
29: ; preds = %25, %21, %13, %10
%30 = load i64, i64* @errno
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = load i64, i64* @EINVAL
store i64 %33, i64* @errno
br label %34
34: ; preds = %32, %29
%35 = load i32, i32* @LOG_ERR
%36 = load i8*, i8** %3
%37 = call i32 @syslog(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %36)
store i32 -1, i32* %2
br label %41
38: ; preds = %25, %17
%39 = load i64, i64* %5
%40 = trunc i64 %39 to i32
store i32 %40, i32* %2
br label %41
41: ; preds = %38, %34
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@EINVAL = global i64 0
@LOG_ERR = global i32 0
@.str = [18 x i8] c"`%s' out of range\00"
define i32 @atoint(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i64 0, i64* @errno
%4 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%5 = load i64, i64* @errno
%6 = icmp ne i64 %5, 0
%7 = icmp eq i64 %4, 0
%8 = select i1 %6, i1 %7, i1 false
%9 = load i8*, i8** %2
%10 = icmp eq i8* %9, %0
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %21, label %12
12: ; preds = %1
%13 = load i64, i64* @ERANGE
%14 = icmp eq i64 %5, %13
br i1 %14, label %15, label %28
15: ; preds = %12
%16 = load i64, i64* @LONG_MAX
%17 = icmp eq i64 %4, %16
%18 = load i64, i64* @LONG_MIN
%19 = icmp eq i64 %4, %18
%20 = select i1 %17, i1 true, i1 %19
br i1 %20, label %21, label %28
21: ; preds = %1, %15
%22 = icmp eq i64 %5, 0
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = load i64, i64* @EINVAL
store i64 %24, i64* @errno
br label %25
25: ; preds = %23, %21
%26 = load i32, i32* @LOG_ERR
%27 = tail call i32 @syslog(i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %30
28: ; preds = %15, %12
%29 = trunc i64 %4 to i32
br label %30
30: ; preds = %28, %25
%31 = phi i32 [ -1, %25 ], [ %29, %28 ]
ret i32 %31
}