#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 */
scalar_t__ strcmp(char *, char *);
int getCommandType(int numOfTokens, char tokenList[50][10]) {
  if (strcmp(tokenList[0], "write") == 0) {
    if ((numOfTokens % 2 != 0) && (numOfTokens > 2))
      return 0;
    else
      return -1;
  } else if (strcmp(tokenList[0], "read") == 0) {
    if (numOfTokens > 1)
      return 1;
    else
      return -1;
  } else if (strcmp(tokenList[0], "add") == 0) {
    return 2;
  } else
    return -1;
}


x86 assembly (clang, -O0):
<getCommandType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed6(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    116f <getCommandType+0x5f>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1163 <getCommandType+0x53>
cmpl   $0x2,-0x8(%rbp)
jle    1163 <getCommandType+0x53>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <getCommandType+0xc8>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <getCommandType+0xc8>
mov    -0x10(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11ab <getCommandType+0x9b>
cmpl   $0x1,-0x8(%rbp)
jle    119f <getCommandType+0x8f>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <getCommandType+0xc8>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <getCommandType+0xc8>
mov    -0x10(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11d1 <getCommandType+0xc1>
movl   $0x2,-0x4(%rbp)
jmp    11d8 <getCommandType+0xc8>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCommandType>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xee1(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1159 <getCommandType+0x49>
lea    0xed3(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     116f <getCommandType+0x5f>
lea    0xec4(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
neg    %rax
sbb    %eax,%eax
or     $0x2,%eax
jmp    117c <getCommandType+0x6c>
test   $0x1,%bpl
sete   %al
cmp    $0x3,%ebp
setl   %cl
or     %al,%cl
movzbl %cl,%eax
neg    %eax
jmp    117c <getCommandType+0x6c>
xor    %eax,%eax
cmp    $0x2,%ebp
setge  %al
add    %eax,%eax
add    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"write\00"
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [4 x i8] c"add\00"
define i32 @getCommandType(i32 %0, [10 x i8]* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [10 x i8]*
store i32 %0, i32* %4
store [10 x i8]* %1, [10 x i8]** %5
%6 = load [10 x i8]*, [10 x i8]** %5
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %2
%12 = load i32, i32* %4
%13 = srem i32 %12, 2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 2
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 0, i32* %3
br label %39
19: ; preds = %15, %11
store i32 -1, i32* %3
br label %39
20: ; preds = %2
%21 = load [10 x i8]*, [10 x i8]** %5
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %21, i64 0
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %22, i64 0, i64 0
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 1, i32* %3
br label %39
30: ; preds = %26
store i32 -1, i32* %3
br label %39
31: ; preds = %20
%32 = load [10 x i8]*, [10 x i8]** %5
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %32, i64 0
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %33, i64 0, i64 0
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 2, i32* %3
br label %39
38: ; preds = %31
store i32 -1, i32* %3
br label %39
39: ; preds = %38, %37, %30, %29, %19, %18
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [6 x i8] c"write\00"
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [4 x i8] c"add\00"
define i32 @getCommandType(i32 %0, [10 x i8]* %1) {
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = and i32 %0, 1
%8 = icmp eq i32 %7, 0
%9 = icmp slt i32 %0, 3
%10 = or i1 %9, %8
%11 = sext i1 %10 to i32
br label %22
12: ; preds = %2
%13 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = icmp sgt i32 %0, 1
%17 = select i1 %16, i32 1, i32 -1
br label %22
18: ; preds = %12
%19 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i32 2, i32 -1
br label %22
22: ; preds = %18, %15, %6
%23 = phi i32 [ %11, %6 ], [ %17, %15 ], [ %21, %18 ]
ret i32 %23
}