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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int read_number(unsigned int *);
int /*<<< orphan*/ stdin;
int store_number(unsigned int *);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int main(int argc, char *argv[], char *envp[]) {
  int res = 0;
  char cmd[20] = {0};
  unsigned int data[100] = {0};
  for (; *argv; ++argv) {
    memset(*argv, 0, strlen(*argv));
  };
  for (; *envp; ++envp) {
    memset(*envp, 0, strlen(*envp));
  };
  printf("----------------------------------------------------\n"
         "  Welcome to doom's crappy number storage service!  \n"
         "          Version 2.0 - With more security!         \n"
         "----------------------------------------------------\n"
         " Commands:                                          \n"
         "    store - store a number into the data storage    \n"
         "    read  - read a number from the data storage     \n"
         "    quit  - exit the program                        \n"
         "----------------------------------------------------\n"
         "   doom has reserved some storage for himself :>    \n"
         "----------------------------------------------------\n"
         "\n");
  while (1) {
    printf("Input command: ");
    res = 1;
    fgets(cmd, sizeof(cmd), stdin);
    cmd[strlen(cmd) - 1] = '\0';
    if (!strncmp(cmd, "store", 5))
      res = store_number(data);
    else if (!strncmp(cmd, "read", 4))
      res = read_number(data);
    else if (!strncmp(cmd, "quit", 4))
      break;
    if (res)
      printf(" Failed to do %s command\n", cmd);
    else
      printf(" Completed %s command successfully\n", cmd);
    memset(cmd, 0, sizeof(cmd));
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
lea    -0x1c0(%rbp),%rdi
xor    %esi,%esi
mov    $0x190,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1200 <main+0x90>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x1c8(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    -0x1c8(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    11b7 <main+0x47>
jmp    1205 <main+0x95>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     124e <main+0xde>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x1d0(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    -0x1d0(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    1205 <main+0x95>
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xfe6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
mov    0x2d6c(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1070 <fgets@plt>
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
lea    0xfb3(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12cd <main+0x15d>
lea    -0x1c0(%rbp),%rdi
call   1080 <store_number@plt>
mov    %eax,-0x1c(%rbp)
jmp    132c <main+0x1bc>
lea    -0x30(%rbp),%rdi
lea    0xf87(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12ff <main+0x18f>
lea    -0x1c0(%rbp),%rdi
call   1090 <read_number@plt>
mov    %eax,-0x1c(%rbp)
jmp    1327 <main+0x1b7>
lea    -0x30(%rbp),%rdi
lea    0xf5a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1322 <main+0x1b2>
jmp    1374 <main+0x204>
jmp    1327 <main+0x1b7>
jmp    132c <main+0x1bc>
cmpl   $0x0,-0x1c(%rbp)
je     134d <main+0x1dd>
lea    -0x30(%rbp),%rsi
lea    0xf28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    135f <main+0x1ef>
lea    -0x30(%rbp),%rsi
lea    0xf2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
jmp    125c <main+0xec>
mov    0x2c5d(%rip),%rax
mov    (%rax),%eax
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1b8,%rsp
mov    %rdx,%r14
mov    %rsi,%rbp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x190,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x0(%rbp),%rbx
test   %rbx,%rbx
je     11f1 <main+0x71>
add    $0x8,%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1070 <memset@plt>
mov    0x0(%rbp),%rbx
add    $0x8,%rbp
test   %rbx,%rbx
jne    11d0 <main+0x50>
mov    (%r14),%rbx
test   %rbx,%rbx
je     1220 <main+0xa0>
add    $0x8,%r14
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1070 <memset@plt>
mov    (%r14),%rbx
add    $0x8,%r14
test   %rbx,%rbx
jne    1200 <main+0x80>
lea    0xe37(%rip),%rdi
call   1040 <puts@plt>
lea    0xdcd(%rip),%r14
mov    0x2dae(%rip),%rbp
mov    %rsp,%rbx
lea    0xdcc(%rip),%r15
lea    0xdd5(%rip),%r12
lea    0xdc4(%rip),%r13
jmp    1293 <main+0x113>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x20(%rsp),%rdi
call   1090 <store_number@plt>
test   %eax,%eax
mov    %r12,%rdi
lea    0xdc4(%rip),%rax
cmove  %rax,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1260 <main+0xe0>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1310 <main+0x190>
mov    %rbx,%rdi
lea    0xd2d(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %r12,%rdi
test   %eax,%eax
jne    127a <main+0xfa>
jmp    131f <main+0x19f>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x20(%rsp),%rdi
call   10a0 <read_number@plt>
jmp    126a <main+0xea>
mov    0x2cb2(%rip),%rax
mov    (%rax),%eax
add    $0x1b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [585 x i8] c"----------------------------------------------------\0A Welcome to doom's crappy number storage service! \0A Version 2.0 - With more security! \0A----------------------------------------------------\0A Commands: \0A store - store a number into the data storage \0A read - read a number from the data storage \0A quit - exit the program \0A----------------------------------------------------\0A doom has reserved some storage for himself :> \0A----------------------------------------------------\0A\0A\00"
@.str.1 = [16 x i8] c"Input command: \00"
@stdin = global i32 0
@.str.2 = [6 x i8] c"store\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [5 x i8] c"quit\00"
@.str.5 = [26 x i8] c" Failed to do %s command\0A\00"
@.str.6 = [36 x i8] c" Completed %s command successfully\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca [20 x i8]
%10 = alloca [100 x i32]
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 0, i32* %8
%11 = bitcast [20 x i8]* %9 to i8*
%12 = bitcast [100 x i32]* %10 to i8*
br label %13
13: ; preds = %24, %3
%14 = load i8**, i8*** %6
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %27
17: ; preds = %13
%18 = load i8**, i8*** %6
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %6
%21 = load i8*, i8** %20
%22 = call i32 @strlen(i8* %21)
%23 = call i32 @memset(i8* %19, i32 0, i32 %22)
br label %24
24: ; preds = %17
%25 = load i8**, i8*** %6
%26 = getelementptr inbounds i8*, i8** %25, i32 1
store i8** %26, i8*** %6
br label %13
27: ; preds = %13
br label %28
28: ; preds = %39, %27
%29 = load i8**, i8*** %7
%30 = load i8*, i8** %29
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i8**, i8*** %7
%34 = load i8*, i8** %33
%35 = load i8**, i8*** %7
%36 = load i8*, i8** %35
%37 = call i32 @strlen(i8* %36)
%38 = call i32 @memset(i8* %34, i32 0, i32 %37)
br label %39
39: ; preds = %32
%40 = load i8**, i8*** %7
%41 = getelementptr inbounds i8*, i8** %40, i32 1
store i8** %41, i8*** %7
br label %28
42: ; preds = %28
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([585 x i8], [585 x i8]* @.str, i64 0, i64 0))
br label %44
44: ; preds = %42, %83
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %8
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%47 = load i32, i32* @stdin
%48 = call i32 @fgets(i8* %46, i32 20, i32 %47)
%49 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 %52
store i8 0, i8* %53
%54 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%55 = call i32 @strncmp(i8* %54, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%56 = icmp ne i32 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %44
%58 = getelementptr inbounds [100 x i32], [100 x i32]* %10, i64 0, i64 0
%59 = call i32 @store_number(i32* %58)
store i32 %59, i32* %8
br label %74
60: ; preds = %44
%61 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%62 = call i32 @strncmp(i8* %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%63 = icmp ne i32 %62, 0
br i1 %63, label %67, label %64
64: ; preds = %60
%65 = getelementptr inbounds [100 x i32], [100 x i32]* %10, i64 0, i64 0
%66 = call i32 @read_number(i32* %65)
store i32 %66, i32* %8
br label %73
67: ; preds = %60
%68 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%69 = call i32 @strncmp(i8* %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%70 = icmp ne i32 %69, 0
br i1 %70, label %72, label %71
71: ; preds = %67
br label %86
72: ; preds = %67
br label %73
73: ; preds = %72, %64
br label %74
74: ; preds = %73, %57
%75 = load i32, i32* %8
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %78)
br label %83
80: ; preds = %74
%81 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i8* %81)
br label %83
83: ; preds = %80, %77
%84 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%85 = call i32 @memset(i8* %84, i32 0, i32 20)
br label %44
86: ; preds = %71
%87 = load i32, i32* @EXIT_SUCCESS
ret i32 %87
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"Input command: \00"
@stdin = global i32 0
@.str.2 = [6 x i8] c"store\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [5 x i8] c"quit\00"
@.str.5 = [26 x i8] c" Failed to do %s command\0A\00"
@.str.6 = [36 x i8] c" Completed %s command successfully\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [584 x i8] c"----------------------------------------------------\0A Welcome to doom's crappy number storage service! \0A Version 2.0 - With more security! \0A----------------------------------------------------\0A Commands: \0A store - store a number into the data storage \0A read - read a number from the data storage \0A quit - exit the program \0A----------------------------------------------------\0A doom has reserved some storage for himself :> \0A----------------------------------------------------\0A\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture %2) {
%4 = alloca [20 x i8]
%5 = alloca [100 x i32]
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = bitcast [100 x i32]* %5 to i8*
%8 = load i8*, i8** %1
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %13, %3
%11 = load i8*, i8** %2
%12 = icmp eq i8* %11, null
br i1 %12, label %29, label %21
13: ; preds = %3, %13
%14 = phi i8* [ %19, %13 ], [ %8, %3 ]
%15 = phi i8** [ %18, %13 ], [ %1, %3 ]
%16 = tail call i32 @strlen(i8* %14)
%17 = tail call i32 @memset(i8* %14, i32 0, i32 %16)
%18 = getelementptr inbounds i8*, i8** %15, i64 1
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %10, label %13
21: ; preds = %10, %21
%22 = phi i8* [ %27, %21 ], [ %11, %10 ]
%23 = phi i8** [ %26, %21 ], [ %2, %10 ]
%24 = tail call i32 @strlen(i8* %22)
%25 = tail call i32 @memset(i8* %22, i32 0, i32 %24)
%26 = getelementptr inbounds i8*, i8** %23, i64 1
%27 = load i8*, i8** %26
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %21
29: ; preds = %21, %10
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([584 x i8], [584 x i8]* @str, i64 0, i64 0))
%31 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 0
br label %32
32: ; preds = %56, %29
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @stdin
%35 = call i32 @fgets(i8* %6, i32 20, i32 %34)
%36 = call i32 @strlen(i8* %6)
%37 = add nsw i32 %36, -1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %38
store i8 0, i8* %39
%40 = call i32 @strncmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %32
%43 = call i32 @store_number(i32* %31)
br label %52
44: ; preds = %32
%45 = call i32 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @read_number(i32* %31)
br label %52
49: ; preds = %44
%50 = call i32 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%51 = icmp eq i32 %50, 0
br i1 %51, label %60, label %56
52: ; preds = %47, %42
%53 = phi i32 [ %48, %47 ], [ %43, %42 ]
%54 = icmp eq i32 %53, 0
%55 = select i1 %54, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0)
br label %56
56: ; preds = %52, %49
%57 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), %49 ], [ %55, %52 ]
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %57, i8* %6)
%59 = call i32 @memset(i8* %6, i32 0, i32 20)
br label %32
60: ; preds = %49
%61 = load i32, i32* @EXIT_SUCCESS
ret i32 %61
}