int hpfilt(int datum, int init) {
  static long y = 0;
  static int data[13], ptr = 0;
  int z, halfPtr;
  if (init) {
    for (ptr = 0; ptr < 13; ++ptr)
      data[ptr] = 0;
    ptr = 0;
    y = 0;
  }
  y += datum - data[ptr];
  halfPtr = ptr - (13 / 2);
  if (halfPtr < 0)
    halfPtr += 13;
  z = data[halfPtr] - (y / 13);
  data[ptr] = datum;
  if (++ptr == 13)
    ptr = 0;
  return z;
}


x86 assembly (clang, -O0):
<hpfilt>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1169 <hpfilt+0x69>
movl   $0x0,0x2f56(%rip)
cmpl   $0xd,0x2f4f(%rip)
jge    1154 <hpfilt+0x54>
movslq 0x2f42(%rip),%rcx
lea    0x2f07(%rip),%rax
movl   $0x0,(%rax,%rcx,4)
mov    0x2f2e(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2f25(%rip)
jmp    111e <hpfilt+0x1e>
movl   $0x0,0x2f16(%rip)
movq   $0x0,0x2ec7(%rip)
mov    -0x4(%rbp),%eax
movslq 0x2f01(%rip),%rdx
lea    0x2ec6(%rip),%rcx
sub    (%rcx,%rdx,4),%eax
cltq
add    0x2eaa(%rip),%rax
mov    %rax,0x2ea3(%rip)
mov    0x2ee1(%rip),%eax
sub    $0x6,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11ac <hpfilt+0xac>
mov    -0x10(%rbp),%eax
add    $0xd,%eax
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rcx
lea    0x2e89(%rip),%rax
movslq (%rax,%rcx,4),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e6a(%rip),%rax
mov    $0xd,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edx
movslq 0x2e8d(%rip),%rcx
lea    0x2e52(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    0x2e7d(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e74(%rip)
cmp    $0xd,%eax
jne    1213 <hpfilt+0x113>
movl   $0x0,0x2e61(%rip)
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hpfilt>:
test   %esi,%esi
je     112e <hpfilt+0x2e>
xorps  %xmm0,%xmm0
movaps %xmm0,0x2f52(%rip)
movaps %xmm0,0x2f3b(%rip)
movaps %xmm0,0x2f24(%rip)
movl   $0x0,0x2f4a(%rip)
xor    %eax,%eax
xor    %ecx,%ecx
xor    %edx,%edx
jmp    1146 <hpfilt+0x46>
movslq 0x2f3f(%rip),%rdx
lea    0x2f04(%rip),%rax
mov    (%rax,%rdx,4),%ecx
mov    0x2eea(%rip),%rax
movslq %edx,%rsi
mov    %edi,%edx
sub    %ecx,%edx
movslq %edx,%rcx
add    %rax,%rcx
lea    -0x6(%rsi),%eax
lea    0x7(%rsi),%r8d
cmp    $0x6,%esi
cmovge %eax,%r8d
movabs $0xb13b13b13b13b13b,%rdx
13 3b b1
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x2,%rdx
add    %edx,%eax
lea    0x2ebb(%rip),%r9
movslq %r8d,%rdx
add    (%r9,%rdx,4),%eax
mov    %rcx,0x2e9d(%rip)
mov    %edi,(%r9,%rsi,4)
lea    0x1(%rsi),%ecx
xor    %edx,%edx
cmp    $0xd,%ecx
cmovne %ecx,%edx
mov    %edx,0x2ecc(%rip)
ret

LLVM IR (-O0):
@hpfilt.y = internal global i64 0
@hpfilt.data = internal global [13 x i32] zeroinitializer
@hpfilt.ptr = internal global i32 0
define i32 @hpfilt(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %2
store i32 0, i32* @hpfilt.ptr
br label %10
10: ; preds = %17, %9
%11 = load i32, i32* @hpfilt.ptr
%12 = icmp slt i32 %11, 13
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* @hpfilt.ptr
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [13 x i32], [13 x i32]* @hpfilt.data, i64 0, i64 %15
store i32 0, i32* %16
br label %17
17: ; preds = %13
%18 = load i32, i32* @hpfilt.ptr
%19 = add nsw i32 %18, 1
store i32 %19, i32* @hpfilt.ptr
br label %10
20: ; preds = %10
store i32 0, i32* @hpfilt.ptr
store i64 0, i64* @hpfilt.y
br label %21
21: ; preds = %20, %2
%22 = load i32, i32* %3
%23 = load i32, i32* @hpfilt.ptr
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [13 x i32], [13 x i32]* @hpfilt.data, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = sub nsw i32 %22, %26
%28 = sext i32 %27 to i64
%29 = load i64, i64* @hpfilt.y
%30 = add nsw i64 %29, %28
store i64 %30, i64* @hpfilt.y
%31 = load i32, i32* @hpfilt.ptr
%32 = sub nsw i32 %31, 6
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %21
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 13
store i32 %37, i32* %6
br label %38
38: ; preds = %35, %21
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [13 x i32], [13 x i32]* @hpfilt.data, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = sext i32 %42 to i64
%44 = load i64, i64* @hpfilt.y
%45 = sdiv i64 %44, 13
%46 = sub nsw i64 %43, %45
%47 = trunc i64 %46 to i32
store i32 %47, i32* %5
%48 = load i32, i32* %3
%49 = load i32, i32* @hpfilt.ptr
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [13 x i32], [13 x i32]* @hpfilt.data, i64 0, i64 %50
store i32 %48, i32* %51
%52 = load i32, i32* @hpfilt.ptr
%53 = add nsw i32 %52, 1
store i32 %53, i32* @hpfilt.ptr
%54 = icmp eq i32 %53, 13
br i1 %54, label %55, label %56
55: ; preds = %38
store i32 0, i32* @hpfilt.ptr
br label %56
56: ; preds = %55, %38
%57 = load i32, i32* %5
ret i32 %57
}

LLVM IR (-O2):
@hpfilt.y = internal unnamed_addr global i64 0
@hpfilt.data = internal unnamed_addr global [13 x i32] zeroinitializer
@hpfilt.ptr = internal unnamed_addr global i32 0
define i32 @hpfilt(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = load i32, i32* @hpfilt.ptr
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [13 x i32], [13 x i32]* @hpfilt.data, i64 0, i64 %6
%8 = load i32, i32* %7
%9 = load i64, i64* @hpfilt.y
br label %11
10: ; preds = %2
br label %11
11: ; preds = %4, %10
%12 = phi i64 [ %9, %4 ], [ 0, %10 ]
%13 = phi i32 [ %8, %4 ], [ 0, %10 ]
%14 = phi i32 [ %5, %4 ], [ 0, %10 ]
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [13 x i32], [13 x i32]* @hpfilt.data, i64 0, i64 %15
%17 = sub nsw i32 %0, %13
%18 = sext i32 %17 to i64
%19 = add nsw i64 %12, %18
store i64 %19, i64* @hpfilt.y
%20 = icmp slt i32 %14, 6
%21 = select i1 %20, i32 7, i32 -6
%22 = add nsw i32 %21, %14
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [13 x i32], [13 x i32]* @hpfilt.data, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = sdiv i64 %19, -13
%27 = trunc i64 %26 to i32
%28 = add i32 %25, %27
store i32 %0, i32* %16
%29 = add nsw i32 %14, 1
%30 = icmp eq i32 %29, 13
%31 = select i1 %30, i32 0, i32 %29
store i32 %31, i32* @hpfilt.ptr
ret i32 %28
}