#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 */
int /*<<< orphan*/ printf(char *, unsigned long);
void threshold(double *phi, unsigned long nvox, double limit) {
  unsigned long m, v;
  v = nvox;
  for (m = 0; m < nvox; m++)
    if (*(phi + m) < limit) {
      *(phi + m) = 0.0;
      --v;
    }
  printf("lib_vwk> Setting density values below %f to zero.\n", limit);
  printf("lib_vwk> Remaining occupied volume: %lu voxels.\n", v);
}


x86 assembly (clang, -O0):
<threshold>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1191 <threshold+0x81>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    117b <threshold+0x6b>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    1180 <threshold+0x70>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1135 <threshold+0x25>
movsd  -0x18(%rbp),%xmm0
movsd  0xe62(%rip),%xmm2
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rax
cvttsd2si %xmm0,%rsi
mov    %rsi,%rcx
sar    $0x3f,%rcx
and    %rcx,%rax
or     %rax,%rsi
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<threshold>:
push   %rbx
test   %rsi,%rsi
je     113c <threshold+0x2c>
cmp    $0x1,%rsi
jne    1179 <threshold+0x69>
xor    %eax,%eax
mov    %rsi,%rbx
test   $0x1,%sil
je     113e <threshold+0x2e>
ucomisd (%rdi,%rax,8),%xmm0
jbe    113e <threshold+0x2e>
movq   $0x0,(%rdi,%rax,8)
add    $0xffffffffffffffff,%rbx
jmp    113e <threshold+0x2e>
xor    %ebx,%ebx
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
subsd  0xeae(%rip),%xmm0
cvttsd2si %xmm0,%rsi
and    %rcx,%rsi
or     %rax,%rsi
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
mov    %rbx,%rsi
pop    %rbx
jmp    1030 <printf@plt>
mov    %rsi,%rcx
and    $0xfffffffffffffffe,%rcx
xor    %eax,%eax
mov    %rsi,%rbx
jmp    1199 <threshold+0x89>
nopw   0x0(%rax,%rax,1)
add    $0x2,%rax
cmp    %rax,%rcx
je     1121 <threshold+0x11>
ucomisd (%rdi,%rax,8),%xmm0
jbe    11ac <threshold+0x9c>
movq   $0x0,(%rdi,%rax,8)
add    $0xffffffffffffffff,%rbx
ucomisd 0x8(%rdi,%rax,8),%xmm0
jbe    1190 <threshold+0x80>
movq   $0x0,0x8(%rdi,%rax,8)
add    $0xffffffffffffffff,%rbx
jmp    1190 <threshold+0x80>

LLVM IR (-O0):
@.str = [51 x i8] c"lib_vwk> Setting density values below %f to zero.\0A\00"
@.str.1 = [49 x i8] c"lib_vwk> Remaining occupied volume: %lu voxels.\0A\00"
define void @threshold(double* %0, i64 %1, double %2) {
%4 = alloca double*
%5 = alloca i64
%6 = alloca double
%7 = alloca i64
%8 = alloca i64
store double* %0, double** %4
store i64 %1, i64* %5
store double %2, double* %6
%9 = load i64, i64* %5
store i64 %9, i64* %8
store i64 0, i64* %7
br label %10
10: ; preds = %28, %3
%11 = load i64, i64* %7
%12 = load i64, i64* %5
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %31
14: ; preds = %10
%15 = load double*, double** %4
%16 = load i64, i64* %7
%17 = getelementptr inbounds double, double* %15, i64 %16
%18 = load double, double* %17
%19 = load double, double* %6
%20 = fcmp olt double %18, %19
br i1 %20, label %21, label %27
21: ; preds = %14
%22 = load double*, double** %4
%23 = load i64, i64* %7
%24 = getelementptr inbounds double, double* %22, i64 %23
store double 0.000000e+00, double* %24
%25 = load i64, i64* %8
%26 = add i64 %25, -1
store i64 %26, i64* %8
br label %27
27: ; preds = %21, %14
br label %28
28: ; preds = %27
%29 = load i64, i64* %7
%30 = add i64 %29, 1
store i64 %30, i64* %7
br label %10
31: ; preds = %10
%32 = load double, double* %6
%33 = fptoui double %32 to i64
%34 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i64 %33)
%35 = load i64, i64* %8
%36 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i64 %35)
ret void
}

LLVM IR (-O2):
@.str = [51 x i8] c"lib_vwk> Setting density values below %f to zero.\0A\00"
@.str.1 = [49 x i8] c"lib_vwk> Remaining occupied volume: %lu voxels.\0A\00"
define void @threshold(double* nocapture %0, i64 %1, double %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %43, label %5
5: ; preds = %3
%6 = and i64 %1, 1
%7 = icmp eq i64 %1, 1
br i1 %7, label %32, label %8
8: ; preds = %5
%9 = and i64 %1, -2
br label %10
10: ; preds = %27, %8
%11 = phi i64 [ %1, %8 ], [ %28, %27 ]
%12 = phi i64 [ 0, %8 ], [ %29, %27 ]
%13 = phi i64 [ 0, %8 ], [ %30, %27 ]
%14 = getelementptr inbounds double, double* %0, i64 %12
%15 = load double, double* %14
%16 = fcmp olt double %15, %2
br i1 %16, label %17, label %19
17: ; preds = %10
store double 0.000000e+00, double* %14
%18 = add i64 %11, -1
br label %19
19: ; preds = %10, %17
%20 = phi i64 [ %18, %17 ], [ %11, %10 ]
%21 = or i64 %12, 1
%22 = getelementptr inbounds double, double* %0, i64 %21
%23 = load double, double* %22
%24 = fcmp olt double %23, %2
br i1 %24, label %25, label %27
25: ; preds = %19
store double 0.000000e+00, double* %22
%26 = add i64 %20, -1
br label %27
27: ; preds = %25, %19
%28 = phi i64 [ %26, %25 ], [ %20, %19 ]
%29 = add nuw i64 %12, 2
%30 = add i64 %13, 2
%31 = icmp eq i64 %30, %9
br i1 %31, label %32, label %10
32: ; preds = %27, %5
%33 = phi i64 [ undef, %5 ], [ %28, %27 ]
%34 = phi i64 [ %1, %5 ], [ %28, %27 ]
%35 = phi i64 [ 0, %5 ], [ %29, %27 ]
%36 = icmp eq i64 %6, 0
br i1 %36, label %43, label %37
37: ; preds = %32
%38 = getelementptr inbounds double, double* %0, i64 %35
%39 = load double, double* %38
%40 = fcmp olt double %39, %2
br i1 %40, label %41, label %43
41: ; preds = %37
store double 0.000000e+00, double* %38
%42 = add i64 %34, -1
br label %43
43: ; preds = %32, %41, %37, %3
%44 = phi i64 [ 0, %3 ], [ %33, %32 ], [ %42, %41 ], [ %34, %37 ]
%45 = fptoui double %2 to i64
%46 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i64 %45)
%47 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i64 %44)
ret void
}