#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*/ quadToTri(double, double, double *, double *, double *);
int GaussLegendreTri(int n1, int n2, double GLr[][3], double *GLwt) {
  int i, j, index = 0;
  double *pt1, *pt2, *wt1, *wt2, dJ;
  const double two = 2.0000000000000000;
  GaussLegendre1D(n1, &pt1, &wt1);
  GaussLegendre1D(n2, &pt2, &wt2);
  for (i = 0; i < n1; i++) {
    for (j = 0; j < n2; j++) {
      quadToTri(pt1[i], pt2[j], &GLr[index][0], &GLr[index][1], &dJ);
      GLr[index][2] = 1.0e0 - GLr[index][0] - GLr[index][1];
      GLwt[index++] = dJ * wt1[i] * wt2[j] * two;
    }
  }
  return index;
}


x86 assembly (clang, -O0):
<GaussLegendreTri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movsd  0xebb(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1030 <GaussLegendre1D@plt>
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1030 <GaussLegendre1D@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    127b <GaussLegendreTri+0x15b>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1268 <GaussLegendreTri+0x148>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x24(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rsi
add    $0x8,%rsi
lea    -0x50(%rbp),%rdx
call   1040 <quadToTri@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movsd  0xe1c(%rip),%xmm0
subsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
subsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x50(%rbp),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x48(%rbp),%rax
movslq -0x20(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  0xdc1(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1184 <GaussLegendreTri+0x64>
jmp    126d <GaussLegendreTri+0x14d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1171 <GaussLegendreTri+0x51>
mov    -0x24(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GaussLegendreTri>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,0x10(%rsp)
mov    %rdx,%r13
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x40(%rsp),%rsi
lea    0x30(%rsp),%rdx
call   1030 <GaussLegendre1D@plt>
lea    0x38(%rsp),%rsi
lea    0x28(%rsp),%rdx
mov    %ebx,%edi
call   1030 <GaussLegendre1D@plt>
test   %ebp,%ebp
jle    1252 <GaussLegendreTri+0x132>
mov    %ebp,%eax
mov    %rax,0x18(%rsp)
mov    %ebx,%r15d
add    $0x8,%r13
xor    %r12d,%r12d
lea    0x20(%rsp),%rbp
xor    %eax,%eax
mov    %r13,0x8(%rsp)
mov    %ebx,(%rsp)
jmp    119f <GaussLegendreTri+0x7f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r12
cmp    0x18(%rsp),%r12
je     1254 <GaussLegendreTri+0x134>
test   %ebx,%ebx
jle    1190 <GaussLegendreTri+0x70>
mov    %eax,0x4(%rsp)
cltq
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,8),%r14
lea    (%rax,%rax,2),%rax
lea    0x0(,%rax,8),%rbx
add    %r13,%rbx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x40(%rsp),%rax
movsd  (%rax,%r12,8),%xmm0
mov    0x38(%rsp),%rax
movsd  (%rax,%r13,8),%xmm1
lea    -0x8(%rbx),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <quadToTri@plt>
movsd  0xe03(%rip),%xmm0
subsd  -0x8(%rbx),%xmm0
subsd  (%rbx),%xmm0
movsd  %xmm0,0x8(%rbx)
movsd  0x20(%rsp),%xmm0
mov    0x30(%rsp),%rax
mulsd  (%rax,%r12,8),%xmm0
mov    0x28(%rsp),%rax
mulsd  (%rax,%r13,8),%xmm0
addsd  %xmm0,%xmm0
movsd  %xmm0,(%r14,%r13,8)
add    $0x1,%r13
add    $0x18,%rbx
cmp    %r13,%r15
jne    11d0 <GaussLegendreTri+0xb0>
mov    0x4(%rsp),%eax
add    %r13d,%eax
mov    0x8(%rsp),%r13
mov    (%rsp),%ebx
jmp    1190 <GaussLegendreTri+0x70>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @GaussLegendreTri(i32 %0, i32 %1, [3 x double]* %2, double* nocapture writeonly %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = bitcast double** %5 to i8*
%11 = bitcast double** %6 to i8*
%12 = bitcast double** %7 to i8*
%13 = bitcast double** %8 to i8*
%14 = bitcast double* %9 to i8*
%15 = call i32 @GaussLegendre1D(i32 %0, double** %5, double** %7)
%16 = call i32 @GaussLegendre1D(i32 %1, double** %6, double** %8)
%17 = icmp sgt i32 %0, 0
br i1 %17, label %18, label %64
18: ; preds = %4
%19 = icmp sgt i32 %1, 0
%20 = zext i32 %0 to i64
%21 = zext i32 %1 to i64
br label %22
22: ; preds = %18, %60
%23 = phi i64 [ 0, %18 ], [ %62, %60 ]
%24 = phi i32 [ 0, %18 ], [ %61, %60 ]
br i1 %19, label %25, label %60
25: ; preds = %22
%26 = sext i32 %24 to i64
br label %27
27: ; preds = %25, %27
%28 = phi i64 [ 0, %25 ], [ %56, %27 ]
%29 = phi i64 [ %26, %25 ], [ %54, %27 ]
%30 = load double*, double** %5
%31 = getelementptr inbounds double, double* %30, i64 %23
%32 = load double, double* %31
%33 = load double*, double** %6
%34 = getelementptr inbounds double, double* %33, i64 %28
%35 = load double, double* %34
%36 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %29, i64 0
%37 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %29, i64 1
%38 = call i32 @quadToTri(double %32, double %35, double* %36, double* %37, double* %9)
%39 = load double, double* %36
%40 = fsub double 1.000000e+00, %39
%41 = load double, double* %37
%42 = fsub double %40, %41
%43 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %29, i64 2
store double %42, double* %43
%44 = load double, double* %9
%45 = load double*, double** %7
%46 = getelementptr inbounds double, double* %45, i64 %23
%47 = load double, double* %46
%48 = fmul double %44, %47
%49 = load double*, double** %8
%50 = getelementptr inbounds double, double* %49, i64 %28
%51 = load double, double* %50
%52 = fmul double %48, %51
%53 = fmul double %52, 2.000000e+00
%54 = add nsw i64 %29, 1
%55 = getelementptr inbounds double, double* %3, i64 %29
store double %53, double* %55
%56 = add nuw nsw i64 %28, 1
%57 = icmp eq i64 %56, %21
br i1 %57, label %58, label %27
58: ; preds = %27
%59 = trunc i64 %54 to i32
br label %60
60: ; preds = %58, %22
%61 = phi i32 [ %24, %22 ], [ %59, %58 ]
%62 = add nuw nsw i64 %23, 1
%63 = icmp eq i64 %62, %20
br i1 %63, label %64, label %22
64: ; preds = %60, %4
%65 = phi i32 [ 0, %4 ], [ %61, %60 ]
ret i32 %65
}