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

/* Variables and functions */
int /*<<< orphan*/ buy();
int /*<<< orphan*/ database_close();
int /*<<< orphan*/ database_init(int);
int /*<<< orphan*/ init_db();
int /*<<< orphan*/ list();
char menu();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sell();
int main() {
  database_init(3);
  init_db();
  printf("Welcome to eCommerce v0.1\n");
  while (1) {
    char choice = menu();
    if (choice == 0)
      break;
    else if (choice == 'a')
      list();
    else if (choice == 'b')
      buy();
    else if (choice == 'c')
      sell();
    else
      printf("Invalid selection\n");
  }
  database_close();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3,%edi
call   10a0 <database_init@plt>
mov    $0x0,%al
call   1090 <init_db@plt>
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <menu@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x0,%eax
jne    11c8 <main+0x48>
jmp    1233 <main+0xb3>
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jne    11e1 <main+0x61>
mov    $0x0,%al
call   1060 <list@plt>
jmp    1229 <main+0xa9>
movsbl -0x5(%rbp),%eax
cmp    $0x62,%eax
jne    11fa <main+0x7a>
mov    $0x0,%al
call   1040 <buy@plt>
jmp    1224 <main+0xa4>
movsbl -0x5(%rbp),%eax
cmp    $0x63,%eax
jne    1213 <main+0x93>
mov    $0x0,%al
call   1070 <sell@plt>
jmp    121f <main+0x9f>
lea    0xe01(%rip),%rdi
call   1050 <printf@plt>
jmp    1224 <main+0xa4>
jmp    1229 <main+0xa9>
jmp    122e <main+0xae>
jmp    11ac <main+0x2c>
mov    $0x0,%al
call   1080 <database_close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x3,%edi
call   10a0 <database_init@plt>
xor    %eax,%eax
call   1090 <init_db@plt>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
lea    0xe75(%rip),%rbx
jmp    11b7 <main+0x37>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <buy@plt>
xor    %eax,%eax
call   1040 <menu@plt>
cmp    $0x61,%al
jle    11e0 <main+0x60>
cmp    $0x62,%al
je     11b0 <main+0x30>
cmp    $0x63,%al
jne    11ef <main+0x6f>
xor    %eax,%eax
call   1070 <sell@plt>
jmp    11b7 <main+0x37>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
jne    11eb <main+0x6b>
xor    %eax,%eax
call   1060 <list@plt>
jmp    11b7 <main+0x37>
test   %al,%al
je     11f9 <main+0x79>
mov    %rbx,%rdi
call   1030 <puts@plt>
jmp    11b7 <main+0x37>
xor    %eax,%eax
call   1080 <database_close@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Welcome to eCommerce v0.1\0A\00"
@.str.1 = [19 x i8] c"Invalid selection\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
store i32 0, i32* %1
%3 = call i32 @database_init(i32 3)
%4 = call i32 (...) @init_db()
%5 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %0, %35
%7 = call signext i8 (...) @menu()
store i8 %7, i8* %2
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %6
br label %36
12: ; preds = %6
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 97
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 (...) @list()
br label %34
18: ; preds = %12
%19 = load i8, i8* %2
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 98
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 (...) @buy()
br label %33
24: ; preds = %18
%25 = load i8, i8* %2
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 99
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 (...) @sell()
br label %32
30: ; preds = %24
%31 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %28
br label %33
33: ; preds = %32, %22
br label %34
34: ; preds = %33, %16
br label %35
35: ; preds = %34
br label %6
36: ; preds = %11
%37 = call i32 (...) @database_close()
ret i32 0
}

LLVM IR (-O2):
@str = [26 x i8] c"Welcome to eCommerce v0.1\00"
@str.2 = [18 x i8] c"Invalid selection\00"
define i32 @main() {
%1 = tail call i32 @database_init(i32 3)
%2 = tail call i32 (...) @init_db()
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %10, %0
%5 = tail call signext i8 (...) @menu()
switch i8 %5, label %13 [
i8 0, label %15
i8 97, label %6
i8 98, label %8
i8 99, label %11
]
6: ; preds = %4
%7 = tail call i32 (...) @list()
br label %10
8: ; preds = %4
%9 = tail call i32 (...) @buy()
br label %10
10: ; preds = %8, %13, %11, %6
br label %4
11: ; preds = %4
%12 = tail call i32 (...) @sell()
br label %10
13: ; preds = %4
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0))
br label %10
15: ; preds = %4
%16 = tail call i32 (...) @database_close()
ret i32 0
}