#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*/ deleteRecord(int /*<<< orphan*/ *);
unsigned int enterChoice();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ newRecord(int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ textFile(int /*<<< orphan*/ *);
int /*<<< orphan*/ updateRecord(int /*<<< orphan*/ *);
void fig11_15() {
  FILE *cfPtr;
  unsigned int choice;
  if ((cfPtr = fopen("credit.dat", "rb+")) == NULL) {
    puts("File could not be opened.");
  } else {
    while ((choice = enterChoice()) != 5) {
      switch (choice) {
      case 1:
        textFile(cfPtr);
        break;
      case 2:
        updateRecord(cfPtr);
        break;
      case 3:
        newRecord(cfPtr);
        break;
      case 4:
        deleteRecord(cfPtr);
        break;
      default:
        puts("Incorrect choice");
        break;
      }
    }
    fclose(cfPtr);
  }
}


x86 assembly (clang, -O0):
<fig11_15>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    11ba <fig11_15+0x3a>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
jmp    124d <fig11_15+0xcd>
jmp    11bf <fig11_15+0x3f>
mov    $0x0,%al
call   1050 <enterChoice@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x5,%eax
je     1244 <fig11_15+0xc4>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     1233 <fig11_15+0xb3>
mov    -0x18(%rbp),%rax
lea    0xe0e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
call   10a0 <textFile@plt>
jmp    123f <fig11_15+0xbf>
mov    -0x8(%rbp),%rdi
call   1070 <updateRecord@plt>
jmp    123f <fig11_15+0xbf>
mov    -0x8(%rbp),%rdi
call   1080 <newRecord@plt>
jmp    123f <fig11_15+0xbf>
mov    -0x8(%rbp),%rdi
call   1060 <deleteRecord@plt>
jmp    123f <fig11_15+0xbf>
lea    0xdff(%rip),%rdi
call   1030 <puts@plt>
jmp    11bf <fig11_15+0x3f>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig11_15>:
push   %r15
push   %r14
push   %rbx
lea    0xe88(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     120d <fig11_15+0x8d>
mov    %rax,%r15
lea    0xe96(%rip),%r14
lea    0xe52(%rip),%rbx
jmp    11c0 <fig11_15+0x40>
mov    %r15,%rdi
call   1060 <deleteRecord@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <enterChoice@plt>
add    $0xffffffff,%eax
cmp    $0x4,%eax
ja     11e2 <fig11_15+0x62>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    %r15,%rdi
call   10a0 <textFile@plt>
jmp    11c0 <fig11_15+0x40>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    11c0 <fig11_15+0x40>
mov    %r15,%rdi
call   1070 <updateRecord@plt>
jmp    11c0 <fig11_15+0x40>
mov    %r15,%rdi
call   1080 <newRecord@plt>
jmp    11c0 <fig11_15+0x40>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>
lea    0xe0f(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"credit.dat\00"
@.str.1 = [4 x i8] c"rb+\00"
@.str.2 = [26 x i8] c"File could not be opened.\00"
@.str.3 = [17 x i8] c"Incorrect choice\00"
define void @fig11_15() {
%1 = alloca i32*
%2 = alloca i32
%3 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %31
7: ; preds = %0
br label %8
8: ; preds = %27, %7
%9 = call i32 (...) @enterChoice()
store i32 %9, i32* %2
%10 = icmp ne i32 %9, 5
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = load i32, i32* %2
switch i32 %12, label %25 [
i32 1, label %13
i32 2, label %16
i32 3, label %19
i32 4, label %22
]
13: ; preds = %11
%14 = load i32*, i32** %1
%15 = call i32 @textFile(i32* %14)
br label %27
16: ; preds = %11
%17 = load i32*, i32** %1
%18 = call i32 @updateRecord(i32* %17)
br label %27
19: ; preds = %11
%20 = load i32*, i32** %1
%21 = call i32 @newRecord(i32* %20)
br label %27
22: ; preds = %11
%23 = load i32*, i32** %1
%24 = call i32 @deleteRecord(i32* %23)
br label %27
25: ; preds = %11
%26 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %22, %19, %16, %13
br label %8
28: ; preds = %8
%29 = load i32*, i32** %1
%30 = call i32 @fclose(i32* %29)
br label %31
31: ; preds = %28, %5
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"credit.dat\00"
@.str.1 = [4 x i8] c"rb+\00"
@.str.2 = [26 x i8] c"File could not be opened.\00"
@.str.3 = [17 x i8] c"Incorrect choice\00"
define void @fig11_15() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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.2, i64 0, i64 0))
br label %20
5: ; preds = %0, %17
%6 = tail call i32 (...) @enterChoice()
switch i32 %6, label %15 [
i32 5, label %18
i32 1, label %7
i32 2, label %9
i32 3, label %11
i32 4, label %13
]
7: ; preds = %5
%8 = tail call i32 @textFile(i32* %1)
br label %17
9: ; preds = %5
%10 = tail call i32 @updateRecord(i32* %1)
br label %17
11: ; preds = %5
%12 = tail call i32 @newRecord(i32* %1)
br label %17
13: ; preds = %5
%14 = tail call i32 @deleteRecord(i32* %1)
br label %17
15: ; preds = %5
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %15, %13, %11, %9, %7
br label %5
18: ; preds = %5
%19 = tail call i32 @fclose(i32* %1)
br label %20
20: ; preds = %18, %3
ret void
}