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

/* Variables and functions */
scalar_t__ SQLITE_OK;
int /*<<< orphan*/ do_delete(int /*<<< orphan*/ *);
int /*<<< orphan*/ do_get_table(int /*<<< orphan*/ *);
int /*<<< orphan*/ do_help();
int /*<<< orphan*/ do_insert(int /*<<< orphan*/ *);
int /*<<< orphan*/ do_query(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, char *);
int scanf(char *, int *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
scalar_t__ sqlite3_open(char *, int /*<<< orphan*/ **);
int main(int argc, char *argv[]) {
  int n;
  sqlite3 *dp;
  if (sqlite3_open("mystudent.db", &dp) != SQLITE_OK) {
    printf("error:%s\n", sqlite3_errmsg(dp));
    exit(-1);
  }
  do_help();
  while (scanf("%d%*c", &n) == 1) {
    switch (n) {
    case 1:
      do_insert(dp);
      break;
    case 2:
      do_delete(dp);
      break;
    case 3:
      do_query(dp);
      break;
    case 4:
      do_get_table(dp);
      break;
    case 5:
      exit(0);
    default:
      do_help();
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe57(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%rax
je     11f8 <main+0x58>
mov    -0x20(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    %rax,%rsi
lea    0xe38(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1080 <do_help@plt>
lea    0xe25(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   10a0 <scanf@plt>
cmp    $0x1,%eax
jne    128c <main+0xec>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x4,%eax
ja     1280 <main+0xe0>
mov    -0x28(%rbp),%rax
lea    0xdc8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rdi
call   1090 <do_insert@plt>
jmp    1287 <main+0xe7>
mov    -0x20(%rbp),%rdi
call   1040 <do_delete@plt>
jmp    1287 <main+0xe7>
mov    -0x20(%rbp),%rdi
call   1050 <do_query@plt>
jmp    1287 <main+0xe7>
mov    -0x20(%rbp),%rdi
call   10c0 <do_get_table@plt>
jmp    1287 <main+0xe7>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1080 <do_help@plt>
jmp    11ff <main+0x5f>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe64(%rip),%rdi
mov    %rsp,%rsi
call   1030 <sqlite3_open@plt>
mov    0x2e29(%rip),%rcx
cmp    (%rcx),%rax
jne    1274 <main+0xd4>
xor    %eax,%eax
call   1080 <do_help@plt>
lea    0xe55(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10a0 <scanf@plt>
cmp    $0x1,%eax
jne    1261 <main+0xc1>
lea    0xe3f(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xe08(%rip),%rbx
jmp    1220 <main+0x80>
xor    %eax,%eax
call   1080 <do_help@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <scanf@plt>
cmp    $0x1,%eax
jne    1261 <main+0xc1>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x4,%eax
ja     11fa <main+0x5a>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    (%rsp),%rdi
call   1090 <do_insert@plt>
jmp    1210 <main+0x70>
mov    (%rsp),%rdi
call   1040 <do_delete@plt>
jmp    1210 <main+0x70>
mov    (%rsp),%rdi
call   1050 <do_query@plt>
jmp    1210 <main+0x70>
mov    (%rsp),%rdi
call   10c0 <do_get_table@plt>
jmp    1210 <main+0x70>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %edi,%edi
call   10b0 <exit@plt>
mov    (%rsp),%rdi
call   1070 <sqlite3_errmsg@plt>
lea    0xd9d(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"mystudent.db\00"
@SQLITE_OK = global i64 0
@.str.1 = [10 x i8] c"error:%s\0A\00"
@.str.2 = [6 x i8] c"%d%*c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 @sqlite3_open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32** %7)
%9 = load i64, i64* @SQLITE_OK
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32*, i32** %7
%13 = call i8* @sqlite3_errmsg(i32* %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = call i32 (...) @do_help()
br label %18
18: ; preds = %39, %16
%19 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %40
21: ; preds = %18
%22 = load i32, i32* %6
switch i32 %22, label %37 [
i32 1, label %23
i32 2, label %26
i32 3, label %29
i32 4, label %32
i32 5, label %35
]
23: ; preds = %21
%24 = load i32*, i32** %7
%25 = call i32 @do_insert(i32* %24)
br label %39
26: ; preds = %21
%27 = load i32*, i32** %7
%28 = call i32 @do_delete(i32* %27)
br label %39
29: ; preds = %21
%30 = load i32*, i32** %7
%31 = call i32 @do_query(i32* %30)
br label %39
32: ; preds = %21
%33 = load i32*, i32** %7
%34 = call i32 @do_get_table(i32* %33)
br label %39
35: ; preds = %21
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %21
%38 = call i32 (...) @do_help()
br label %39
39: ; preds = %37, %32, %29, %26, %23
br label %18
40: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"mystudent.db\00"
@SQLITE_OK = global i64 0
@.str.1 = [10 x i8] c"error:%s\0A\00"
@.str.2 = [6 x i8] c"%d%*c\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32** %4 to i8*
%7 = call i64 @sqlite3_open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32** %4)
%8 = load i64, i64* @SQLITE_OK
%9 = icmp eq i64 %7, %8
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i32*, i32** %4
%12 = call i8* @sqlite3_errmsg(i32* %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
%16 = call i32 (...) @do_help()
%17 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %40
19: ; preds = %15, %37
%20 = load i32, i32* %3
switch i32 %20, label %35 [
i32 1, label %21
i32 2, label %24
i32 3, label %27
i32 4, label %30
i32 5, label %33
]
21: ; preds = %19
%22 = load i32*, i32** %4
%23 = call i32 @do_insert(i32* %22)
br label %37
24: ; preds = %19
%25 = load i32*, i32** %4
%26 = call i32 @do_delete(i32* %25)
br label %37
27: ; preds = %19
%28 = load i32*, i32** %4
%29 = call i32 @do_query(i32* %28)
br label %37
30: ; preds = %19
%31 = load i32*, i32** %4
%32 = call i32 @do_get_table(i32* %31)
br label %37
33: ; preds = %19
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %19
%36 = call i32 (...) @do_help()
br label %37
37: ; preds = %35, %30, %27, %24, %21
%38 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%39 = icmp eq i32 %38, 1
br i1 %39, label %19, label %40
40: ; preds = %37, %15
ret i32 0
}