#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*/ EIO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int scanf(char *, int *);
int /*<<< orphan*/ stderr;
int read_input() {
  int input;
  printf("Enter limit: ");
  int scan = scanf("%d", &input);
  if (scan != 1) {
    fprintf(stderr, "Invalid input.\n");
    exit(EIO);
  }
  return input;
}


x86 assembly (clang, -O0):
<read_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb3(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     1194 <read_input+0x54>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_input>:
push   %rax
lea    0xeb8(%rip),%rdi
call   1030 <printf@plt>
lea    0xeba(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1169 <read_input+0x29>
mov    0x4(%rsp),%eax
pop    %rcx
ret
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Enter limit: \00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [16 x i8] c"Invalid input.\0A\00"
@EIO = global i32 0
define i32 @read_input() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 1
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @EIO
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = load i32, i32* %1
ret i32 %13
}

LLVM IR (-O2):
@.str = [14 x i8] c"Enter limit: \00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [16 x i8] c"Invalid input.\0A\00"
@EIO = global i32 0
define i32 @read_input() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %11, label %6
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @EIO
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = load i32, i32* %1
ret i32 %12
}