#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 */
typedef int /*<<< orphan*/ line;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ isNumber(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int getUserInput(void) {
  int n = -1;
  char line[10];
  while (n < 0) {
    printf("Please input n for fibonacci(n) or 'q' to quit: ");
    if (fgets(line, sizeof(line), stdin)) {
      if (isNumber(line)) {
        sscanf(line, "%d", &n);
      } else {
        if (strcmp(line, "q\n") == 0) {
          break;
        }
      }
    }
  }
  return n;
}


x86 assembly (clang, -O0):
<getUserInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11f0 <getUserInput+0xa0>
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
lea    -0xe(%rbp),%rdi
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11eb <getUserInput+0x9b>
lea    -0xe(%rbp),%rdi
call   1060 <isNumber@plt>
cmp    $0x0,%rax
je     11c2 <getUserInput+0x72>
lea    -0xe(%rbp),%rdi
lea    0xe7d(%rip),%rsi
lea    -0x4(%rbp),%rdx
call   1070 <sscanf@plt>
jmp    11e6 <getUserInput+0x96>
lea    -0xe(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11e1 <getUserInput+0x91>
jmp    11f0 <getUserInput+0xa0>
jmp    11e6 <getUserInput+0x96>
jmp    11eb <getUserInput+0x9b>
jmp    115f <getUserInput+0xf>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getUserInput>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0xffffffff,0x8(%rsp)
ff
lea    0xe93(%rip),%r14
mov    0x2e74(%rip),%rbp
lea    0xe(%rsp),%rbx
lea    0xeb4(%rip),%r15
lea    0xeaa(%rip),%r12
lea    0x8(%rsp),%r13
jmp    11a3 <getUserInput+0x53>
xchg   %ax,%ax
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <sscanf@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
jns    11e4 <getUserInput+0x94>
mov    %r14,%rdi
call   1030 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     119b <getUserInput+0x4b>
mov    %rbx,%rdi
call   1060 <isNumber@plt>
mov    %rbx,%rdi
test   %rax,%rax
jne    1190 <getUserInput+0x40>
mov    %r15,%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
mov    0x8(%rsp),%eax
test   %rcx,%rcx
jne    119f <getUserInput+0x4f>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"Please input n for fibonacci(n) or 'q' to quit: \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"q\0A\00"
define i32 @getUserInput() {
%1 = alloca i32
%2 = alloca [10 x i8]
store i32 -1, i32* %1
br label %3
3: ; preds = %26, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %27
6: ; preds = %3
%7 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i64 @fgets(i8* %8, i32 10, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %6
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%14 = call i64 @isNumber(i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
br label %25
19: ; preds = %12
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
br label %27
24: ; preds = %19
br label %25
25: ; preds = %24, %16
br label %26
26: ; preds = %25, %6
br label %3
27: ; preds = %23, %3
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [49 x i8] c"Please input n for fibonacci(n) or 'q' to quit: \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"q\0A\00"
define i32 @getUserInput() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
br label %5
5: ; preds = %24, %0
%6 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdin
%8 = call i64 @fgets(i8* %4, i32 10, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %5
%11 = call i64 @isNumber(i8* %4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
br label %21
15: ; preds = %10
%16 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
%18 = load i32, i32* %1
%19 = icmp slt i32 %18, 0
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %24, label %25
21: ; preds = %13, %5
%22 = load i32, i32* %1
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21, %15
br label %5
25: ; preds = %15, %21
%26 = phi i32 [ %18, %15 ], [ %22, %21 ]
ret i32 %26
}