#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 pow(int, int);
double midpoint(double (*func)(double, int, double, double), double a, double b,
                int n, int nk, double ppot, double sigma2) {
  int it, i;
  double tnm, del, ddel, sum, x;
  static double s;
  if (n == 1)
    return (s = (b - a) * func(0.5 * (a + b), nk, ppot, sigma2));
  else {
    it = pow(3, n - 2);
    tnm = it;
    del = (b - a) / (3. * tnm);
    ddel = del + del;
    x = a + 0.5 * del;
    sum = 0;
    for (i = 0; i < it; i++) {
      sum += func(x, nk, ppot, sigma2);
      x += ddel;
      sum += func(x, nk, ppot, sigma2);
      x += del;
    }
    s = (s + (b - a) * sum / tnm) / 3.;
    return s;
  }
}


x86 assembly (clang, -O0):
<midpoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %esi,-0x24(%rbp)
mov    %edx,-0x28(%rbp)
movsd  %xmm2,-0x30(%rbp)
movsd  %xmm3,-0x38(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    1196 <midpoint+0x86>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x18(%rbp),%xmm1
addsd  -0x20(%rbp),%xmm1
movsd  0xe9b(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x28(%rbp),%edi
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x2ea4(%rip)
movsd  %xmm0,-0x8(%rbp)
jmp    12cd <midpoint+0x1bd>
mov    -0x24(%rbp),%esi
sub    $0x2,%esi
mov    $0x3,%edi
call   1030 <pow@plt>
mov    %eax,-0x3c(%rbp)
cvtsi2sdl -0x3c(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe43(%rip),%xmm1
mulsd  -0x48(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  0xe0c(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    128c <midpoint+0x17c>
mov    -0x10(%rbp),%rax
movsd  -0x68(%rbp),%xmm0
mov    -0x28(%rbp),%edi
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
call   *%rax
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x68(%rbp),%xmm0
mov    -0x28(%rbp),%edi
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
call   *%rax
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1210 <midpoint+0x100>
movsd  0x2d9c(%rip),%xmm0
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
divsd  -0x48(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  0xd54(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x2d70(%rip)
movsd  0x2d68(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<midpoint>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %edx,%r14d
mov    %rdi,%rbx
cmp    $0x1,%esi
jne    1153 <midpoint+0x43>
movapd %xmm1,%xmm4
subsd  %xmm0,%xmm4
movsd  %xmm4,(%rsp)
addsd  %xmm1,%xmm0
mulsd  0xecc(%rip),%xmm0
mov    %r14d,%edi
movapd %xmm2,%xmm1
movapd %xmm3,%xmm2
call   *%rbx
mulsd  (%rsp),%xmm0
jmp    1273 <midpoint+0x163>
movsd  %xmm2,0x18(%rsp)
movsd  %xmm3,0x20(%rsp)
add    $0xfffffffe,%esi
mov    $0x3,%edi
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
call   1030 <pow@plt>
movsd  (%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
subsd  %xmm3,%xmm1
test   %eax,%eax
movsd  %xmm1,0x8(%rsp)
movsd  %xmm2,0x28(%rsp)
jle    124f <midpoint+0x13f>
mov    %eax,%ebp
movsd  0xe55(%rip),%xmm0
mulsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x30(%rsp)
movsd  0xe3f(%rip),%xmm0
movsd  %xmm1,0x38(%rsp)
mulsd  %xmm1,%xmm0
addsd  %xmm3,%xmm0
xorpd  %xmm1,%xmm1
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
mov    %r14d,%edi
movsd  0x18(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
call   *%rbx
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
addsd  0x30(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
mov    %r14d,%edi
movsd  0x18(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
call   *%rbx
movapd %xmm0,%xmm1
movsd  (%rsp),%xmm0
addsd  0x10(%rsp),%xmm1
addsd  0x38(%rsp),%xmm0
add    $0xffffffff,%ebp
jne    11e0 <midpoint+0xd0>
jmp    1253 <midpoint+0x143>
xorpd  %xmm1,%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
divsd  0x28(%rsp),%xmm0
addsd  0x2dc5(%rip),%xmm0
divsd  0xd8d(%rip),%xmm0
movsd  %xmm0,0x2db5(%rip)
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@midpoint.s = internal unnamed_addr global double 0.000000e+00
define double @midpoint(double (double, i32, double, double)* nocapture %0, double %1, double %2, i32 %3, i32 %4, double %5, double %6) {
%8 = icmp eq i32 %3, 1
br i1 %8, label %9, label %15
9: ; preds = %7
%10 = fsub double %2, %1
%11 = fadd double %1, %2
%12 = fmul double %11, 5.000000e-01
%13 = tail call double %0(double %12, i32 %4, double %5, double %6)
%14 = fmul double %10, %13
br label %45
15: ; preds = %7
%16 = add nsw i32 %3, -2
%17 = tail call i32 @pow(i32 3, i32 %16)
%18 = sitofp i32 %17 to double
%19 = fsub double %2, %1
%20 = fmul double %18, 3.000000e+00
%21 = fdiv double %19, %20
%22 = fadd double %21, %21
%23 = icmp sgt i32 %17, 0
br i1 %23, label %24, label %38
24: ; preds = %15
%25 = tail call double @llvm.fmuladd.f64(double %21, double 5.000000e-01, double %1)
br label %26
26: ; preds = %24, %26
%27 = phi double [ %35, %26 ], [ %25, %24 ]
%28 = phi double [ %34, %26 ], [ 0.000000e+00, %24 ]
%29 = phi i32 [ %36, %26 ], [ 0, %24 ]
%30 = tail call double %0(double %27, i32 %4, double %5, double %6)
%31 = fadd double %28, %30
%32 = fadd double %22, %27
%33 = tail call double %0(double %32, i32 %4, double %5, double %6)
%34 = fadd double %31, %33
%35 = fadd double %21, %32
%36 = add nuw nsw i32 %29, 1
%37 = icmp eq i32 %36, %17
br i1 %37, label %38, label %26
38: ; preds = %26, %15
%39 = phi double [ 0.000000e+00, %15 ], [ %34, %26 ]
%40 = load double, double* @midpoint.s
%41 = fmul double %19, %39
%42 = fdiv double %41, %18
%43 = fadd double %42, %40
%44 = fdiv double %43, 3.000000e+00
br label %45
45: ; preds = %38, %9
%46 = phi double [ %44, %38 ], [ %14, %9 ]
store double %46, double* @midpoint.s
ret double %46
}