#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 /*<<< orphan*/ uint8_t;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
void set_sid_coefficients(volatile uint8_t *filter_ram, uint16_t *coefficients,
                          int mul, int div) {
  for (int i = 0; i < 1024; i++) {
    uint32_t value = coefficients[i];
    value *= mul;
    value /= div;
    *(filter_ram++) = (value & 0xFF);
    *(filter_ram++) = (value >> 8);
  }
}


x86 assembly (clang, -O0):
<set_sid_coefficients>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x400,-0x1c(%rbp)
jge    1189 <set_sid_coefficients+0x89>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
mov    -0x20(%rbp),%ecx
sar    $0x8,%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1119 <set_sid_coefficients+0x19>
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_sid_coefficients>:
mov    %edx,%r8d
xor    %r9d,%r9d
cs nopw 0x0(%rax,%rax,1)
mov    (%rsi,%r9,4),%eax
imul   %r8d,%eax
cltd
idiv   %ecx
movzbl %al,%edx
mov    %edx,(%rdi,%r9,8)
sar    $0x8,%eax
mov    %eax,0x4(%rdi,%r9,8)
mov    0x4(%rsi,%r9,4),%eax
imul   %r8d,%eax
cltd
idiv   %ecx
movzbl %al,%edx
mov    %edx,0x8(%rdi,%r9,8)
sar    $0x8,%eax
mov    %eax,0xc(%rdi,%r9,8)
add    $0x2,%r9
cmp    $0x400,%r9
jne    1110 <set_sid_coefficients+0x10>
ret

LLVM IR (-O0):
define void @set_sid_coefficients(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %11
11: ; preds = %34, %4
%12 = load i32, i32* %9
%13 = icmp slt i32 %12, 1024
br i1 %13, label %14, label %37
14: ; preds = %11
%15 = load i32*, i32** %6
%16 = load i32, i32* %9
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
store i32 %19, i32* %10
%20 = load i32, i32* %7
%21 = load i32, i32* %10
%22 = mul nsw i32 %21, %20
store i32 %22, i32* %10
%23 = load i32, i32* %8
%24 = load i32, i32* %10
%25 = sdiv i32 %24, %23
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = and i32 %26, 255
%28 = load i32*, i32** %5
%29 = getelementptr inbounds i32, i32* %28, i32 1
store i32* %29, i32** %5
store volatile i32 %27, i32* %28
%30 = load i32, i32* %10
%31 = ashr i32 %30, 8
%32 = load i32*, i32** %5
%33 = getelementptr inbounds i32, i32* %32, i32 1
store i32* %33, i32** %5
store volatile i32 %31, i32* %32
br label %34
34: ; preds = %14
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %11
37: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @set_sid_coefficients(i32* %0, i32* nocapture %1, i32 %2, i32 %3) {
br label %6
5: ; preds = %6
ret void
6: ; preds = %6, %4
%7 = phi i64 [ 0, %4 ], [ %26, %6 ]
%8 = phi i32* [ %0, %4 ], [ %25, %6 ]
%9 = getelementptr inbounds i32, i32* %1, i64 %7
%10 = load i32, i32* %9
%11 = mul nsw i32 %10, %2
%12 = sdiv i32 %11, %3
%13 = and i32 %12, 255
%14 = getelementptr inbounds i32, i32* %8, i64 1
store volatile i32 %13, i32* %8
%15 = ashr i32 %12, 8
%16 = getelementptr inbounds i32, i32* %8, i64 2
store volatile i32 %15, i32* %14
%17 = or i64 %7, 1
%18 = getelementptr inbounds i32, i32* %1, i64 %17
%19 = load i32, i32* %18
%20 = mul nsw i32 %19, %2
%21 = sdiv i32 %20, %3
%22 = and i32 %21, 255
%23 = getelementptr inbounds i32, i32* %8, i64 3
store volatile i32 %22, i32* %16
%24 = ashr i32 %21, 8
%25 = getelementptr inbounds i32, i32* %8, i64 4
store volatile i32 %24, i32* %23
%26 = add nuw nsw i64 %7, 2
%27 = icmp eq i64 %26, 1024
br i1 %27, label %5, label %6
}