#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 EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
int get_num(char *prompt, int lower, int upper, int default_value) {
  int number = -1;
  int result;
  static char numbuf[40];
  do {
    if (default_value != -1)
      printf("%s [%d]? ", prompt, default_value);
    else
      printf("%s? ", prompt);
    if (!fgets(numbuf, 40, stdin) || numbuf[0] == 'q') {
      printf("\nGoodbye!\n");
      exit(0);
    }
    result = sscanf(numbuf, "%d", &number);
  } while (result == 0 ||
           (result != EOF && (number < lower || number > upper)));
  return (result == EOF ? default_value : number);
}


x86 assembly (clang, -O0):
<get_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     1180 <get_num+0x40>
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1192 <get_num+0x52>
mov    -0x8(%rbp),%rsi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
lea    0x2eae(%rip),%rdi
mov    $0x28,%esi
call   1040 <fgets@plt>
cmp    $0x0,%eax
je     11c5 <get_num+0x85>
movsbl 0x2e94(%rip),%eax
cmp    $0x71,%eax
jne    11da <get_num+0x9a>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
lea    0x2e6f(%rip),%rdi
lea    0xe32(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
je     1243 <get_num+0x103>
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
mov    0x2dd1(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1e(%rbp)
je     123d <get_num+0xfd>
mov    -0x18(%rbp),%ecx
mov    $0x1,%al
cmp    -0xc(%rbp),%ecx
mov    %al,-0x1f(%rbp)
jl     1237 <get_num+0xf7>
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
setg   %al
mov    %al,-0x1f(%rbp)
mov    -0x1f(%rbp),%al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    115c <get_num+0x1c>
mov    -0x1c(%rbp),%eax
mov    0x2d88(%rip),%rcx
cmp    (%rcx),%eax
jne    126b <get_num+0x12b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1271 <get_num+0x131>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_num>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,0x4(%rsp)
mov    %esi,%r15d
mov    %rdi,%r13
movl   $0xffffffff,(%rsp)
lea    0x2eeb(%rip),%rbp
lea    0xe93(%rip),%r12
mov    %rsp,%r14
nop
cmp    $0xffffffff,%ebx
je     11a0 <get_num+0x50>
lea    0xe74(%rip),%rdi
mov    %r13,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b1 <get_num+0x61>
nopw   0x0(%rax,%rax,1)
lea    0xe63(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    $0x28,%esi
call   1050 <fgets@plt>
test   %eax,%eax
je     1212 <get_num+0xc2>
cmpb   $0x71,0x2e8e(%rip)
je     1212 <get_num+0xc2>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1060 <sscanf@plt>
test   %eax,%eax
je     1180 <get_num+0x30>
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%eax
je     1201 <get_num+0xb1>
mov    (%rsp),%eax
cmp    %r15d,%eax
jl     1180 <get_num+0x30>
cmp    0x4(%rsp),%eax
jg     1180 <get_num+0x30>
jmp    1203 <get_num+0xb3>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf9(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@get_num.numbuf = internal global [40 x i8] zeroinitializer
@.str = [10 x i8] c"%s [%d]? \00"
@.str.1 = [5 x i8] c"%s? \00"
@stdin = global i32 0
@.str.2 = [11 x i8] c"\0AGoodbye!\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@EOF = global i32 0
define i32 @get_num(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 -1, i32* %9
br label %11
11: ; preds = %53, %4
%12 = load i32, i32* %8
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = load i32, i32* %8
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %16)
br label %21
18: ; preds = %11
%19 = load i8*, i8** %5
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %14
%22 = load i32, i32* @stdin
%23 = call i32 @fgets(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @get_num.numbuf, i64 0, i64 0), i32 40, i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @get_num.numbuf, i64 0, i64 0)
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 113
br i1 %28, label %29, label %32
29: ; preds = %25, %21
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %25
%33 = call i32 @sscanf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @get_num.numbuf, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %9)
store i32 %33, i32* %10
br label %34
34: ; preds = %32
%35 = load i32, i32* %10
%36 = icmp eq i32 %35, 0
br i1 %36, label %53, label %37
37: ; preds = %34
%38 = load i32, i32* %10
%39 = load i32, i32* @EOF
%40 = icmp ne i32 %38, %39
br i1 %40, label %41, label %51
41: ; preds = %37
%42 = load i32, i32* %9
%43 = load i32, i32* %6
%44 = icmp slt i32 %42, %43
br i1 %44, label %49, label %45
45: ; preds = %41
%46 = load i32, i32* %9
%47 = load i32, i32* %7
%48 = icmp sgt i32 %46, %47
br label %49
49: ; preds = %45, %41
%50 = phi i1 [ true, %41 ], [ %48, %45 ]
br label %51
51: ; preds = %49, %37
%52 = phi i1 [ false, %37 ], [ %50, %49 ]
br label %53
53: ; preds = %51, %34
%54 = phi i1 [ true, %34 ], [ %52, %51 ]
br i1 %54, label %11, label %55
55: ; preds = %53
%56 = load i32, i32* %10
%57 = load i32, i32* @EOF
%58 = icmp eq i32 %56, %57
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = load i32, i32* %8
br label %63
61: ; preds = %55
%62 = load i32, i32* %9
br label %63
63: ; preds = %61, %59
%64 = phi i32 [ %60, %59 ], [ %62, %61 ]
ret i32 %64
}

LLVM IR (-O2):
@get_num.numbuf = internal global [40 x i8] zeroinitializer
@.str = [10 x i8] c"%s [%d]? \00"
@.str.1 = [5 x i8] c"%s? \00"
@stdin = global i32 0
@.str.3 = [3 x i8] c"%d\00"
@EOF = global i32 0
@str = [10 x i8] c"\0AGoodbye!\00"
define i32 @get_num(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 -1, i32* %5
%7 = icmp eq i32 %3, -1
br label %8
8: ; preds = %34, %4
br i1 %7, label %11, label %9
9: ; preds = %8
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %3)
br label %13
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %11, %9
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @get_num.numbuf, i64 0, i64 0), i32 40, i32 %14)
%16 = icmp eq i32 %15, 0
%17 = load i8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @get_num.numbuf, i64 0, i64 0)
%18 = icmp eq i8 %17, 113
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %13
%24 = call i32 @sscanf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @get_num.numbuf, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%25 = icmp eq i32 %24, 0
br i1 %25, label %34, label %26
26: ; preds = %23
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %24, %27
br i1 %28, label %35, label %29
29: ; preds = %26
%30 = load i32, i32* %5
%31 = icmp slt i32 %30, %1
%32 = icmp sgt i32 %30, %2
%33 = or i1 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %29, %23
br label %8
35: ; preds = %29, %26
%36 = phi i32 [ %3, %26 ], [ %30, %29 ]
ret i32 %36
}