#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 addInstructionToMemory(int);
int getElementAddressFromStr(char *, int);
int /*<<< orphan*/ isalpha(char);
int strlen2(char *);
int variableExistsInTable(char);
int createInputInstruction(char tokenArray[][20], int numberOfTokens) {
  int variableIdx;
  int instruction;
  int variableAddress;
  if (numberOfTokens < 3) {
    return -1;
  }
  for (variableIdx = 2; variableIdx < numberOfTokens; variableIdx++) {
    if (!isalpha(tokenArray[variableIdx][0]))
      return -1;
    instruction = 10 * 10000;
    variableAddress = variableExistsInTable(tokenArray[variableIdx][0]);
    if (strlen2(tokenArray[variableIdx]) == 2 &&
        tokenArray[variableIdx][1] == '$') {
      instruction = 15 * 10000;
    } else if (strlen2(tokenArray[variableIdx]) > 3) {
      variableAddress =
          getElementAddressFromStr(tokenArray[variableIdx], variableAddress);
      if (variableAddress == -1) {
        return -1;
      }
    }
    instruction += variableAddress;
    if (addInstructionToMemory(instruction) == -1)
      return -1;
    ;
  }
  return 1;
}


x86 assembly (clang, -O0):
<createInputInstruction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    1175 <createInputInstruction+0x25>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <createInputInstruction+0x161>
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12aa <createInputInstruction+0x15a>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
movsbl (%rax),%edi
call   1060 <isalpha@plt>
cmp    $0x0,%eax
jne    11b4 <createInputInstruction+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <createInputInstruction+0x161>
movl   $0x186a0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
movsbl (%rax),%edi
call   1030 <variableExistsInTable@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
imul   $0x14,%rax,%rax
add    %rax,%rdi
call   1040 <strlen2@plt>
cmp    $0x2,%eax
jne    121a <createInputInstruction+0xca>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
movsbl 0x1(%rax),%eax
cmp    $0x24,%eax
jne    121a <createInputInstruction+0xca>
movl   $0x249f0,-0x1c(%rbp)
jmp    1271 <createInputInstruction+0x121>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
imul   $0x14,%rax,%rax
add    %rax,%rdi
call   1040 <strlen2@plt>
cmp    $0x3,%eax
jle    126c <createInputInstruction+0x11c>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
imul   $0x14,%rax,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%esi
call   1070 <getElementAddressFromStr@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1267 <createInputInstruction+0x117>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <createInputInstruction+0x161>
jmp    126c <createInputInstruction+0x11c>
jmp    1271 <createInputInstruction+0x121>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <addInstructionToMemory@plt>
cmp    $0xffffffff,%eax
jne    1297 <createInputInstruction+0x147>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <createInputInstruction+0x161>
jmp    129c <createInputInstruction+0x14c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117c <createInputInstruction+0x2c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createInputInstruction>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r14d
cmp    $0x3,%esi
jl     11f3 <createInputInstruction+0xa3>
mov    %rdi,%rbx
mov    %esi,%r12d
add    $0x28,%rbx
add    $0xfffffffffffffffe,%r12
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%rbx),%edi
call   1060 <isalpha@plt>
test   %eax,%eax
je     11f3 <createInputInstruction+0xa3>
movsbl (%rbx),%edi
call   1030 <variableExistsInTable@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1040 <strlen2@plt>
cmp    $0x2,%eax
jne    11af <createInputInstruction+0x5f>
mov    $0x249f0,%ebp
cmpb   $0x24,0x1(%rbx)
je     11d4 <createInputInstruction+0x84>
mov    %rbx,%rdi
call   1040 <strlen2@plt>
mov    $0x186a0,%ebp
cmp    $0x4,%eax
jl     11d4 <createInputInstruction+0x84>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1070 <getElementAddressFromStr@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     11f3 <createInputInstruction+0xa3>
add    %r15d,%ebp
mov    %ebp,%edi
call   1050 <addInstructionToMemory@plt>
cmp    $0xffffffff,%eax
je     11f3 <createInputInstruction+0xa3>
add    $0x14,%rbx
add    $0xffffffffffffffff,%r12
jne    1180 <createInputInstruction+0x30>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @createInputInstruction([20 x i8]* %0, i32 %1) {
%3 = alloca i32
%4 = alloca [20 x i8]*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store [20 x i8]* %0, [20 x i8]** %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %86
12: ; preds = %2
store i32 2, i32* %6
br label %13
13: ; preds = %82, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %85
17: ; preds = %13
%18 = load [20 x i8]*, [20 x i8]** %4
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %18, i64 %20
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %21, i64 0, i64 0
%23 = load i8, i8* %22
%24 = call i32 @isalpha(i8 signext %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %17
store i32 -1, i32* %3
br label %86
27: ; preds = %17
store i32 100000, i32* %7
%28 = load [20 x i8]*, [20 x i8]** %4
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %28, i64 %30
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %31, i64 0, i64 0
%33 = load i8, i8* %32
%34 = call i32 @variableExistsInTable(i8 signext %33)
store i32 %34, i32* %8
%35 = load [20 x i8]*, [20 x i8]** %4
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %35, i64 %37
%39 = getelementptr inbounds [20 x i8], [20 x i8]* %38, i64 0, i64 0
%40 = call i32 @strlen2(i8* %39)
%41 = icmp eq i32 %40, 2
br i1 %41, label %42, label %52
42: ; preds = %27
%43 = load [20 x i8]*, [20 x i8]** %4
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %43, i64 %45
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %46, i64 0, i64 1
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 36
br i1 %50, label %51, label %52
51: ; preds = %42
store i32 150000, i32* %7
br label %73
52: ; preds = %42, %27
%53 = load [20 x i8]*, [20 x i8]** %4
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [20 x i8], [20 x i8]* %53, i64 %55
%57 = getelementptr inbounds [20 x i8], [20 x i8]* %56, i64 0, i64 0
%58 = call i32 @strlen2(i8* %57)
%59 = icmp sgt i32 %58, 3
br i1 %59, label %60, label %72
60: ; preds = %52
%61 = load [20 x i8]*, [20 x i8]** %4
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [20 x i8], [20 x i8]* %61, i64 %63
%65 = getelementptr inbounds [20 x i8], [20 x i8]* %64, i64 0, i64 0
%66 = load i32, i32* %8
%67 = call i32 @getElementAddressFromStr(i8* %65, i32 %66)
store i32 %67, i32* %8
%68 = load i32, i32* %8
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %71
70: ; preds = %60
store i32 -1, i32* %3
br label %86
71: ; preds = %60
br label %72
72: ; preds = %71, %52
br label %73
73: ; preds = %72, %51
%74 = load i32, i32* %8
%75 = load i32, i32* %7
%76 = add nsw i32 %75, %74
store i32 %76, i32* %7
%77 = load i32, i32* %7
%78 = call i32 @addInstructionToMemory(i32 %77)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %81
80: ; preds = %73
store i32 -1, i32* %3
br label %86
81: ; preds = %73
br label %82
82: ; preds = %81
%83 = load i32, i32* %6
%84 = add nsw i32 %83, 1
store i32 %84, i32* %6
br label %13
85: ; preds = %13
store i32 1, i32* %3
br label %86
86: ; preds = %85, %80, %70, %26, %11
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
define i32 @createInputInstruction([20 x i8]* %0, i32 %1) {
%3 = icmp slt i32 %1, 3
br i1 %3, label %36, label %4
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %8
6: ; preds = %29
%7 = icmp eq i64 %35, %5
br i1 %7, label %36, label %8
8: ; preds = %4, %6
%9 = phi i64 [ 2, %4 ], [ %35, %6 ]
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %0, i64 %9, i64 0
%11 = load i8, i8* %10
%12 = tail call i32 @isalpha(i8 signext %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %36, label %14
14: ; preds = %8
%15 = load i8, i8* %10
%16 = tail call i32 @variableExistsInTable(i8 signext %15)
%17 = tail call i32 @strlen2(i8* %10)
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %0, i64 %9, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 36
br i1 %22, label %29, label %23
23: ; preds = %19, %14
%24 = tail call i32 @strlen2(i8* %10)
%25 = icmp sgt i32 %24, 3
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = tail call i32 @getElementAddressFromStr(i8* %10, i32 %16)
%28 = icmp eq i32 %27, -1
br i1 %28, label %36, label %29
29: ; preds = %19, %23, %26
%30 = phi i32 [ 100000, %26 ], [ 100000, %23 ], [ 150000, %19 ]
%31 = phi i32 [ %27, %26 ], [ %16, %23 ], [ %16, %19 ]
%32 = add nsw i32 %31, %30
%33 = tail call i32 @addInstructionToMemory(i32 %32)
%34 = icmp eq i32 %33, -1
%35 = add nuw nsw i64 %9, 1
br i1 %34, label %36, label %6
36: ; preds = %8, %26, %29, %6, %2
%37 = phi i32 [ -1, %2 ], [ -1, %8 ], [ -1, %26 ], [ -1, %29 ], [ 1, %6 ]
ret i32 %37
}