#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 local_trap(double a, double b, int n) {
  double h;
  double x;
  double my_result;
  double local_a;
  double local_b;
  int i;
  int local_n;
  int my_rank = 0;
  int thread_count = 1;
  h = (b - a) / n;
  local_n = n / thread_count;
  local_a = a + my_rank * local_n * h;
  local_b = local_a + local_n * h;
  my_result = (f(local_a) + f(local_b)) / 2.0;
  for (i = 1; i <= local_n - 1; i++) {
    x = local_a + i * h;
    my_result += f(x);
  }
  my_result = my_result * h;
  return my_result;
}


x86 assembly (clang, -O0):
<local_trap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x1,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cltd
idivl  -0x50(%rbp)
mov    %eax,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm1
mov    -0x4c(%rbp),%eax
imul   -0x48(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
cvtsi2sdl -0x48(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <f@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xe40(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x48(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     121f <local_trap+0x10f>
movsd  -0x38(%rbp),%xmm1
cvtsi2sdl -0x44(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <f@plt>
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11d0 <local_trap+0xc0>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<local_trap>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
subsd  %xmm0,%xmm1
cvtsi2sd %edi,%xmm3
divsd  %xmm3,%xmm1
xorpd  %xmm2,%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm1,0x10(%rsp)
mulsd  %xmm1,%xmm3
addsd  %xmm2,%xmm3
movsd  %xmm3,0x8(%rsp)
movsd  %xmm2,0x18(%rsp)
movapd %xmm2,%xmm0
call   1030 <f@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <f@plt>
addsd  (%rsp),%xmm0
mulsd  0xe91(%rip),%xmm0
cmp    $0x2,%ebx
jl     11c6 <local_trap+0xb6>
add    $0xffffffff,%ebx
movsd  0xe89(%rip),%xmm1
nop
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  0xe47(%rip),%xmm1
add    $0xffffffff,%ebx
jne    1180 <local_trap+0x70>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

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