#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 char2byte(char);
char *strtok(int /*<<< orphan*/ *, char *);
unsigned short parse_ADD() {
  unsigned short instruction = 0x0000;
  char *arg;
  arg = strtok(NULL, " ,");
  if (arg[0] == 'I') {
    instruction = 0xF01E;
    arg = strtok(NULL, " ,");
    instruction |= (char2byte(arg[1]) & 0x0F) << 8;
  } else {
    if (arg[0] != 'V') {
      return 0xFFFF;
    }
    instruction |= (char2byte(arg[1]) & 0x0F) << 8;
    arg = strtok(NULL, " ,");
    if (arg[0] == 'V') {
      instruction |= 0x8004;
      instruction |= (char2byte(arg[1]) & 0x0F) << 4;
    } else {
      instruction |= 0x7000;
      instruction |= (char2byte(arg[0]) & 0x0F) << 4;
      instruction |= (char2byte(arg[1]) & 0x0F) << 0;
    }
  }
  return instruction;
}


x86 assembly (clang, -O0):
<parse_ADD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movw   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xec7(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x49,%eax
jne    1190 <parse_ADD+0x70>
movw   $0xf01e,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe9d(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ecx
and    $0xf,%ecx
shl    $0x8,%ecx
movzwl -0x4(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x4(%rbp)
jmp    126e <parse_ADD+0x14e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x56,%eax
je     11ab <parse_ADD+0x8b>
movw   $0xffff,-0x2(%rbp)
jmp    1276 <parse_ADD+0x156>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ecx
and    $0xf,%ecx
shl    $0x8,%ecx
movzwl -0x4(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe2b(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x56,%eax
jne    121f <parse_ADD+0xff>
movzwl -0x4(%rbp),%eax
or     $0x8004,%eax
mov    %ax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ecx
and    $0xf,%ecx
shl    $0x4,%ecx
movzwl -0x4(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x4(%rbp)
jmp    1269 <parse_ADD+0x149>
movzwl -0x4(%rbp),%eax
or     $0x7000,%eax
mov    %ax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ecx
and    $0xf,%ecx
shl    $0x4,%ecx
movzwl -0x4(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ecx
and    $0xf,%ecx
shl    $0x0,%ecx
movzwl -0x4(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x4(%rbp)
jmp    126e <parse_ADD+0x14e>
mov    -0x4(%rbp),%ax
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ADD>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
mov    (%rax),%cl
cmp    $0x56,%cl
je     1167 <parse_ADD+0x47>
mov    $0xffff,%ax
cmp    $0x49,%cl
jne    11d2 <parse_ADD+0xb2>
lea    0xeb3(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
movsbl 0x1(%rax),%edi
call   1030 <char2byte@plt>
shl    $0x8,%eax
or     $0xf01e,%eax
jmp    11d2 <parse_ADD+0xb2>
movsbl 0x1(%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ebx
and    $0xf,%ebx
shl    $0x8,%ebx
lea    0xe81(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
mov    %rax,%r14
mov    (%rax),%al
cmp    $0x56,%al
jne    11ab <parse_ADD+0x8b>
movsbl 0x1(%r14),%edi
call   1030 <char2byte@plt>
shl    $0x4,%eax
movzbl %al,%ecx
movzwl %bx,%eax
or     %ecx,%eax
or     $0x8004,%eax
jmp    11d2 <parse_ADD+0xb2>
movsbl %al,%edi
call   1030 <char2byte@plt>
shl    $0x4,%eax
movzbl %al,%eax
movzwl %bx,%ebx
or     %eax,%ebx
movsbl 0x1(%r14),%edi
call   1030 <char2byte@plt>
and    $0xf,%eax
or     %ebx,%eax
or     $0x7000,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c" ,\00"
define zeroext i16 @parse_ADD() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca i8*
store i16 0, i16* %2
%4 = call i8* @strtok(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 73
br i1 %9, label %10, label %22
10: ; preds = %0
store i16 -4066, i16* %2
%11 = call i8* @strtok(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = call i32 @char2byte(i8 signext %14)
%16 = and i32 %15, 15
%17 = shl i32 %16, 8
%18 = load i16, i16* %2
%19 = zext i16 %18 to i32
%20 = or i32 %19, %17
%21 = trunc i32 %20 to i16
store i16 %21, i16* %2
br label %87
22: ; preds = %0
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 86
br i1 %27, label %28, label %29
28: ; preds = %22
store i16 -1, i16* %1
br label %89
29: ; preds = %22
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = call i32 @char2byte(i8 signext %32)
%34 = and i32 %33, 15
%35 = shl i32 %34, 8
%36 = load i16, i16* %2
%37 = zext i16 %36 to i32
%38 = or i32 %37, %35
%39 = trunc i32 %38 to i16
store i16 %39, i16* %2
%40 = call i8* @strtok(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %40, i8** %3
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 86
br i1 %45, label %46, label %61
46: ; preds = %29
%47 = load i16, i16* %2
%48 = zext i16 %47 to i32
%49 = or i32 %48, 32772
%50 = trunc i32 %49 to i16
store i16 %50, i16* %2
%51 = load i8*, i8** %3
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8, i8* %52
%54 = call i32 @char2byte(i8 signext %53)
%55 = and i32 %54, 15
%56 = shl i32 %55, 4
%57 = load i16, i16* %2
%58 = zext i16 %57 to i32
%59 = or i32 %58, %56
%60 = trunc i32 %59 to i16
store i16 %60, i16* %2
br label %86
61: ; preds = %29
%62 = load i16, i16* %2
%63 = zext i16 %62 to i32
%64 = or i32 %63, 28672
%65 = trunc i32 %64 to i16
store i16 %65, i16* %2
%66 = load i8*, i8** %3
%67 = getelementptr inbounds i8, i8* %66, i64 0
%68 = load i8, i8* %67
%69 = call i32 @char2byte(i8 signext %68)
%70 = and i32 %69, 15
%71 = shl i32 %70, 4
%72 = load i16, i16* %2
%73 = zext i16 %72 to i32
%74 = or i32 %73, %71
%75 = trunc i32 %74 to i16
store i16 %75, i16* %2
%76 = load i8*, i8** %3
%77 = getelementptr inbounds i8, i8* %76, i64 1
%78 = load i8, i8* %77
%79 = call i32 @char2byte(i8 signext %78)
%80 = and i32 %79, 15
%81 = shl i32 %80, 0
%82 = load i16, i16* %2
%83 = zext i16 %82 to i32
%84 = or i32 %83, %81
%85 = trunc i32 %84 to i16
store i16 %85, i16* %2
br label %86
86: ; preds = %61, %46
br label %87
87: ; preds = %86, %10
%88 = load i16, i16* %2
store i16 %88, i16* %1
br label %89
89: ; preds = %87, %28
%90 = load i16, i16* %1
ret i16 %90
}

LLVM IR (-O2):
@.str = [3 x i8] c" ,\00"
define zeroext i16 @parse_ADD() {
%1 = tail call i8* @strtok(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%2 = load i8, i8* %1
switch i8 %2, label %43 [
i8 73, label %3
i8 86, label %11
]
3: ; preds = %0
%4 = tail call i8* @strtok(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds i8, i8* %4, i64 1
%6 = load i8, i8* %5
%7 = tail call i32 @char2byte(i8 signext %6)
%8 = trunc i32 %7 to i16
%9 = shl i16 %8, 8
%10 = or i16 %9, -4066
br label %43
11: ; preds = %0
%12 = getelementptr inbounds i8, i8* %1, i64 1
%13 = load i8, i8* %12
%14 = tail call i32 @char2byte(i8 signext %13)
%15 = trunc i32 %14 to i16
%16 = shl i16 %15, 8
%17 = and i16 %16, 3840
%18 = tail call i8* @strtok(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 86
br i1 %20, label %21, label %30
21: ; preds = %11
%22 = getelementptr inbounds i8, i8* %18, i64 1
%23 = load i8, i8* %22
%24 = tail call i32 @char2byte(i8 signext %23)
%25 = trunc i32 %24 to i16
%26 = shl i16 %25, 4
%27 = and i16 %26, 240
%28 = or i16 %17, %27
%29 = or i16 %28, -32764
br label %43
30: ; preds = %11
%31 = tail call i32 @char2byte(i8 signext %19)
%32 = trunc i32 %31 to i16
%33 = shl i16 %32, 4
%34 = and i16 %33, 240
%35 = or i16 %17, %34
%36 = getelementptr inbounds i8, i8* %18, i64 1
%37 = load i8, i8* %36
%38 = tail call i32 @char2byte(i8 signext %37)
%39 = trunc i32 %38 to i16
%40 = and i16 %39, 15
%41 = or i16 %35, %40
%42 = or i16 %41, 28672
br label %43
43: ; preds = %3, %30, %21, %0
%44 = phi i16 [ -1, %0 ], [ %10, %3 ], [ %29, %21 ], [ %42, %30 ]
ret i16 %44
}