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


x86 assembly (clang, -O0):
<parse_DRW>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movw   $0xd000,-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_DRW+0x3d>
movw   $0xffff,-0x2(%rbp)
jmp    1204 <parse_DRW+0xe4>
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
je     11ab <parse_DRW+0x8b>
movw   $0xffff,-0x2(%rbp)
jmp    1204 <parse_DRW+0xe4>
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)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe2b(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%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_DRW>:
push   %rbp
push   %rbx
push   %rax
lea    0xed6(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
mov    $0xffff,%bx
cmpb   $0x56,(%rax)
jne    1190 <parse_DRW+0x70>
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    1190 <parse_DRW+0x70>
and    $0xf,%ebp
shl    $0x8,%ebp
movsbl 0x1(%rax),%edi
call   1030 <char2byte@plt>
shl    $0x4,%eax
movzbl %al,%ebx
or     %ebp,%ebx
lea    0xe8a(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
movsbl (%rax),%edi
call   1030 <char2byte@plt>
and    $0xf,%eax
add    %eax,%ebx
add    $0xd000,%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_DRW() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca i8*
store i16 -12288, 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 %52
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 ne i32 %26, 86
br i1 %27, label %28, label %29
28: ; preds = %11
store i16 -1, i16* %1
br label %52
29: ; preds = %11
%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, 4
%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 = call i32 @char2byte(i8 signext %43)
%45 = and i32 %44, 15
%46 = shl i32 %45, 0
%47 = load i16, i16* %2
%48 = zext i16 %47 to i32
%49 = or i32 %48, %46
%50 = trunc i32 %49 to i16
store i16 %50, i16* %2
%51 = load i16, i16* %2
store i16 %51, i16* %1
br label %52
52: ; preds = %29, %28, %10
%53 = load i16, i16* %1
ret i16 %53
}

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