#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 */
struct elem {
  int dummy;
};

/* Variables and functions */
scalar_t__ ERANGE;
long LONG_MAX;
long LONG_MIN;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int print_page(char const *, int, struct elem const *, char const *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
long strtol(char *, char **, int);
int getanswer(const char *name, int page_num, const struct elem *objects,
              const char *additional) {
  static char *p = NULL;
  static size_t n;
  int max;
  char *s;
  char *endptr;
  long val;
print:
  max = print_page(name, page_num, objects, additional);
  putc('\n', stdout);
foo:
  printf("Enter your %s code number here [q to quit, 0 to repeat]: ", name);
  if (getline(&p, &n, stdin) == -1) {
    if (feof(stdin))
      do {
        fputs("\nGot EOF on stdin, aborting...\n", stderr);
        exit(1);
      } while (0);
    ;
    perror(NULL);
    exit(1);
  }
  s = p;
  errno = 0;
  val = strtol(s, &endptr, 10);
  if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) ||
      (errno != 0 && val == 0)) {
    perror("strtol");
    exit(1);
  }
  if (endptr == s) {
    fprintf(stderr, "No digits were found\n");
    exit(1);
  }
  while (*s == ' ')
    s++;
  if (*s == 'q' || *s == 'Q')
    exit(0);
  if (val > max)
    goto foo;
  if (val == 0)
    goto print;
  return (int)val;
}


