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


x86 assembly (clang, -O0):
<parse_RND>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movw   $0xc000,-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_RND+0x3d>
movw   $0xffff,-0x2(%rbp)
jmp    11d5 <parse_RND+0xb5>
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),%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_RND>:
push   %r15
push   %r14
push   %rbx
lea    0xed4(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
mov    %rax,%rcx
mov    $0xffff,%ax
cmpb   $0x56,(%rcx)
jne    1188 <parse_RND+0x68>
movsbl 0x1(%rcx),%edi
call   1030 <char2byte@plt>
mov    %eax,%ebx
and    $0xf,%ebx
shl    $0x8,%ebx
lea    0xea9(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
mov    %rax,%r14
movsbl (%rax),%edi
call   1030 <char2byte@plt>
shl    $0x4,%eax
movzbl %al,%r15d
or     %ebx,%r15d
movsbl 0x1(%r14),%edi
call   1030 <char2byte@plt>
and    $0xf,%eax
add    %r15d,%eax
add    $0xc000,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c" ,\00"
define zeroext i16 @parse_RND() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca i8*
store i16 -16384, 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 %44
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 = call i32 @char2byte(i8 signext %25)
%27 = and i32 %26, 15
%28 = shl i32 %27, 4
%29 = load i16, i16* %2
%30 = zext i16 %29 to i32
%31 = or i32 %30, %28
%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, 0
%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
%43 = load i16, i16* %2
store i16 %43, i16* %1
br label %44
44: ; preds = %11, %10
%45 = load i16, i16* %1
ret i16 %45
}

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