#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 */
scalar_t__ ceil(int);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ smooth_double(double *, int *, double *, double *, int);
int /*<<< orphan*/ subsample_double(double *, double *, int *, int *);
void smooth_subsample_double(double *vol, int dims[3], double separations[3],
                             double s[3], int use_mask, int samp) {
  int i, nvol_samp, nvol;
  int dims_samp[3];
  double *vol_samp, separations_samp[3];
  for (i = 0; i < 3; i++)
    dims_samp[i] = (int)ceil((dims[i] - 1) / ((double)samp)) + 1;
  for (i = 0; i < 3; i++)
    separations_samp[i] =
        separations[i] * ((double)dims[i] / (double)dims_samp[i]);
  nvol = dims[0] * dims[1] * dims[2];
  nvol_samp = dims_samp[0] * dims_samp[1] * dims_samp[2];
  vol_samp = (double *)malloc(sizeof(double) * nvol_samp);
  subsample_double(vol, vol_samp, dims, dims_samp);
  smooth_double(vol_samp, dims_samp, separations_samp, s, use_mask);
  subsample_double(vol_samp, vol, dims_samp, dims);
  free(vol_samp);
}


x86 assembly (clang, -O0):
<smooth_subsample_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x2c(%rbp)
jge    11c0 <smooth_subsample_double+0x70>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <ceil@plt>
mov    %eax,%ecx
add    $0x1,%ecx
movslq -0x2c(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1177 <smooth_subsample_double+0x27>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x2c(%rbp)
jge    1215 <smooth_subsample_double+0xc5>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm1
movslq -0x2c(%rbp),%rax
cvtsi2sdl -0x40(%rbp,%rax,4),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movslq -0x2c(%rbp),%rax
movsd  %xmm0,-0x60(%rbp,%rax,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c7 <smooth_subsample_double+0x77>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
imul   0x4(%rcx),%eax
mov    -0x10(%rbp),%rcx
imul   0x8(%rcx),%eax
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%eax
imul   -0x3c(%rbp),%eax
imul   -0x38(%rbp),%eax
mov    %eax,-0x30(%rbp)
movslq -0x30(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1060 <subsample_double@plt>
mov    -0x48(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x60(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
call   1030 <smooth_double@plt>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x40(%rbp),%rdx
mov    -0x10(%rbp),%rcx
call   1060 <subsample_double@plt>
mov    -0x48(%rbp),%rdi
call   1040 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smooth_subsample_double>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
cvtsi2sd %r9d,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    (%rsi),%eax
add    $0xffffffff,%eax
cvtsi2sd %eax,%xmm0
mov    %r8d,0x4(%rsp)
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rdi,%r14
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <ceil@plt>
mov    0x4(%rbx),%ecx
add    $0xffffffff,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mov    %rax,%rbp
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <ceil@plt>
movd   %ebp,%xmm1
movd   %eax,%xmm0
punpckldq %xmm0,%xmm1
pcmpeqd %xmm0,%xmm0
psubd  %xmm0,%xmm1
movdqa %xmm1,0x20(%rsp)
movd   %xmm1,0x14(%rsp)
pshufd $0x55,%xmm1,%xmm0
movd   %xmm0,%r15d
movd   %xmm0,0x18(%rsp)
mov    0x8(%rbx),%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movd   %xmm1,%ebp
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <ceil@plt>
add    $0x1,%eax
mov    %eax,0x1c(%rsp)
cvtdq2pd (%rbx),%xmm0
cvtdq2pd 0x20(%rsp),%xmm1
movupd 0x0(%r13),%xmm2
divpd  %xmm1,%xmm0
mulpd  %xmm2,%xmm0
movapd %xmm0,0x30(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sdl 0x8(%rbx),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
mulsd  0x10(%r13),%xmm0
movsd  %xmm0,0x40(%rsp)
imul   %eax,%ebp
imul   %r15d,%ebp
shl    $0x3,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
lea    0x14(%rsp),%r13
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
call   1060 <subsample_double@plt>
lea    0x30(%rsp),%rdx
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12,%rcx
mov    0x4(%rsp),%r8d
call   1030 <smooth_double@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1060 <subsample_double@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @smooth_subsample_double(double* %0, i32* %1, double* %2, double* %3, i32 %4, i32 %5) {
%7 = alloca double*
%8 = alloca i32*
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [3 x i32]
%17 = alloca double*
%18 = alloca [3 x double]
store double* %0, double** %7
store i32* %1, i32** %8
store double* %2, double** %9
store double* %3, double** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store i32 0, i32* %13
br label %19
19: ; preds = %40, %6
%20 = load i32, i32* %13
%21 = icmp slt i32 %20, 3
br i1 %21, label %22, label %43
22: ; preds = %19
%23 = load i32*, i32** %8
%24 = load i32, i32* %13
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = sub nsw i32 %27, 1
%29 = sitofp i32 %28 to double
%30 = load i32, i32* %12
%31 = sitofp i32 %30 to double
%32 = fdiv double %29, %31
%33 = fptosi double %32 to i32
%34 = call i64 @ceil(i32 %33)
%35 = trunc i64 %34 to i32
%36 = add nsw i32 %35, 1
%37 = load i32, i32* %13
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 %38
store i32 %36, i32* %39
br label %40
40: ; preds = %22
%41 = load i32, i32* %13
%42 = add nsw i32 %41, 1
store i32 %42, i32* %13
br label %19
43: ; preds = %19
store i32 0, i32* %13
br label %44
44: ; preds = %69, %43
%45 = load i32, i32* %13
%46 = icmp slt i32 %45, 3
br i1 %46, label %47, label %72
47: ; preds = %44
%48 = load double*, double** %9
%49 = load i32, i32* %13
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
%52 = load double, double* %51
%53 = load i32*, i32** %8
%54 = load i32, i32* %13
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = load i32, i32* %56
%58 = sitofp i32 %57 to double
%59 = load i32, i32* %13
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 %60
%62 = load i32, i32* %61
%63 = sitofp i32 %62 to double
%64 = fdiv double %58, %63
%65 = fmul double %52, %64
%66 = load i32, i32* %13
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [3 x double], [3 x double]* %18, i64 0, i64 %67
store double %65, double* %68
br label %69
69: ; preds = %47
%70 = load i32, i32* %13
%71 = add nsw i32 %70, 1
store i32 %71, i32* %13
br label %44
72: ; preds = %44
%73 = load i32*, i32** %8
%74 = getelementptr inbounds i32, i32* %73, i64 0
%75 = load i32, i32* %74
%76 = load i32*, i32** %8
%77 = getelementptr inbounds i32, i32* %76, i64 1
%78 = load i32, i32* %77
%79 = mul nsw i32 %75, %78
%80 = load i32*, i32** %8
%81 = getelementptr inbounds i32, i32* %80, i64 2
%82 = load i32, i32* %81
%83 = mul nsw i32 %79, %82
store i32 %83, i32* %15
%84 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 0
%85 = load i32, i32* %84
%86 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 1
%87 = load i32, i32* %86
%88 = mul nsw i32 %85, %87
%89 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 2
%90 = load i32, i32* %89
%91 = mul nsw i32 %88, %90
store i32 %91, i32* %14
%92 = load i32, i32* %14
%93 = sext i32 %92 to i64
%94 = mul i64 8, %93
%95 = trunc i64 %94 to i32
%96 = call i64 @malloc(i32 %95)
%97 = inttoptr i64 %96 to double*
store double* %97, double** %17
%98 = load double*, double** %7
%99 = load double*, double** %17
%100 = load i32*, i32** %8
%101 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 0
%102 = call i32 @subsample_double(double* %98, double* %99, i32* %100, i32* %101)
%103 = load double*, double** %17
%104 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 0
%105 = getelementptr inbounds [3 x double], [3 x double]* %18, i64 0, i64 0
%106 = load double*, double** %10
%107 = load i32, i32* %11
%108 = call i32 @smooth_double(double* %103, i32* %104, double* %105, double* %106, i32 %107)
%109 = load double*, double** %17
%110 = load double*, double** %7
%111 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 0
%112 = load i32*, i32** %8
%113 = call i32 @subsample_double(double* %109, double* %110, i32* %111, i32* %112)
%114 = load double*, double** %17
%115 = call i32 @free(double* %114)
ret void
}

LLVM IR (-O2):
define void @smooth_subsample_double(double* %0, i32* %1, double* nocapture %2, double* %3, i32 %4, i32 %5) {
%7 = alloca [3 x i32]
%8 = alloca [3 x double]
%9 = bitcast [3 x i32]* %7 to i8*
%10 = bitcast [3 x double]* %8 to i8*
%11 = sitofp i32 %5 to double
%12 = load i32, i32* %1
%13 = add nsw i32 %12, -1
%14 = sitofp i32 %13 to double
%15 = fdiv double %14, %11
%16 = fptosi double %15 to i32
%17 = tail call i64 @ceil(i32 %16)
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%19 = getelementptr inbounds i32, i32* %1, i64 1
%20 = load i32, i32* %19
%21 = add nsw i32 %20, -1
%22 = sitofp i32 %21 to double
%23 = fdiv double %22, %11
%24 = fptosi double %23 to i32
%25 = tail call i64 @ceil(i32 %24)
%26 = insertelement <2 x i64> poison, i64 %17, i64 0
%27 = insertelement <2 x i64> %26, i64 %25, i64 1
%28 = trunc <2 x i64> %27 to <2 x i32>
%29 = add nsw <2 x i32> %28, <i32 1, i32 1>
%30 = extractelement <2 x i32> %29, i64 0
store i32 %30, i32* %18
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 1
%32 = extractelement <2 x i32> %29, i64 1
store i32 %32, i32* %31
%33 = getelementptr inbounds i32, i32* %1, i64 2
%34 = load i32, i32* %33
%35 = add nsw i32 %34, -1
%36 = sitofp i32 %35 to double
%37 = fdiv double %36, %11
%38 = fptosi double %37 to i32
%39 = tail call i64 @ceil(i32 %38)
%40 = trunc i64 %39 to i32
%41 = add nsw i32 %40, 1
%42 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 2
store i32 %41, i32* %42
%43 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%44 = bitcast double* %2 to <2 x double>*
%45 = load <2 x double>, <2 x double>* %44
%46 = bitcast i32* %1 to <2 x i32>*
%47 = load <2 x i32>, <2 x i32>* %46
%48 = sitofp <2 x i32> %47 to <2 x double>
%49 = sitofp <2 x i32> %29 to <2 x double>
%50 = fdiv <2 x double> %48, %49
%51 = fmul <2 x double> %45, %50
%52 = bitcast [3 x double]* %8 to <2 x double>*
store <2 x double> %51, <2 x double>* %52
%53 = getelementptr inbounds double, double* %2, i64 2
%54 = load double, double* %53
%55 = load i32, i32* %33
%56 = sitofp i32 %55 to double
%57 = sitofp i32 %41 to double
%58 = fdiv double %56, %57
%59 = fmul double %54, %58
%60 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 2
store double %59, double* %60
%61 = shl i32 %30, 3
%62 = mul i32 %61, %32
%63 = mul i32 %62, %41
%64 = tail call i64 @malloc(i32 %63)
%65 = inttoptr i64 %64 to double*
%66 = call i32 @subsample_double(double* %0, double* %65, i32* %1, i32* %18)
%67 = call i32 @smooth_double(double* %65, i32* %18, double* %43, double* %3, i32 %4)
%68 = call i32 @subsample_double(double* %65, double* %0, i32* %18, i32* %1)
%69 = call i32 @free(double* %65)
ret void
}