#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 */
typedef int /*<<< orphan*/ intmax_t;

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ errno;
int /*<<< orphan*/ error(char *, char const *);
scalar_t__ isspace(unsigned char);
int /*<<< orphan*/ strtoimax(char const *, char **, int);
intmax_t getq(const char *s) {
  char *p;
  intmax_t r;
  errno = 0;
  r = strtoimax(s, &p, 10);
  if (s == p)
    error("%s: bad number", s);
  if (errno != 0)
    error((errno == EINVAL) ? "%s: bad number" : "%s: out of range", s);
  while (isspace((unsigned char)*p))
    p++;
  if (*p)
    error("%s: bad number", s);
  return r;
}


x86 assembly (clang, -O0):
<getq>:
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   1030 <strtoimax@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    117d <getq+0x4d>
mov    -0x8(%rbp),%rsi
lea    0xe88(%rip),%rdi
call   1050 <error@plt>
mov    0x2e5c(%rip),%rax
cmpq   $0x0,(%rax)
je     11c0 <getq+0x90>
mov    0x2e4b(%rip),%rax
mov    (%rax),%rcx
mov    0x2e39(%rip),%rax
mov    (%rax),%rdx
lea    0xe66(%rip),%rdi
lea    0xe50(%rip),%rax
cmp    %rdx,%rcx
cmove  %rax,%rdi
mov    -0x8(%rbp),%rsi
call   1050 <error@plt>
jmp    11c5 <getq+0x95>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11ec <getq+0xbc>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11c5 <getq+0x95>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1209 <getq+0xd9>
mov    -0x8(%rbp),%rsi
lea    0xdfc(%rip),%rdi
call   1050 <error@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getq>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e9e(%rip),%rbp
movq   $0x0,0x0(%rbp)
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtoimax@plt>
mov    %eax,%r14d
cmp    %rbx,0x8(%rsp)
jne    1172 <getq+0x42>
lea    0xe96(%rip),%rdi
mov    %rbx,%rsi
call   1050 <error@plt>
mov    0x0(%rbp),%rax
test   %rax,%rax
je     119f <getq+0x6f>
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%rax
lea    0xe74(%rip),%rax
lea    0xe7c(%rip),%rdi
cmove  %rax,%rdi
mov    %rbx,%rsi
call   1050 <error@plt>
mov    0x8(%rsp),%rax
movzbl (%rax),%edi
nopw   0x0(%rax,%rax,1)
call   1040 <isspace@plt>
test   %rax,%rax
je     11ce <getq+0x9e>
mov    0x8(%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x8(%rsp)
movzbl 0x1(%rax),%edi
jmp    11b0 <getq+0x80>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     11e7 <getq+0xb7>
lea    0xe21(%rip),%rdi
mov    %rbx,%rsi
call   1050 <error@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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