#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 iirLPFilterSingle(int32_t in, int32_t attenuation, int32_t *filt) {
  int32_t inScaled;
  int32_t filttmp = *filt;
  int16_t out;
  if (attenuation > (1 << 8)) {
    attenuation = (1 << 8);
  } else if (attenuation < 1) {
    attenuation = 1;
  }
  inScaled = in << 8;
  filttmp = filttmp + (((inScaled - filttmp) >> 8) * attenuation);
  out = (filttmp >> 8) + ((filttmp & (1 << (8 - 1))) >> (8 - 1));
  *filt = filttmp;
  return out;
}


x86 assembly (clang, -O0):
<iirLPFilterSingle>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x100,-0x8(%rbp)
jle    1130 <iirLPFilterSingle+0x30>
movl   $0x100,-0x8(%rbp)
jmp    1146 <iirLPFilterSingle+0x46>
cmpl   $0x1,-0x8(%rbp)
jge    1141 <iirLPFilterSingle+0x41>
movl   $0x1,-0x8(%rbp)
jmp    1146 <iirLPFilterSingle+0x46>
mov    -0x4(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    -0x18(%rbp),%ecx
sar    $0x8,%ecx
imul   -0x8(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
mov    -0x18(%rbp),%ecx
and    $0x80,%ecx
sar    $0x7,%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<iirLPFilterSingle>:
mov    (%rdx),%eax
test   %esi,%esi
mov    $0x1,%ecx
cmovg  %esi,%ecx
cmp    $0x100,%ecx
mov    $0x100,%esi
cmovb  %ecx,%esi
shl    $0x8,%edi
sub    %eax,%edi
sar    $0x8,%edi
imul   %esi,%edi
add    %eax,%edi
mov    %edi,%eax
mov    %edi,(%rdx)
sar    $0x8,%edi
shr    $0x7,%eax
and    $0x1,%eax
add    %edi,%eax
ret

LLVM IR (-O0):
define i32 @iirLPFilterSingle(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%10 = load i32*, i32** %6
%11 = load i32, i32* %10
store i32 %11, i32* %8
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 256
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 256, i32* %5
br label %20
15: ; preds = %3
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 1, i32* %5
br label %19
19: ; preds = %18, %15
br label %20
20: ; preds = %19, %14
%21 = load i32, i32* %4
%22 = shl i32 %21, 8
store i32 %22, i32* %7
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = sub nsw i32 %24, %25
%27 = ashr i32 %26, 8
%28 = load i32, i32* %5
%29 = mul nsw i32 %27, %28
%30 = add nsw i32 %23, %29
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = ashr i32 %31, 8
%33 = load i32, i32* %8
%34 = and i32 %33, 128
%35 = ashr i32 %34, 7
%36 = add nsw i32 %32, %35
store i32 %36, i32* %9
%37 = load i32, i32* %8
%38 = load i32*, i32** %6
store i32 %37, i32* %38
%39 = load i32, i32* %9
ret i32 %39
}

LLVM IR (-O2):
define i32 @iirLPFilterSingle(i32 %0, i32 %1, i32* nocapture %2) {
%4 = load i32, i32* %2
%5 = icmp sgt i32 %1, 1
%6 = select i1 %5, i32 %1, i32 1
%7 = icmp ult i32 %6, 256
%8 = select i1 %7, i32 %6, i32 256
%9 = shl i32 %0, 8
%10 = sub nsw i32 %9, %4
%11 = ashr i32 %10, 8
%12 = mul nsw i32 %11, %8
%13 = add nsw i32 %12, %4
%14 = ashr i32 %13, 8
%15 = lshr i32 %13, 7
%16 = and i32 %15, 1
%17 = add nsw i32 %16, %14
store i32 %13, i32* %2
ret i32 %17
}