#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*/ result;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
long strtol(char *, int /*<<< orphan*/ *, int);
int add_remove_audit(void) {
  int k = 0;
  while (k != 1) {
    printf("Here you can Add and/or Remove Courses from the current audit: \n "
           "1) Add \n 2) Remove \n 3) Exit \n Enter 1 or 2 or 3 :\n");
    char result[2];
    fgets(result, sizeof(result), stdin);
    fgets(result, sizeof(result), stdin);
    if (result == NULL) {
      printf("invalid entry");
    } else {
      long int value = strtol(result, NULL, 10);
      if (value == 1 || value == 2 || value == 3) {
        if (value == 1) {
          return 1;
        } else if (value == 2) {
          return 2;
        } else if (value == 3) {
          return 3;
        }
      } else {
        printf("Invalid Entry");
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<add_remove_audit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     121f <add_remove_audit+0xef>
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
lea    -0xa(%rbp),%rdi
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1040 <fgets@plt>
lea    -0xa(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1040 <fgets@plt>
lea    -0xa(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
je     11ba <add_remove_audit+0x8a>
cmpq   $0x2,-0x18(%rbp)
je     11ba <add_remove_audit+0x8a>
cmpq   $0x3,-0x18(%rbp)
jne    120e <add_remove_audit+0xde>
cmpq   $0x1,-0x18(%rbp)
jne    11d1 <add_remove_audit+0xa1>
movl   $0x1,-0x4(%rbp)
jmp    1226 <add_remove_audit+0xf6>
cmpq   $0x2,-0x18(%rbp)
jne    11e8 <add_remove_audit+0xb8>
movl   $0x2,-0x4(%rbp)
jmp    1226 <add_remove_audit+0xf6>
cmpq   $0x3,-0x18(%rbp)
jne    11ff <add_remove_audit+0xcf>
movl   $0x3,-0x4(%rbp)
jmp    1226 <add_remove_audit+0xf6>
jmp    1204 <add_remove_audit+0xd4>
jmp    1209 <add_remove_audit+0xd9>
jmp    121a <add_remove_audit+0xea>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
jmp    113f <add_remove_audit+0xf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_remove_audit>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xebf(%rip),%r14
mov    0x2e92(%rip),%r12
lea    0x6(%rsp),%rbx
lea    0xe9e(%rip),%r15
jmp    1178 <add_remove_audit+0x38>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1050 <fgets@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
add    $0xffffffffffffffff,%rax
cmp    $0x2,%rax
ja     1170 <add_remove_audit+0x30>
ja     1178 <add_remove_audit+0x38>
add    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [117 x i8] c"Here you can Add and/or Remove Courses from the current audit: \0A 1) Add \0A 2) Remove \0A 3) Exit \0A Enter 1 or 2 or 3 :\0A\00"
@stdin = global i32 0
@.str.1 = [14 x i8] c"Invalid Entry\00"
define i32 @add_remove_audit() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i8]
%4 = alloca i64
store i32 0, i32* %2
br label %5
5: ; preds = %43, %0
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 1
br i1 %7, label %8, label %44
8: ; preds = %5
%9 = call i32 @printf(i8* getelementptr inbounds ([117 x i8], [117 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %10, i32 2, i32 %11)
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %13, i32 2, i32 %14)
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%17 = call i64 @strtol(i8* %16, i32* null, i32 10)
store i64 %17, i64* %4
%18 = load i64, i64* %4
%19 = icmp eq i64 %18, 1
br i1 %19, label %26, label %20
20: ; preds = %8
%21 = load i64, i64* %4
%22 = icmp eq i64 %21, 2
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i64, i64* %4
%25 = icmp eq i64 %24, 3
br i1 %25, label %26, label %41
26: ; preds = %23, %20, %8
%27 = load i64, i64* %4
%28 = icmp eq i64 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 1, i32* %1
br label %45
30: ; preds = %26
%31 = load i64, i64* %4
%32 = icmp eq i64 %31, 2
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 2, i32* %1
br label %45
34: ; preds = %30
%35 = load i64, i64* %4
%36 = icmp eq i64 %35, 3
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 3, i32* %1
br label %45
38: ; preds = %34
br label %39
39: ; preds = %38
br label %40
40: ; preds = %39
br label %43
41: ; preds = %23
%42 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %40
br label %5
44: ; preds = %5
store i32 0, i32* %1
br label %45
45: ; preds = %44, %37, %33, %29
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [14 x i8] c"Invalid Entry\00"
@str = [116 x i8] c"Here you can Add and/or Remove Courses from the current audit: \0A 1) Add \0A 2) Remove \0A 3) Exit \0A Enter 1 or 2 or 3 :\00"
define i32 @add_remove_audit() {
%1 = alloca [2 x i8]
%2 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %17, %0
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([116 x i8], [116 x i8]* @str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %2, i32 2, i32 %5)
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %2, i32 2, i32 %7)
%9 = call i64 @strtol(i8* nocapture %2, i32* null, i32 10)
%10 = add i64 %9, -1
%11 = icmp ult i64 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = add i64 %9, -1
%14 = icmp ult i64 %13, 3
br i1 %14, label %18, label %17
15: ; preds = %3
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %12, %15
br label %3
18: ; preds = %12
%19 = trunc i64 %13 to i32
%20 = add i32 %19, 1
ret i32 %20
}