#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 sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
int get_bounded_integer(int lower_bound, int upper_bound) {
  int user_input;
  int flag = 0;
  char buffer[133];
  while (flag < 1) {
    printf("Enter and integer: ");
    fgets(buffer, 133, stdin);
    flag = sscanf(buffer, "%d", &user_input);
    if (flag == -1)
      printf("Please enter an integer\n");
    else if (flag == 0)
      printf("That's is not an integer - please enter an integer\n");
    else {
      if (user_input < lower_bound) {
        printf("Please enter an integer >= %d\n", lower_bound);
        flag = 0;
      } else if (user_input > upper_bound) {
        printf("Please enter an integer <= %d\n", upper_bound);
        flag = 0;
      }
    }
  }
  return user_input;
}


x86 assembly (clang, -O0):
<get_bounded_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jge    122f <get_bounded_integer+0xff>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xa0(%rbp),%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
mov    $0x85,%esi
call   1040 <fgets@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe8c(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11b1 <get_bounded_integer+0x81>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122a <get_bounded_integer+0xfa>
cmpl   $0x0,-0x10(%rbp)
jne    11ce <get_bounded_integer+0x9e>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1225 <get_bounded_integer+0xf5>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11f7 <get_bounded_integer+0xc7>
mov    -0x4(%rbp),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
jmp    1220 <get_bounded_integer+0xf0>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    121b <get_bounded_integer+0xeb>
mov    -0x8(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
jmp    1220 <get_bounded_integer+0xf0>
jmp    1225 <get_bounded_integer+0xf5>
jmp    122a <get_bounded_integer+0xfa>
jmp    1148 <get_bounded_integer+0x18>
mov    -0xc(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bounded_integer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %esi,0x8(%rsp)
mov    %edi,%r12d
mov    0x2e89(%rip),%r15
lea    0x10(%rsp),%rbx
lea    0xea9(%rip),%r13
lea    0xc(%rsp),%rbp
jmp    1198 <get_bounded_integer+0x58>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
test   %r14d,%r14d
jg     1228 <get_bounded_integer+0xe8>
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x85,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <sscanf@plt>
test   %eax,%eax
je     1180 <get_bounded_integer+0x40>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    11f0 <get_bounded_integer+0xb0>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
jmp    118f <get_bounded_integer+0x4f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0xc(%rsp),%eax
cmp    %r12d,%eax
jge    1208 <get_bounded_integer+0xc8>
xor    %r14d,%r14d
lea    0xe14(%rip),%rdi
mov    %r12d,%esi
jmp    121c <get_bounded_integer+0xdc>
cmp    0x8(%rsp),%eax
jle    118f <get_bounded_integer+0x4f>
xor    %r14d,%r14d
lea    0xe1e(%rip),%rdi
mov    0x8(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    118f <get_bounded_integer+0x4f>
mov    0xc(%rsp),%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter and integer: \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"Please enter an integer\0A\00"
@.str.3 = [52 x i8] c"That's is not an integer - please enter an integer\0A\00"
@.str.4 = [31 x i8] c"Please enter an integer >= %d\0A\00"
@.str.5 = [31 x i8] c"Please enter an integer <= %d\0A\00"
define i32 @get_bounded_integer(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [133 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %6
br label %8
8: ; preds = %44, %2
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %45
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [133 x i8], [133 x i8]* %7, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %13, i32 133, i32 %14)
%16 = getelementptr inbounds [133 x i8], [133 x i8]* %7, i64 0, i64 0
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %44
22: ; preds = %11
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
br label %43
27: ; preds = %22
%28 = load i32, i32* %5
%29 = load i32, i32* %3
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* %3
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %32)
store i32 0, i32* %6
br label %42
34: ; preds = %27
%35 = load i32, i32* %5
%36 = load i32, i32* %4
%37 = icmp sgt i32 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32, i32* %4
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %39)
store i32 0, i32* %6
br label %41
41: ; preds = %38, %34
br label %42
42: ; preds = %41, %31
br label %43
43: ; preds = %42, %25
br label %44
44: ; preds = %43, %20
br label %8
45: ; preds = %8
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter and integer: \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.4 = [31 x i8] c"Please enter an integer >= %d\0A\00"
@.str.5 = [31 x i8] c"Please enter an integer <= %d\0A\00"
@str = [51 x i8] c"That's is not an integer - please enter an integer\00"
@str.6 = [24 x i8] c"Please enter an integer\00"
define i32 @get_bounded_integer(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca [133 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [133 x i8], [133 x i8]* %4, i64 0, i64 0
br label %7
7: ; preds = %2, %25
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %6, i32 133, i32 %9)
%11 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
switch i32 %11, label %16 [
i32 -1, label %12
i32 0, label %14
]
12: ; preds = %7
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
br label %25
14: ; preds = %7
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
br label %25
16: ; preds = %7
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, %0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %0)
br label %25
21: ; preds = %16
%22 = icmp sgt i32 %17, %1
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %1)
br label %25
25: ; preds = %14, %21, %23, %19, %12
%26 = phi i32 [ -1, %12 ], [ 0, %14 ], [ 0, %19 ], [ 0, %23 ], [ %11, %21 ]
%27 = icmp slt i32 %26, 1
br i1 %27, label %7, label %28
28: ; preds = %25
%29 = load i32, i32* %3
ret i32 %29
}