#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 *, char *);
int LeerOpcion(void) {
  int opcion;
  char c;
  do {
    c = 0;
    printf("Ingrese la opcion: ");
    scanf("%d%c", &opcion, &c);
    if (c != '\n') {
      while (getchar() != '\n')
        ;
      printf(
          "Debe ingresar solo un numero entero entre 1 y 4 y luego enter.\n");
    } else if (opcion >= 5 || opcion <= 0) {
      printf("El numero debe ser 1 2 3 o 4.\n");
    }
  } while (c != '\n' || opcion >= 5 || opcion <= 0);
  return opcion;
}


x86 assembly (clang, -O0):
<LeerOpcion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x0,-0x5(%rbp)
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0x4(%rbp),%rsi
lea    -0x5(%rbp),%rdx
call   1050 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
je     1197 <LeerOpcion+0x67>
jmp    116e <LeerOpcion+0x3e>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1186 <LeerOpcion+0x56>
jmp    116e <LeerOpcion+0x3e>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
jmp    11bc <LeerOpcion+0x8c>
cmpl   $0x5,-0x4(%rbp)
jge    11ab <LeerOpcion+0x7b>
cmpl   $0x0,-0x4(%rbp)
jg     11b7 <LeerOpcion+0x87>
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
jmp    11bc <LeerOpcion+0x8c>
jmp    11c1 <LeerOpcion+0x91>
movsbl -0x5(%rbp),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x6(%rbp)
jne    11ec <LeerOpcion+0xbc>
mov    $0x1,%al
cmpl   $0x5,-0x4(%rbp)
mov    %al,-0x6(%rbp)
jge    11ec <LeerOpcion+0xbc>
cmpl   $0x0,-0x4(%rbp)
setle  %al
mov    %al,-0x6(%rbp)
mov    -0x6(%rbp),%al
test   $0x1,%al
jne    1138 <LeerOpcion+0x8>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LeerOpcion>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%r14
lea    0xebb(%rip),%r15
lea    0x4(%rsp),%r12
lea    0x3(%rsp),%rbx
lea    0xeaf(%rip),%r13
lea    0xec6(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x3(%rsp)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <scanf@plt>
cmpb   $0xa,0x3(%rsp)
jne    11c0 <LeerOpcion+0x80>
mov    0x4(%rsp),%eax
add    $0xfffffffb,%eax
mov    %r13,%rdi
cmp    $0xfffffffb,%eax
jbe    11ce <LeerOpcion+0x8e>
cmpb   $0xa,0x3(%rsp)
je     11da <LeerOpcion+0x9a>
jmp    1180 <LeerOpcion+0x40>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    11c0 <LeerOpcion+0x80>
mov    %rbp,%rdi
call   1030 <puts@plt>
cmpb   $0xa,0x3(%rsp)
jne    1180 <LeerOpcion+0x40>
mov    0x4(%rsp),%eax
cmp    $0x4,%eax
jg     1180 <LeerOpcion+0x40>
test   %eax,%eax
jle    1180 <LeerOpcion+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Ingrese la opcion: \00"
@.str.1 = [5 x i8] c"%d%c\00"
@.str.2 = [64 x i8] c"Debe ingresar solo un numero entero entre 1 y 4 y luego enter.\0A\00"
@.str.3 = [31 x i8] c"El numero debe ser 1 2 3 o 4.\0A\00"
define i32 @LeerOpcion() {
%1 = alloca i32
%2 = alloca i8
br label %3
3: ; preds = %37, %0
store i8 0, i8* %2
%4 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %1, i8* %2)
%6 = load i8, i8* %2
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 10
br i1 %8, label %9, label %17
9: ; preds = %3
br label %10
10: ; preds = %14, %9
%11 = call signext i8 (...) @getchar()
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 10
br i1 %13, label %14, label %15
14: ; preds = %10
br label %10
15: ; preds = %10
%16 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
br label %26
17: ; preds = %3
%18 = load i32, i32* %1
%19 = icmp sge i32 %18, 5
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i32, i32* %1
%22 = icmp sle i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20, %17
%24 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
br label %26
26: ; preds = %25, %15
br label %27
27: ; preds = %26
%28 = load i8, i8* %2
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 10
br i1 %30, label %37, label %31
31: ; preds = %27
%32 = load i32, i32* %1
%33 = icmp sge i32 %32, 5
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* %1
%36 = icmp sle i32 %35, 0
br label %37
37: ; preds = %34, %31, %27
%38 = phi i1 [ true, %31 ], [ true, %27 ], [ %36, %34 ]
br i1 %38, label %3, label %39
39: ; preds = %37
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [20 x i8] c"Ingrese la opcion: \00"
@.str.1 = [5 x i8] c"%d%c\00"
@str = [30 x i8] c"El numero debe ser 1 2 3 o 4.\00"
@str.4 = [63 x i8] c"Debe ingresar solo un numero entero entre 1 y 4 y luego enter.\00"
define i32 @LeerOpcion() {
%1 = alloca i32
%2 = alloca i8
%3 = bitcast i32* %1 to i8*
br label %4
4: ; preds = %19, %0
store i8 0, i8* %2
%5 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %1, i8* %2)
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, 10
br i1 %8, label %12, label %9
9: ; preds = %4, %9
%10 = call signext i8 (...) @getchar()
%11 = icmp eq i8 %10, 10
br i1 %11, label %16, label %9
12: ; preds = %4
%13 = load i32, i32* %1
%14 = add i32 %13, -5
%15 = icmp ult i32 %14, -4
br i1 %15, label %16, label %19
16: ; preds = %9, %12
%17 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0), %12 ], [ getelementptr inbounds ([63 x i8], [63 x i8]* @str.4, i64 0, i64 0), %9 ]
%18 = call i32 @puts(i8* dereferenceable(1) %17)
br label %19
19: ; preds = %16, %12
%20 = load i8, i8* %2
%21 = icmp ne i8 %20, 10
%22 = load i32, i32* %1
%23 = icmp sgt i32 %22, 4
%24 = select i1 %21, i1 true, i1 %23
%25 = icmp slt i32 %22, 1
%26 = select i1 %24, i1 true, i1 %25
br i1 %26, label %4, label %27
27: ; preds = %19
ret i32 %22
}