#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 /*<<< orphan*/ addTransaction(int /*<<< orphan*/ *);
int enterChoice();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ textFile(int /*<<< orphan*/ *);
int main() {
  FILE *cfPtr;
  int choice;
  if ((cfPtr = fopen("trans.dat", "ab")) == NULL)
    printf("File could not be opened.\n");
  else {
    while ((choice = enterChoice()) != 2) {
      switch (choice) {
      case 1:
        addTransaction(cfPtr);
        break;
      default:
        printf("INVALID OPTION - Please try again!\n");
        break;
      }
    }
    fclose(cfPtr);
  }
  cfPtr = fopen("trans.dat", "rb");
  textFile(cfPtr);
  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    0xe76(%rip),%rdi
call   1040 <printf@plt>
jmp    11f2 <main+0x92>
jmp    11a6 <main+0x46>
mov    $0x0,%al
call   1060 <enterChoice@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x2,%eax
je     11e9 <main+0x89>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
jne    11d8 <main+0x78>
jmp    11ca <main+0x6a>
mov    -0x10(%rbp),%rdi
call   1050 <addTransaction@plt>
jmp    11e4 <main+0x84>
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
jmp    11a6 <main+0x46>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe07(%rip),%rdi
lea    0xe4c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <textFile@plt>
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     11bd <main+0x5d>
mov    %rax,%rbx
lea    0xe8a(%rip),%r14
jmp    1198 <main+0x38>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <addTransaction@plt>
xor    %eax,%eax
call   1060 <enterChoice@plt>
cmp    $0x1,%eax
je     1190 <main+0x30>
cmp    $0x2,%eax
je     11b3 <main+0x53>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1198 <main+0x38>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11c9 <main+0x69>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe30(%rip),%rdi
lea    0xe36(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <textFile@plt>
mov    %rbx,%rdi
call   1040 <fclose@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 = [3 x i8] c"ab\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"
@.str.4 = [3 x i8] c"rb\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 ([3 x i8], [3 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 %23
8: ; preds = %0
br label %9
9: ; preds = %19, %8
%10 = call i32 (...) @enterChoice()
store i32 %10, i32* %3
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32, i32* %3
switch i32 %13, label %17 [
i32 1, label %14
]
14: ; preds = %12
%15 = load i32*, i32** %2
%16 = call i32 @addTransaction(i32* %15)
br label %19
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
br label %9
20: ; preds = %9
%21 = load i32*, i32** %2
%22 = call i32 @fclose(i32* %21)
br label %23
23: ; preds = %20, %6
%24 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %24, i32** %2
%25 = load i32*, i32** %2
%26 = call i32 @textFile(i32* %25)
%27 = load i32*, i32** %2
%28 = call i32 @fclose(i32* %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"trans.dat\00"
@.str.1 = [3 x i8] c"ab\00"
@.str.4 = [3 x i8] c"rb\00"
@str = [35 x i8] c"INVALID OPTION - Please try again!\00"
@str.5 = [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 ([3 x i8], [3 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.5, i64 0, i64 0))
br label %14
5: ; preds = %0, %11
%6 = tail call i32 (...) @enterChoice()
switch i32 %6, label %9 [
i32 2, label %12
i32 1, label %7
]
7: ; preds = %5
%8 = tail call i32 @addTransaction(i32* %1)
br label %11
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %9, %7
br label %5
12: ; preds = %5
%13 = tail call i32 @fclose(i32* %1)
br label %14
14: ; preds = %12, %3
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%16 = tail call i32 @textFile(i32* %15)
%17 = tail call i32 @fclose(i32* %15)
ret i32 0
}