#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*/ addRecord(int /*<<< orphan*/ *);
int /*<<< orphan*/ deleteRecord(int /*<<< orphan*/ *);
int /*<<< orphan*/ displayRecords(int /*<<< orphan*/ *);
int enterChoice();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ initialiseRecords(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ textFile(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ updateRecord(int /*<<< orphan*/ *);
int main() {
  FILE *cfPtr;
  int choice;
  if ((cfPtr = fopen("hardware.dat", "rb+")) == NULL) {
    cfPtr = fopen("hardware.dat", "wb+");
    fclose(cfPtr);
    cfPtr = fopen("hardware.dat", "rb+");
    initialiseRecords(cfPtr);
  }
  while ((choice = enterChoice()) != 6) {
    switch (choice) {
    case 1:
      textFile(cfPtr, "Hardware.txt");
      break;
    case 2:
      addRecord(cfPtr);
      break;
    case 3:
      updateRecord(cfPtr);
      break;
    case 4:
      deleteRecord(cfPtr);
      break;
    case 5:
      displayRecords(cfPtr);
      break;
    default:
      printf("\nINVALID OPTION - Please try again!\n\n");
      break;
    }
  }
  fclose(cfPtr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5e(%rip),%rdi
lea    0xe64(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1210 <main+0x70>
lea    0xe3d(%rip),%rdi
lea    0xe47(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe1d(%rip),%rdi
lea    0xe23(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <initialiseRecords@plt>
jmp    1215 <main+0x75>
mov    $0x0,%al
call   1070 <enterChoice@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x6,%eax
je     12af <main+0x10f>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x4,%eax
ja     129e <main+0xfe>
mov    -0x20(%rbp),%rax
lea    0xdb8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   10b0 <textFile@plt>
jmp    12aa <main+0x10a>
mov    -0x10(%rbp),%rdi
call   10c0 <addRecord@plt>
jmp    12aa <main+0x10a>
mov    -0x10(%rbp),%rdi
call   1090 <updateRecord@plt>
jmp    12aa <main+0x10a>
mov    -0x10(%rbp),%rdi
call   1080 <deleteRecord@plt>
jmp    12aa <main+0x10a>
mov    -0x10(%rbp),%rdi
call   1030 <displayRecords@plt>
jmp    12aa <main+0x10a>
lea    0xd91(%rip),%rdi
call   1050 <printf@plt>
jmp    1215 <main+0x75>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe69(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11fb <main+0x5b>
lea    0xe4e(%rip),%rbx
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rdi
call   1050 <fclose@plt>
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <initialiseRecords@plt>
lea    0xe38(%rip),%r14
lea    0xdf7(%rip),%rbx
lea    0xe1d(%rip),%r15
jmp    1220 <main+0x80>
mov    %r12,%rdi
call   1040 <displayRecords@plt>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <enterChoice@plt>
add    $0xffffffff,%eax
cmp    $0x5,%eax
ja     1245 <main+0xa5>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    %r12,%rdi
mov    %r15,%rsi
call   10b0 <textFile@plt>
jmp    1220 <main+0x80>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1220 <main+0x80>
mov    %r12,%rdi
call   10c0 <addRecord@plt>
jmp    1220 <main+0x80>
mov    %r12,%rdi
call   1090 <updateRecord@plt>
jmp    1220 <main+0x80>
mov    %r12,%rdi
call   1080 <deleteRecord@plt>
jmp    1220 <main+0x80>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"hardware.dat\00"
@.str.1 = [4 x i8] c"rb+\00"
@.str.2 = [4 x i8] c"wb+\00"
@.str.3 = [13 x i8] c"Hardware.txt\00"
@.str.4 = [38 x i8] c"\0AINVALID OPTION - Please try again!\0A\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 ([13 x i8], [13 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 %13
6: ; preds = %0
%7 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = call i32 @fclose(i32* %8)
%10 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %2
%11 = load i32*, i32** %2
%12 = call i32 @initialiseRecords(i32* %11)
br label %13
13: ; preds = %6, %0
br label %14
14: ; preds = %36, %13
%15 = call i32 (...) @enterChoice()
store i32 %15, i32* %3
%16 = icmp ne i32 %15, 6
br i1 %16, label %17, label %37
17: ; preds = %14
%18 = load i32, i32* %3
switch i32 %18, label %34 [
i32 1, label %19
i32 2, label %22
i32 3, label %25
i32 4, label %28
i32 5, label %31
]
19: ; preds = %17
%20 = load i32*, i32** %2
%21 = call i32 @textFile(i32* %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %36
22: ; preds = %17
%23 = load i32*, i32** %2
%24 = call i32 @addRecord(i32* %23)
br label %36
25: ; preds = %17
%26 = load i32*, i32** %2
%27 = call i32 @updateRecord(i32* %26)
br label %36
28: ; preds = %17
%29 = load i32*, i32** %2
%30 = call i32 @deleteRecord(i32* %29)
br label %36
31: ; preds = %17
%32 = load i32*, i32** %2
%33 = call i32 @displayRecords(i32* %32)
br label %36
34: ; preds = %17
%35 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34, %31, %28, %25, %22, %19
br label %14
37: ; preds = %14
%38 = load i32*, i32** %2
%39 = call i32 @fclose(i32* %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"hardware.dat\00"
@.str.1 = [4 x i8] c"rb+\00"
@.str.2 = [4 x i8] c"wb+\00"
@.str.3 = [13 x i8] c"Hardware.txt\00"
@str = [37 x i8] c"\0AINVALID OPTION - Please try again!\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 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 %8
3: ; preds = %0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @fclose(i32* %4)
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @initialiseRecords(i32* %6)
br label %8
8: ; preds = %3, %0
%9 = phi i32* [ %6, %3 ], [ %1, %0 ]
br label %10
10: ; preds = %24, %8
%11 = tail call i32 (...) @enterChoice()
switch i32 %11, label %22 [
i32 6, label %25
i32 1, label %12
i32 2, label %14
i32 3, label %16
i32 4, label %18
i32 5, label %20
]
12: ; preds = %10
%13 = tail call i32 @textFile(i32* %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %24
14: ; preds = %10
%15 = tail call i32 @addRecord(i32* %9)
br label %24
16: ; preds = %10
%17 = tail call i32 @updateRecord(i32* %9)
br label %24
18: ; preds = %10
%19 = tail call i32 @deleteRecord(i32* %9)
br label %24
20: ; preds = %10
%21 = tail call i32 @displayRecords(i32* %9)
br label %24
22: ; preds = %10
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %20, %18, %16, %14, %12
br label %10
25: ; preds = %10
%26 = tail call i32 @fclose(i32* %9)
ret i32 0
}