#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_SYS() {
  unsigned short instruction = 0x0000;
  char *addr;
  addr = strtok(NULL, " ,");
  instruction |= (char2byte(addr[0]) & 0x0F) << 8;
  instruction |= (char2byte(addr[1]) & 0x0F) << 4;
  instruction |= (char2byte(addr[2]) & 0x0F) << 0;
  return instruction;
}


x86 assembly (clang, -O0):
<parse_SYS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movw   $0x0,-0x2(%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),%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_SYS>:
push   %rbp
push   %r14
push   %rbx
lea    0xed5(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
mov    %rax,%r14
movsbl (%rax),%edi
call   1030 <char2byte@plt>
mov    %eax,%ebp
and    $0xf,%ebp
shl    $0x8,%ebp
movsbl 0x1(%r14),%edi
call   1030 <char2byte@plt>
shl    $0x4,%eax
movzbl %al,%ebx
or     %ebp,%ebx
movsbl 0x2(%r14),%edi
call   1030 <char2byte@plt>
and    $0xf,%eax
or     %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c" ,\00"
define zeroext i16 @parse_SYS() {
%1 = alloca i16
%2 = alloca i8*
store i16 0, i16* %1
%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 = call i32 @char2byte(i8 signext %6)
%8 = and i32 %7, 15
%9 = shl i32 %8, 8
%10 = load i16, i16* %1
%11 = zext i16 %10 to i32
%12 = or i32 %11, %9
%13 = trunc i32 %12 to i16
store i16 %13, i16* %1
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = call i32 @char2byte(i8 signext %16)
%18 = and i32 %17, 15
%19 = shl i32 %18, 4
%20 = load i16, i16* %1
%21 = zext i16 %20 to i32
%22 = or i32 %21, %19
%23 = trunc i32 %22 to i16
store i16 %23, i16* %1
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 2
%26 = load i8, i8* %25
%27 = call i32 @char2byte(i8 signext %26)
%28 = and i32 %27, 15
%29 = shl i32 %28, 0
%30 = load i16, i16* %1
%31 = zext i16 %30 to i32
%32 = or i32 %31, %29
%33 = trunc i32 %32 to i16
store i16 %33, i16* %1
%34 = load i16, i16* %1
ret i16 %34
}

LLVM IR (-O2):
@.str = [3 x i8] c" ,\00"
define zeroext i16 @parse_SYS() {
%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 = tail call i32 @char2byte(i8 signext %2)
%4 = shl i32 %3, 8
%5 = and i32 %4, 3840
%6 = getelementptr inbounds i8, i8* %1, i64 1
%7 = load i8, i8* %6
%8 = tail call i32 @char2byte(i8 signext %7)
%9 = shl i32 %8, 4
%10 = and i32 %9, 240
%11 = or i32 %10, %5
%12 = getelementptr inbounds i8, i8* %1, i64 2
%13 = load i8, i8* %12
%14 = tail call i32 @char2byte(i8 signext %13)
%15 = and i32 %14, 15
%16 = or i32 %11, %15
%17 = trunc i32 %16 to i16
ret i16 %17
}