#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;
long long LLONG_MAX;
long long LLONG_MIN;
scalar_t__ errno;
int /*<<< orphan*/ error(char *, char const *);
scalar_t__ isspace(unsigned char);
long long strtoll(char const *, char **, int);
long long getn(const char *s) {
  char *p;
  long long r;
  errno = 0;
  r = strtoll(s, &p, 10);
  if (errno != 0)
    if (errno == ERANGE && (r == LLONG_MAX || r == LLONG_MIN))
      error("%s: out of range", s);
  while (isspace((unsigned char)*p))
    p++;
  if (*p || p == s)
    error("%s: bad number", s);
  return r;
}


x86 assembly (clang, -O0):
<getn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e85(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoll@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e61(%rip),%rax
cmpq   $0x0,(%rax)
je     11c8 <getn+0x98>
mov    0x2e50(%rip),%rax
mov    (%rax),%rax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
jne    11c3 <getn+0x93>
mov    -0x18(%rbp),%rax
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%rax
je     11b3 <getn+0x83>
mov    -0x18(%rbp),%rax
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%rax
jne    11c3 <getn+0x93>
mov    -0x8(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   1050 <error@plt>
jmp    11c8 <getn+0x98>
jmp    11cd <getn+0x9d>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     11f4 <getn+0xc4>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11cd <getn+0x9d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1212 <getn+0xe2>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    1222 <getn+0xf2>
mov    -0x8(%rbp),%rsi
lea    0xdf4(%rip),%rdi
call   1050 <error@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getn>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
mov    0x2e85(%rip),%rbx
movq   $0x0,(%rbx)
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtoll@plt>
mov    %rax,%r14
mov    (%rbx),%rax
test   %rax,%rax
je     1197 <getn+0x67>
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%rax
jne    1197 <getn+0x67>
mov    0x2e69(%rip),%rax
cmp    (%rax),%r14
je     1188 <getn+0x58>
mov    0x2e4d(%rip),%rax
cmp    (%rax),%r14
jne    1197 <getn+0x67>
lea    0xe71(%rip),%rdi
mov    %r15,%rsi
call   1050 <error@plt>
mov    0x8(%rsp),%rbx
add    $0xffffffffffffffff,%rbx
movzbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isspace@plt>
test   %rax,%rax
jne    11a0 <getn+0x70>
cmp    %r15,%rbx
je     11bc <getn+0x8c>
cmpb   $0x0,(%rbx)
je     11cb <getn+0x9b>
lea    0xe4e(%rip),%rdi
mov    %r15,%rsi
call   1050 <error@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@LLONG_MAX = global i64 0
@LLONG_MIN = global i64 0
@.str = [17 x i8] c"%s: out of range\00"
@.str.1 = [15 x i8] c"%s: bad number\00"
define i64 @getn(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* @errno
%5 = load i8*, i8** %2
%6 = call i64 @strtoll(i8* %5, i8** %3, i32 10)
store i64 %6, i64* %4
%7 = load i64, i64* @errno
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = load i64, i64* @ERANGE
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i64, i64* %4
%15 = load i64, i64* @LLONG_MAX
%16 = icmp eq i64 %14, %15
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i64, i64* %4
%19 = load i64, i64* @LLONG_MIN
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %17, %13
%22 = load i8*, i8** %2
%23 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %17, %9
br label %25
25: ; preds = %24, %1
br label %26
26: ; preds = %31, %25
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
%29 = call i64 @isspace(i8 zeroext %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
br label %26
34: ; preds = %26
%35 = load i8*, i8** %3
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %34
%40 = load i8*, i8** %3
%41 = load i8*, i8** %2
%42 = icmp eq i8* %40, %41
br i1 %42, label %43, label %46
43: ; preds = %39, %34
%44 = load i8*, i8** %2
%45 = call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %43, %39
%47 = load i64, i64* %4
ret i64 %47
}

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