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

/* 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 mmenu(void) {
  printf("Welcome to Class Tracker! Your personal system for keeping records "
         "on all of you courses. \n Please select from the menu options: \n 1) "
         "Create an audit \n 2) Exit \n Enter 1 or 2: \n");
  char str[2];
  char *result = fgets(str, sizeof(str), stdin);
  char len = strlen(str);
  if (result != NULL && str[len - 1] == '\n') {
    str[len - 1] = '\0';
  } else {
  }
  long int value = strtol(result, NULL, 10);
  return value;
}


x86 assembly (clang, -O0):
<mmenu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
lea    -0x2(%rbp),%rdi
mov    0x2e89(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1050 <fgets@plt>
mov    %rax,-0x10(%rbp)
lea    -0x2(%rbp),%rdi
call   1030 <strlen@plt>
mov    %al,-0x11(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b0 <mmenu+0x70>
movsbl -0x11(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x2(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    11b0 <mmenu+0x70>
movsbl -0x11(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x2(%rbp,%rax,1)
jmp    11b5 <mmenu+0x75>
jmp    11b5 <mmenu+0x75>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmenu>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
lea    0x6(%rsp),%r14
mov    %r14,%rdi
mov    $0x2,%esi
call   1050 <fgets@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %rbx,%rbx
je     118c <mmenu+0x4c>
movsbq %al,%rax
cmpb   $0xa,-0x1(%rax,%r14,1)
jne    118c <mmenu+0x4c>
movb   $0x0,0x5(%rsp,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [178 x i8] c"Welcome to Class Tracker! Your personal system for keeping records on all of you courses. \0A Please select from the menu options: \0A 1) Create an audit \0A 2) Exit \0A Enter 1 or 2: \0A\00"
@stdin = global i32 0
define i32 @mmenu() {
%1 = alloca [2 x i8]
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i64
%5 = call i32 @printf(i8* getelementptr inbounds ([178 x i8], [178 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i8* @fgets(i8* %6, i32 2, i32 %7)
store i8* %8, i8** %2
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%10 = call signext i8 @strlen(i8* %9)
store i8 %10, i8* %3
%11 = load i8*, i8** %2
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %28
13: ; preds = %0
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %28
22: ; preds = %13
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 %26
store i8 0, i8* %27
br label %29
28: ; preds = %13, %0
br label %29
29: ; preds = %28, %22
%30 = load i8*, i8** %2
%31 = call i64 @strtol(i8* %30, i32* null, i32 10)
store i64 %31, i64* %4
%32 = load i64, i64* %4
%33 = trunc i64 %32 to i32
ret i32 %33
}

LLVM IR (-O2):
@stdin = global i32 0
@str = [177 x i8] c"Welcome to Class Tracker! Your personal system for keeping records on all of you courses. \0A Please select from the menu options: \0A 1) Create an audit \0A 2) Exit \0A Enter 1 or 2: \00"
define i32 @mmenu() {
%1 = alloca [2 x i8]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([177 x i8], [177 x i8]* @str, i64 0, i64 0))
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%4 = load i32, i32* @stdin
%5 = call i8* @fgets(i8* %3, i32 2, i32 %4)
%6 = call signext i8 @strlen(i8* %3)
%7 = icmp eq i8* %5, null
br i1 %7, label %15, label %8
8: ; preds = %0
%9 = sext i8 %6 to i64
%10 = add nsw i64 %9, -1
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 10
br i1 %13, label %14, label %15
14: ; preds = %8
store i8 0, i8* %11
br label %15
15: ; preds = %0, %8, %14
%16 = call i64 @strtol(i8* nocapture %5, i32* null, i32 10)
%17 = trunc i64 %16 to i32
ret i32 %17
}