#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int readIntInRange(int a, int b) {
  int x = a - 1;
  if (a < b) {
    scanf("%d", &x);
    while (getchar() != '\n')
      ;
    while (x < a || x > b) {
      printf("ERRO: Entrada invalida. Digite um numero valido x[%d,%d]\n", a,
             b);
      printf("» ");
      scanf("%d", &x);
      while (getchar() != '\n')
        ;
    }
  } else {
    while (getchar() != '\n')
      ;
  }
  return x;
}


x86 assembly (clang, -O0):
<readIntInRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1201 <readIntInRange+0xd1>
lea    0xea6(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     117b <readIntInRange+0x4b>
jmp    1163 <readIntInRange+0x33>
jmp    1180 <readIntInRange+0x50>
mov    -0xc(%rbp),%ecx
mov    $0x1,%al
cmp    -0x4(%rbp),%ecx
mov    %al,-0xd(%rbp)
jl     119d <readIntInRange+0x6d>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
setg   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    11ad <readIntInRange+0x7d>
jmp    11fc <readIntInRange+0xcc>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe2a(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11f7 <readIntInRange+0xc7>
jmp    11df <readIntInRange+0xaf>
jmp    1180 <readIntInRange+0x50>
jmp    1223 <readIntInRange+0xf3>
jmp    1206 <readIntInRange+0xd6>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     121e <readIntInRange+0xee>
jmp    1206 <readIntInRange+0xd6>
jmp    1223 <readIntInRange+0xf3>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readIntInRange>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    -0x1(%rbx),%ebp
mov    %ebp,0xc(%rsp)
cmp    %esi,%edi
jge    1170 <readIntInRange+0x40>
mov    %esi,%r14d
lea    0xeb1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    1160 <readIntInRange+0x30>
jmp    11cb <readIntInRange+0x9b>
nopl   (%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    1170 <readIntInRange+0x40>
jmp    11d8 <readIntInRange+0xa8>
nopl   (%rax)
lea    0xe7c(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe58(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    11c0 <readIntInRange+0x90>
mov    0xc(%rsp),%ebp
cmp    %ebx,%ebp
jl     1180 <readIntInRange+0x50>
cmp    %r14d,%ebp
jg     1180 <readIntInRange+0x50>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [58 x i8] c"ERRO: Entrada invalida. Digite um numero valido x[%d,%d]\0A\00"
@.str.2 = [4 x i8] c"\C2\BB \00"
define i32 @readIntInRange(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = sub nsw i32 %6, 1
store i32 %7, i32* %5
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %42
11: ; preds = %2
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
br label %13
13: ; preds = %17, %11
%14 = call signext i8 (...) @getchar()
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 10
br i1 %16, label %17, label %18
17: ; preds = %13
br label %13
18: ; preds = %13
br label %19
19: ; preds = %40, %18
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = icmp sgt i32 %24, %25
br label %27
27: ; preds = %23, %19
%28 = phi i1 [ true, %19 ], [ %26, %23 ]
br i1 %28, label %29, label %41
29: ; preds = %27
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
br label %35
35: ; preds = %39, %29
%36 = call signext i8 (...) @getchar()
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 10
br i1 %38, label %39, label %40
39: ; preds = %35
br label %35
40: ; preds = %35
br label %19
41: ; preds = %27
br label %49
42: ; preds = %2
br label %43
43: ; preds = %47, %42
%44 = call signext i8 (...) @getchar()
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 10
br i1 %46, label %47, label %48
47: ; preds = %43
br label %43
48: ; preds = %43
br label %49
49: ; preds = %48, %41
%50 = load i32, i32* %5
ret i32 %50
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [58 x i8] c"ERRO: Entrada invalida. Digite um numero valido x[%d,%d]\0A\00"
@.str.2 = [4 x i8] c"\C2\BB \00"
define i32 @readIntInRange(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = add nsw i32 %0, -1
store i32 %5, i32* %3
%6 = icmp slt i32 %0, %1
br i1 %6, label %7, label %29
7: ; preds = %2
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %9
9: ; preds = %9, %7
%10 = call signext i8 (...) @getchar()
%11 = icmp eq i8 %10, 10
br i1 %11, label %12, label %9
12: ; preds = %9
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, %0
%15 = icmp sgt i32 %13, %1
%16 = or i1 %14, %15
br i1 %16, label %22, label %32
17: ; preds = %26
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, %0
%20 = icmp sgt i32 %18, %1
%21 = or i1 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %12, %17
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %1)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %26
26: ; preds = %26, %22
%27 = call signext i8 (...) @getchar()
%28 = icmp eq i8 %27, 10
br i1 %28, label %17, label %26
29: ; preds = %2, %29
%30 = tail call signext i8 (...) @getchar()
%31 = icmp eq i8 %30, 10
br i1 %31, label %32, label %29
32: ; preds = %29, %17, %12
%33 = phi i32 [ %13, %12 ], [ %18, %17 ], [ %5, %29 ]
ret i32 %33
}