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


x86 assembly (clang, -O0):
<getn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e9d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e79(%rip),%rax
cmpq   $0x0,(%rax)
je     1181 <getn+0x51>
mov    -0x8(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1050 <error@plt>
jmp    1186 <getn+0x56>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     11ad <getn+0x7d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1186 <getn+0x56>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ca <getn+0x9a>
mov    -0x8(%rbp),%rsi
lea    0xe4c(%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    0x2e9d(%rip),%rbx
movq   $0x0,(%rbx)
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%r14
cmpq   $0x0,(%rbx)
je     1171 <getn+0x41>
lea    0xe97(%rip),%rdi
mov    %r15,%rsi
call   1050 <error@plt>
mov    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx),%edi
call   1030 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1180 <getn+0x50>
cmpb   $0x0,-0x1(%rbx)
je     11a6 <getn+0x76>
lea    0xe73(%rip),%rdi
mov    %r15,%rsi
call   1050 <error@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [17 x i8] c"%s: out of range\00"
@.str.1 = [15 x i8] c"%s: bad number\00"
define i32 @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 @strtol(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 %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %9, %1
br label %13
13: ; preds = %18, %12
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = call i64 @isspace(i8 zeroext %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
br label %13
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = icmp ne i8 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i8*, i8** %2
%27 = call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %21
%29 = load i64, i64* %4
%30 = trunc i64 %29 to i32
ret i32 %30
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [17 x i8] c"%s: out of range\00"
@.str.1 = [15 x i8] c"%s: bad number\00"
define i32 @getn(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 10)
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %1
%10 = load i8*, i8** %2
br label %11
11: ; preds = %11, %9
%12 = phi i8* [ %16, %11 ], [ %10, %9 ]
%13 = load i8, i8* %12
%14 = tail call i64 @isspace(i8 zeroext %13)
%15 = icmp eq i64 %14, 0
%16 = getelementptr inbounds i8, i8* %12, i64 1
br i1 %15, label %17, label %11
17: ; preds = %11
%18 = load i8, i8* %12
%19 = icmp eq i8 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %22
22: ; preds = %20, %17
%23 = trunc i64 %4 to i32
ret i32 %23
}