#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
double fabs(double const);
int /*<<< orphan*/ ndim_array_access_lin2n(int, int, int, int /*<<< orphan*/,
                                           int *);
extern uint32_t grid_getWeightsCIC(const double *dist, double *weight) {
  double w[3][3];
  uint32_t k[3];
  uint32_t i, j;
  assert(dist != NULL);
  assert(weight != NULL);
  for (i = 0; i < 3; i++) {
    w[i][0] = (dist[i] < 0.0) ? -1.0 * dist[i] : 0.0;
    w[i][1] = 1.0 - fabs(dist[i]);
    w[i][2] = (dist[i] > 0.0) ? dist[i] : 0.0;
  }
  for (i = 0; i < ((3) * (3) * (3)); i++) {
    weight[i] = 1.0;
    ndim_array_access_lin2n(3, i, 3, 0, k);
    for (j = 0; j < 3; j++)
      weight[i] *= w[j][k[j]];
  }
  return 3;
}


x86 assembly (clang, -O0):
<grid_getWeightsCIC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movl   $0x0,-0x70(%rbp)
cmpl   $0x3,-0x70(%rbp)
jge    1268 <grid_getWeightsCIC+0x148>
mov    -0x8(%rbp),%rax
movslq -0x70(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    119d <grid_getWeightsCIC+0x7d>
mov    -0x8(%rbp),%rax
movslq -0x70(%rbp),%rcx
movsd  0xe7a(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    11aa <grid_getWeightsCIC+0x8a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    11aa <grid_getWeightsCIC+0x8a>
movsd  -0x80(%rbp),%xmm0
movslq -0x70(%rbp),%rcx
lea    -0x60(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movslq -0x70(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movaps 0xe3a(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe1e(%rip),%xmm0
subsd  %xmm1,%xmm0
movslq -0x70(%rbp),%rcx
lea    -0x60(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movslq -0x70(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    122e <grid_getWeightsCIC+0x10e>
mov    -0x8(%rbp),%rax
movslq -0x70(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
jmp    123e <grid_getWeightsCIC+0x11e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
jmp    123e <grid_getWeightsCIC+0x11e>
movsd  -0x88(%rbp),%xmm0
ff
movslq -0x70(%rbp),%rcx
lea    -0x60(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movsd  %xmm0,0x10(%rax)
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    115e <grid_getWeightsCIC+0x3e>
movl   $0x0,-0x70(%rbp)
cmpl   $0x1b,-0x70(%rbp)
jge    1304 <grid_getWeightsCIC+0x1e4>
mov    -0x10(%rbp),%rax
movslq -0x70(%rbp),%rcx
movsd  0xd77(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x70(%rbp),%esi
lea    -0x6c(%rbp),%r8
mov    $0x3,%edx
xor    %ecx,%ecx
mov    %edx,%edi
call   1040 <ndim_array_access_lin2n@plt>
movl   $0x0,-0x74(%rbp)
cmpl   $0x3,-0x74(%rbp)
jge    12f1 <grid_getWeightsCIC+0x1d1>
movslq -0x74(%rbp),%rcx
lea    -0x60(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x74(%rbp),%rcx
movslq -0x6c(%rbp,%rcx,4),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x70(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    12aa <grid_getWeightsCIC+0x18a>
jmp    12f6 <grid_getWeightsCIC+0x1d6>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    126f <grid_getWeightsCIC+0x14f>
mov    $0x3,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grid_getWeightsCIC>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1030 <assert@plt>
movsd  (%r14),%xmm4
movapd 0xea6(%rip),%xmm1
movapd %xmm4,%xmm2
xorpd  %xmm1,%xmm2
xorpd  %xmm0,%xmm0
movapd %xmm4,%xmm3
cmpltsd %xmm0,%xmm3
andpd  %xmm2,%xmm3
movlpd %xmm3,0x10(%rsp)
movapd 0xe8f(%rip),%xmm2
movapd %xmm4,%xmm5
andpd  %xmm2,%xmm5
movsd  0xe8f(%rip),%xmm3
movapd %xmm3,%xmm6
subsd  %xmm5,%xmm6
movsd  %xmm6,0x18(%rsp)
maxsd  %xmm0,%xmm4
movsd  %xmm4,0x20(%rsp)
movsd  0x8(%r14),%xmm4
movapd %xmm4,%xmm5
xorpd  %xmm1,%xmm5
movapd %xmm4,%xmm6
cmpltsd %xmm0,%xmm6
andpd  %xmm5,%xmm6
movlpd %xmm6,0x28(%rsp)
movapd %xmm4,%xmm5
andpd  %xmm2,%xmm5
movapd %xmm3,%xmm6
subsd  %xmm5,%xmm6
movsd  %xmm6,0x30(%rsp)
maxsd  %xmm0,%xmm4
movsd  %xmm4,0x38(%rsp)
movsd  0x10(%r14),%xmm4
xorpd  %xmm4,%xmm1
movapd %xmm4,%xmm5
cmpltsd %xmm0,%xmm5
andpd  %xmm1,%xmm5
movlpd %xmm5,0x40(%rsp)
andpd  %xmm4,%xmm2
subsd  %xmm2,%xmm3
movsd  %xmm3,0x48(%rsp)
maxsd  %xmm0,%xmm4
movsd  %xmm4,0x50(%rsp)
xor    %ebx,%ebx
movabs $0x3ff0000000000000,%r12
lea    0x4(%rsp),%r14
mov    %r12,(%r15,%rbx,8)
mov    $0x3,%edi
mov    %ebx,%esi
mov    $0x3,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <ndim_array_access_lin2n@plt>
movslq 0x4(%rsp),%rax
movsd  0x10(%rsp,%rax,8),%xmm0
mulsd  (%r15,%rbx,8),%xmm0
movslq 0x8(%rsp),%rax
mulsd  0x28(%rsp,%rax,8),%xmm0
movslq 0xc(%rsp),%rax
mulsd  0x40(%rsp,%rax,8),%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    $0x1b,%rbx
jne    1230 <grid_getWeightsCIC+0x110>
mov    $0x3,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @grid_getWeightsCIC(double* %0, double* %1) {
%3 = alloca [3 x [3 x double]]
%4 = alloca [3 x i32]
%5 = bitcast [3 x [3 x double]]* %3 to i8*
%6 = bitcast [3 x i32]* %4 to i8*
%7 = icmp ne double* %0, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp ne double* %1, null
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = load double, double* %0
%14 = fcmp olt double %13, 0.000000e+00
%15 = fneg double %13
%16 = select i1 %14, double %15, double 0.000000e+00
%17 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 0, i64 0
store double %16, double* %17
%18 = tail call double @llvm.fabs.f64(double %13)
%19 = fsub double 1.000000e+00, %18
%20 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 0, i64 1
store double %19, double* %20
%21 = fcmp ogt double %13, 0.000000e+00
%22 = select i1 %21, double %13, double 0.000000e+00
%23 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 0, i64 2
store double %22, double* %23
%24 = getelementptr inbounds double, double* %0, i64 1
%25 = load double, double* %24
%26 = fcmp olt double %25, 0.000000e+00
%27 = fneg double %25
%28 = select i1 %26, double %27, double 0.000000e+00
%29 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 1, i64 0
store double %28, double* %29
%30 = tail call double @llvm.fabs.f64(double %25)
%31 = fsub double 1.000000e+00, %30
%32 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 1, i64 1
store double %31, double* %32
%33 = fcmp ogt double %25, 0.000000e+00
%34 = select i1 %33, double %25, double 0.000000e+00
%35 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 1, i64 2
store double %34, double* %35
%36 = getelementptr inbounds double, double* %0, i64 2
%37 = load double, double* %36
%38 = fcmp olt double %37, 0.000000e+00
%39 = fneg double %37
%40 = select i1 %38, double %39, double 0.000000e+00
%41 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 2, i64 0
store double %40, double* %41
%42 = tail call double @llvm.fabs.f64(double %37)
%43 = fsub double 1.000000e+00, %42
%44 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 2, i64 1
store double %43, double* %44
%45 = fcmp ogt double %37, 0.000000e+00
%46 = select i1 %45, double %37, double 0.000000e+00
%47 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 2, i64 2
store double %46, double* %47
%48 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%49 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
%50 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 2
br label %51
51: ; preds = %2, %51
%52 = phi i64 [ 0, %2 ], [ %72, %51 ]
%53 = getelementptr inbounds double, double* %1, i64 %52
store double 1.000000e+00, double* %53
%54 = trunc i64 %52 to i32
%55 = call i32 @ndim_array_access_lin2n(i32 3, i32 %54, i32 3, i32 0, i32* %48)
%56 = load double, double* %53
%57 = load i32, i32* %48
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 0, i64 %58
%60 = load double, double* %59
%61 = fmul double %60, %56
%62 = load i32, i32* %49
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 1, i64 %63
%65 = load double, double* %64
%66 = fmul double %65, %61
%67 = load i32, i32* %50
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 2, i64 %68
%70 = load double, double* %69
%71 = fmul double %70, %66
store double %71, double* %53
%72 = add nuw nsw i64 %52, 1
%73 = icmp eq i64 %72, 27
br i1 %73, label %74, label %51
74: ; preds = %51
ret i32 3
}