#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int dialogue(char *text, char *options[], int size) {
  printf("%s\n", text);
  int i;
  for (i = 0; i < size; i++) {
    printf("%d. %s\n", i + 1, options[i]);
  }
  int *in;
  int bad = 1;
  while (bad) {
    scanf("%d", in);
    if (*in <= size && *in >= 1) {
      bad = 0;
      return (int)in;
    } else
      printf("Invalid Input\n");
  }
}


x86 assembly (clang, -O0):
<dialogue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1186 <dialogue+0x66>
mov    -0x20(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114c <dialogue+0x2c>
movl   $0x1,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11e9 <dialogue+0xc9>
mov    -0x28(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
cmp    -0x1c(%rbp),%eax
jg     11d6 <dialogue+0xb6>
mov    -0x28(%rbp),%rax
cmpl   $0x1,(%rax)
jl     11d6 <dialogue+0xb6>
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11e9 <dialogue+0xc9>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118d <dialogue+0x6d>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dialogue>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r15
call   1030 <puts@plt>
test   %ebx,%ebx
jle    1179 <dialogue+0x49>
mov    %ebx,%r12d
lea    0xeb0(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15,%rbx,8),%rdx
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %rbx,%r12
jne    1160 <dialogue+0x30>
lea    0xe88(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <scanf@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [8 x i8] c"%d. %s\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [15 x i8] c"Invalid Input\0A\00"
define i32 @dialogue(i8* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 0, i32* %8
br label %13
13: ; preds = %26, %3
%14 = load i32, i32* %8
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %29
17: ; preds = %13
%18 = load i32, i32* %8
%19 = add nsw i32 %18, 1
%20 = load i8**, i8*** %6
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %19, i8* %24)
br label %26
26: ; preds = %17
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %13
29: ; preds = %13
store i32 1, i32* %10
br label %30
30: ; preds = %49, %29
%31 = load i32, i32* %10
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %50
33: ; preds = %30
%34 = load i32*, i32** %9
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %34)
%36 = load i32*, i32** %9
%37 = load i32, i32* %36
%38 = load i32, i32* %7
%39 = icmp sle i32 %37, %38
br i1 %39, label %40, label %47
40: ; preds = %33
%41 = load i32*, i32** %9
%42 = load i32, i32* %41
%43 = icmp sge i32 %42, 1
br i1 %43, label %44, label %47
44: ; preds = %40
store i32 0, i32* %10
%45 = load i32*, i32** %9
%46 = ptrtoint i32* %45 to i32
store i32 %46, i32* %4
br label %50
47: ; preds = %40, %33
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47
br label %30
50: ; preds = %44, %30
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"%d. %s\0A\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @dialogue(i8* nocapture %0, i8** nocapture %1, i32 %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) %0)
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %16
6: ; preds = %3
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %10, %8 ]
%10 = add nuw nsw i64 %9, 1
%11 = getelementptr inbounds i8*, i8** %1, i64 %9
%12 = load i8*, i8** %11
%13 = trunc i64 %10 to i32
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %13, i8* %12)
%15 = icmp eq i64 %10, %7
br i1 %15, label %16, label %8
16: ; preds = %8, %3
%17 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* undef)
ret i32 undef
}