#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 */
struct Cyc_Sexp_Parser {
  int dummy;
};

/* Variables and functions */
unsigned int Cyc_Sexp_hex2value(struct Cyc_Sexp_Parser *, int);
int Cyc_Sexp_pgetc(struct Cyc_Sexp_Parser *);
unsigned short Cyc_Sexp_parse_short(struct Cyc_Sexp_Parser *p) {
  unsigned _T0;
  unsigned _T1;
  unsigned _T2;
  unsigned short _T3;
  unsigned res = 0U;
  {
    unsigned i = 0U;
  _TL6B:
    if (i < 4U)
      goto _TL69;
    else {
      goto _TL6A;
    }
  _TL69 : {
    int ch = Cyc_Sexp_pgetc(p);
    unsigned v = Cyc_Sexp_hex2value(p, ch);
    _T0 = res << 4;
    _T1 = v;
    res = _T0 | _T1;
  }
    i = i + 1;
    goto _TL6B;
  _TL6A:;
  }
  _T2 = res;
  _T3 = (unsigned short)_T2;
  return _T3;
}


x86 assembly (clang, -O0):
<Cyc_Sexp_parse_short>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jae    1149 <Cyc_Sexp_parse_short+0x29>
jmp    114e <Cyc_Sexp_parse_short+0x2e>
jmp    118f <Cyc_Sexp_parse_short+0x6f>
mov    -0x8(%rbp),%rdi
call   1040 <Cyc_Sexp_pgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <Cyc_Sexp_hex2value@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113a <Cyc_Sexp_parse_short+0x1a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %ax,-0x16(%rbp)
movzwl -0x16(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Cyc_Sexp_parse_short>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <Cyc_Sexp_pgetc@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <Cyc_Sexp_hex2value@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1040 <Cyc_Sexp_pgetc@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <Cyc_Sexp_hex2value@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1040 <Cyc_Sexp_pgetc@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <Cyc_Sexp_hex2value@plt>
mov    %eax,%ebx
shl    $0x8,%r14d
shl    $0x4,%ebp
or     %r14d,%ebp
or     %ebp,%ebx
mov    %r15,%rdi
call   1040 <Cyc_Sexp_pgetc@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <Cyc_Sexp_hex2value@plt>
shl    $0x4,%ebx
or     %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Cyc_Sexp_Parser = type { i32 }
define zeroext i16 @Cyc_Sexp_parse_short(%struct.Cyc_Sexp_Parser* %0) {
%2 = alloca %struct.Cyc_Sexp_Parser*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i16
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store %struct.Cyc_Sexp_Parser* %0, %struct.Cyc_Sexp_Parser** %2
store i32 0, i32* %7
store i32 0, i32* %8
br label %11
11: ; preds = %16, %1
%12 = load i32, i32* %8
%13 = icmp ult i32 %12, 4
br i1 %13, label %14, label %15
14: ; preds = %11
br label %16
15: ; preds = %11
br label %30
16: ; preds = %14
%17 = load %struct.Cyc_Sexp_Parser*, %struct.Cyc_Sexp_Parser** %2
%18 = call i32 @Cyc_Sexp_pgetc(%struct.Cyc_Sexp_Parser* %17)
store i32 %18, i32* %9
%19 = load %struct.Cyc_Sexp_Parser*, %struct.Cyc_Sexp_Parser** %2
%20 = load i32, i32* %9
%21 = call i32 @Cyc_Sexp_hex2value(%struct.Cyc_Sexp_Parser* %19, i32 %20)
store i32 %21, i32* %10
%22 = load i32, i32* %7
%23 = shl i32 %22, 4
store i32 %23, i32* %3
%24 = load i32, i32* %10
store i32 %24, i32* %4
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = or i32 %25, %26
store i32 %27, i32* %7
%28 = load i32, i32* %8
%29 = add i32 %28, 1
store i32 %29, i32* %8
br label %11
30: ; preds = %15
%31 = load i32, i32* %7
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = trunc i32 %32 to i16
store i16 %33, i16* %6
%34 = load i16, i16* %6
ret i16 %34
}

LLVM IR (-O2):
%struct.Cyc_Sexp_Parser = type { i32 }
define zeroext i16 @Cyc_Sexp_parse_short(%struct.Cyc_Sexp_Parser* %0) {
%2 = tail call i32 @Cyc_Sexp_pgetc(%struct.Cyc_Sexp_Parser* %0)
%3 = tail call i32 @Cyc_Sexp_hex2value(%struct.Cyc_Sexp_Parser* %0, i32 %2)
%4 = tail call i32 @Cyc_Sexp_pgetc(%struct.Cyc_Sexp_Parser* %0)
%5 = tail call i32 @Cyc_Sexp_hex2value(%struct.Cyc_Sexp_Parser* %0, i32 %4)
%6 = tail call i32 @Cyc_Sexp_pgetc(%struct.Cyc_Sexp_Parser* %0)
%7 = tail call i32 @Cyc_Sexp_hex2value(%struct.Cyc_Sexp_Parser* %0, i32 %6)
%8 = shl i32 %3, 8
%9 = shl i32 %5, 4
%10 = or i32 %8, %9
%11 = or i32 %7, %10
%12 = tail call i32 @Cyc_Sexp_pgetc(%struct.Cyc_Sexp_Parser* %0)
%13 = tail call i32 @Cyc_Sexp_hex2value(%struct.Cyc_Sexp_Parser* %0, i32 %12)
%14 = shl i32 %11, 4
%15 = or i32 %13, %14
%16 = trunc i32 %15 to i16
ret i16 %16
}