#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*/ GaussLegendre1D(int, double **, double **);
int /*<<< orphan*/ brickToTet(double, double, double, double *, double *,
                              double *, double *);
int GaussLegendreTet(int n1, int n2, int n3, double GLrstw[][4], double *GLwt) {
  int i, j, k, index = 0;
  double *pt1, *pt2, *pt3, *wt1, *wt2, *wt3, dJ;
  const double six = 6.000000000000000;
  GaussLegendre1D(n1, &pt1, &wt1);
  GaussLegendre1D(n2, &pt2, &wt2);
  GaussLegendre1D(n3, &pt3, &wt3);
  for (i = 0; i < n1; i++) {
    for (j = 0; j < n2; j++) {
      for (k = 0; k < n3; k++) {
        brickToTet(pt1[i], pt2[j], pt3[k], &GLrstw[index][0], &GLrstw[index][1],
                   &GLrstw[index][2], &dJ);
        GLrstw[index][3] =
            1.0e0 - GLrstw[index][0] - GLrstw[index][1] - GLrstw[index][2];
        GLwt[index++] = dJ * wt1[i] * wt2[j] * wt3[k] * six;
      }
    }
  }
  return index;
}


x86 assembly (clang, -O0):
<GaussLegendreTet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
movsd  0xeb8(%rip),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1040 <GaussLegendre1D@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x58(%rbp),%rdx
call   1040 <GaussLegendre1D@plt>
mov    -0xc(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1040 <GaussLegendre1D@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12f5 <GaussLegendreTet+0x1d5>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12e2 <GaussLegendreTet+0x1c2>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12cf <GaussLegendreTet+0x1af>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x48(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rdi
movslq -0x30(%rbp),%rax
shl    $0x5,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x30(%rbp),%rax
shl    $0x5,%rax
add    %rax,%rsi
add    $0x8,%rsi
mov    -0x18(%rbp),%rdx
movslq -0x30(%rbp),%rax
shl    $0x5,%rax
add    %rax,%rdx
add    $0x10,%rdx
lea    -0x68(%rbp),%rcx
call   1030 <brickToTet@plt>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
shl    $0x5,%rcx
add    %rcx,%rax
movsd  0xdd6(%rip),%xmm0
subsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
shl    $0x5,%rcx
add    %rcx,%rax
subsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
shl    $0x5,%rcx
add    %rcx,%rax
subsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
shl    $0x5,%rcx
add    %rcx,%rax
movsd  %xmm0,0x18(%rax)
movsd  -0x68(%rbp),%xmm0
mov    -0x50(%rbp),%rax
movslq -0x24(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x58(%rbp),%rax
movslq -0x28(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x60(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  0xd5a(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11aa <GaussLegendreTet+0x8a>
jmp    12d4 <GaussLegendreTet+0x1b4>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1197 <GaussLegendreTet+0x77>
jmp    12e7 <GaussLegendreTet+0x1c7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1184 <GaussLegendreTet+0x64>
mov    -0x30(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GaussLegendreTet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r8,0x20(%rsp)
mov    %rcx,0x18(%rsp)
mov    %edx,%ebp
mov    %esi,%r14d
mov    %edi,%ebx
lea    0x70(%rsp),%rsi
lea    0x58(%rsp),%rdx
call   1040 <GaussLegendre1D@plt>
lea    0x68(%rsp),%rsi
lea    0x50(%rsp),%rdx
mov    %r14d,%edi
call   1040 <GaussLegendre1D@plt>
lea    0x60(%rsp),%rsi
lea    0x48(%rsp),%rdx
mov    %ebp,%edi
call   1040 <GaussLegendre1D@plt>
test   %ebx,%ebx
jle    12cf <GaussLegendreTet+0x1af>
mov    %ebx,%eax
mov    %rax,0x10(%rsp)
mov    %r14d,%eax
mov    %rax,0x28(%rsp)
mov    %ebp,%r12d
shl    $0x3,%r12
xor    %r13d,%r13d
lea    0x40(%rsp),%rbx
xor    %esi,%esi
mov    %ebp,0x8(%rsp)
mov    %r14d,0x4(%rsp)
jmp    11c4 <GaussLegendreTet+0xa4>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r13
cmp    0x10(%rsp),%r13
mov    0x4(%rsp),%r14d
je     12d1 <GaussLegendreTet+0x1b1>
test   %r14d,%r14d
jle    11b0 <GaussLegendreTet+0x90>
xor    %edi,%edi
jmp    11df <GaussLegendreTet+0xbf>
nopl   (%rax)
add    $0x1,%rdi
cmp    0x28(%rsp),%rdi
mov    0x8(%rsp),%ebp
je     11b0 <GaussLegendreTet+0x90>
test   %ebp,%ebp
jle    11d0 <GaussLegendreTet+0xb0>
movslq %esi,%r15
mov    0x20(%rsp),%rax
lea    (%rax,%r15,8),%rax
mov    %rax,0x30(%rsp)
shl    $0x5,%r15
add    0x18(%rsp),%r15
xor    %r14d,%r14d
xor    %ebp,%ebp
mov    %rdi,0x38(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %esi,0xc(%rsp)
mov    0x70(%rsp),%rax
movsd  (%rax,%r13,8),%xmm0
mov    0x68(%rsp),%rax
movsd  (%rax,%rdi,8),%xmm1
mov    0x60(%rsp),%rax
movsd  (%rax,%rbp,1),%xmm2
lea    (%r15,%r14,1),%rdi
lea    (%r15,%r14,1),%rsi
add    $0x8,%rsi
lea    (%r15,%r14,1),%rdx
add    $0x10,%rdx
mov    %rbx,%rcx
call   1030 <brickToTet@plt>
mov    0x38(%rsp),%rdi
movsd  0xdac(%rip),%xmm1
movsd  0xd9c(%rip),%xmm0
mov    0xc(%rsp),%esi
subsd  (%r15,%rbp,4),%xmm0
subsd  0x8(%r15,%rbp,4),%xmm0
subsd  0x10(%r15,%rbp,4),%xmm0
movsd  %xmm0,0x18(%r15,%rbp,4)
movsd  0x40(%rsp),%xmm0
mov    0x58(%rsp),%rax
mulsd  (%rax,%r13,8),%xmm0
mov    0x50(%rsp),%rax
mulsd  (%rax,%rdi,8),%xmm0
mov    0x48(%rsp),%rax
mulsd  (%rax,%rbp,1),%xmm0
mulsd  %xmm1,%xmm0
mov    0x30(%rsp),%rax
movsd  %xmm0,(%rax,%rbp,1)
add    $0x8,%rbp
add    $0x20,%r14
add    $0x1,%esi
cmp    %rbp,%r12
jne    1210 <GaussLegendreTet+0xf0>
jmp    11d0 <GaussLegendreTet+0xb0>
xor    %esi,%esi
mov    %esi,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @GaussLegendreTet(i32 %0, i32 %1, i32 %2, [4 x double]* %3, double* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4 x double]*
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double*
%16 = alloca double*
%17 = alloca double*
%18 = alloca double*
%19 = alloca double*
%20 = alloca double*
%21 = alloca double
%22 = alloca double
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store [4 x double]* %3, [4 x double]** %9
store double* %4, double** %10
store i32 0, i32* %14
store double 6.000000e+00, double* %22
%23 = load i32, i32* %6
%24 = call i32 @GaussLegendre1D(i32 %23, double** %15, double** %18)
%25 = load i32, i32* %7
%26 = call i32 @GaussLegendre1D(i32 %25, double** %16, double** %19)
%27 = load i32, i32* %8
%28 = call i32 @GaussLegendre1D(i32 %27, double** %17, double** %20)
store i32 0, i32* %11
br label %29
29: ; preds = %134, %5
%30 = load i32, i32* %11
%31 = load i32, i32* %6
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %137
33: ; preds = %29
store i32 0, i32* %12
br label %34
34: ; preds = %130, %33
%35 = load i32, i32* %12
%36 = load i32, i32* %7
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %133
38: ; preds = %34
store i32 0, i32* %13
br label %39
39: ; preds = %126, %38
%40 = load i32, i32* %13
%41 = load i32, i32* %8
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %129
43: ; preds = %39
%44 = load double*, double** %15
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
%49 = load double*, double** %16
%50 = load i32, i32* %12
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
%53 = load double, double* %52
%54 = load double*, double** %17
%55 = load i32, i32* %13
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %54, i64 %56
%58 = load double, double* %57
%59 = load [4 x double]*, [4 x double]** %9
%60 = load i32, i32* %14
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [4 x double], [4 x double]* %59, i64 %61
%63 = getelementptr inbounds [4 x double], [4 x double]* %62, i64 0, i64 0
%64 = load [4 x double]*, [4 x double]** %9
%65 = load i32, i32* %14
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [4 x double], [4 x double]* %64, i64 %66
%68 = getelementptr inbounds [4 x double], [4 x double]* %67, i64 0, i64 1
%69 = load [4 x double]*, [4 x double]** %9
%70 = load i32, i32* %14
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [4 x double], [4 x double]* %69, i64 %71
%73 = getelementptr inbounds [4 x double], [4 x double]* %72, i64 0, i64 2
%74 = call i32 @brickToTet(double %48, double %53, double %58, double* %63, double* %68, double* %73, double* %21)
%75 = load [4 x double]*, [4 x double]** %9
%76 = load i32, i32* %14
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [4 x double], [4 x double]* %75, i64 %77
%79 = getelementptr inbounds [4 x double], [4 x double]* %78, i64 0, i64 0
%80 = load double, double* %79
%81 = fsub double 1.000000e+00, %80
%82 = load [4 x double]*, [4 x double]** %9
%83 = load i32, i32* %14
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [4 x double], [4 x double]* %82, i64 %84
%86 = getelementptr inbounds [4 x double], [4 x double]* %85, i64 0, i64 1
%87 = load double, double* %86
%88 = fsub double %81, %87
%89 = load [4 x double]*, [4 x double]** %9
%90 = load i32, i32* %14
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [4 x double], [4 x double]* %89, i64 %91
%93 = getelementptr inbounds [4 x double], [4 x double]* %92, i64 0, i64 2
%94 = load double, double* %93
%95 = fsub double %88, %94
%96 = load [4 x double]*, [4 x double]** %9
%97 = load i32, i32* %14
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [4 x double], [4 x double]* %96, i64 %98
%100 = getelementptr inbounds [4 x double], [4 x double]* %99, i64 0, i64 3
store double %95, double* %100
%101 = load double, double* %21
%102 = load double*, double** %18
%103 = load i32, i32* %11
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds double, double* %102, i64 %104
%106 = load double, double* %105
%107 = fmul double %101, %106
%108 = load double*, double** %19
%109 = load i32, i32* %12
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds double, double* %108, i64 %110
%112 = load double, double* %111
%113 = fmul double %107, %112
%114 = load double*, double** %20
%115 = load i32, i32* %13
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds double, double* %114, i64 %116
%118 = load double, double* %117
%119 = fmul double %113, %118
%120 = fmul double %119, 6.000000e+00
%121 = load double*, double** %10
%122 = load i32, i32* %14
%123 = add nsw i32 %122, 1
store i32 %123, i32* %14
%124 = sext i32 %122 to i64
%125 = getelementptr inbounds double, double* %121, i64 %124
store double %120, double* %125
br label %126
126: ; preds = %43
%127 = load i32, i32* %13
%128 = add nsw i32 %127, 1
store i32 %128, i32* %13
br label %39
129: ; preds = %39
br label %130
130: ; preds = %129
%131 = load i32, i32* %12
%132 = add nsw i32 %131, 1
store i32 %132, i32* %12
br label %34
133: ; preds = %34
br label %134
134: ; preds = %133
%135 = load i32, i32* %11
%136 = add nsw i32 %135, 1
store i32 %136, i32* %11
br label %29
137: ; preds = %29
%138 = load i32, i32* %14
ret i32 %138
}

LLVM IR (-O2):
define i32 @GaussLegendreTet(i32 %0, i32 %1, i32 %2, [4 x double]* %3, double* nocapture writeonly %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double
%13 = bitcast double** %6 to i8*
%14 = bitcast double** %7 to i8*
%15 = bitcast double** %8 to i8*
%16 = bitcast double** %9 to i8*
%17 = bitcast double** %10 to i8*
%18 = bitcast double** %11 to i8*
%19 = bitcast double* %12 to i8*
%20 = call i32 @GaussLegendre1D(i32 %0, double** %6, double** %9)
%21 = call i32 @GaussLegendre1D(i32 %1, double** %7, double** %10)
%22 = call i32 @GaussLegendre1D(i32 %2, double** %8, double** %11)
%23 = icmp sgt i32 %0, 0
br i1 %23, label %24, label %89
24: ; preds = %5
%25 = icmp sgt i32 %1, 0
%26 = icmp sgt i32 %2, 0
%27 = zext i32 %0 to i64
%28 = zext i32 %1 to i64
%29 = zext i32 %2 to i64
br label %30
30: ; preds = %24, %85
%31 = phi i64 [ 0, %24 ], [ %87, %85 ]
%32 = phi i32 [ 0, %24 ], [ %86, %85 ]
br i1 %25, label %33, label %85
33: ; preds = %30, %81
%34 = phi i64 [ %83, %81 ], [ 0, %30 ]
%35 = phi i32 [ %82, %81 ], [ %32, %30 ]
br i1 %26, label %36, label %81
36: ; preds = %33
%37 = sext i32 %35 to i64
br label %38
38: ; preds = %36, %38
%39 = phi i64 [ 0, %36 ], [ %77, %38 ]
%40 = phi i64 [ %37, %36 ], [ %75, %38 ]
%41 = load double*, double** %6
%42 = getelementptr inbounds double, double* %41, i64 %31
%43 = load double, double* %42
%44 = load double*, double** %7
%45 = getelementptr inbounds double, double* %44, i64 %34
%46 = load double, double* %45
%47 = load double*, double** %8
%48 = getelementptr inbounds double, double* %47, i64 %39
%49 = load double, double* %48
%50 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 %40, i64 0
%51 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 %40, i64 1
%52 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 %40, i64 2
%53 = call i32 @brickToTet(double %43, double %46, double %49, double* %50, double* %51, double* %52, double* %12)
%54 = load double, double* %50
%55 = fsub double 1.000000e+00, %54
%56 = load double, double* %51
%57 = fsub double %55, %56
%58 = load double, double* %52
%59 = fsub double %57, %58
%60 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 %40, i64 3
store double %59, double* %60
%61 = load double, double* %12
%62 = load double*, double** %9
%63 = getelementptr inbounds double, double* %62, i64 %31
%64 = load double, double* %63
%65 = fmul double %61, %64
%66 = load double*, double** %10
%67 = getelementptr inbounds double, double* %66, i64 %34
%68 = load double, double* %67
%69 = fmul double %65, %68
%70 = load double*, double** %11
%71 = getelementptr inbounds double, double* %70, i64 %39
%72 = load double, double* %71
%73 = fmul double %69, %72
%74 = fmul double %73, 6.000000e+00
%75 = add nsw i64 %40, 1
%76 = getelementptr inbounds double, double* %4, i64 %40
store double %74, double* %76
%77 = add nuw nsw i64 %39, 1
%78 = icmp eq i64 %77, %29
br i1 %78, label %79, label %38
79: ; preds = %38
%80 = trunc i64 %75 to i32
br label %81
81: ; preds = %79, %33
%82 = phi i32 [ %35, %33 ], [ %80, %79 ]
%83 = add nuw nsw i64 %34, 1
%84 = icmp eq i64 %83, %28
br i1 %84, label %85, label %33
85: ; preds = %81, %30
%86 = phi i32 [ %32, %30 ], [ %82, %81 ]
%87 = add nuw nsw i64 %31, 1
%88 = icmp eq i64 %87, %27
br i1 %88, label %89, label %30
89: ; preds = %85, %5
%90 = phi i32 [ 0, %5 ], [ %86, %85 ]
ret i32 %90
}