#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int buy(char const *, char const *, int, char const **);
int /*<<< orphan*/ error(char *, ...);
int history(char const *, char const *, int, char const **);
int inventory(char const *, char const *, int, char const **);
scalar_t__ is_help(char const *);
int sell(char const *, char const *, int, char const **);
scalar_t__ strncmp(char const *, char *, int);
int usage(char const *, int /*<<< orphan*/);
int main(int argc, const char **argv) {
  const char *pname = argv[0];
  if (argc >= 2 && is_help(argv[1])) {
    return usage(pname, EXIT_SUCCESS);
  } else if (argc >= 3 && is_help(argv[2])) {
    return usage(pname, EXIT_SUCCESS);
  } else if (argc <= 2) {
    error("Not enough arguments");
    return usage(pname, EXIT_FAILURE);
  }
  const char *fname = argv[1];
  const char *action = argv[2];
  int sub_argc = argc - 3;
  const char **sub_argv = argv + 3;
  if (strncmp(action, "buy", 4) == 0) {
    return buy(pname, fname, sub_argc, sub_argv);
  } else if (strncmp(action, "sell", 5) == 0) {
    return sell(pname, fname, sub_argc, sub_argv);
  } else if (strncmp(action, "inventory", 10) == 0) {
    return inventory(pname, fname, sub_argc, sub_argv);
  } else if (strncmp(action, "state", 6) == 0) {
    return inventory(pname, fname, sub_argc, sub_argv);
  } else if (strncmp(action, "history", 8) == 0) {
    return history(pname, fname, sub_argc, sub_argv);
  } else {
    error("Unknown action %s", action);
    return usage(argv[0], EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11dc <main+0x5c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <is_help@plt>
cmp    $0x0,%rax
je     11dc <main+0x5c>
mov    -0x18(%rbp),%rdi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
call   1070 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    13d1 <main+0x251>
cmpl   $0x3,-0x8(%rbp)
jl     1217 <main+0x97>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <is_help@plt>
cmp    $0x0,%rax
je     1217 <main+0x97>
mov    -0x18(%rbp),%rdi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
call   1070 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    13d1 <main+0x251>
cmpl   $0x2,-0x8(%rbp)
jg     1249 <main+0xc9>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1090 <error@plt>
mov    -0x18(%rbp),%rdi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
call   1070 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    13d1 <main+0x251>
jmp    124e <main+0xce>
jmp    1253 <main+0xd3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd8a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12bb <main+0x13b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1050 <buy@plt>
mov    %eax,-0x4(%rbp)
jmp    13d1 <main+0x251>
mov    -0x28(%rbp),%rdi
lea    0xd53(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12f6 <main+0x176>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1080 <sell@plt>
mov    %eax,-0x4(%rbp)
jmp    13d1 <main+0x251>
mov    -0x28(%rbp),%rdi
lea    0xd1d(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1331 <main+0x1b1>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1060 <inventory@plt>
mov    %eax,-0x4(%rbp)
jmp    13d1 <main+0x251>
mov    -0x28(%rbp),%rdi
lea    0xcec(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    136c <main+0x1ec>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1060 <inventory@plt>
mov    %eax,-0x4(%rbp)
jmp    13d1 <main+0x251>
mov    -0x28(%rbp),%rdi
lea    0xcb7(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    13a7 <main+0x227>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1040 <history@plt>
mov    %eax,-0x4(%rbp)
jmp    13d1 <main+0x251>
mov    -0x28(%rbp),%rsi
lea    0xc84(%rip),%rdi
mov    $0x0,%al
call   1090 <error@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2c19(%rip),%rax
mov    (%rax),%esi
call   1070 <usage@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%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
mov    (%rsi),%r14
cmp    $0x2,%edi
jl     128c <main+0x10c>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   10a0 <is_help@plt>
test   %rax,%rax
je     11b6 <main+0x36>
mov    0x2e27(%rip),%rax
jmp    12a1 <main+0x121>
cmp    $0x3,%ebp
jb     128c <main+0x10c>
mov    0x10(%rbx),%rdi
call   10a0 <is_help@plt>
test   %rax,%rax
jne    11aa <main+0x2a>
mov    0x8(%rbx),%r12
mov    0x10(%rbx),%r13
add    $0xfffffffd,%ebp
lea    0x18(%rbx),%r15
lea    0xe32(%rip),%rsi
mov    %r13,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12b9 <main+0x139>
lea    0xe19(%rip),%rsi
mov    %r13,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12f5 <main+0x175>
lea    0xe01(%rip),%rsi
mov    %r13,%rdi
mov    $0xa,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12d7 <main+0x157>
lea    0xdee(%rip),%rsi
mov    %r13,%rdi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12d7 <main+0x157>
lea    0xdd7(%rip),%rsi
mov    %r13,%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1313 <main+0x193>
lea    0xdc2(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1090 <error@plt>
mov    (%rbx),%rdi
mov    0x2d58(%rip),%rax
mov    (%rax),%esi
jmp    12a6 <main+0x126>
lea    0xd6d(%rip),%rdi
xor    %eax,%eax
call   1090 <error@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <usage@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r15,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <buy@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r15,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <inventory@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r15,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <sell@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r15,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <history@plt>

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@.str = [21 x i8] c"Not enough arguments\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"buy\00"
@.str.2 = [5 x i8] c"sell\00"
@.str.3 = [10 x i8] c"inventory\00"
@.str.4 = [6 x i8] c"state\00"
@.str.5 = [8 x i8] c"history\00"
@.str.6 = [18 x i8] c"Unknown action %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
store i8* %13, i8** %6
%14 = load i32, i32* %4
%15 = icmp sge i32 %14, 2
br i1 %15, label %16, label %26
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @is_help(i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i8*, i8** %6
%24 = load i32, i32* @EXIT_SUCCESS
%25 = call i32 @usage(i8* %23, i32 %24)
store i32 %25, i32* %3
br label %117
26: ; preds = %16, %2
%27 = load i32, i32* %4
%28 = icmp sge i32 %27, 3
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i64 @is_help(i8* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %29
%36 = load i8*, i8** %6
%37 = load i32, i32* @EXIT_SUCCESS
%38 = call i32 @usage(i8* %36, i32 %37)
store i32 %38, i32* %3
br label %117
39: ; preds = %29, %26
%40 = load i32, i32* %4
%41 = icmp sle i32 %40, 2
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%44 = load i8*, i8** %6
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @usage(i8* %44, i32 %45)
store i32 %46, i32* %3
br label %117
47: ; preds = %39
br label %48
48: ; preds = %47
br label %49
49: ; preds = %48
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
store i8* %52, i8** %7
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
store i8* %55, i8** %8
%56 = load i32, i32* %4
%57 = sub nsw i32 %56, 3
store i32 %57, i32* %9
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 3
store i8** %59, i8*** %10
%60 = load i8*, i8** %8
%61 = call i64 @strncmp(i8* %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %69
63: ; preds = %49
%64 = load i8*, i8** %6
%65 = load i8*, i8** %7
%66 = load i32, i32* %9
%67 = load i8**, i8*** %10
%68 = call i32 @buy(i8* %64, i8* %65, i32 %66, i8** %67)
store i32 %68, i32* %3
br label %117
69: ; preds = %49
%70 = load i8*, i8** %8
%71 = call i64 @strncmp(i8* %70, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 5)
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %69
%74 = load i8*, i8** %6
%75 = load i8*, i8** %7
%76 = load i32, i32* %9
%77 = load i8**, i8*** %10
%78 = call i32 @sell(i8* %74, i8* %75, i32 %76, i8** %77)
store i32 %78, i32* %3
br label %117
79: ; preds = %69
%80 = load i8*, i8** %8
%81 = call i64 @strncmp(i8* %80, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 10)
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %89
83: ; preds = %79
%84 = load i8*, i8** %6
%85 = load i8*, i8** %7
%86 = load i32, i32* %9
%87 = load i8**, i8*** %10
%88 = call i32 @inventory(i8* %84, i8* %85, i32 %86, i8** %87)
store i32 %88, i32* %3
br label %117
89: ; preds = %79
%90 = load i8*, i8** %8
%91 = call i64 @strncmp(i8* %90, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 6)
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %99
93: ; preds = %89
%94 = load i8*, i8** %6
%95 = load i8*, i8** %7
%96 = load i32, i32* %9
%97 = load i8**, i8*** %10
%98 = call i32 @inventory(i8* %94, i8* %95, i32 %96, i8** %97)
store i32 %98, i32* %3
br label %117
99: ; preds = %89
%100 = load i8*, i8** %8
%101 = call i64 @strncmp(i8* %100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 8)
%102 = icmp eq i64 %101, 0
br i1 %102, label %103, label %109
103: ; preds = %99
%104 = load i8*, i8** %6
%105 = load i8*, i8** %7
%106 = load i32, i32* %9
%107 = load i8**, i8*** %10
%108 = call i32 @history(i8* %104, i8* %105, i32 %106, i8** %107)
store i32 %108, i32* %3
br label %117
109: ; preds = %99
%110 = load i8*, i8** %8
%111 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %110)
%112 = load i8**, i8*** %5
%113 = getelementptr inbounds i8*, i8** %112, i64 0
%114 = load i8*, i8** %113
%115 = load i32, i32* @EXIT_FAILURE
%116 = call i32 @usage(i8* %114, i32 %115)
store i32 %116, i32* %3
br label %117
117: ; preds = %109, %103, %93, %83, %73, %63, %42, %35, %22
%118 = load i32, i32* %3
ret i32 %118
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@.str = [21 x i8] c"Not enough arguments\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"buy\00"
@.str.2 = [5 x i8] c"sell\00"
@.str.3 = [10 x i8] c"inventory\00"
@.str.4 = [6 x i8] c"state\00"
@.str.5 = [8 x i8] c"history\00"
@.str.6 = [18 x i8] c"Unknown action %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %23
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i64 @is_help(i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = load i32, i32* @EXIT_SUCCESS
%12 = tail call i32 @usage(i8* %3, i32 %11)
br label %61
13: ; preds = %5
%14 = icmp ugt i32 %0, 2
br i1 %14, label %15, label %23
15: ; preds = %13
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i64 @is_help(i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %15
%21 = load i32, i32* @EXIT_SUCCESS
%22 = tail call i32 @usage(i8* %3, i32 %21)
br label %61
23: ; preds = %2, %13
%24 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @usage(i8* %3, i32 %25)
br label %61
27: ; preds = %15
%28 = load i8*, i8** %6
%29 = load i8*, i8** %16
%30 = add nsw i32 %0, -3
%31 = getelementptr inbounds i8*, i8** %1, i64 3
%32 = tail call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = tail call i32 @buy(i8* %3, i8* %28, i32 %30, i8** %31)
br label %61
36: ; preds = %27
%37 = tail call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 5)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = tail call i32 @sell(i8* %3, i8* %28, i32 %30, i8** %31)
br label %61
41: ; preds = %36
%42 = tail call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 10)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = tail call i32 @inventory(i8* %3, i8* %28, i32 %30, i8** %31)
br label %61
46: ; preds = %41
%47 = tail call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 6)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = tail call i32 @inventory(i8* %3, i8* %28, i32 %30, i8** %31)
br label %61
51: ; preds = %46
%52 = tail call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 8)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = tail call i32 @history(i8* %3, i8* %28, i32 %30, i8** %31)
br label %61
56: ; preds = %51
%57 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %29)
%58 = load i8*, i8** %1
%59 = load i32, i32* @EXIT_FAILURE
%60 = tail call i32 @usage(i8* %58, i32 %59)
br label %61
61: ; preds = %34, %39, %44, %49, %54, %56, %23, %20, %10
%62 = phi i32 [ %12, %10 ], [ %22, %20 ], [ %26, %23 ], [ %35, %34 ], [ %40, %39 ], [ %45, %44 ], [ %50, %49 ], [ %55, %54 ], [ %60, %56 ]
ret i32 %62
}