short cst_ulaw_to_short(unsigned char ulawbyte) {
  static const int exp_lut[8] = {0, 132, 396, 924, 1980, 4092, 8316, 16764};
  int sign, exponent, mantissa;
  short sample;
  ulawbyte = ~ulawbyte;
  sign = (ulawbyte & 0x80);
  exponent = (ulawbyte >> 4) & 0x07;
  mantissa = ulawbyte & 0x0F;
  sample = exp_lut[exponent] + (mantissa << (exponent + 3));
  if (sign != 0)
    sample = -sample;
  return sample;
}


x86 assembly (clang, -O0):
<cst_ulaw_to_short>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
xor    $0xffffffff,%eax
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
and    $0x80,%eax
mov    %eax,-0x8(%rbp)
movzbl -0x1(%rbp),%eax
sar    $0x4,%eax
and    $0x7,%eax
mov    %eax,-0xc(%rbp)
movzbl -0x1(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x10(%rbp)
movslq -0xc(%rbp),%rcx
lea    0xebe(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
add    $0x3,%ecx
shl    %cl,%edx
mov    %edx,%ecx
add    %ecx,%eax
mov    %ax,-0x12(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     116e <cst_ulaw_to_short+0x6e>
movswl -0x12(%rbp),%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %ax,-0x12(%rbp)
movswl -0x12(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cst_ulaw_to_short>:
not    %dil
movzbl %dil,%edx
mov    %edx,%eax
shr    $0x4,%eax
and    $0x7,%eax
mov    %edx,%esi
and    $0xf,%esi
mov    %eax,%ecx
add    $0x3,%cl
shl    %cl,%esi
lea    0xede(%rip),%rcx
add    (%rcx,%rax,4),%esi
mov    %esi,%eax
neg    %eax
test   $0x80,%dl
cmove  %esi,%eax
ret

LLVM IR (-O0):
@cst_ulaw_to_short.exp_lut = internal constant [8 x i32] [i32 0, i32 132, i32 396, i32 924, i32 1980, i32 4092, i32 8316, i32 16764]
define signext i16 @cst_ulaw_to_short(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i16
store i8 %0, i8* %2
%7 = load i8, i8* %2
%8 = zext i8 %7 to i32
%9 = xor i32 %8, -1
%10 = trunc i32 %9 to i8
store i8 %10, i8* %2
%11 = load i8, i8* %2
%12 = zext i8 %11 to i32
%13 = and i32 %12, 128
store i32 %13, i32* %3
%14 = load i8, i8* %2
%15 = zext i8 %14 to i32
%16 = ashr i32 %15, 4
%17 = and i32 %16, 7
store i32 %17, i32* %4
%18 = load i8, i8* %2
%19 = zext i8 %18 to i32
%20 = and i32 %19, 15
store i32 %20, i32* %5
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [8 x i32], [8 x i32]* @cst_ulaw_to_short.exp_lut, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = load i32, i32* %5
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 3
%28 = shl i32 %25, %27
%29 = add nsw i32 %24, %28
%30 = trunc i32 %29 to i16
store i16 %30, i16* %6
%31 = load i32, i32* %3
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %1
%34 = load i16, i16* %6
%35 = sext i16 %34 to i32
%36 = sub nsw i32 0, %35
%37 = trunc i32 %36 to i16
store i16 %37, i16* %6
br label %38
38: ; preds = %33, %1
%39 = load i16, i16* %6
ret i16 %39
}

LLVM IR (-O2):
@cst_ulaw_to_short.exp_lut = internal unnamed_addr constant [8 x i32] [i32 0, i32 132, i32 396, i32 924, i32 1980, i32 4092, i32 8316, i32 16764]
define signext i16 @cst_ulaw_to_short(i8 zeroext %0) {
%2 = xor i8 %0, -1
%3 = zext i8 %2 to i32
%4 = and i32 %3, 128
%5 = lshr i32 %3, 4
%6 = and i32 %5, 7
%7 = and i32 %3, 15
%8 = zext i32 %6 to i64
%9 = getelementptr inbounds [8 x i32], [8 x i32]* @cst_ulaw_to_short.exp_lut, i64 0, i64 %8
%10 = load i32, i32* %9
%11 = add nuw nsw i32 %6, 3
%12 = shl nuw nsw i32 %7, %11
%13 = add nsw i32 %10, %12
%14 = trunc i32 %13 to i16
%15 = icmp eq i32 %4, 0
%16 = sub i16 0, %14
%17 = select i1 %15, i16 %14, i16 %16
ret i16 %17
}