#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 omp_get_wtime();
int /*<<< orphan*/ omp_set_dynamic(int /*<<< orphan*/);
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, double);
main() {
  int i, tid, NTHR;
  float a[100000], b[100000], c[100000];
  float sum = 0;
  for (i = 0; i < 100000; i++)
    a[i] = b[i] = i * 1.0;
  double start = omp_get_wtime();
  omp_set_dynamic(0);
  omp_set_num_threads(4);
#pragma omp parallel shared(sum, b, c) private(i)
  {
#pragma omp for schedule(static) reduction(+ : sum)
    for (i = 0; i < 100000; i++)
      sum += a[i] * b[i];
  }
  double end = omp_get_wtime();
  printf("start time = %f\n", start);
  printf("end time = %f\n", end);
  printf("diff time = %f\n", end - start);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x124fb0,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x124f94(%rbp)
ff
movl   $0x0,-0x8(%rbp)
cmpl   $0x186a0,-0x8(%rbp)
jge    11ae <main+0x6e>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe82(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movslq -0x8(%rbp),%rax
movss  %xmm0,-0xc3510(%rbp,%rax,4)
f3 ff
movslq -0x8(%rbp),%rax
movss  %xmm0,-0x61a90(%rbp,%rax,4)
f9 ff
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1164 <main+0x24>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x124fa0(%rbp)
ff
xor    %edi,%edi
call   1050 <omp_set_dynamic@plt>
mov    $0x4,%edi
call   1060 <omp_set_num_threads@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x186a0,-0x8(%rbp)
jge    1222 <main+0xe2>
movslq -0x8(%rbp),%rax
movss  -0x61a90(%rbp,%rax,4),%xmm0
f9 ff
movslq -0x8(%rbp),%rax
movss  -0xc3510(%rbp,%rax,4),%xmm2
f3 ff
movss  -0x124f94(%rbp),%xmm1
ff
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x124f94(%rbp)
ff
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d5 <main+0x95>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x124fa8(%rbp)
ff
movsd  -0x124fa0(%rbp),%xmm0
ff
lea    0xdc8(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x124fa8(%rbp),%xmm0
ff
lea    0xdc5(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x124fa8(%rbp),%xmm0
ff
subsd  -0x124fa0(%rbp),%xmm0
ff
lea    0xdb8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x124fb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x10(%rsp)
xor    %edi,%edi
call   1050 <omp_set_dynamic@plt>
mov    $0x4,%edi
call   1060 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xe8a(%rip),%rdi
movsd  0x10(%rsp),%xmm0
call   1040 <printf@plt>
lea    0xe89(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"start time = %f\0A\00"
@.str.1 = [15 x i8] c"end time = %f\0A\00"
@.str.2 = [16 x i8] c"diff time = %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100000 x float]
%6 = alloca [100000 x float]
%7 = alloca [100000 x float]
%8 = alloca float
%9 = alloca double
%10 = alloca double
store i32 0, i32* %1
store float 0.000000e+00, float* %8
store i32 0, i32* %2
br label %11
11: ; preds = %25, %0
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 100000
br i1 %13, label %14, label %28
14: ; preds = %11
%15 = load i32, i32* %2
%16 = sitofp i32 %15 to double
%17 = fmul double %16, 1.000000e+00
%18 = fptrunc double %17 to float
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100000 x float], [100000 x float]* %6, i64 0, i64 %20
store float %18, float* %21
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [100000 x float], [100000 x float]* %5, i64 0, i64 %23
store float %18, float* %24
br label %25
25: ; preds = %14
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %11
28: ; preds = %11
%29 = call double (...) @omp_get_wtime()
store double %29, double* %9
%30 = call i32 @omp_set_dynamic(i32 0)
%31 = call i32 @omp_set_num_threads(i32 4)
store i32 0, i32* %2
br label %32
32: ; preds = %46, %28
%33 = load i32, i32* %2
%34 = icmp slt i32 %33, 100000
br i1 %34, label %35, label %49
35: ; preds = %32
%36 = load i32, i32* %2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [100000 x float], [100000 x float]* %5, i64 0, i64 %37
%39 = load float, float* %38
%40 = load i32, i32* %2
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [100000 x float], [100000 x float]* %6, i64 0, i64 %41
%43 = load float, float* %42
%44 = load float, float* %8
%45 = call float @llvm.fmuladd.f32(float %39, float %43, float %44)
store float %45, float* %8
br label %46
46: ; preds = %35
%47 = load i32, i32* %2
%48 = add nsw i32 %47, 1
store i32 %48, i32* %2
br label %32
49: ; preds = %32
%50 = call double (...) @omp_get_wtime()
store double %50, double* %10
%51 = load double, double* %9
%52 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), double %51)
%53 = load double, double* %10
%54 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %53)
%55 = load double, double* %10
%56 = load double, double* %9
%57 = fsub double %55, %56
%58 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %57)
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@.str = [17 x i8] c"start time = %f\0A\00"
@.str.1 = [15 x i8] c"end time = %f\0A\00"
@.str.2 = [16 x i8] c"diff time = %f\0A\00"
define i32 @main() {
%1 = tail call double (...) @omp_get_wtime()
%2 = tail call i32 @omp_set_dynamic(i32 0)
%3 = tail call i32 @omp_set_num_threads(i32 4)
%4 = tail call double (...) @omp_get_wtime()
%5 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), double %1)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %4)
%7 = fsub double %4, %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %7)
ret i32 0
}