#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 */
double f(double);
double Trap(double a, double b, int n, int thread_count) {
  double h, approx;
  int i;
  h = (b - a) / n;
  approx = (f(a) + f(b)) / 2.0;
#pragma omp parallel for num_threads(thread_count) reduction(+ : approx)
  for (i = 1; i <= n - 1; i++)
    approx += f(a + i * h);
  approx = h * approx;
  return approx;
}


x86 assembly (clang, -O0):
<Trap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %esi,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <f@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xe93(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11c2 <Trap+0xb2>
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <f@plt>
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117d <Trap+0x6d>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Trap>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm3
subsd  %xmm0,%xmm3
cvtsi2sd %edi,%xmm2
divsd  %xmm2,%xmm3
movsd  %xmm3,0x10(%rsp)
movsd  %xmm0,0x18(%rsp)
call   1030 <f@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1030 <f@plt>
addsd  0x8(%rsp),%xmm0
mulsd  0xea5(%rip),%xmm0
cmp    $0x2,%ebx
jl     11b6 <Trap+0xa6>
add    $0xffffffff,%ebx
movsd  0xe9d(%rip),%xmm1
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
movapd %xmm1,%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
call   1030 <f@plt>
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm0
addsd  0xe57(%rip),%xmm1
add    $0xffffffff,%ebx
jne    1170 <Trap+0x60>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @Trap(double %0, double %1, i32 %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca i32
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load double, double* %6
%13 = load double, double* %5
%14 = fsub double %12, %13
%15 = load i32, i32* %7
%16 = sitofp i32 %15 to double
%17 = fdiv double %14, %16
store double %17, double* %9
%18 = load double, double* %5
%19 = call double @f(double %18)
%20 = load double, double* %6
%21 = call double @f(double %20)
%22 = fadd double %19, %21
%23 = fdiv double %22, 2.000000e+00
store double %23, double* %10
store i32 1, i32* %11
br label %24
24: ; preds = %38, %4
%25 = load i32, i32* %11
%26 = load i32, i32* %7
%27 = sub nsw i32 %26, 1
%28 = icmp sle i32 %25, %27
br i1 %28, label %29, label %41
29: ; preds = %24
%30 = load double, double* %5
%31 = load i32, i32* %11
%32 = sitofp i32 %31 to double
%33 = load double, double* %9
%34 = call double @llvm.fmuladd.f64(double %32, double %33, double %30)
%35 = call double @f(double %34)
%36 = load double, double* %10
%37 = fadd double %36, %35
store double %37, double* %10
br label %38
38: ; preds = %29
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 1
store i32 %40, i32* %11
br label %24
41: ; preds = %24
%42 = load double, double* %9
%43 = load double, double* %10
%44 = fmul double %42, %43
store double %44, double* %10
%45 = load double, double* %10
ret double %45
}

LLVM IR (-O2):
define double @Trap(double %0, double %1, i32 %2, i32 %3) {
%5 = fsub double %1, %0
%6 = sitofp i32 %2 to double
%7 = fdiv double %5, %6
%8 = tail call double @f(double %0)
%9 = tail call double @f(double %1)
%10 = fadd double %8, %9
%11 = fmul double %10, 5.000000e-01
%12 = icmp sgt i32 %2, 1
br i1 %12, label %13, label %22
13: ; preds = %4, %13
%14 = phi i32 [ %20, %13 ], [ 1, %4 ]
%15 = phi double [ %19, %13 ], [ %11, %4 ]
%16 = sitofp i32 %14 to double
%17 = tail call double @llvm.fmuladd.f64(double %16, double %7, double %0)
%18 = tail call double @f(double %17)
%19 = fadd double %15, %18
%20 = add nuw nsw i32 %14, 1
%21 = icmp eq i32 %20, %2
br i1 %21, label %22, label %13
22: ; preds = %13, %4
%23 = phi double [ %11, %4 ], [ %19, %13 ]
%24 = fmul double %7, %23
ret double %24
}