#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 */
struct Connection {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ atof(char *);
int atoi(char *);
int /*<<< orphan*/ close(struct Connection *);
int /*<<< orphan*/ create(struct Connection *);
int /*<<< orphan*/ delete (struct Connection *, int);
int /*<<< orphan*/ err(char *);
int /*<<< orphan*/ get(struct Connection *, int);
int /*<<< orphan*/ insert(struct Connection *, int, char *, char *,
                          int /*<<< orphan*/);
struct Connection *open(char *, char);
int /*<<< orphan*/ print(struct Connection *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write(struct Connection *);
int main(int argc, char *argv[]) {
  if (argc < 3)
    err("Usage: ./stubase <databasefile> <action> [parameters]");
  char *filename = argv[1];
  char action = argv[2][0];
  struct Connection *conn = open(filename, action);
  int id = 0;
  if (argc > 3)
    id = atoi(argv[3]);
  if (id >= 10)
    err("There's not that many records.");
  switch (action) {
  case 'h':
    if (argc == 3)
      printf("Stubase Help\n\n"
             "Usage: ./stubase <databasefile> <action> [parameters]\n\n"
             "Available action:\n"
             "c = Create database\n"
             "i = Insert data into database\n"
             "d = Delete data from database\n"
             "g = Get data from database\n"
             "p = Print data from database\n\n"
             "See README for more details\n");
    break;
  case 'c':
    create(conn);
    write(conn);
    break;
  case 'i':
    if (argc != 7)
      err("Need id, npm, name, and score to insert");
    insert(conn, id, argv[4], argv[5], atof(argv[6]));
    write(conn);
    break;
  case 'd':
    if (argc != 4)
      err("Need an id to delete");
    delete (conn, id);
    write(conn);
    break;
  case 'g':
    if (argc != 4)
      err("Need an id to get / row is available");
    get(conn, id);
    break;
  case 'p':
    print(conn);
    break;
  default:
    err("Invalid action, only: c=create, i=insert, d=delete, g=get, p=print");
  }
  close(conn);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ec <main+0x2c>
lea    0xe51(%rip),%rdi
call   1090 <err@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rdi
movsbl -0x19(%rbp),%esi
call   10c0 <open@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    1237 <main+0x77>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jl     124d <main+0x8d>
lea    0xe26(%rip),%rdi
call   1090 <err@plt>
movsbl -0x19(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0xd,%eax
ja     137c <main+0x1bc>
mov    -0x38(%rbp),%rax
lea    0xd92(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x3,-0x8(%rbp)
jne    128d <main+0xcd>
lea    0xe05(%rip),%rdi
call   1050 <printf@plt>
jmp    1388 <main+0x1c8>
mov    -0x28(%rbp),%rdi
call   1080 <create@plt>
mov    -0x28(%rbp),%rdi
call   1040 <write@plt>
jmp    1388 <main+0x1c8>
cmpl   $0x7,-0x8(%rbp)
je     12bf <main+0xff>
lea    0xed0(%rip),%rdi
call   1090 <err@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rdi
call   1030 <atof@plt>
mov    -0x58(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    %eax,%r8d
call   10b0 <insert@plt>
mov    -0x28(%rbp),%rdi
call   1040 <write@plt>
jmp    1388 <main+0x1c8>
cmpl   $0x4,-0x8(%rbp)
je     132d <main+0x16d>
lea    0xe8a(%rip),%rdi
call   1090 <err@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   10e0 <delete@plt>
mov    -0x28(%rbp),%rdi
call   1040 <write@plt>
jmp    1388 <main+0x1c8>
cmpl   $0x4,-0x8(%rbp)
je     135d <main+0x19d>
lea    0xe6f(%rip),%rdi
call   1090 <err@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   10a0 <get@plt>
jmp    1388 <main+0x1c8>
mov    -0x28(%rbp),%rdi
call   1070 <print@plt>
jmp    1388 <main+0x1c8>
lea    0xe69(%rip),%rdi
call   1090 <err@plt>
mov    -0x28(%rbp),%rdi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %edi,%ebp
cmp    $0x2,%edi
jg     11de <main+0x1e>
lea    0xe5f(%rip),%rdi
call   1090 <err@plt>
mov    0x8(%r12),%rdi
mov    0x10(%r12),%rax
movsbl (%rax),%ebx
mov    %ebx,%esi
call   10c0 <open@plt>
mov    %rax,%r14
xor    %r15d,%r15d
cmp    $0x4,%ebp
jl     121b <main+0x5b>
mov    0x18(%r12),%rdi
call   10d0 <atoi@plt>
mov    %eax,%r15d
cmp    $0xa,%eax
jl     121b <main+0x5b>
lea    0xe58(%rip),%rdi
call   1090 <err@plt>
add    $0xffffff9d,%ebx
cmp    $0xd,%ebx
ja     125e <main+0x9e>
lea    0xdd6(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    %r14,%rdi
call   1080 <create@plt>
jmp    12d6 <main+0x116>
cmp    $0x4,%ebp
je     1251 <main+0x91>
lea    0xe69(%rip),%rdi
call   1090 <err@plt>
mov    %r14,%rdi
mov    %r15d,%esi
call   10e0 <delete@plt>
jmp    12d6 <main+0x116>
lea    0xe8a(%rip),%rdi
call   1090 <err@plt>
jmp    12e8 <main+0x128>
cmp    $0x4,%ebp
je     127d <main+0xbd>
lea    0xe52(%rip),%rdi
call   1090 <err@plt>
mov    %r14,%rdi
mov    %r15d,%esi
call   10a0 <get@plt>
jmp    12e8 <main+0x128>
cmp    $0x3,%ebp
jne    12e8 <main+0x128>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
jmp    12e8 <main+0x128>
cmp    $0x7,%ebp
je     12ae <main+0xee>
lea    0xde4(%rip),%rdi
call   1090 <err@plt>
mov    0x20(%r12),%rbx
mov    0x28(%r12),%rbp
mov    0x30(%r12),%rdi
call   1040 <atof@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %eax,%r8d
call   10b0 <insert@plt>
mov    %r14,%rdi
call   1050 <write@plt>
jmp    12e8 <main+0x128>
mov    %r14,%rdi
call   1070 <print@plt>
mov    %r14,%rdi
call   1060 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Connection = type { i32 }
@.str = [54 x i8] c"Usage: ./stubase <databasefile> <action> [parameters]\00"
@.str.1 = [31 x i8] c"There's not that many records.\00"
@.str.2 = [253 x i8] c"Stubase Help\0A\0AUsage: ./stubase <databasefile> <action> [parameters]\0A\0AAvailable action:\0Ac = Create database\0Ai = Insert data into database\0Ad = Delete data from database\0Ag = Get data from database\0Ap = Print data from database\0A\0ASee README for more details\0A\00"
@.str.3 = [40 x i8] c"Need id, npm, name, and score to insert\00"
@.str.4 = [21 x i8] c"Need an id to delete\00"
@.str.5 = [37 x i8] c"Need an id to get / row is available\00"
@.str.6 = [67 x i8] c"Invalid action, only: c=create, i=insert, d=delete, g=get, p=print\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8
%8 = alloca %struct.Connection*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @err(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
store i8 %22, i8* %7
%23 = load i8*, i8** %6
%24 = load i8, i8* %7
%25 = call %struct.Connection* @open(i8* %23, i8 signext %24)
store %struct.Connection* %25, %struct.Connection** %8
store i32 0, i32* %9
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 3
br i1 %27, label %28, label %33
28: ; preds = %14
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %9
br label %33
33: ; preds = %28, %14
%34 = load i32, i32* %9
%35 = icmp sge i32 %34, 10
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @err(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
%39 = load i8, i8* %7
%40 = sext i8 %39 to i32
switch i32 %40, label %96 [
i32 104, label %41
i32 99, label %47
i32 105, label %52
i32 100, label %73
i32 103, label %84
i32 112, label %93
]
41: ; preds = %38
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 3
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @printf(i8* getelementptr inbounds ([253 x i8], [253 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
br label %98
47: ; preds = %38
%48 = load %struct.Connection*, %struct.Connection** %8
%49 = call i32 @create(%struct.Connection* %48)
%50 = load %struct.Connection*, %struct.Connection** %8
%51 = call i32 @write(%struct.Connection* %50)
br label %98
52: ; preds = %38
%53 = load i32, i32* %4
%54 = icmp ne i32 %53, 7
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @err(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %55, %52
%58 = load %struct.Connection*, %struct.Connection** %8
%59 = load i32, i32* %9
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 4
%62 = load i8*, i8** %61
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 5
%65 = load i8*, i8** %64
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 6
%68 = load i8*, i8** %67
%69 = call i32 @atof(i8* %68)
%70 = call i32 @insert(%struct.Connection* %58, i32 %59, i8* %62, i8* %65, i32 %69)
%71 = load %struct.Connection*, %struct.Connection** %8
%72 = call i32 @write(%struct.Connection* %71)
br label %98
73: ; preds = %38
%74 = load i32, i32* %4
%75 = icmp ne i32 %74, 4
br i1 %75, label %76, label %78
76: ; preds = %73
%77 = call i32 @err(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %78
78: ; preds = %76, %73
%79 = load %struct.Connection*, %struct.Connection** %8
%80 = load i32, i32* %9
%81 = call i32 @delete(%struct.Connection* %79, i32 %80)
%82 = load %struct.Connection*, %struct.Connection** %8
%83 = call i32 @write(%struct.Connection* %82)
br label %98
84: ; preds = %38
%85 = load i32, i32* %4
%86 = icmp ne i32 %85, 4
br i1 %86, label %87, label %89
87: ; preds = %84
%88 = call i32 @err(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %89
89: ; preds = %87, %84
%90 = load %struct.Connection*, %struct.Connection** %8
%91 = load i32, i32* %9
%92 = call i32 @get(%struct.Connection* %90, i32 %91)
br label %98
93: ; preds = %38
%94 = load %struct.Connection*, %struct.Connection** %8
%95 = call i32 @print(%struct.Connection* %94)
br label %98
96: ; preds = %38
%97 = call i32 @err(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.6, i64 0, i64 0))
br label %98
98: ; preds = %96, %93, %89, %78, %57, %47, %46
%99 = load %struct.Connection*, %struct.Connection** %8
%100 = call i32 @close(%struct.Connection* %99)
ret i32 0
}

LLVM IR (-O2):
%struct.Connection = type { i32 }
@.str = [54 x i8] c"Usage: ./stubase <databasefile> <action> [parameters]\00"
@.str.1 = [31 x i8] c"There's not that many records.\00"
@.str.3 = [40 x i8] c"Need id, npm, name, and score to insert\00"
@.str.4 = [21 x i8] c"Need an id to delete\00"
@.str.5 = [37 x i8] c"Need an id to get / row is available\00"
@.str.6 = [67 x i8] c"Invalid action, only: c=create, i=insert, d=delete, g=get, p=print\00"
@str = [252 x i8] c"Stubase Help\0A\0AUsage: ./stubase <databasefile> <action> [parameters]\0A\0AAvailable action:\0Ac = Create database\0Ai = Insert data into database\0Ad = Delete data from database\0Ag = Get data from database\0Ap = Print data from database\0A\0ASee README for more details\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @err(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = tail call %struct.Connection* @open(i8* %8, i8 signext %11)
%13 = icmp sgt i32 %0, 3
br i1 %13, label %14, label %21
14: ; preds = %6
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = icmp sgt i32 %17, 9
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @err(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %6, %19, %14
%22 = phi i32 [ %17, %19 ], [ %17, %14 ], [ 0, %6 ]
%23 = sext i8 %11 to i32
switch i32 %23, label %60 [
i32 104, label %24
i32 99, label %28
i32 105, label %31
i32 100, label %45
i32 103, label %52
i32 112, label %58
]
24: ; preds = %21
%25 = icmp eq i32 %0, 3
br i1 %25, label %26, label %62
26: ; preds = %24
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([252 x i8], [252 x i8]* @str, i64 0, i64 0))
br label %62
28: ; preds = %21
%29 = tail call i32 @create(%struct.Connection* %12)
%30 = tail call i32 @write(%struct.Connection* %12)
br label %62
31: ; preds = %21
%32 = icmp eq i32 %0, 7
br i1 %32, label %35, label %33
33: ; preds = %31
%34 = tail call i32 @err(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %31
%36 = getelementptr inbounds i8*, i8** %1, i64 4
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8*, i8** %1, i64 5
%39 = load i8*, i8** %38
%40 = getelementptr inbounds i8*, i8** %1, i64 6
%41 = load i8*, i8** %40
%42 = tail call i32 @atof(i8* %41)
%43 = tail call i32 @insert(%struct.Connection* %12, i32 %22, i8* %37, i8* %39, i32 %42)
%44 = tail call i32 @write(%struct.Connection* %12)
br label %62
45: ; preds = %21
%46 = icmp eq i32 %0, 4
br i1 %46, label %49, label %47
47: ; preds = %45
%48 = tail call i32 @err(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %49
49: ; preds = %47, %45
%50 = tail call i32 @delete(%struct.Connection* %12, i32 %22)
%51 = tail call i32 @write(%struct.Connection* %12)
br label %62
52: ; preds = %21
%53 = icmp eq i32 %0, 4
br i1 %53, label %56, label %54
54: ; preds = %52
%55 = tail call i32 @err(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %56
56: ; preds = %54, %52
%57 = tail call i32 @get(%struct.Connection* %12, i32 %22)
br label %62
58: ; preds = %21
%59 = tail call i32 @print(%struct.Connection* %12)
br label %62
60: ; preds = %21
%61 = tail call i32 @err(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.6, i64 0, i64 0))
br label %62
62: ; preds = %24, %26, %60, %58, %56, %49, %35, %28
%63 = tail call i32 @close(%struct.Connection* %12)
ret i32 0
}