#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*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int getExerciseNumber(int argc, char *argv[]) {
  if (argc <= 0 || argc > 2) {
    printf("Illegal Usage");
    exit(-2);
  }
  if (argc == 2) {
    char *str = argv[1];
    int crit = 1;
    crit = crit && (str[0] == '-');
    crit = crit && (str[1] == 'e');
    crit = crit && (str[2] == 'x');
    if (crit)
      if (str[3] > '0' && str[3] <= '9')
        return (str[3] - '0');
    printf("Illegal argument");
    exit(-3);
  }
  if (argc == 1) {
    int exerciseNum = 0;
    for (;;) {
      printf("Please input your exercise number: ");
      scanf("%d", &exerciseNum);
      fflush(stdin);
      if (exerciseNum > 0 && exerciseNum < 10)
        return exerciseNum;
      printf("Illegal input, try again");
    }
  }
}


x86 assembly (clang, -O0):
<getExerciseNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1163 <getExerciseNumber+0x23>
cmpl   $0x2,-0x8(%rbp)
jle    1179 <getExerciseNumber+0x39>
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
mov    $0xfffffffe,%edi
call   1060 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1270 <getExerciseNumber+0x130>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x21(%rbp)
je     11b5 <getExerciseNumber+0x75>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x22(%rbp)
je     11e0 <getExerciseNumber+0xa0>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x65,%eax
sete   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x23(%rbp)
je     120b <getExerciseNumber+0xcb>
mov    -0x18(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x78,%eax
sete   %al
mov    %al,-0x23(%rbp)
mov    -0x23(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     125a <getExerciseNumber+0x11a>
mov    -0x18(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x30,%eax
jle    1255 <getExerciseNumber+0x115>
mov    -0x18(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x39,%eax
jg     1255 <getExerciseNumber+0x115>
mov    -0x18(%rbp),%rax
movsbl 0x3(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    12db <getExerciseNumber+0x19b>
jmp    125a <getExerciseNumber+0x11a>
lea    0xdad(%rip),%rdi
call   1030 <printf@plt>
mov    $0xfffffffd,%edi
call   1060 <exit@plt>
cmpl   $0x1,-0x8(%rbp)
jne    12db <getExerciseNumber+0x19b>
movl   $0x0,-0x20(%rbp)
lea    0xd97(%rip),%rdi
call   1030 <printf@plt>
lea    0xdaf(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <scanf@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
cmpl   $0x0,-0x20(%rbp)
jle    12ca <getExerciseNumber+0x18a>
cmpl   $0xa,-0x20(%rbp)
jge    12ca <getExerciseNumber+0x18a>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12db <getExerciseNumber+0x19b>
lea    0xd75(%rip),%rdi
call   1030 <printf@plt>
jmp    1281 <getExerciseNumber+0x141>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getExerciseNumber>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    -0x3(%rdi),%eax
cmp    $0xfffffffd,%eax
jbe    1254 <getExerciseNumber+0x114>
cmp    $0x2,%edi
jne    1197 <getExerciseNumber+0x57>
mov    0x8(%rsi),%rax
cmpb   $0x2d,(%rax)
jne    123e <getExerciseNumber+0xfe>
cmpb   $0x65,0x1(%rax)
jne    123e <getExerciseNumber+0xfe>
cmpb   $0x78,0x2(%rax)
jne    123e <getExerciseNumber+0xfe>
movzbl 0x3(%rax),%eax
lea    -0x31(%rax),%ecx
cmp    $0x8,%cl
ja     123e <getExerciseNumber+0xfe>
add    $0xffffffd0,%eax
jmp    1230 <getExerciseNumber+0xf0>
movl   $0x0,0xc(%rsp)
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
lea    0xe91(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x2e25(%rip),%r13
mov    0x0(%r13),%edi
call   1040 <fflush@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
cmp    $0x9,%ecx
jb     1230 <getExerciseNumber+0xf0>
lea    0xe67(%rip),%r14
lea    0xe39(%rip),%r15
lea    0xe56(%rip),%r12
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0x0(%r13),%edi
call   1040 <fflush@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
cmp    $0x9,%ecx
jae    1200 <getExerciseNumber+0xc0>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xdc9(%rip),%rdi
call   1030 <printf@plt>
mov    $0xfffffffd,%edi
call   1060 <exit@plt>
lea    0xda5(%rip),%rdi
call   1030 <printf@plt>
mov    $0xfffffffe,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Illegal Usage\00"
@.str.1 = [17 x i8] c"Illegal argument\00"
@.str.2 = [36 x i8] c"Please input your exercise number: \00"
@.str.3 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.4 = [25 x i8] c"Illegal input, try again\00"
define i32 @getExerciseNumber(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 2
br i1 %13, label %14, label %17
14: ; preds = %11, %2
%15 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -2)
unreachable
17: ; preds = %11
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %81
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
store i8* %23, i8** %6
store i32 1, i32* %7
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 45
br label %32
32: ; preds = %26, %20
%33 = phi i1 [ false, %20 ], [ %31, %26 ]
%34 = zext i1 %33 to i32
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %32
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 101
br label %43
43: ; preds = %37, %32
%44 = phi i1 [ false, %32 ], [ %42, %37 ]
%45 = zext i1 %44 to i32
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %43
%49 = load i8*, i8** %6
%50 = getelementptr inbounds i8, i8* %49, i64 2
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 120
br label %54
54: ; preds = %48, %43
%55 = phi i1 [ false, %43 ], [ %53, %48 ]
%56 = zext i1 %55 to i32
store i32 %56, i32* %7
%57 = load i32, i32* %7
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %78
59: ; preds = %54
%60 = load i8*, i8** %6
%61 = getelementptr inbounds i8, i8* %60, i64 3
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp sgt i32 %63, 48
br i1 %64, label %65, label %77
65: ; preds = %59
%66 = load i8*, i8** %6
%67 = getelementptr inbounds i8, i8* %66, i64 3
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp sle i32 %69, 57
br i1 %70, label %71, label %77
71: ; preds = %65
%72 = load i8*, i8** %6
%73 = getelementptr inbounds i8, i8* %72, i64 3
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = sub nsw i32 %75, 48
store i32 %76, i32* %3
br label %99
77: ; preds = %65, %59
br label %78
78: ; preds = %77, %54
%79 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%80 = call i32 @exit(i32 -3)
unreachable
81: ; preds = %17
%82 = load i32, i32* %4
%83 = icmp eq i32 %82, 1
br i1 %83, label %84, label %99
84: ; preds = %81
store i32 0, i32* %8
br label %85
85: ; preds = %97, %84
%86 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%87 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %8)
%88 = load i32, i32* @stdin
%89 = call i32 @fflush(i32 %88)
%90 = load i32, i32* %8
%91 = icmp sgt i32 %90, 0
br i1 %91, label %92, label %97
92: ; preds = %85
%93 = load i32, i32* %8
%94 = icmp slt i32 %93, 10
br i1 %94, label %95, label %97
95: ; preds = %92
%96 = load i32, i32* %8
store i32 %96, i32* %3
br label %99
97: ; preds = %92, %85
%98 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %85
99: ; preds = %71, %95, %81
%100 = load i32, i32* %3
ret i32 %100
}

LLVM IR (-O2):
@.str = [14 x i8] c"Illegal Usage\00"
@.str.1 = [17 x i8] c"Illegal argument\00"
@.str.2 = [36 x i8] c"Please input your exercise number: \00"
@.str.3 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.4 = [25 x i8] c"Illegal input, try again\00"
define i32 @getExerciseNumber(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = add i32 %0, -3
%5 = icmp ult i32 %4, -2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -2)
unreachable
9: ; preds = %2
%10 = icmp eq i32 %0, 2
br i1 %10, label %11, label %35
11: ; preds = %9
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 45
br i1 %15, label %16, label %32
16: ; preds = %11
%17 = getelementptr inbounds i8, i8* %13, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 101
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %13, i64 2
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 120
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = getelementptr inbounds i8, i8* %13, i64 3
%26 = load i8, i8* %25
%27 = add i8 %26, -49
%28 = icmp ult i8 %27, 9
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = zext i8 %26 to i32
%31 = add nsw i32 %30, -48
br label %55
32: ; preds = %11, %16, %24, %20
%33 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%34 = tail call i32 @exit(i32 -3)
unreachable
35: ; preds = %9
%36 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%37 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%39 = load i32, i32* @stdin
%40 = call i32 @fflush(i32 %39)
%41 = load i32, i32* %3
%42 = add i32 %41, -1
%43 = icmp ult i32 %42, 9
br i1 %43, label %44, label %46
44: ; preds = %46, %35
%45 = phi i32 [ %41, %35 ], [ %52, %46 ]
br label %55
46: ; preds = %35, %46
%47 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%50 = load i32, i32* @stdin
%51 = call i32 @fflush(i32 %50)
%52 = load i32, i32* %3
%53 = add i32 %52, -1
%54 = icmp ult i32 %53, 9
br i1 %54, label %44, label %46
55: ; preds = %29, %44
%56 = phi i32 [ %31, %29 ], [ %45, %44 ]
ret i32 %56
}