#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 */
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
char strlen(char *);
long strtol(char *, int /*<<< orphan*/ *, int);
int mod_audit(void) {
  int k = 0;
  while (k != 1) {
    printf("Please select the desiered Action:\n 1) Add/Remove courses \n 2) "
           "View Curent Audit \n 3) Exit \n Please Enter 1 or 2 or 3 : \n");
    char result[2];
    fgets(result, sizeof(result), stdin);
    char *results = fgets(result, sizeof(result), stdin);
    char len = strlen(result);
    if (result != NULL && result[len - 1] == '\n') {
      result[len - 1] = '\0';
    } else {
    }
    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):
<mod_audit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     126e <mod_audit+0x12e>
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
lea    -0xa(%rbp),%rdi
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1050 <fgets@plt>
lea    -0xa(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1050 <fgets@plt>
mov    %rax,-0x18(%rbp)
lea    -0xa(%rbp),%rdi
call   1030 <strlen@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0xa(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    11cd <mod_audit+0x8d>
movsbl -0x19(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0xa(%rbp,%rax,1)
jmp    11d2 <mod_audit+0x92>
jmp    11d2 <mod_audit+0x92>
lea    -0xa(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x1,-0x28(%rbp)
je     1209 <mod_audit+0xc9>
cmpq   $0x2,-0x28(%rbp)
je     1209 <mod_audit+0xc9>
cmpq   $0x3,-0x28(%rbp)
jne    125d <mod_audit+0x11d>
cmpq   $0x1,-0x28(%rbp)
jne    1220 <mod_audit+0xe0>
movl   $0x1,-0x4(%rbp)
jmp    1275 <mod_audit+0x135>
cmpq   $0x2,-0x28(%rbp)
jne    1237 <mod_audit+0xf7>
movl   $0x2,-0x4(%rbp)
jmp    1275 <mod_audit+0x135>
cmpq   $0x3,-0x28(%rbp)
jne    124e <mod_audit+0x10e>
movl   $0x3,-0x4(%rbp)
jmp    1275 <mod_audit+0x135>
jmp    1253 <mod_audit+0x113>
jmp    1258 <mod_audit+0x118>
jmp    1269 <mod_audit+0x129>
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
jmp    114f <mod_audit+0xf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mod_audit>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeaf(%rip),%r14
mov    0x2e82(%rip),%r12
lea    0x6(%rsp),%rbx
lea    0xe8e(%rip),%r15
jmp    1188 <mod_audit+0x38>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1060 <fgets@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movsbq %al,%rax
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11ca <mod_audit+0x7a>
movb   $0x0,0x5(%rsp,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
add    $0xffffffffffffffff,%rax
cmp    $0x2,%rax
ja     1180 <mod_audit+0x30>
ja     1188 <mod_audit+0x38>
add    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [122 x i8] c"Please select the desiered Action:\0A 1) Add/Remove courses \0A 2) View Curent Audit \0A 3) Exit \0A Please Enter 1 or 2 or 3 : \0A\00"
@stdin = global i32 0
@.str.1 = [14 x i8] c"Invalid Entry\00"
define i32 @mod_audit() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i8]
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i64
store i32 0, i32* %2
br label %7
7: ; preds = %63, %0
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 1
br i1 %9, label %10, label %64
10: ; preds = %7
%11 = call i32 @printf(i8* getelementptr inbounds ([122 x i8], [122 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i8* @fgets(i8* %12, i32 2, i32 %13)
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%16 = load i32, i32* @stdin
%17 = call i8* @fgets(i8* %15, i32 2, i32 %16)
store i8* %17, i8** %4
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%19 = call signext i8 @strlen(i8* %18)
store i8 %19, i8* %5
%20 = load i8, i8* %5
%21 = sext i8 %20 to i32
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %34
28: ; preds = %10
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 %32
store i8 0, i8* %33
br label %35
34: ; preds = %10
br label %35
35: ; preds = %34, %28
%36 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%37 = call i64 @strtol(i8* %36, i32* null, i32 10)
store i64 %37, i64* %6
%38 = load i64, i64* %6
%39 = icmp eq i64 %38, 1
br i1 %39, label %46, label %40
40: ; preds = %35
%41 = load i64, i64* %6
%42 = icmp eq i64 %41, 2
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = load i64, i64* %6
%45 = icmp eq i64 %44, 3
br i1 %45, label %46, label %61
46: ; preds = %43, %40, %35
%47 = load i64, i64* %6
%48 = icmp eq i64 %47, 1
br i1 %48, label %49, label %50
49: ; preds = %46
store i32 1, i32* %1
br label %65
50: ; preds = %46
%51 = load i64, i64* %6
%52 = icmp eq i64 %51, 2
br i1 %52, label %53, label %54
53: ; preds = %50
store i32 2, i32* %1
br label %65
54: ; preds = %50
%55 = load i64, i64* %6
%56 = icmp eq i64 %55, 3
br i1 %56, label %57, label %58
57: ; preds = %54
store i32 3, i32* %1
br label %65
58: ; preds = %54
br label %59
59: ; preds = %58
br label %60
60: ; preds = %59
br label %63
61: ; preds = %43
%62 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %63
63: ; preds = %61, %60
br label %7
64: ; preds = %7
store i32 0, i32* %1
br label %65
65: ; preds = %64, %57, %53, %49
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [14 x i8] c"Invalid Entry\00"
@str = [121 x i8] c"Please select the desiered Action:\0A 1) Add/Remove courses \0A 2) View Curent Audit \0A 3) Exit \0A Please Enter 1 or 2 or 3 : \00"
define i32 @mod_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 = %25, %0
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([121 x i8], [121 x i8]* @str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i8* @fgets(i8* %2, i32 2, i32 %5)
%7 = load i32, i32* @stdin
%8 = call i8* @fgets(i8* %2, i32 2, i32 %7)
%9 = call signext i8 @strlen(i8* %2)
%10 = sext i8 %9 to i64
%11 = add nsw i64 %10, -1
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %16
15: ; preds = %3
store i8 0, i8* %12
br label %16
16: ; preds = %3, %15
%17 = call i64 @strtol(i8* nocapture %2, i32* null, i32 10)
%18 = add i64 %17, -1
%19 = icmp ult i64 %18, 3
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = add i64 %17, -1
%22 = icmp ult i64 %21, 3
br i1 %22, label %26, label %25
23: ; preds = %16
%24 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %20, %23
br label %3
26: ; preds = %20
%27 = trunc i64 %21 to i32
%28 = add i32 %27, 1
ret i32 %28
}