#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);
int omp_get_num_threads();
int omp_get_thread_num();
double Local_trap(double a, double b, int n) {
  double h, x, my_result;
  double local_a, local_b;
  int i, local_n;
  int my_rank = omp_get_thread_num();
  int thread_count = omp_get_num_threads();
  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)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x4c(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-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   1040 <f@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <f@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xe1a(%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     1245 <Local_trap+0x115>
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   1040 <f@plt>
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11f6 <Local_trap+0xc6>
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   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %eax,%ecx
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
subsd  %xmm2,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  %xmm0,%xmm1
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%ebx
imul   %eax,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
movsd  %xmm1,0x10(%rsp)
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,0x18(%rsp)
movsd  %xmm0,0x20(%rsp)
call   1040 <f@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1040 <f@plt>
addsd  0x8(%rsp),%xmm0
mulsd  0xe31(%rip),%xmm0
cmp    $0x2,%ebx
jl     122a <Local_trap+0xfa>
add    $0xffffffff,%ebx
movsd  0xe29(%rip),%xmm1
nop
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x8(%rsp)
movapd %xmm1,%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
call   1040 <f@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x18(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
addsd  0xde3(%rip),%xmm1
add    $0xffffffff,%ebx
jne    11e0 <Local_trap+0xb0>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
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
%16 = call i32 (...) @omp_get_thread_num()
store i32 %16, i32* %14
%17 = call i32 (...) @omp_get_num_threads()
store i32 %17, i32* %15
%18 = load double, double* %5
%19 = load double, double* %4
%20 = fsub double %18, %19
%21 = load i32, i32* %6
%22 = sitofp i32 %21 to double
%23 = fdiv double %20, %22
store double %23, double* %7
%24 = load i32, i32* %6
%25 = load i32, i32* %15
%26 = sdiv i32 %24, %25
store i32 %26, i32* %13
%27 = load double, double* %4
%28 = load i32, i32* %14
%29 = load i32, i32* %13
%30 = mul nsw i32 %28, %29
%31 = sitofp i32 %30 to double
%32 = load double, double* %7
%33 = call double @llvm.fmuladd.f64(double %31, double %32, double %27)
store double %33, double* %10
%34 = load double, double* %10
%35 = load i32, i32* %13
%36 = sitofp i32 %35 to double
%37 = load double, double* %7
%38 = call double @llvm.fmuladd.f64(double %36, double %37, double %34)
store double %38, double* %11
%39 = load double, double* %10
%40 = call double @f(double %39)
%41 = load double, double* %11
%42 = call double @f(double %41)
%43 = fadd double %40, %42
%44 = fdiv double %43, 2.000000e+00
store double %44, double* %9
store i32 1, i32* %12
br label %45
45: ; preds = %60, %3
%46 = load i32, i32* %12
%47 = load i32, i32* %13
%48 = sub nsw i32 %47, 1
%49 = icmp sle i32 %46, %48
br i1 %49, label %50, label %63
50: ; preds = %45
%51 = load double, double* %10
%52 = load i32, i32* %12
%53 = sitofp i32 %52 to double
%54 = load double, double* %7
%55 = call double @llvm.fmuladd.f64(double %53, double %54, double %51)
store double %55, double* %8
%56 = load double, double* %8
%57 = call double @f(double %56)
%58 = load double, double* %9
%59 = fadd double %58, %57
store double %59, double* %9
br label %60
60: ; preds = %50
%61 = load i32, i32* %12
%62 = add nsw i32 %61, 1
store i32 %62, i32* %12
br label %45
63: ; preds = %45
%64 = load double, double* %9
%65 = load double, double* %7
%66 = fmul double %64, %65
store double %66, double* %9
%67 = load double, double* %9
ret double %67
}

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