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

/* Variables and functions */
int enterChoice();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ newRecord(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ textFile(int /*<<< orphan*/ *);
int main() {
  FILE *cfPtr;
  int choice;
  if ((cfPtr = fopen("trans.dat", "rb+")) == NULL)
    printf("File could not be opened.\n");
  else {
    while ((choice = enterChoice()) != 3) {
      switch (choice) {
      case 1:
        textFile(cfPtr);
        break;
      case 2:
        newRecord(cfPtr);
        break;
      default:
        printf("INVALID OPTION - Please try again!\n");
        break;
      }
    }
    fclose(cfPtr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a1 <main+0x41>
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
jmp    1214 <main+0xb4>
jmp    11a6 <main+0x46>
mov    $0x0,%al
call   1050 <enterChoice@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x3,%eax
je     120b <main+0xab>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x1,%eax
je     11de <main+0x7e>
jmp    11cd <main+0x6d>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
je     11ec <main+0x8c>
jmp    11fa <main+0x9a>
mov    -0x10(%rbp),%rdi
call   1080 <textFile@plt>
jmp    1206 <main+0xa6>
mov    -0x10(%rbp),%rdi
call   1060 <newRecord@plt>
jmp    1206 <main+0xa6>
lea    0xe28(%rip),%rdi
call   1040 <printf@plt>
jmp    11a6 <main+0x46>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d4 <main+0x74>
mov    %rax,%rbx
lea    0xe88(%rip),%r14
jmp    1198 <main+0x38>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <newRecord@plt>
xor    %eax,%eax
call   1050 <enterChoice@plt>
cmp    $0x1,%eax
je     11c0 <main+0x60>
cmp    $0x2,%eax
je     1190 <main+0x30>
cmp    $0x3,%eax
je     11ca <main+0x6a>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1198 <main+0x38>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <textFile@plt>
jmp    1198 <main+0x38>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11e0 <main+0x80>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"trans.dat\00"
@.str.1 = [4 x i8] c"rb+\00"
@.str.2 = [27 x i8] c"File could not be opened.\0A\00"
@.str.3 = [36 x i8] c"INVALID OPTION - Please try again!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %26
8: ; preds = %0
br label %9
9: ; preds = %22, %8
%10 = call i32 (...) @enterChoice()
store i32 %10, i32* %3
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = load i32, i32* %3
switch i32 %13, label %20 [
i32 1, label %14
i32 2, label %17
]
14: ; preds = %12
%15 = load i32*, i32** %2
%16 = call i32 @textFile(i32* %15)
br label %22
17: ; preds = %12
%18 = load i32*, i32** %2
%19 = call i32 @newRecord(i32* %18)
br label %22
20: ; preds = %12
%21 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %17, %14
br label %9
23: ; preds = %9
%24 = load i32*, i32** %2
%25 = call i32 @fclose(i32* %24)
br label %26
26: ; preds = %23, %6
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"trans.dat\00"
@.str.1 = [4 x i8] c"rb+\00"
@str = [35 x i8] c"INVALID OPTION - Please try again!\00"
@str.4 = [26 x i8] c"File could not be opened.\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.4, i64 0, i64 0))
br label %16
5: ; preds = %0, %13
%6 = tail call i32 (...) @enterChoice()
switch i32 %6, label %11 [
i32 3, label %14
i32 1, label %7
i32 2, label %9
]
7: ; preds = %5
%8 = tail call i32 @textFile(i32* %1)
br label %13
9: ; preds = %5
%10 = tail call i32 @newRecord(i32* %1)
br label %13
11: ; preds = %5
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %13
13: ; preds = %11, %9, %7
br label %5
14: ; preds = %5
%15 = tail call i32 @fclose(i32* %1)
br label %16
16: ; preds = %14, %3
ret i32 0
}