#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 parallel_trap(double a, double b, int n) {
  int i;
  double h;
  double approx;
  int my_rank = 0;
  int thread_count = 1;
  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):
<parallel_trap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x30(%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  0xe88(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11cd <parallel_trap+0xbd>
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x18(%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    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1188 <parallel_trap+0x78>
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):
<parallel_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 <parallel_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 <parallel_trap+0x60>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

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