#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 */
double fabs(double);
int TruncateCoeffs(int fOrder, double threshold, double *kArray) {
  int i;
  for (i = fOrder; i >= 0; i--) {
    kArray[i] = (fabs(kArray[i]) > threshold) ? kArray[i] : 0.0;
    if (kArray[i] != 0.0)
      return i;
  }
  return 0;
}


x86 assembly (clang, -O0):
<TruncateCoeffs>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11bc <TruncateCoeffs+0xbc>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xecc(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    115a <TruncateCoeffs+0x5a>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1167 <TruncateCoeffs+0x67>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1167 <TruncateCoeffs+0x67>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    119e <TruncateCoeffs+0x9e>
jp     119e <TruncateCoeffs+0x9e>
jmp    11a9 <TruncateCoeffs+0xa9>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c3 <TruncateCoeffs+0xc3>
jmp    11ae <TruncateCoeffs+0xae>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1116 <TruncateCoeffs+0x16>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<TruncateCoeffs>:
xor    %eax,%eax
test   %edi,%edi
js     1153 <TruncateCoeffs+0x53>
mov    %edi,%ecx
movapd 0xef0(%rip),%xmm1
xorpd  %xmm2,%xmm2
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%rsi,%rcx,8),%xmm3
movapd %xmm3,%xmm4
andpd  %xmm1,%xmm4
movapd %xmm0,%xmm5
cmpltsd %xmm4,%xmm5
andpd  %xmm3,%xmm5
movlpd %xmm5,(%rsi,%rcx,8)
ucomisd %xmm2,%xmm5
jne    1154 <TruncateCoeffs+0x54>
jp     1154 <TruncateCoeffs+0x54>
lea    -0x1(%rcx),%rdx
test   %rcx,%rcx
mov    %rdx,%rcx
jg     1120 <TruncateCoeffs+0x20>
ret
mov    %ecx,%eax
ret

LLVM IR (-O0):
define i32 @TruncateCoeffs(i32 %0, double %1, double* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca double*
%8 = alloca i32
store i32 %0, i32* %5
store double %1, double* %6
store double* %2, double** %7
%9 = load i32, i32* %5
store i32 %9, i32* %8
br label %10
10: ; preds = %44, %3
%11 = load i32, i32* %8
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %47
13: ; preds = %10
%14 = load double*, double** %7
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = call double @llvm.fabs.f64(double %18)
%20 = load double, double* %6
%21 = fcmp ogt double %19, %20
br i1 %21, label %22, label %28
22: ; preds = %13
%23 = load double*, double** %7
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
br label %29
28: ; preds = %13
br label %29
29: ; preds = %28, %22
%30 = phi double [ %27, %22 ], [ 0.000000e+00, %28 ]
%31 = load double*, double** %7
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
store double %30, double* %34
%35 = load double*, double** %7
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = fcmp une double %39, 0.000000e+00
br i1 %40, label %41, label %43
41: ; preds = %29
%42 = load i32, i32* %8
store i32 %42, i32* %4
br label %48
43: ; preds = %29
br label %44
44: ; preds = %43
%45 = load i32, i32* %8
%46 = add nsw i32 %45, -1
store i32 %46, i32* %8
br label %10
47: ; preds = %10
store i32 0, i32* %4
br label %48
48: ; preds = %47, %41
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
define i32 @TruncateCoeffs(i32 %0, double %1, double* nocapture %2) {
%4 = icmp sgt i32 %0, -1
br i1 %4, label %5, label %20
5: ; preds = %3
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %15
%8 = phi i64 [ %6, %5 ], [ %16, %15 ]
%9 = getelementptr inbounds double, double* %2, i64 %8
%10 = load double, double* %9
%11 = tail call double @llvm.fabs.f64(double %10)
%12 = fcmp ogt double %11, %1
%13 = select i1 %12, double %10, double 0.000000e+00
store double %13, double* %9
%14 = fcmp une double %13, 0.000000e+00
br i1 %14, label %18, label %15
15: ; preds = %7
%16 = add nsw i64 %8, -1
%17 = icmp sgt i64 %8, 0
br i1 %17, label %7, label %20
18: ; preds = %7
%19 = trunc i64 %8 to i32
br label %20
20: ; preds = %15, %18, %3
%21 = phi i32 [ 0, %3 ], [ %19, %18 ], [ 0, %15 ]
ret i32 %21
}