#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
double lib_integrate_c_omp(double a, double b, int N) {
  double s = 0.0;
  double dx = (b - a) / N;
  int i;
  if (dx == 0.0) {
    fprintf(stderr, "dx == 0!\n");
    return 0.0;
  }
#pragma omp parallel for reduction(+ : s) lastprivate(a)
  for (i = 0; i < N; i++) {
    s += f(a + (i + 1. / 2.) * dx) * dx;
  }
  return s;
}


x86 assembly (clang, -O0):
<lib_integrate_c_omp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    118f <lib_integrate_c_omp+0x6f>
jp     118f <lib_integrate_c_omp+0x6f>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1040 <fprintf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f9 <lib_integrate_c_omp+0xd9>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ef <lib_integrate_c_omp+0xcf>
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x34(%rbp),%xmm0
movsd  0xe4c(%rip),%xmm2
addsd  %xmm2,%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <f@plt>
movsd  -0x30(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1196 <lib_integrate_c_omp+0x76>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lib_integrate_c_omp>:
push   %rbx
sub    $0x20,%rsp
movapd %xmm0,%xmm2
subsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
divsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    115f <lib_integrate_c_omp+0x3f>
jp     115f <lib_integrate_c_omp+0x3f>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
lea    0xebc(%rip),%rsi
call   1040 <fprintf@plt>
xorpd  %xmm0,%xmm0
jmp    11da <lib_integrate_c_omp+0xba>
mov    %edi,%ebx
test   %edi,%edi
jle    11da <lib_integrate_c_omp+0xba>
xorpd  %xmm3,%xmm3
xorpd  %xmm0,%xmm0
movsd  %xmm1,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
nopl   0x0(%rax)
movsd  %xmm3,0x18(%rsp)
movsd  %xmm0,(%rsp)
movapd %xmm3,%xmm0
addsd  0xe69(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
call   1030 <f@plt>
movsd  0x18(%rsp),%xmm3
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movsd  (%rsp),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
movsd  0x8(%rsp),%xmm2
movsd  (%rsp),%xmm0
addsd  0xe33(%rip),%xmm3
add    $0xffffffff,%ebx
jne    1180 <lib_integrate_c_omp+0x60>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [10 x i8] c"dx == 0!\0A\00"
define double @lib_integrate_c_omp(double %0, double %1, i32 %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca i32
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
store double 0.000000e+00, double* %8
%11 = load double, double* %6
%12 = load double, double* %5
%13 = fsub double %11, %12
%14 = load i32, i32* %7
%15 = sitofp i32 %14 to double
%16 = fdiv double %13, %15
store double %16, double* %9
%17 = load double, double* %9
%18 = fcmp oeq double %17, 0.000000e+00
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store double 0.000000e+00, double* %4
br label %43
22: ; preds = %3
store i32 0, i32* %10
br label %23
23: ; preds = %38, %22
%24 = load i32, i32* %10
%25 = load i32, i32* %7
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %41
27: ; preds = %23
%28 = load double, double* %5
%29 = load i32, i32* %10
%30 = sitofp i32 %29 to double
%31 = fadd double %30, 5.000000e-01
%32 = load double, double* %9
%33 = call double @llvm.fmuladd.f64(double %31, double %32, double %28)
%34 = call double @f(double %33)
%35 = load double, double* %9
%36 = load double, double* %8
%37 = call double @llvm.fmuladd.f64(double %34, double %35, double %36)
store double %37, double* %8
br label %38
38: ; preds = %27
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
br label %23
41: ; preds = %23
%42 = load double, double* %8
store double %42, double* %4
br label %43
43: ; preds = %41, %19
%44 = load double, double* %4
ret double %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [10 x i8] c"dx == 0!\0A\00"
define double @lib_integrate_c_omp(double %0, double %1, i32 %2) {
%4 = fsub double %1, %0
%5 = sitofp i32 %2 to double
%6 = fdiv double %4, %5
%7 = fcmp oeq double %6, 0.000000e+00
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = icmp sgt i32 %2, 0
br i1 %9, label %13, label %23
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %23
13: ; preds = %8, %13
%14 = phi i32 [ %21, %13 ], [ 0, %8 ]
%15 = phi double [ %20, %13 ], [ 0.000000e+00, %8 ]
%16 = sitofp i32 %14 to double
%17 = fadd double %16, 5.000000e-01
%18 = tail call double @llvm.fmuladd.f64(double %17, double %6, double %0)
%19 = tail call double @f(double %18)
%20 = tail call double @llvm.fmuladd.f64(double %19, double %6, double %15)
%21 = add nuw nsw i32 %14, 1
%22 = icmp eq i32 %21, %2
br i1 %22, label %23, label %13
23: ; preds = %13, %8, %10
%24 = phi double [ 0.000000e+00, %10 ], [ 0.000000e+00, %8 ], [ %20, %13 ]
ret double %24
}