#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 step_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;
    } else
      *(phi + m) = 1.0;
  }
  printf("lib_vwk> Setting density values below %f to zero and equal or above "
         "to one.\n",
         limit);
  printf("lib_vwk> Remaining occupied volume: %lu voxels.\n", v);
}


x86 assembly (clang, -O0):
<step_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    11ab <step_threshold+0x9b>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1180 <step_threshold+0x70>
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    1195 <step_threshold+0x85>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  0xe78(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    119a <step_threshold+0x8a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1135 <step_threshold+0x25>
movsd  -0x18(%rbp),%xmm0
movsd  0xe48(%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    0xe33(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<step_threshold>:
push   %rbx
test   %rsi,%rsi
je     1147 <step_threshold+0x37>
cmp    $0x1,%rsi
jne    114e <step_threshold+0x3e>
xor    %eax,%eax
mov    %rsi,%rbx
test   $0x1,%sil
je     11d1 <step_threshold+0xc1>
ucomisd (%rdi,%rax,8),%xmm0
jbe    11c3 <step_threshold+0xb3>
movq   $0x0,(%rdi,%rax,8)
add    $0xffffffffffffffff,%rbx
jmp    11d1 <step_threshold+0xc1>
xor    %ebx,%ebx
jmp    11d1 <step_threshold+0xc1>
mov    %rsi,%rcx
and    $0xfffffffffffffffe,%rcx
xor    %eax,%eax
movabs $0x3ff0000000000000,%rdx
mov    %rsi,%rbx
jmp    1186 <step_threshold+0x76>
cs nopw 0x0(%rax,%rax,1)
movq   $0x0,0x8(%rdi,%rax,8)
add    $0xffffffffffffffff,%rbx
add    $0x2,%rax
cmp    %rax,%rcx
je     1121 <step_threshold+0x11>
ucomisd (%rdi,%rax,8),%xmm0
jbe    11b0 <step_threshold+0xa0>
movq   $0x0,(%rdi,%rax,8)
add    $0xffffffffffffffff,%rbx
ucomisd 0x8(%rdi,%rax,8),%xmm0
ja     1170 <step_threshold+0x60>
jmp    11bc <step_threshold+0xac>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rdx,(%rdi,%rax,8)
ucomisd 0x8(%rdi,%rax,8),%xmm0
ja     1170 <step_threshold+0x60>
mov    %rdx,0x8(%rdi,%rax,8)
jmp    117d <step_threshold+0x6d>
movabs $0x3ff0000000000000,%rcx
mov    %rcx,(%rdi,%rax,8)
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
subsd  0xe1b(%rip),%xmm0
cvttsd2si %xmm0,%rsi
and    %rcx,%rsi
or     %rax,%rsi
lea    0xe11(%rip),%rdi
call   1030 <printf@plt>
lea    0xe52(%rip),%rdi
mov    %rbx,%rsi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [77 x i8] c"lib_vwk> Setting density values below %f to zero and equal or above to one.\0A\00"
@.str.1 = [49 x i8] c"lib_vwk> Remaining occupied volume: %lu voxels.\0A\00"
define void @step_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 = %32, %3
%11 = load i64, i64* %7
%12 = load i64, i64* %5
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %35
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 %31
27: ; preds = %14
%28 = load double*, double** %4
%29 = load i64, i64* %7
%30 = getelementptr inbounds double, double* %28, i64 %29
store double 1.000000e+00, double* %30
br label %31
31: ; preds = %27, %21
br label %32
32: ; preds = %31
%33 = load i64, i64* %7
%34 = add i64 %33, 1
store i64 %34, i64* %7
br label %10
35: ; preds = %10
%36 = load double, double* %6
%37 = fptoui double %36 to i64
%38 = call i32 @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0), i64 %37)
%39 = load i64, i64* %8
%40 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i64 %39)
ret void
}

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