#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 omp_get_thread_num();
double integrate_omp(double (*func)(double), double a, double b, int n) {
  double h = (b - a) / n;
  double sum = 0.0;
  double thread_sum[32];
#pragma omp parallel
  {
    int tid = omp_get_thread_num();
    thread_sum[tid] = 0;
#pragma omp for
    for (int i = 0; i < n; i++)
      thread_sum[tid] += func(a + h * (i + 0.5));
#pragma omp atomic
    sum += thread_sum[tid];
  }
  sum *= h;
  return sum;
}


x86 assembly (clang, -O0):
<integrate_omp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x134(%rbp)
movslq -0x134(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x130(%rbp,%rax,8)
ff ff
movl   $0x0,-0x138(%rbp)
mov    -0x138(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11de <integrate_omp+0xce>
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x138(%rbp),%xmm2
ff
movsd  0xe5d(%rip),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   *%rax
movslq -0x134(%rbp),%rax
addsd  -0x130(%rbp,%rax,8),%xmm0
ff ff
movsd  %xmm0,-0x130(%rbp,%rax,8)
ff ff
mov    -0x138(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x138(%rbp)
jmp    1176 <integrate_omp+0x66>
movslq -0x134(%rbp),%rax
movsd  -0x130(%rbp,%rax,8),%xmm0
ff ff
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<integrate_omp>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
movsd  %xmm0,0x18(%rsp)
subsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %esi,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
xorpd  %xmm1,%xmm1
test   %ebx,%ebx
jle    119e <integrate_omp+0x8e>
xorpd  %xmm0,%xmm0
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
movsd  %xmm1,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
addsd  0xe96(%rip),%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
call   *%r14
movsd  0x20(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
addsd  0xe77(%rip),%xmm0
add    $0xffffffff,%ebx
jne    1150 <integrate_omp+0x40>
xorpd  %xmm0,%xmm0
addsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @integrate_omp(double (double)* %0, double %1, double %2, i32 %3) {
%5 = alloca double (double)*
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca [32 x double]
%12 = alloca i32
%13 = alloca i32
store double (double)* %0, double (double)** %5
store double %1, double* %6
store double %2, double* %7
store i32 %3, i32* %8
%14 = load double, double* %7
%15 = load double, double* %6
%16 = fsub double %14, %15
%17 = load i32, i32* %8
%18 = sitofp i32 %17 to double
%19 = fdiv double %16, %18
store double %19, double* %9
store double 0.000000e+00, double* %10
%20 = call i32 (...) @omp_get_thread_num()
store i32 %20, i32* %12
%21 = load i32, i32* %12
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [32 x double], [32 x double]* %11, i64 0, i64 %22
store double 0.000000e+00, double* %23
store i32 0, i32* %13
br label %24
24: ; preds = %42, %4
%25 = load i32, i32* %13
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %45
28: ; preds = %24
%29 = load double (double)*, double (double)** %5
%30 = load double, double* %6
%31 = load double, double* %9
%32 = load i32, i32* %13
%33 = sitofp i32 %32 to double
%34 = fadd double %33, 5.000000e-01
%35 = call double @llvm.fmuladd.f64(double %31, double %34, double %30)
%36 = call double %29(double %35)
%37 = load i32, i32* %12
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [32 x double], [32 x double]* %11, i64 0, i64 %38
%40 = load double, double* %39
%41 = fadd double %40, %36
store double %41, double* %39
br label %42
42: ; preds = %28
%43 = load i32, i32* %13
%44 = add nsw i32 %43, 1
store i32 %44, i32* %13
br label %24
45: ; preds = %24
%46 = load i32, i32* %12
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [32 x double], [32 x double]* %11, i64 0, i64 %47
%49 = load double, double* %48
%50 = load double, double* %10
%51 = fadd double %50, %49
store double %51, double* %10
%52 = load double, double* %9
%53 = load double, double* %10
%54 = fmul double %53, %52
store double %54, double* %10
%55 = load double, double* %10
ret double %55
}

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