#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 hex2dec(char);
unsigned short GetWord(char *buffer) {
  return hex2dec(buffer[0]) * 0x1000 + hex2dec(buffer[1]) * 0x100 +
         hex2dec(buffer[2]) * 0x10 + hex2dec(buffer[3]);
}


x86 assembly (clang, -O0):
<GetWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <hex2dec@plt>
shl    $0xc,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <hex2dec@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
shl    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <hex2dec@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
shl    $0x4,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x3(%rax),%edi
call   1030 <hex2dec@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
add    %ecx,%eax
movzwl %ax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetWord>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1030 <hex2dec@plt>
mov    %eax,%ebp
shl    $0xc,%ebp
movsbl 0x1(%r14),%edi
call   1030 <hex2dec@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
add    %ebp,%ebx
movsbl 0x2(%r14),%edi
call   1030 <hex2dec@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
add    %ebx,%ebp
movsbl 0x3(%r14),%edi
call   1030 <hex2dec@plt>
add    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i16 @GetWord(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = getelementptr inbounds i8, i8* %3, i64 0
%5 = load i8, i8* %4
%6 = call i32 @hex2dec(i8 signext %5)
%7 = mul nsw i32 %6, 4096
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = call i32 @hex2dec(i8 signext %10)
%12 = mul nsw i32 %11, 256
%13 = add nsw i32 %7, %12
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 2
%16 = load i8, i8* %15
%17 = call i32 @hex2dec(i8 signext %16)
%18 = mul nsw i32 %17, 16
%19 = add nsw i32 %13, %18
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 3
%22 = load i8, i8* %21
%23 = call i32 @hex2dec(i8 signext %22)
%24 = add nsw i32 %19, %23
%25 = trunc i32 %24 to i16
ret i16 %25
}

LLVM IR (-O2):
define zeroext i16 @GetWord(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i32 @hex2dec(i8 signext %2)
%4 = shl nsw i32 %3, 12
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = tail call i32 @hex2dec(i8 signext %6)
%8 = shl nsw i32 %7, 8
%9 = add nsw i32 %8, %4
%10 = getelementptr inbounds i8, i8* %0, i64 2
%11 = load i8, i8* %10
%12 = tail call i32 @hex2dec(i8 signext %11)
%13 = shl nsw i32 %12, 4
%14 = add nsw i32 %9, %13
%15 = getelementptr inbounds i8, i8* %0, i64 3
%16 = load i8, i8* %15
%17 = tail call i32 @hex2dec(i8 signext %16)
%18 = add nsw i32 %14, %17
%19 = trunc i32 %18 to i16
ret i16 %19
}