#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*/ math_gauss_quad_coefficients(int, double const **,
                                                double const **);
int math_gauss_quad(int n, double *p1, double *p2) {
  static const double *xGQ = NULL;
  static const double *wGQ = NULL;
  static int i, j, n_itv;
  static double h;
  static double x0;
  if (n > 0) {
    if (xGQ == NULL)
      math_gauss_quad_coefficients(6, &xGQ, &wGQ);
    n_itv = (n + 6 - 1) / 6;
    i = j = 0;
    h = (*p2 - (x0 = *p1)) / n_itv;
    return 6 * n_itv;
  }
  if (i == n_itv)
    return 1;
  *p1 = x0 + xGQ[j] * h;
  *p2 = wGQ[j] * h;
  if (++j == 6) {
    i++;
    j = 0;
    x0 += h;
  }
  return 0;
}


x86 assembly (clang, -O0):
<math_gauss_quad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11bd <math_gauss_quad+0xad>
cmpq   $0x0,0x2efb(%rip)
jne    1153 <math_gauss_quad+0x43>
mov    $0x6,%edi
lea    0x2ee9(%rip),%rsi
lea    0x2eea(%rip),%rdx
call   1030 <math_gauss_quad_coefficients@plt>
mov    -0x8(%rbp),%eax
add    $0x6,%eax
sub    $0x1,%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %eax,0x2ede(%rip)
movl   $0x0,0x2ed0(%rip)
movl   $0x0,0x2ec2(%rip)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
movsd  %xmm1,0x2ec2(%rip)
subsd  %xmm1,%xmm0
cvtsi2sdl 0x2ea6(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x2ea2(%rip)
imul   $0x6,0x2e93(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    1281 <math_gauss_quad+0x171>
mov    0x2e7d(%rip),%eax
cmp    0x2e7f(%rip),%eax
jne    11db <math_gauss_quad+0xcb>
movl   $0x1,-0x4(%rbp)
jmp    1281 <math_gauss_quad+0x171>
movsd  0x2e75(%rip),%xmm1
mov    0x2e46(%rip),%rax
movslq 0x2e53(%rip),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0x2e52(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    0x2e23(%rip),%rax
movslq 0x2e28(%rip),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  0x2e27(%rip),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    0x2e0d(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e04(%rip)
cmp    $0x6,%eax
jne    127a <math_gauss_quad+0x16a>
mov    0x2df1(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2de8(%rip)
movl   $0x0,0x2de2(%rip)
movsd  0x2de6(%rip),%xmm0
addsd  0x2de6(%rip),%xmm0
movsd  %xmm0,0x2dde(%rip)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<math_gauss_quad>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
test   %edi,%edi
jle    11a4 <math_gauss_quad+0x94>
mov    %edi,%ebx
cmpq   $0x0,0x2f03(%rip)
jne    1147 <math_gauss_quad+0x37>
lea    0x2efa(%rip),%rsi
lea    0x2efb(%rip),%rdx
mov    $0x6,%edi
call   1030 <math_gauss_quad_coefficients@plt>
add    $0x5,%ebx
mov    $0xaaaaaaab,%eax
imul   %rbx,%rax
shr    $0x22,%rax
mov    %eax,0x2eeb(%rip)
movl   $0x0,0x2edd(%rip)
movl   $0x0,0x2ecf(%rip)
movsd  (%r14),%xmm0
movsd  (%r15),%xmm1
movsd  %xmm1,0x2ed5(%rip)
subsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x2eb6(%rip)
add    %eax,%eax
lea    (%rax,%rax,2),%eax
jmp    122b <math_gauss_quad+0x11b>
mov    0x2e96(%rip),%ecx
mov    $0x1,%eax
cmp    0x2e93(%rip),%ecx
je     122b <math_gauss_quad+0x11b>
movsd  0x2e99(%rip),%xmm0
mov    0x2e6a(%rip),%rax
movslq 0x2e77(%rip),%rdx
movsd  0x2e7b(%rip),%xmm1
movsd  (%rax,%rdx,8),%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%r15)
mov    0x2e4a(%rip),%rax
movsd  (%rax,%rdx,8),%xmm2
mulsd  %xmm1,%xmm2
movsd  %xmm2,(%r14)
add    $0x1,%edx
mov    %edx,0x2e3f(%rip)
xor    %eax,%eax
cmp    $0x6,%edx
jne    122b <math_gauss_quad+0x11b>
add    $0x1,%ecx
mov    %ecx,0x2e2b(%rip)
movl   $0x0,0x2e25(%rip)
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2e2d(%rip)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@math_gauss_quad.xGQ = internal global double* null
@math_gauss_quad.wGQ = internal global double* null
@math_gauss_quad.i = internal global i32 0
@math_gauss_quad.j = internal global i32 0
@math_gauss_quad.n_itv = internal global i32 0
@math_gauss_quad.h = internal global double 0.000000e+00
@math_gauss_quad.x0 = internal global double 0.000000e+00
define i32 @math_gauss_quad(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
store i32 %0, i32* %5
store double* %1, double** %6
store double* %2, double** %7
%8 = load i32, i32* %5
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %30
10: ; preds = %3
%11 = load double*, double** @math_gauss_quad.xGQ
%12 = icmp eq double* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @math_gauss_quad_coefficients(i32 6, double** @math_gauss_quad.xGQ, double** @math_gauss_quad.wGQ)
br label %15
15: ; preds = %13, %10
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 6
%18 = sub nsw i32 %17, 1
%19 = sdiv i32 %18, 6
store i32 %19, i32* @math_gauss_quad.n_itv
store i32 0, i32* @math_gauss_quad.j
store i32 0, i32* @math_gauss_quad.i
%20 = load double*, double** %7
%21 = load double, double* %20
%22 = load double*, double** %6
%23 = load double, double* %22
store double %23, double* @math_gauss_quad.x0
%24 = fsub double %21, %23
%25 = load i32, i32* @math_gauss_quad.n_itv
%26 = sitofp i32 %25 to double
%27 = fdiv double %24, %26
store double %27, double* @math_gauss_quad.h
%28 = load i32, i32* @math_gauss_quad.n_itv
%29 = mul nsw i32 6, %28
store i32 %29, i32* %4
br label %63
30: ; preds = %3
%31 = load i32, i32* @math_gauss_quad.i
%32 = load i32, i32* @math_gauss_quad.n_itv
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 1, i32* %4
br label %63
35: ; preds = %30
%36 = load double, double* @math_gauss_quad.x0
%37 = load double*, double** @math_gauss_quad.xGQ
%38 = load i32, i32* @math_gauss_quad.j
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
%42 = load double, double* @math_gauss_quad.h
%43 = call double @llvm.fmuladd.f64(double %41, double %42, double %36)
%44 = load double*, double** %6
store double %43, double* %44
%45 = load double*, double** @math_gauss_quad.wGQ
%46 = load i32, i32* @math_gauss_quad.j
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
%50 = load double, double* @math_gauss_quad.h
%51 = fmul double %49, %50
%52 = load double*, double** %7
store double %51, double* %52
%53 = load i32, i32* @math_gauss_quad.j
%54 = add nsw i32 %53, 1
store i32 %54, i32* @math_gauss_quad.j
%55 = icmp eq i32 %54, 6
br i1 %55, label %56, label %62
56: ; preds = %35
%57 = load i32, i32* @math_gauss_quad.i
%58 = add nsw i32 %57, 1
store i32 %58, i32* @math_gauss_quad.i
store i32 0, i32* @math_gauss_quad.j
%59 = load double, double* @math_gauss_quad.h
%60 = load double, double* @math_gauss_quad.x0
%61 = fadd double %60, %59
store double %61, double* @math_gauss_quad.x0
br label %62
62: ; preds = %56, %35
store i32 0, i32* %4
br label %63
63: ; preds = %62, %34, %15
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
@math_gauss_quad.xGQ = internal global double* null
@math_gauss_quad.wGQ = internal global double* null
@math_gauss_quad.i = internal unnamed_addr global i32 0
@math_gauss_quad.j = internal unnamed_addr global i32 0
@math_gauss_quad.n_itv = internal unnamed_addr global i32 0
@math_gauss_quad.h = internal unnamed_addr global double 0.000000e+00
@math_gauss_quad.x0 = internal unnamed_addr global double 0.000000e+00
define i32 @math_gauss_quad(i32 %0, double* nocapture %1, double* nocapture %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %19
5: ; preds = %3
%6 = load double*, double** @math_gauss_quad.xGQ
%7 = icmp eq double* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @math_gauss_quad_coefficients(i32 6, double** @math_gauss_quad.xGQ, double** @math_gauss_quad.wGQ)
br label %10
10: ; preds = %8, %5
%11 = add nuw nsw i32 %0, 5
%12 = udiv i32 %11, 6
store i32 %12, i32* @math_gauss_quad.n_itv
store i32 0, i32* @math_gauss_quad.j
store i32 0, i32* @math_gauss_quad.i
%13 = load double, double* %2
%14 = load double, double* %1
store double %14, double* @math_gauss_quad.x0
%15 = fsub double %13, %14
%16 = sitofp i32 %12 to double
%17 = fdiv double %15, %16
store double %17, double* @math_gauss_quad.h
%18 = mul nuw nsw i32 %12, 6
br label %41
19: ; preds = %3
%20 = load i32, i32* @math_gauss_quad.i
%21 = load i32, i32* @math_gauss_quad.n_itv
%22 = icmp eq i32 %20, %21
br i1 %22, label %41, label %23
23: ; preds = %19
%24 = load double, double* @math_gauss_quad.x0
%25 = load double*, double** @math_gauss_quad.xGQ
%26 = load i32, i32* @math_gauss_quad.j
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = load double, double* @math_gauss_quad.h
%31 = tail call double @llvm.fmuladd.f64(double %29, double %30, double %24)
store double %31, double* %1
%32 = load double*, double** @math_gauss_quad.wGQ
%33 = getelementptr inbounds double, double* %32, i64 %27
%34 = load double, double* %33
%35 = fmul double %30, %34
store double %35, double* %2
%36 = add nsw i32 %26, 1
store i32 %36, i32* @math_gauss_quad.j
%37 = icmp eq i32 %36, 6
br i1 %37, label %38, label %41
38: ; preds = %23
%39 = add nsw i32 %20, 1
store i32 %39, i32* @math_gauss_quad.i
store i32 0, i32* @math_gauss_quad.j
%40 = fadd double %24, %30
store double %40, double* @math_gauss_quad.x0
br label %41
41: ; preds = %23, %38, %19, %10
%42 = phi i32 [ %18, %10 ], [ 1, %19 ], [ 0, %38 ], [ 0, %23 ]
ret i32 %42
}