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


x86 assembly (clang, -O0):
<parse_SNE>:
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    $0x56,%eax
je     115d <parse_SNE+0x3d>
movw   $0xffff,-0x2(%rbp)
jmp    1223 <parse_SNE+0x103>
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    0xe79(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x56,%eax
jne    11d1 <parse_SNE+0xb1>
movzwl -0x4(%rbp),%eax
or     $0x9000,%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    121b <parse_SNE+0xfb>
movzwl -0x4(%rbp),%eax
or     $0x4000,%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)
mov    -0x4(%rbp),%ax
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_SNE>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
mov    %rax,%rcx
mov    $0xffff,%ax
cmpb   $0x56,(%rcx)
jne    11a9 <parse_SNE+0x89>
movsbl 0x1(%rcx),%edi
call   1030 <char2byte@plt>
mov    %eax,%ebx
and    $0xf,%ebx
shl    $0x8,%ebx
lea    0xeaa(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
mov    %rax,%r14
mov    (%rax),%al
cmp    $0x56,%al
jne    1182 <parse_SNE+0x62>
movsbl 0x1(%r14),%edi
call   1030 <char2byte@plt>
shl    $0x4,%eax
movzbl %al,%ecx
movzwl %bx,%eax
or     %ecx,%eax
or     $0x9000,%eax
jmp    11a9 <parse_SNE+0x89>
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     $0x4000,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c" ,\00"
define zeroext i16 @parse_SNE() {
%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 ne i32 %8, 86
br i1 %9, label %10, label %11
10: ; preds = %0
store i16 -1, i16* %1
br label %70
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 = 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
%22 = call i8* @strtok(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %3
%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 eq i32 %26, 86
br i1 %27, label %28, label %43
28: ; preds = %11
%29 = load i16, i16* %2
%30 = zext i16 %29 to i32
%31 = or i32 %30, 36864
%32 = trunc i32 %31 to i16
store i16 %32, i16* %2
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = call i32 @char2byte(i8 signext %35)
%37 = and i32 %36, 15
%38 = shl i32 %37, 4
%39 = load i16, i16* %2
%40 = zext i16 %39 to i32
%41 = or i32 %40, %38
%42 = trunc i32 %41 to i16
store i16 %42, i16* %2
br label %68
43: ; preds = %11
%44 = load i16, i16* %2
%45 = zext i16 %44 to i32
%46 = or i32 %45, 16384
%47 = trunc i32 %46 to i16
store i16 %47, i16* %2
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i64 0
%50 = load i8, i8* %49
%51 = call i32 @char2byte(i8 signext %50)
%52 = and i32 %51, 15
%53 = shl i32 %52, 4
%54 = load i16, i16* %2
%55 = zext i16 %54 to i32
%56 = or i32 %55, %53
%57 = trunc i32 %56 to i16
store i16 %57, i16* %2
%58 = load i8*, i8** %3
%59 = getelementptr inbounds i8, i8* %58, i64 1
%60 = load i8, i8* %59
%61 = call i32 @char2byte(i8 signext %60)
%62 = and i32 %61, 15
%63 = shl i32 %62, 0
%64 = load i16, i16* %2
%65 = zext i16 %64 to i32
%66 = or i32 %65, %63
%67 = trunc i32 %66 to i16
store i16 %67, i16* %2
br label %68
68: ; preds = %43, %28
%69 = load i16, i16* %2
store i16 %69, i16* %1
br label %70
70: ; preds = %68, %10
%71 = load i16, i16* %1
ret i16 %71
}

LLVM IR (-O2):
@.str = [3 x i8] c" ,\00"
define zeroext i16 @parse_SNE() {
%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 %36
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 = trunc i32 %7 to i16
%9 = shl i16 %8, 8
%10 = and i16 %9, 3840
%11 = tail call i8* @strtok(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 86
br i1 %13, label %14, label %23
14: ; preds = %4
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = load i8, i8* %15
%17 = tail call i32 @char2byte(i8 signext %16)
%18 = trunc i32 %17 to i16
%19 = shl i16 %18, 4
%20 = and i16 %19, 240
%21 = or i16 %10, %20
%22 = or i16 %21, -28672
br label %36
23: ; preds = %4
%24 = tail call i32 @char2byte(i8 signext %12)
%25 = trunc i32 %24 to i16
%26 = shl i16 %25, 4
%27 = and i16 %26, 240
%28 = or i16 %10, %27
%29 = getelementptr inbounds i8, i8* %11, i64 1
%30 = load i8, i8* %29
%31 = tail call i32 @char2byte(i8 signext %30)
%32 = trunc i32 %31 to i16
%33 = and i16 %32, 15
%34 = or i16 %28, %33
%35 = or i16 %34, 16384
br label %36
36: ; preds = %14, %23, %0
%37 = phi i16 [ -1, %0 ], [ %22, %14 ], [ %35, %23 ]
ret i16 %37
}