void dsp_protocol_linear2Q15(const unsigned short int input,
                             unsigned short int *scale,
                             unsigned short int *power2) {
  unsigned long int val = 0x00A3D70A * input;
  do {
  } while (0);
  if (input == 0) {
    *scale = 0;
    *power2 = 0;
  } else {
    *power2 = 1;
    while (val < 0x40000000) {
      (*power2)--;
      val <<= 1;
    }
    *scale = val >> 16;
  }
  do {
  } while (0);
  do {
  } while (0);
}


x86 assembly (clang, -O0):
<dsp_protocol_linear2Q15>:
push   %rbp
mov    %rsp,%rbp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movzwl -0x2(%rbp),%eax
imul   $0xa3d70a,%eax,%eax
cltq
mov    %rax,-0x20(%rbp)
jmp    1128 <dsp_protocol_linear2Q15+0x28>
movzwl -0x2(%rbp),%eax
cmp    $0x0,%eax
jne    114c <dsp_protocol_linear2Q15+0x4c>
mov    -0x10(%rbp),%rax
movw   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movw   $0x0,(%rax)
jmp    1194 <dsp_protocol_linear2Q15+0x94>
mov    -0x18(%rbp),%rax
movw   $0x1,(%rax)
cmpq   $0x40000000,-0x20(%rbp)
40
jae    1182 <dsp_protocol_linear2Q15+0x82>
mov    -0x18(%rbp),%rax
mov    (%rax),%cx
add    $0xffff,%cx
mov    %cx,(%rax)
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1155 <dsp_protocol_linear2Q15+0x55>
mov    -0x20(%rbp),%rax
shr    $0x10,%rax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
jmp    1199 <dsp_protocol_linear2Q15+0x99>
jmp    119e <dsp_protocol_linear2Q15+0x9e>
jmp    11a3 <dsp_protocol_linear2Q15+0xa3>
jmp    11a8 <dsp_protocol_linear2Q15+0xa8>
pop    %rbp
ret

x86 assembly (clang, -O2):
<dsp_protocol_linear2Q15>:
test   %edi,%edi
je     113d <dsp_protocol_linear2Q15+0x3d>
movzwl %di,%eax
imul   $0xa3d70a,%eax,%eax
movw   $0x1,(%rdx)
cmp    $0x3fffffff,%eax
ja     1135 <dsp_protocol_linear2Q15+0x35>
mov    $0x1,%cx
nopl   (%rax)
mov    %rax,%rdi
add    $0xffffffff,%ecx
add    %rax,%rax
cmp    $0x20000000,%rdi
jb     1120 <dsp_protocol_linear2Q15+0x20>
mov    %cx,(%rdx)
shr    $0x10,%rax
mov    %ax,(%rsi)
ret
movw   $0x0,(%rsi)
movw   $0x0,(%rdx)
ret

LLVM IR (-O0):
define void @dsp_protocol_linear2Q15(i16 zeroext %0, i16* %1, i16* %2) {
%4 = alloca i16
%5 = alloca i16*
%6 = alloca i16*
%7 = alloca i64
store i16 %0, i16* %4
store i16* %1, i16** %5
store i16* %2, i16** %6
%8 = load i16, i16* %4
%9 = zext i16 %8 to i32
%10 = mul nsw i32 10737418, %9
%11 = sext i32 %10 to i64
store i64 %11, i64* %7
br label %12
12: ; preds = %3
br label %13
13: ; preds = %12
%14 = load i16, i16* %4
%15 = zext i16 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i16*, i16** %5
store i16 0, i16* %18
%19 = load i16*, i16** %6
store i16 0, i16* %19
br label %36
20: ; preds = %13
%21 = load i16*, i16** %6
store i16 1, i16* %21
br label %22
22: ; preds = %25, %20
%23 = load i64, i64* %7
%24 = icmp ult i64 %23, 1073741824
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i16*, i16** %6
%27 = load i16, i16* %26
%28 = add i16 %27, -1
store i16 %28, i16* %26
%29 = load i64, i64* %7
%30 = shl i64 %29, 1
store i64 %30, i64* %7
br label %22
31: ; preds = %22
%32 = load i64, i64* %7
%33 = lshr i64 %32, 16
%34 = trunc i64 %33 to i16
%35 = load i16*, i16** %5
store i16 %34, i16* %35
br label %36
36: ; preds = %31, %17
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37
br label %39
39: ; preds = %38
br label %40
40: ; preds = %39
ret void
}

LLVM IR (-O2):
define void @dsp_protocol_linear2Q15(i16 zeroext %0, i16* nocapture writeonly %1, i16* nocapture %2) {
%4 = icmp eq i16 %0, 0
br i1 %4, label %5, label %6
5: ; preds = %3
store i16 0, i16* %1
store i16 0, i16* %2
br label %22
6: ; preds = %3
%7 = zext i16 %0 to i64
%8 = mul nuw nsw i64 %7, 10737418
%9 = and i64 %8, 4294967294
store i16 1, i16* %2
%10 = icmp ult i64 %9, 1073741824
br i1 %10, label %11, label %18
11: ; preds = %6, %11
%12 = phi i16 [ %14, %11 ], [ 1, %6 ]
%13 = phi i64 [ %15, %11 ], [ %9, %6 ]
%14 = add i16 %12, -1
%15 = shl nuw nsw i64 %13, 1
%16 = icmp ult i64 %13, 536870912
br i1 %16, label %11, label %17
17: ; preds = %11
store i16 %14, i16* %2
br label %18
18: ; preds = %17, %6
%19 = phi i64 [ %15, %17 ], [ %9, %6 ]
%20 = lshr i64 %19, 16
%21 = trunc i64 %20 to i16
store i16 %21, i16* %1
br label %22
22: ; preds = %18, %5
ret void
}