#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 */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
long strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int ReadN() {
  char input[80];
  long int number;
  int ctr = 0;
  while (ctr == 0) {
    fgets(input, 80, stdin);
    number = strtol(input, NULL, 0);
    if ((sizeof(int) == 2) && (number > 32767))
      printf("This number is too big. The maximum is 32767. Try Again\n");
    else if ((sizeof(int) == 4) && (number > 2147483647))
      printf("This number is too big. The maximum is 2147483647. Try Again\n");
    else
      ctr = 1;
    if (number < 0)
      number = -1;
  }
  return number;
}


x86 assembly (clang, -O0):
<ReadN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    11b1 <ReadN+0x81>
lea    -0x50(%rbp),%rdi
mov    0x2e94(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1040 <fgets@plt>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x7fffffff,-0x58(%rbp)
7f
jle    1192 <ReadN+0x62>
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
jmp    1199 <ReadN+0x69>
movl   $0x1,-0x5c(%rbp)
cmpq   $0x0,-0x58(%rbp)
jge    11ac <ReadN+0x7c>
movq   $0xffffffffffffffff,-0x58(%rbp)
ff
jmp    113f <ReadN+0xf>
mov    -0x58(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadN>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    0x2ea8(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
call   1040 <fgets@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    $0x80000000,%ecx
cmp    %rcx,%rax
jl     11ac <ReadN+0x7c>
lea    0xe90(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x50,%esi
call   1040 <fgets@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
cmp    $0x7fffffff,%rax
jg     1180 <ReadN+0x50>
test   %rax,%rax
mov    $0xffffffff,%ecx
cmovns %eax,%ecx
mov    %ecx,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [62 x i8] c"This number is too big. The maximum is 2147483647. Try Again\0A\00"
define i32 @ReadN() {
%1 = alloca [80 x i8]
%2 = alloca i64
%3 = alloca i32
store i32 0, i32* %3
br label %4
4: ; preds = %22, %0
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %23
7: ; preds = %4
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %8, i32 80, i32 %9)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%12 = call i64 @strtol(i8* %11, i32* null, i32 0)
store i64 %12, i64* %2
%13 = load i64, i64* %2
%14 = icmp sgt i64 %13, 2147483647
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %18
17: ; preds = %7
store i32 1, i32* %3
br label %18
18: ; preds = %17, %15
%19 = load i64, i64* %2
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
store i64 -1, i64* %2
br label %22
22: ; preds = %21, %18
br label %4
23: ; preds = %4
%24 = load i64, i64* %2
%25 = trunc i64 %24 to i32
ret i32 %25
}

LLVM IR (-O2):
@stdin = global i32 0
@str = [61 x i8] c"This number is too big. The maximum is 2147483647. Try Again\00"
define i32 @ReadN() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32 @fgets(i8* %2, i32 80, i32 %3)
%5 = call i64 @strtol(i8* nocapture %2, i32* null, i32 0)
%6 = icmp sgt i64 %5, 2147483647
br i1 %6, label %7, label %13
7: ; preds = %0, %7
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str, i64 0, i64 0))
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %2, i32 80, i32 %9)
%11 = call i64 @strtol(i8* nocapture %2, i32* null, i32 0)
%12 = icmp sgt i64 %11, 2147483647
br i1 %12, label %7, label %13
13: ; preds = %7, %0
%14 = phi i64 [ %5, %0 ], [ %11, %7 ]
%15 = icmp slt i64 %14, 0
%16 = trunc i64 %14 to i32
%17 = select i1 %15, i32 -1, i32 %16
ret i32 %17
}