#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*/ addSword();
int /*<<< orphan*/ deleteSword();
int /*<<< orphan*/ editSword();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
char getchar();
int /*<<< orphan*/ openShop();
int /*<<< orphan*/ putMenu();
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ showSword();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(void) {
  setbuf(stdin, 0);
  setbuf(stdout, 0);
  setbuf(stderr, 0);
  int pid;
  char temp;
  char choose;
  openShop();
  puts("Welcome back to you sword shop");
  while (1) {
    putMenu();
    choose = getchar();
    while ((temp = getchar()) != '\n') {
      if (temp == 0)
        break;
      if (temp == -1)
        break;
    }
    switch (choose) {
    case '1':
      addSword();
      break;
    case '2':
      deleteSword();
      break;
    case '3':
      editSword();
      break;
    case '4':
      showSword();
      break;
    case '5':
      pid = fork();
      if (pid == 0) {
        openShop();
      } else if (pid > 0) {
        wait(NULL);
      } else if (pid == -1) {
        puts("Something Wrong");
        exit(0);
      }
      break;
    case '6':
      exit(0);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1060 <setbuf@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1060 <setbuf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1060 <setbuf@plt>
mov    $0x0,%al
call   1070 <openShop@plt>
lea    0xe0b(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1040 <putMenu@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0xa(%rbp)
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     1262 <main+0xa2>
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jne    124b <main+0x8b>
jmp    1262 <main+0xa2>
movsbl -0x9(%rbp),%eax
cmp    $0xffffffff,%eax
jne    125d <main+0x9d>
jmp    1262 <main+0xa2>
jmp    1223 <main+0x63>
movsbl -0xa(%rbp),%eax
add    $0xffffffcf,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     1327 <main+0x167>
mov    -0x18(%rbp),%rax
lea    0xd7d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1030 <addSword@plt>
jmp    1327 <main+0x167>
mov    $0x0,%al
call   10a0 <deleteSword@plt>
jmp    1327 <main+0x167>
mov    $0x0,%al
call   10d0 <editSword@plt>
jmp    1327 <main+0x167>
mov    $0x0,%al
call   1090 <showSword@plt>
jmp    1327 <main+0x167>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    12dc <main+0x11c>
mov    $0x0,%al
call   1070 <openShop@plt>
jmp    131b <main+0x15b>
cmpl   $0x0,-0x8(%rbp)
jle    12f4 <main+0x134>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <wait@plt>
jmp    1316 <main+0x156>
cmpl   $0xffffffff,-0x8(%rbp)
jne    1311 <main+0x151>
lea    0xd32(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    1316 <main+0x156>
jmp    131b <main+0x15b>
jmp    1327 <main+0x167>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    1212 <main+0x52>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1060 <setbuf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1060 <setbuf@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1060 <setbuf@plt>
xor    %eax,%eax
call   1070 <openShop@plt>
lea    0xe15(%rip),%rdi
call   1050 <puts@plt>
mov    $0x803,%r14d
lea    0xdeb(%rip),%r15
jmp    1220 <main+0x60>
xor    %eax,%eax
call   1090 <showSword@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <putMenu@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <getchar@plt>
add    $0x1,%al
cmp    $0xb,%al
ja     1230 <main+0x70>
movzbl %al,%eax
bt     %rax,%r14
jae    1230 <main+0x70>
movsbl %bl,%eax
add    $0xffffffcf,%eax
cmp    $0x5,%eax
ja     1220 <main+0x60>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
xor    %eax,%eax
call   1030 <addSword@plt>
jmp    1220 <main+0x60>
xor    %eax,%eax
call   10a0 <deleteSword@plt>
jmp    1220 <main+0x60>
xor    %eax,%eax
call   10d0 <editSword@plt>
jmp    1220 <main+0x60>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     128b <main+0xcb>
jle    1294 <main+0xd4>
xor    %edi,%edi
call   10c0 <wait@plt>
jmp    1220 <main+0x60>
xor    %eax,%eax
call   1070 <openShop@plt>
jmp    1220 <main+0x60>
cmp    $0xffffffff,%eax
jne    1220 <main+0x60>
lea    0xd97(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Welcome back to you sword shop\00"
@.str.1 = [16 x i8] c"Something Wrong\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8
store i32 0, i32* %1
%5 = load i32, i32* @stdin
%6 = call i32 @setbuf(i32 %5, i32 0)
%7 = load i32, i32* @stdout
%8 = call i32 @setbuf(i32 %7, i32 0)
%9 = load i32, i32* @stderr
%10 = call i32 @setbuf(i32 %9, i32 0)
%11 = call i32 (...) @openShop()
%12 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %0, %64
%14 = call i32 (...) @putMenu()
%15 = call signext i8 (...) @getchar()
store i8 %15, i8* %4
br label %16
16: ; preds = %30, %13
%17 = call signext i8 (...) @getchar()
store i8 %17, i8* %3
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 10
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
br label %31
25: ; preds = %20
%26 = load i8, i8* %3
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %25
br label %31
30: ; preds = %25
br label %16
31: ; preds = %29, %24, %16
%32 = load i8, i8* %4
%33 = sext i8 %32 to i32
switch i32 %33, label %64 [
i32 49, label %34
i32 50, label %36
i32 51, label %38
i32 52, label %40
i32 53, label %42
i32 54, label %62
]
34: ; preds = %31
%35 = call i32 (...) @addSword()
br label %64
36: ; preds = %31
%37 = call i32 (...) @deleteSword()
br label %64
38: ; preds = %31
%39 = call i32 (...) @editSword()
br label %64
40: ; preds = %31
%41 = call i32 (...) @showSword()
br label %64
42: ; preds = %31
%43 = call i32 (...) @fork()
store i32 %43, i32* %2
%44 = load i32, i32* %2
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 (...) @openShop()
br label %61
48: ; preds = %42
%49 = load i32, i32* %2
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 @wait(i32* null)
br label %60
53: ; preds = %48
%54 = load i32, i32* %2
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%58 = call i32 @exit(i32 0)
unreachable
59: ; preds = %53
br label %60
60: ; preds = %59, %51
br label %61
61: ; preds = %60, %46
br label %64
62: ; preds = %31
%63 = call i32 @exit(i32 0)
unreachable
64: ; preds = %31, %61, %40, %38, %36, %34
br label %13
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Welcome back to you sword shop\00"
@.str.1 = [16 x i8] c"Something Wrong\00"
define i32 @main() {
%1 = load i32, i32* @stdin
%2 = tail call i32 @setbuf(i32 %1, i32 0)
%3 = load i32, i32* @stdout
%4 = tail call i32 @setbuf(i32 %3, i32 0)
%5 = load i32, i32* @stderr
%6 = tail call i32 @setbuf(i32 %5, i32 0)
%7 = tail call i32 (...) @openShop()
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %29, %0
%10 = tail call i32 (...) @putMenu()
%11 = tail call signext i8 (...) @getchar()
br label %12
12: ; preds = %12, %9
%13 = tail call signext i8 (...) @getchar()
switch i8 %13, label %12 [
i8 -1, label %14
i8 10, label %14
i8 0, label %14
]
14: ; preds = %12, %12, %12
%15 = sext i8 %11 to i32
switch i32 %15, label %29 [
i32 49, label %16
i32 50, label %18
i32 51, label %20
i32 52, label %22
i32 53, label %24
i32 54, label %39
]
16: ; preds = %14
%17 = tail call i32 (...) @addSword()
br label %29
18: ; preds = %14
%19 = tail call i32 (...) @deleteSword()
br label %29
20: ; preds = %14
%21 = tail call i32 (...) @editSword()
br label %29
22: ; preds = %14
%23 = tail call i32 (...) @showSword()
br label %29
24: ; preds = %14
%25 = tail call i32 (...) @fork()
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = tail call i32 (...) @openShop()
br label %29
29: ; preds = %27, %34, %32, %14, %22, %20, %18, %16
br label %9
30: ; preds = %24
%31 = icmp sgt i32 %25, 0
br i1 %31, label %32, label %34
32: ; preds = %30
%33 = tail call i32 @wait(i32* null)
br label %29
34: ; preds = %30
%35 = icmp eq i32 %25, -1
br i1 %35, label %36, label %29
36: ; preds = %34
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%38 = tail call i32 @exit(i32 0)
unreachable
39: ; preds = %14
%40 = tail call i32 @exit(i32 0)
unreachable
}