#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_SUB() {
  unsigned short instruction = 0x8005;
  char *arg;
  arg = strtok(NULL, " ,");
  if (arg[0] != 'V') {
    return 0xFFFF;
  }
  instruction |= (char2byte(arg[1])) << 8;
  arg = strtok(NULL, " ,");
  if (arg[0] != 'V') {
    return 0xFFFF;
  }
  instruction |= (char2byte(arg[1])) << 4;
  return instruction;
}


x86 assembly (clang, -O0):
<parse_SUB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movw   $0x8005,-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    $0x56,%eax
je     115d <parse_SUB+0x3d>
movw   $0xffff,-0x2(%rbp)
jmp    11cc <parse_SUB+0xac>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ecx
shl    $0x8,%ecx
movzwl -0x4(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe7c(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x56,%eax
je     11a8 <parse_SUB+0x88>
movw   $0xffff,-0x2(%rbp)
jmp    11cc <parse_SUB+0xac>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ecx
shl    $0x4,%ecx
movzwl -0x4(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x4(%rbp)
mov    -0x4(%rbp),%ax
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_SUB>:
push   %rbp
push   %rbx
push   %rax
lea    0xed6(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
mov    $0xffff,%bx
cmpb   $0x56,(%rax)
jne    1171 <parse_SUB+0x51>
movsbl 0x1(%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ebp
lea    0xeb4(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
cmpb   $0x56,(%rax)
jne    1171 <parse_SUB+0x51>
shl    $0x8,%ebp
movsbl 0x1(%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
or     %ebp,%ebx
or     $0x8005,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c" ,\00"
define zeroext i16 @parse_SUB() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca i8*
store i16 -32763, 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 ne i32 %8, 86
br i1 %9, label %10, label %11
10: ; preds = %0
store i16 -1, i16* %1
br label %39
11: ; preds = %0
%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 = shl i32 %15, 8
%17 = load i16, i16* %2
%18 = zext i16 %17 to i32
%19 = or i32 %18, %16
%20 = trunc i32 %19 to i16
store i16 %20, i16* %2
%21 = call i8* @strtok(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %21, i8** %3
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 86
br i1 %26, label %27, label %28
27: ; preds = %11
store i16 -1, i16* %1
br label %39
28: ; preds = %11
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8, i8* %30
%32 = call i32 @char2byte(i8 signext %31)
%33 = shl i32 %32, 4
%34 = load i16, i16* %2
%35 = zext i16 %34 to i32
%36 = or i32 %35, %33
%37 = trunc i32 %36 to i16
store i16 %37, i16* %2
%38 = load i16, i16* %2
store i16 %38, i16* %1
br label %39
39: ; preds = %28, %27, %10
%40 = load i16, i16* %1
ret i16 %40
}

LLVM IR (-O2):
@.str = [3 x i8] c" ,\00"
define zeroext i16 @parse_SUB() {
%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
%3 = icmp eq i8 %2, 86
br i1 %3, label %4, label %20
4: ; preds = %0
%5 = getelementptr inbounds i8, i8* %1, i64 1
%6 = load i8, i8* %5
%7 = tail call i32 @char2byte(i8 signext %6)
%8 = tail call i8* @strtok(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 86
br i1 %10, label %11, label %20
11: ; preds = %4
%12 = shl i32 %7, 8
%13 = getelementptr inbounds i8, i8* %8, i64 1
%14 = load i8, i8* %13
%15 = tail call i32 @char2byte(i8 signext %14)
%16 = shl i32 %15, 4
%17 = or i32 %16, %12
%18 = trunc i32 %17 to i16
%19 = or i16 %18, -32763
br label %20
20: ; preds = %4, %0, %11
%21 = phi i16 [ %19, %11 ], [ -1, %0 ], [ -1, %4 ]
ret i16 %21
}