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


x86 assembly (clang, -O0):
<parse_JP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
mov    %eax,%edi
lea    0xecd(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x56,%eax
jne    11c7 <parse_JP+0xa7>
movw   $0xb000,-0x2(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xea3(%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    $0x8,%ecx
movzwl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x2(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ecx
and    $0xf,%ecx
shl    $0x4,%ecx
movzwl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x2(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ecx
and    $0xf,%ecx
shl    $0x0,%ecx
movzwl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x2(%rbp)
jmp    1229 <parse_JP+0x109>
movw   $0x1000,-0x2(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ecx
and    $0xf,%ecx
shl    $0x8,%ecx
movzwl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x2(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ecx
and    $0xf,%ecx
shl    $0x4,%ecx
movzwl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x2(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ecx
and    $0xf,%ecx
shl    $0x0,%ecx
movzwl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_JP>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
mov    %rax,%r15
mov    (%rax),%al
cmp    $0x56,%al
jne    1158 <parse_JP+0x38>
lea    0xebb(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
mov    %rax,%r15
mov    (%rax),%al
mov    $0xb000,%r14w
jmp    115d <parse_JP+0x3d>
mov    $0x1000,%r14w
movsbl %al,%edi
call   1030 <char2byte@plt>
mov    %eax,%ebp
and    $0xf,%ebp
shl    $0x8,%ebp
movsbl 0x1(%r15),%edi
call   1030 <char2byte@plt>
shl    $0x4,%eax
movzbl %al,%ebx
or     %ebp,%ebx
movsbl 0x2(%r15),%edi
call   1030 <char2byte@plt>
and    $0xf,%eax
or     %ebx,%eax
or     %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c" ,\00"
define zeroext i16 @parse_JP() {
%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 %7
4: ; preds = %0
%5 = tail call i8* @strtok(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = load i8, i8* %5
br label %7
7: ; preds = %0, %4
%8 = phi i8 [ %6, %4 ], [ %2, %0 ]
%9 = phi i8* [ %5, %4 ], [ %1, %0 ]
%10 = phi i16 [ -20480, %4 ], [ 4096, %0 ]
%11 = tail call i32 @char2byte(i8 signext %8)
%12 = shl i32 %11, 8
%13 = and i32 %12, 3840
%14 = getelementptr inbounds i8, i8* %9, 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 = getelementptr inbounds i8, i8* %9, i64 2
%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 %10, %25
ret i16 %26
}