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

/* Variables and functions */
int /*<<< orphan*/ quickMedianFilter3(int /*<<< orphan*/ *);
int32_t applyBarometerMedianFilter(int32_t newPressureReading) {
  static int32_t barometerFilterSamples[3];
  static int currentFilterSampleIndex = 0;
  static bool medianFilterReady = false;
  int nextSampleIndex;
  nextSampleIndex = (currentFilterSampleIndex + 1);
  if (nextSampleIndex == 3) {
    nextSampleIndex = 0;
    medianFilterReady = true;
  }
  barometerFilterSamples[currentFilterSampleIndex] = newPressureReading;
  currentFilterSampleIndex = nextSampleIndex;
  if (medianFilterReady)
    return quickMedianFilter3(barometerFilterSamples);
  else
    return newPressureReading;
}


x86 assembly (clang, -O0):
<applyBarometerMedianFilter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2f17(%rip),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jne    1142 <applyBarometerMedianFilter+0x32>
movl   $0x0,-0xc(%rbp)
movl   $0x1,0x2efa(%rip)
mov    -0x8(%rbp),%edx
movslq 0x2eec(%rip),%rcx
lea    0x2ed9(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
mov    %eax,0x2ed9(%rip)
cmpl   $0x0,0x2ed6(%rip)
je     1180 <applyBarometerMedianFilter+0x70>
lea    0x2eb9(%rip),%rdi
call   1030 <quickMedianFilter3@plt>
mov    %eax,-0x4(%rbp)
jmp    1186 <applyBarometerMedianFilter+0x76>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<applyBarometerMedianFilter>:
mov    0x2f22(%rip),%eax
lea    0x1(%rax),%ecx
cmp    $0x3,%ecx
jne    113b <applyBarometerMedianFilter+0x2b>
movb   $0x1,0x2f17(%rip)
lea    0x2f00(%rip),%rcx
mov    %edi,(%rcx,%rax,4)
movl   $0x0,0x2eff(%rip)
jmp    1158 <applyBarometerMedianFilter+0x48>
mov    0x2efb(%rip),%dl
cltq
lea    0x2ee2(%rip),%rsi
mov    %edi,(%rsi,%rax,4)
mov    %ecx,0x2ee5(%rip)
cmp    $0x1,%dl
jne    1164 <applyBarometerMedianFilter+0x54>
lea    0x2ecd(%rip),%rdi
jmp    1030 <quickMedianFilter3@plt>
mov    %edi,%eax
ret

LLVM IR (-O0):
@applyBarometerMedianFilter.barometerFilterSamples = internal global [3 x i32] zeroinitializer
@applyBarometerMedianFilter.currentFilterSampleIndex = internal global i32 0
@applyBarometerMedianFilter.medianFilterReady = internal global i32 0
define i32 @applyBarometerMedianFilter(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* @applyBarometerMedianFilter.currentFilterSampleIndex
%6 = add nsw i32 %5, 1
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 3
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %4
store i32 1, i32* @applyBarometerMedianFilter.medianFilterReady
br label %10
10: ; preds = %9, %1
%11 = load i32, i32* %3
%12 = load i32, i32* @applyBarometerMedianFilter.currentFilterSampleIndex
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [3 x i32], [3 x i32]* @applyBarometerMedianFilter.barometerFilterSamples, i64 0, i64 %13
store i32 %11, i32* %14
%15 = load i32, i32* %4
store i32 %15, i32* @applyBarometerMedianFilter.currentFilterSampleIndex
%16 = load i32, i32* @applyBarometerMedianFilter.medianFilterReady
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 @quickMedianFilter3(i32* getelementptr inbounds ([3 x i32], [3 x i32]* @applyBarometerMedianFilter.barometerFilterSamples, i64 0, i64 0))
store i32 %19, i32* %2
br label %22
20: ; preds = %10
%21 = load i32, i32* %3
store i32 %21, i32* %2
br label %22
22: ; preds = %20, %18
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@applyBarometerMedianFilter.barometerFilterSamples = internal global [3 x i32] zeroinitializer
@applyBarometerMedianFilter.currentFilterSampleIndex = internal unnamed_addr global i32 0
@applyBarometerMedianFilter.medianFilterReady = internal unnamed_addr global i1 false
define i32 @applyBarometerMedianFilter(i32 %0) {
%2 = load i32, i32* @applyBarometerMedianFilter.currentFilterSampleIndex
%3 = add nsw i32 %2, 1
%4 = icmp eq i32 %3, 3
br i1 %4, label %5, label %8
5: ; preds = %1
store i1 true, i1* @applyBarometerMedianFilter.medianFilterReady
%6 = zext i32 %2 to i64
%7 = getelementptr inbounds [3 x i32], [3 x i32]* @applyBarometerMedianFilter.barometerFilterSamples, i64 0, i64 %6
store i32 %0, i32* %7
store i32 0, i32* @applyBarometerMedianFilter.currentFilterSampleIndex
br label %12
8: ; preds = %1
%9 = load i1, i1* @applyBarometerMedianFilter.medianFilterReady
%10 = sext i32 %2 to i64
%11 = getelementptr inbounds [3 x i32], [3 x i32]* @applyBarometerMedianFilter.barometerFilterSamples, i64 0, i64 %10
store i32 %0, i32* %11
store i32 %3, i32* @applyBarometerMedianFilter.currentFilterSampleIndex
br i1 %9, label %12, label %14
12: ; preds = %5, %8
%13 = tail call i32 @quickMedianFilter3(i32* getelementptr inbounds ([3 x i32], [3 x i32]* @applyBarometerMedianFilter.barometerFilterSamples, i64 0, i64 0))
br label %14
14: ; preds = %8, %12
%15 = phi i32 [ %13, %12 ], [ %0, %8 ]
ret i32 %15
}