x86 assembly (clang, -O0):
<getanswer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <print_page@plt>
mov    %eax,-0x24(%rbp)
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1060 <putc@plt>
mov    -0x8(%rbp),%rsi
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
lea    0x2e77(%rip),%rdi
lea    0x2e78(%rip),%rsi
call   10b0 <getline@plt>
cmp    $0xffffffff,%eax
jne    1265 <getanswer+0xc5>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     1252 <getanswer+0xb2>
jmp    1233 <getanswer+0x93>
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
lea    0xdf7(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2e0c(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d41(%rip),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1090 <strtol@plt>
mov    %rax,-0x40(%rbp)
mov    0x2d1d(%rip),%rax
mov    (%rax),%rax
mov    0x2d33(%rip),%rcx
cmp    (%rcx),%rax
jne    12d6 <getanswer+0x136>
mov    -0x40(%rbp),%rax
mov    0x2d07(%rip),%rcx
cmp    (%rcx),%rax
je     12f2 <getanswer+0x152>
mov    -0x40(%rbp),%rax
mov    0x2d13(%rip),%rcx
cmp    (%rcx),%rax
je     12f2 <getanswer+0x152>
mov    0x2cdb(%rip),%rax
cmpq   $0x0,(%rax)
je     1308 <getanswer+0x168>
cmpq   $0x0,-0x40(%rbp)
jne    1308 <getanswer+0x168>
lea    0xd61(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    1335 <getanswer+0x195>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
lea    0xd3b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    133a <getanswer+0x19a>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    135b <getanswer+0x1bb>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    133a <getanswer+0x19a>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x71,%eax
je     137b <getanswer+0x1db>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x51,%eax
jne    1382 <getanswer+0x1e2>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x40(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmp    %rcx,%rax
jle    1398 <getanswer+0x1f8>
jmp    11e1 <getanswer+0x41>
cmpq   $0x0,-0x40(%rbp)
jne    13a8 <getanswer+0x208>
jmp    11b7 <getanswer+0x17>
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getanswer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,0x18(%rsp)
mov    %rdx,0x10(%rsp)
mov    %esi,0xc(%rsp)
mov    %rdi,%rbx
mov    0x2df2(%rip),%r13
lea    0x20(%rsp),%r15
mov    0x2e06(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%rdx
mov    0x18(%rsp),%rcx
call   1030 <print_page@plt>
mov    %eax,%r12d
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1060 <putc@plt>
movslq %r12d,%r14
nop
lea    0xde9(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edx
lea    0x2e49(%rip),%rdi
lea    0x2e4a(%rip),%rsi
call   10b0 <getline@plt>
cmp    $0xffffffff,%eax
je     12eb <getanswer+0x14b>
mov    0x2e2d(%rip),%r12
movq   $0x0,0x0(%r13)
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1090 <strtol@plt>
mov    0x0(%r13),%rcx
cmp    0x0(%rbp),%rcx
jne    1285 <getanswer+0xe5>
mov    0x2d4c(%rip),%rdx
cmp    (%rdx),%rax
je     12e2 <getanswer+0x142>
mov    0x2d60(%rip),%rdx
cmp    (%rdx),%rax
je     12e2 <getanswer+0x142>
test   %rcx,%rcx
je     128f <getanswer+0xef>
test   %rax,%rax
je     12e2 <getanswer+0x142>
cmp    %r12,0x20(%rsp)
je     130f <getanswer+0x16f>
cs nopw 0x0(%rax,%rax,1)
movzbl (%r12),%ecx
cmp    $0x20,%cl
jne    12b0 <getanswer+0x110>
add    $0x1,%r12
jmp    12a0 <getanswer+0x100>
cmp    $0x51,%cl
je     12db <getanswer+0x13b>
cmp    $0x71,%cl
je     12db <getanswer+0x13b>
cmp    %r14,%rax
jg     1210 <getanswer+0x70>
test   %rax,%rax
je     11e0 <getanswer+0x40>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xd71(%rip),%rdi
jmp    1300 <getanswer+0x160>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
call   1080 <feof@plt>
test   %rax,%rax
jne    132e <getanswer+0x18e>
xor    %edi,%edi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
lea    0xd42(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2c93(%rip),%rax
mov    (%rax),%esi
lea    0xcfc(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.elem = type { i32 }
@getanswer.p = internal global i8* null
@getanswer.n = internal global i64 0
@stdout = global i32 0
@.str = [58 x i8] c"Enter your %s code number here [q to quit, 0 to repeat]: \00"
@stdin = global i32 0
@.str.1 = [32 x i8] c"\0AGot EOF on stdin, aborting...\0A\00"
@stderr = global i32 0
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str.2 = [7 x i8] c"strtol\00"
@.str.3 = [22 x i8] c"No digits were found\0A\00"
define i32 @getanswer(i8* %0, i32 %1, %struct.elem* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.elem*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store %struct.elem* %2, %struct.elem** %7
store i8* %3, i8** %8
br label %13
13: ; preds = %102, %4
%14 = load i8*, i8** %5
%15 = load i32, i32* %6
%16 = load %struct.elem*, %struct.elem** %7
%17 = load i8*, i8** %8
%18 = call i32 @print_page(i8* %14, i32 %15, %struct.elem* %16, i8* %17)
store i32 %18, i32* %9
%19 = load i32, i32* @stdout
%20 = call i32 @putc(i8 signext 10, i32 %19)
br label %21
21: ; preds = %98, %13
%22 = load i8*, i8** %5
%23 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @stdin
%25 = call i32 @getline(i8** @getanswer.p, i64* @getanswer.n, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %40
27: ; preds = %21
%28 = load i32, i32* @stdin
%29 = call i64 @feof(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %27
br label %32
32: ; preds = %31
%33 = load i32, i32* @stderr
%34 = call i32 @fputs(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; No predecessors!
br label %37
37: ; preds = %36, %27
%38 = call i32 @perror(i8* null)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %21
%41 = load i8*, i8** @getanswer.p
store i8* %41, i8** %10
store i64 0, i64* @errno
%42 = load i8*, i8** %10
%43 = call i64 @strtol(i8* %42, i8** %11, i32 10)
store i64 %43, i64* %12
%44 = load i64, i64* @errno
%45 = load i64, i64* @ERANGE
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %55
47: ; preds = %40
%48 = load i64, i64* %12
%49 = load i64, i64* @LONG_MAX
%50 = icmp eq i64 %48, %49
br i1 %50, label %61, label %51
51: ; preds = %47
%52 = load i64, i64* %12
%53 = load i64, i64* @LONG_MIN
%54 = icmp eq i64 %52, %53
br i1 %54, label %61, label %55
55: ; preds = %51, %40
%56 = load i64, i64* @errno
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %64
58: ; preds = %55
%59 = load i64, i64* %12
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %58, %51, %47
%62 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %58, %55
%65 = load i8*, i8** %11
%66 = load i8*, i8** %10
%67 = icmp eq i8* %65, %66
br i1 %67, label %68, label %72
68: ; preds = %64
%69 = load i32, i32* @stderr
%70 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %64
br label %73
73: ; preds = %78, %72
%74 = load i8*, i8** %10
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp eq i32 %76, 32
br i1 %77, label %78, label %81
78: ; preds = %73
%79 = load i8*, i8** %10
%80 = getelementptr inbounds i8, i8* %79, i32 1
store i8* %80, i8** %10
br label %73
81: ; preds = %73
%82 = load i8*, i8** %10
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = icmp eq i32 %84, 113
br i1 %85, label %91, label %86
86: ; preds = %81
%87 = load i8*, i8** %10
%88 = load i8, i8* %87
%89 = sext i8 %88 to i32
%90 = icmp eq i32 %89, 81
br i1 %90, label %91, label %93
91: ; preds = %86, %81
%92 = call i32 @exit(i32 0)
unreachable
93: ; preds = %86
%94 = load i64, i64* %12
%95 = load i32, i32* %9
%96 = sext i32 %95 to i64
%97 = icmp sgt i64 %94, %96
br i1 %97, label %98, label %99
98: ; preds = %93
br label %21
99: ; preds = %93
%100 = load i64, i64* %12
%101 = icmp eq i64 %100, 0
br i1 %101, label %102, label %103
102: ; preds = %99
br label %13
103: ; preds = %99
%104 = load i64, i64* %12
%105 = trunc i64 %104 to i32
ret i32 %105
}

LLVM IR (-O2):
%struct.elem = type { i32 }
@getanswer.p = internal global i8* null
@getanswer.n = internal global i64 0
@stdout = global i32 0
@.str = [58 x i8] c"Enter your %s code number here [q to quit, 0 to repeat]: \00"
@stdin = global i32 0
@.str.1 = [32 x i8] c"\0AGot EOF on stdin, aborting...\0A\00"
@stderr = global i32 0
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str.2 = [7 x i8] c"strtol\00"
@.str.3 = [22 x i8] c"No digits were found\0A\00"
define i32 @getanswer(i8* %0, i32 %1, %struct.elem* %2, i8* %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
br label %7
7: ; preds = %63, %4
%8 = tail call i32 @print_page(i8* %0, i32 %1, %struct.elem* %2, i8* %3)
%9 = load i32, i32* @stdout
%10 = tail call i32 @putc(i8 signext 10, i32 %9)
%11 = sext i32 %8 to i64
br label %12
12: ; preds = %61, %7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = load i32, i32* @stdin
%15 = tail call i32 @getline(i8** @getanswer.p, i64* @getanswer.n, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %28
17: ; preds = %12
%18 = load i32, i32* @stdin
%19 = tail call i64 @feof(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = tail call i32 @fputs(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = tail call i32 @perror(i8* null)
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %12
%29 = load i8*, i8** @getanswer.p
store i64 0, i64* @errno
%30 = call i64 @strtol(i8* %29, i8** %5, i32 10)
%31 = load i64, i64* @errno
%32 = load i64, i64* @ERANGE
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %40
34: ; preds = %28
%35 = load i64, i64* @LONG_MAX
%36 = icmp eq i64 %30, %35
%37 = load i64, i64* @LONG_MIN
%38 = icmp eq i64 %30, %37
%39 = select i1 %36, i1 true, i1 %38
br i1 %39, label %44, label %40
40: ; preds = %34, %28
%41 = icmp ne i64 %31, 0
%42 = icmp eq i64 %30, 0
%43 = select i1 %41, i1 %42, i1 false
br i1 %43, label %44, label %47
44: ; preds = %40, %34
%45 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %40
%48 = load i8*, i8** %5
%49 = icmp eq i8* %48, %29
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = load i32, i32* @stderr
%52 = tail call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%53 = tail call i32 @exit(i32 1)
unreachable
54: ; preds = %47, %57
%55 = phi i8* [ %58, %57 ], [ %29, %47 ]
%56 = load i8, i8* %55
switch i8 %56, label %61 [
i8 32, label %57
i8 113, label %59
i8 81, label %59
]
57: ; preds = %54
%58 = getelementptr inbounds i8, i8* %55, i64 1
br label %54
59: ; preds = %54, %54
%60 = tail call i32 @exit(i32 0)
unreachable
61: ; preds = %54
%62 = icmp sgt i64 %30, %11
br i1 %62, label %12, label %63
63: ; preds = %61
br i1 %42, label %7, label %64
64: ; preds = %63
%65 = trunc i64 %30 to i32
ret i32 %65
}