#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 */
int /*<<< orphan*/ clrscr();
int /*<<< orphan*/ doesDatabaseExist(char *);
int /*<<< orphan*/ environment(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ free(char *);
int inputYOrN(int);
int isUserAdmin(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ lineBreak();
int /*<<< orphan*/ openDBResponse(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ searchForUser(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int sqlite3_open(char *, int /*<<< orphan*/ **);
char *stringInput(int);
int main(void) {
  sqlite3 *db;
  int rc;
  char *databaseName = "Database.db";
  char *username, *password;
  int login;
  doesDatabaseExist(databaseName);
  rc = sqlite3_open(databaseName, &db);
  openDBResponse(rc);
  do {
    int isAdmin;
    login = inputYOrN(1);
    lineBreak();
    if (login == 1) {
      printf("Enter your username: ");
      username = stringInput(0);
      printf("Enter your password: ");
      password = stringInput(1);
      if (searchForUser(db, username, password)) {
        isAdmin = isUserAdmin(db, username, password);
        clrscr();
        environment(db, username, isAdmin);
      } else {
        printf("\nIncorrect username or password. Try again.\n");
        lineBreak();
      }
      free(username);
      free(password);
    }
  } while (login);
  puts("Bye!");
  sleep(1);
  clrscr();
  sqlite3_close(db);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xdfa(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <doesDatabaseExist@plt>
mov    -0x20(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   10b0 <sqlite3_open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   10a0 <openDBResponse@plt>
mov    $0x1,%edi
call   1060 <inputYOrN@plt>
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   10e0 <lineBreak@plt>
cmpl   $0x1,-0x34(%rbp)
jne    12ea <main+0xfa>
lea    0xdbc(%rip),%rdi
call   10d0 <printf@plt>
xor    %edi,%edi
call   1090 <stringInput@plt>
mov    %rax,-0x28(%rbp)
lea    0xdbb(%rip),%rdi
call   10d0 <printf@plt>
mov    $0x1,%edi
call   1090 <stringInput@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   10c0 <searchForUser@plt>
cmp    $0x0,%rax
je     12c5 <main+0xd5>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1080 <isUserAdmin@plt>
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1050 <clrscr@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%edx
call   10f0 <environment@plt>
jmp    12d8 <main+0xe8>
lea    0xd6c(%rip),%rdi
call   10d0 <printf@plt>
mov    $0x0,%al
call   10e0 <lineBreak@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    12ef <main+0xff>
cmpl   $0x0,-0x34(%rbp)
jne    122b <main+0x3b>
lea    0xd65(%rip),%rdi
call   1070 <puts@plt>
mov    $0x1,%edi
call   1110 <sleep@plt>
mov    $0x0,%al
call   1050 <clrscr@plt>
mov    -0x10(%rbp),%rdi
call   1100 <sqlite3_close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xdfe(%rip),%rbx
mov    %rbx,%rdi
call   1040 <doesDatabaseExist@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   10b0 <sqlite3_open@plt>
mov    %eax,%edi
call   10a0 <openDBResponse@plt>
lea    0xde9(%rip),%r14
lea    0xdf8(%rip),%r12
lea    0xe0c(%rip),%r15
jmp    1248 <main+0x58>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %ebx,%ebx
je     12e7 <main+0xf7>
mov    $0x1,%edi
call   1060 <inputYOrN@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10e0 <lineBreak@plt>
cmp    $0x1,%ebx
jne    1240 <main+0x50>
mov    %r14,%rdi
call   10d0 <printf@plt>
xor    %edi,%edi
call   1090 <stringInput@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   10d0 <printf@plt>
mov    $0x1,%edi
call   1090 <stringInput@plt>
mov    %rax,%r13
mov    (%rsp),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   10c0 <searchForUser@plt>
test   %rax,%rax
je     12c3 <main+0xd3>
mov    (%rsp),%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1080 <isUserAdmin@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <clrscr@plt>
mov    (%rsp),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   10f0 <environment@plt>
jmp    12d2 <main+0xe2>
mov    %r15,%rdi
call   1070 <puts@plt>
xor    %eax,%eax
call   10e0 <lineBreak@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    1248 <main+0x58>
lea    0xd4a(%rip),%rdi
call   1070 <puts@plt>
mov    $0x1,%edi
call   1110 <sleep@plt>
xor    %eax,%eax
call   1050 <clrscr@plt>
mov    (%rsp),%rdi
call   1100 <sqlite3_close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Database.db\00"
@.str.1 = [22 x i8] c"Enter your username: \00"
@.str.2 = [22 x i8] c"Enter your password: \00"
@.str.3 = [45 x i8] c"\0AIncorrect username or password. Try again.\0A\00"
@.str.4 = [5 x i8] c"Bye!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @doesDatabaseExist(i8* %9)
%11 = load i8*, i8** %4
%12 = call i32 @sqlite3_open(i8* %11, i32** %2)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = call i32 @openDBResponse(i32 %13)
br label %15
15: ; preds = %49, %0
%16 = call i32 @inputYOrN(i32 1)
store i32 %16, i32* %7
%17 = call i32 (...) @lineBreak()
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %48
20: ; preds = %15
%21 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%22 = call i8* @stringInput(i32 0)
store i8* %22, i8** %5
%23 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%24 = call i8* @stringInput(i32 1)
store i8* %24, i8** %6
%25 = load i32*, i32** %2
%26 = load i8*, i8** %5
%27 = load i8*, i8** %6
%28 = call i64 @searchForUser(i32* %25, i8* %26, i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %20
%31 = load i32*, i32** %2
%32 = load i8*, i8** %5
%33 = load i8*, i8** %6
%34 = call i32 @isUserAdmin(i32* %31, i8* %32, i8* %33)
store i32 %34, i32* %8
%35 = call i32 (...) @clrscr()
%36 = load i32*, i32** %2
%37 = load i8*, i8** %5
%38 = load i32, i32* %8
%39 = call i32 @environment(i32* %36, i8* %37, i32 %38)
br label %43
40: ; preds = %20
%41 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%42 = call i32 (...) @lineBreak()
br label %43
43: ; preds = %40, %30
%44 = load i8*, i8** %5
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %6
%47 = call i32 @free(i8* %46)
br label %48
48: ; preds = %43, %15
br label %49
49: ; preds = %48
%50 = load i32, i32* %7
%51 = icmp ne i32 %50, 0
br i1 %51, label %15, label %52
52: ; preds = %49
%53 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @sleep(i32 1)
%55 = call i32 (...) @clrscr()
%56 = load i32*, i32** %2
%57 = call i32 @sqlite3_close(i32* %56)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Database.db\00"
@.str.1 = [22 x i8] c"Enter your username: \00"
@.str.2 = [22 x i8] c"Enter your password: \00"
@.str.4 = [5 x i8] c"Bye!\00"
@str = [44 x i8] c"\0AIncorrect username or password. Try again.\00"
define i32 @main() {
%1 = alloca i32*
%2 = bitcast i32** %1 to i8*
%3 = tail call i32 @doesDatabaseExist(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @sqlite3_open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32** %1)
%5 = call i32 @openDBResponse(i32 %4)
br label %6
6: ; preds = %9, %0
%7 = call i32 @inputYOrN(i32 1)
%8 = call i32 (...) @lineBreak()
switch i32 %7, label %9 [
i32 1, label %10
i32 0, label %30
]
9: ; preds = %6, %27
br label %6
10: ; preds = %6
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%12 = call i8* @stringInput(i32 0)
%13 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%14 = call i8* @stringInput(i32 1)
%15 = load i32*, i32** %1
%16 = call i64 @searchForUser(i32* %15, i8* %12, i8* %14)
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %10
%19 = load i32*, i32** %1
%20 = call i32 @isUserAdmin(i32* %19, i8* %12, i8* %14)
%21 = call i32 (...) @clrscr()
%22 = load i32*, i32** %1
%23 = call i32 @environment(i32* %22, i8* %12, i32 %20)
br label %27
24: ; preds = %10
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%26 = call i32 (...) @lineBreak()
br label %27
27: ; preds = %24, %18
%28 = call i32 @free(i8* %12)
%29 = call i32 @free(i8* %14)
br label %9
30: ; preds = %6
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @sleep(i32 1)
%33 = call i32 (...) @clrscr()
%34 = load i32*, i32** %1
%35 = call i32 @sqlite3_close(i32* %34)
ret i32 0
}