#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 mpu_write_mem(int, int, unsigned char *);
int dmp_set_shake_reject_thresh(long sf, unsigned short thresh) {
  unsigned char tmp[4];
  long thresh_scaled = sf / 1000 * thresh;
  tmp[0] = (unsigned char)(((long)thresh_scaled >> 24) & 0xFF);
  tmp[1] = (unsigned char)(((long)thresh_scaled >> 16) & 0xFF);
  tmp[2] = (unsigned char)(((long)thresh_scaled >> 8) & 0xFF);
  tmp[3] = (unsigned char)((long)thresh_scaled & 0xFF);
  return mpu_write_mem((256 + 92), 4, tmp);
}


x86 assembly (clang, -O0):
<dmp_set_shake_reject_thresh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
movzwl -0xa(%rbp),%ecx
imul   %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sar    $0x18,%rax
and    $0xff,%rax
mov    %al,-0xe(%rbp)
mov    -0x18(%rbp),%rax
sar    $0x10,%rax
and    $0xff,%rax
mov    %al,-0xd(%rbp)
mov    -0x18(%rbp),%rax
sar    $0x8,%rax
and    $0xff,%rax
mov    %al,-0xc(%rbp)
mov    -0x18(%rbp),%rax
and    $0xff,%rax
mov    %al,-0xb(%rbp)
lea    -0xe(%rbp),%rdx
mov    $0x15c,%edi
mov    $0x4,%esi
call   1030 <mpu_write_mem@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmp_set_shake_reject_thresh>:
push   %rax
mov    %rdi,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x7,%rdx
add    %eax,%edx
imul   %esi,%edx
bswap  %edx
mov    %edx,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    $0x15c,%edi
mov    $0x4,%esi
call   1030 <mpu_write_mem@plt>
pop    %rcx
ret

LLVM IR (-O0):
define i32 @dmp_set_shake_reject_thresh(i64 %0, i16 zeroext %1) {
%3 = alloca i64
%4 = alloca i16
%5 = alloca [4 x i8]
%6 = alloca i64
store i64 %0, i64* %3
store i16 %1, i16* %4
%7 = load i64, i64* %3
%8 = sdiv i64 %7, 1000
%9 = load i16, i16* %4
%10 = zext i16 %9 to i64
%11 = mul nsw i64 %8, %10
store i64 %11, i64* %6
%12 = load i64, i64* %6
%13 = ashr i64 %12, 24
%14 = and i64 %13, 255
%15 = trunc i64 %14 to i8
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
store i8 %15, i8* %16
%17 = load i64, i64* %6
%18 = ashr i64 %17, 16
%19 = and i64 %18, 255
%20 = trunc i64 %19 to i8
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
store i8 %20, i8* %21
%22 = load i64, i64* %6
%23 = ashr i64 %22, 8
%24 = and i64 %23, 255
%25 = trunc i64 %24 to i8
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
store i8 %25, i8* %26
%27 = load i64, i64* %6
%28 = and i64 %27, 255
%29 = trunc i64 %28 to i8
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
store i8 %29, i8* %30
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%32 = call i32 @mpu_write_mem(i32 348, i32 4, i8* %31)
ret i32 %32
}

LLVM IR (-O2):
define i32 @dmp_set_shake_reject_thresh(i64 %0, i16 zeroext %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = sdiv i64 %0, 1000
%6 = zext i16 %1 to i64
%7 = mul nsw i64 %5, %6
%8 = lshr i64 %7, 24
%9 = trunc i64 %8 to i8
store i8 %9, i8* %4
%10 = lshr i64 %7, 16
%11 = trunc i64 %10 to i8
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
store i8 %11, i8* %12
%13 = lshr i64 %7, 8
%14 = trunc i64 %13 to i8
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
store i8 %14, i8* %15
%16 = trunc i64 %7 to i8
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
store i8 %16, i8* %17
%18 = call i32 @mpu_write_mem(i32 348, i32 4, i8* %4)
ret i32 %18
}