#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 */
typedef int int32_t;
typedef int int16_t;

/* Variables and functions */
int16_t get_scaled_mv(int16_t mv, int scale) {
  int32_t scaled = scale * mv;
  return ((((-32768)) > (((((32767)) < (((scaled + 127 + (scaled < 0)) >> 8)))
                              ? ((32767))
                              : (((scaled + 127 + (scaled < 0)) >> 8)))))
              ? ((-32768))
              : (((((32767)) < (((scaled + 127 + (scaled < 0)) >> 8)))
                      ? ((32767))
                      : (((scaled + 127 + (scaled < 0)) >> 8)))));
}


x86 assembly (clang, -O0):
<get_scaled_mv>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
imul   -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
add    $0x7f,%ecx
cmpl   $0x0,-0xc(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
add    %eax,%ecx
sar    $0x8,%ecx
mov    $0x7fff,%eax
cmp    %ecx,%eax
jge    1145 <get_scaled_mv+0x45>
mov    $0x7fff,%eax
mov    %eax,-0x10(%rbp)
jmp    1160 <get_scaled_mv+0x60>
mov    -0xc(%rbp),%eax
add    $0x7f,%eax
cmpl   $0x0,-0xc(%rbp)
setl   %cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
sar    $0x8,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
mov    $0xffff8000,%eax
cmp    %ecx,%eax
jle    117d <get_scaled_mv+0x7d>
mov    $0xffff8000,%eax
mov    %eax,-0x14(%rbp)
jmp    11cf <get_scaled_mv+0xcf>
mov    -0xc(%rbp),%ecx
add    $0x7f,%ecx
cmpl   $0x0,-0xc(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
add    %eax,%ecx
sar    $0x8,%ecx
mov    $0x7fff,%eax
cmp    %ecx,%eax
jge    11ae <get_scaled_mv+0xae>
mov    $0x7fff,%eax
mov    %eax,-0x18(%rbp)
jmp    11c9 <get_scaled_mv+0xc9>
mov    -0xc(%rbp),%eax
add    $0x7f,%eax
cmpl   $0x0,-0xc(%rbp)
setl   %cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
sar    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_scaled_mv>:
imul   %esi,%edi
mov    %edi,%eax
shr    $0x1f,%eax
add    %edi,%eax
add    $0x7f,%eax
mov    %eax,%ecx
sar    $0x8,%ecx
cmp    $0x800000,%eax
mov    $0x7fff,%edx
cmovl  %ecx,%edx
cmp    $0xff800000,%eax
mov    $0xffff8000,%eax
cmovge %edx,%eax
ret

LLVM IR (-O0):
define i32 @get_scaled_mv(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = load i32, i32* %3
%8 = mul nsw i32 %6, %7
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = add nsw i32 %9, 127
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 0
%13 = zext i1 %12 to i32
%14 = add nsw i32 %10, %13
%15 = ashr i32 %14, 8
%16 = icmp slt i32 32767, %15
br i1 %16, label %17, label %18
17: ; preds = %2
br label %26
18: ; preds = %2
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 127
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 0
%23 = zext i1 %22 to i32
%24 = add nsw i32 %20, %23
%25 = ashr i32 %24, 8
br label %26
26: ; preds = %18, %17
%27 = phi i32 [ 32767, %17 ], [ %25, %18 ]
%28 = icmp sgt i32 -32768, %27
br i1 %28, label %29, label %30
29: ; preds = %26
br label %50
30: ; preds = %26
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 127
%33 = load i32, i32* %5
%34 = icmp slt i32 %33, 0
%35 = zext i1 %34 to i32
%36 = add nsw i32 %32, %35
%37 = ashr i32 %36, 8
%38 = icmp slt i32 32767, %37
br i1 %38, label %39, label %40
39: ; preds = %30
br label %48
40: ; preds = %30
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 127
%43 = load i32, i32* %5
%44 = icmp slt i32 %43, 0
%45 = zext i1 %44 to i32
%46 = add nsw i32 %42, %45
%47 = ashr i32 %46, 8
br label %48
48: ; preds = %40, %39
%49 = phi i32 [ 32767, %39 ], [ %47, %40 ]
br label %50
50: ; preds = %48, %29
%51 = phi i32 [ -32768, %29 ], [ %49, %48 ]
ret i32 %51
}

LLVM IR (-O2):
define i32 @get_scaled_mv(i32 %0, i32 %1) {
%3 = mul nsw i32 %1, %0
%4 = add nsw i32 %3, 127
%5 = lshr i32 %3, 31
%6 = add nsw i32 %4, %5
%7 = ashr i32 %6, 8
%8 = icmp sgt i32 %6, 8388607
%9 = icmp slt i32 %6, -8388608
%10 = select i1 %8, i32 32767, i32 %7
%11 = select i1 %9, i32 -32768, i32 %10
ret i32 %11
}