#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int omp_get_num_threads();
int omp_get_thread_num();
int /*<<< orphan*/ printf(char *, double);
int main(int argc, char *argv[]) {
  double a[1000];
  double sum = 0.0;
  int i, n, tid;
#pragma omp parallel shared(a) private(i)
  {
    tid = omp_get_thread_num();
#pragma omp single
    {
      n = omp_get_num_threads();
      printf("Number of threads = %d\n", n);
    }
#pragma omp for
    for (i = 0; i < 1000; i++) {
      a[i] = 1.0;
    }
#pragma omp for reduction(+ : sum)
    for (i = 0; i < 1000; i++) {
      sum = sum + (a[i]);
    }
  }
  printf("   Sum = %2.1f\n", sum);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1f58(%rbp)
ff
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x1f64(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x1f60(%rbp)
cvtsi2sdl -0x1f60(%rbp),%xmm0
ff
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x1f5c(%rbp)
cmpl   $0x3e8,-0x1f5c(%rbp)
jge    11d8 <main+0x98>
movslq -0x1f5c(%rbp),%rax
movsd  0xe45(%rip),%xmm0
movsd  %xmm0,-0x1f50(%rbp,%rax,8)
ff ff
mov    -0x1f5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f5c(%rbp)
jmp    119c <main+0x5c>
movl   $0x0,-0x1f5c(%rbp)
cmpl   $0x3e8,-0x1f5c(%rbp)
jge    1226 <main+0xe6>
movsd  -0x1f58(%rbp),%xmm0
ff
movslq -0x1f5c(%rbp),%rax
addsd  -0x1f50(%rbp,%rax,8),%xmm0
ff ff
movsd  %xmm0,-0x1f58(%rbp)
ff
mov    -0x1f5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f5c(%rbp)
jmp    11e2 <main+0xa2>
movsd  -0x1f58(%rbp),%xmm0
ff
lea    0xdeb(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
sub    $0x1f48,%rsp
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
cvtsi2sd %eax,%xmm0
lea    0xeb0(%rip),%rdi
call   1040 <printf@plt>
mov    $0x12,%eax
movapd 0xe8e(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movapd %xmm0,-0x90(%rsp,%rax,8)
ff ff
movapd %xmm0,-0x80(%rsp,%rax,8)
movapd %xmm0,-0x70(%rsp,%rax,8)
movapd %xmm0,-0x60(%rsp,%rax,8)
movapd %xmm0,-0x50(%rsp,%rax,8)
movapd %xmm0,-0x40(%rsp,%rax,8)
movapd %xmm0,-0x30(%rsp,%rax,8)
movapd %xmm0,-0x20(%rsp,%rax,8)
movapd %xmm0,-0x10(%rsp,%rax,8)
movapd %xmm0,(%rsp,%rax,8)
add    $0x14,%rax
cmp    $0x3fa,%rax
jne    1180 <main+0x40>
xorpd  %xmm0,%xmm0
mov    $0x7,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addsd  -0x38(%rsp,%rax,8),%xmm0
addsd  -0x30(%rsp,%rax,8),%xmm0
addsd  -0x28(%rsp,%rax,8),%xmm0
addsd  -0x20(%rsp,%rax,8),%xmm0
addsd  -0x18(%rsp,%rax,8),%xmm0
addsd  -0x10(%rsp,%rax,8),%xmm0
addsd  -0x8(%rsp,%rax,8),%xmm0
addsd  (%rsp,%rax,8),%xmm0
add    $0x8,%rax
cmp    $0x3ef,%rax
jne    11e0 <main+0xa0>
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Number of threads = %d\0A\00"
@.str.1 = [16 x i8] c" Sum = %2.1f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000 x double]
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %7
%11 = call i32 (...) @omp_get_thread_num()
store i32 %11, i32* %10
%12 = call i32 (...) @omp_get_num_threads()
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = sitofp i32 %13 to double
%15 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %14)
store i32 0, i32* %8
br label %16
16: ; preds = %23, %2
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 1000
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [1000 x double], [1000 x double]* %6, i64 0, i64 %21
store double 1.000000e+00, double* %22
br label %23
23: ; preds = %19
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %16
26: ; preds = %16
store i32 0, i32* %8
br label %27
27: ; preds = %37, %26
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 1000
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = load double, double* %7
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [1000 x double], [1000 x double]* %6, i64 0, i64 %33
%35 = load double, double* %34
%36 = fadd double %31, %35
store double %36, double* %7
br label %37
37: ; preds = %30
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %27
40: ; preds = %27
%41 = load double, double* %7
%42 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), double %41)
%43 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [24 x i8] c"Number of threads = %d\0A\00"
@.str.1 = [16 x i8] c" Sum = %2.1f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1000 x double]
%4 = bitcast [1000 x double]* %3 to i8*
%5 = tail call i32 (...) @omp_get_thread_num()
%6 = tail call i32 (...) @omp_get_num_threads()
%7 = sitofp i32 %6 to double
%8 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %7)
br label %9
9: ; preds = %9, %2
%10 = phi i64 [ 0, %2 ], [ %35, %9 ]
%11 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %10
%12 = bitcast double* %11 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %12
%13 = getelementptr inbounds double, double* %11, i64 2
%14 = bitcast double* %13 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %14
%15 = add nuw nsw i64 %10, 4
%16 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %15
%17 = bitcast double* %16 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %17
%18 = getelementptr inbounds double, double* %16, i64 2
%19 = bitcast double* %18 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %19
%20 = add nuw nsw i64 %10, 8
%21 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %20
%22 = bitcast double* %21 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %22
%23 = getelementptr inbounds double, double* %21, i64 2
%24 = bitcast double* %23 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %24
%25 = add nuw nsw i64 %10, 12
%26 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %25
%27 = bitcast double* %26 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %27
%28 = getelementptr inbounds double, double* %26, i64 2
%29 = bitcast double* %28 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %29
%30 = add nuw nsw i64 %10, 16
%31 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %30
%32 = bitcast double* %31 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %32
%33 = getelementptr inbounds double, double* %31, i64 2
%34 = bitcast double* %33 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %34
%35 = add nuw nsw i64 %10, 20
%36 = icmp eq i64 %35, 1000
br i1 %36, label %37, label %9
37: ; preds = %9, %37
%38 = phi i64 [ %71, %37 ], [ 0, %9 ]
%39 = phi double [ %70, %37 ], [ 0.000000e+00, %9 ]
%40 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %38
%41 = load double, double* %40
%42 = fadd double %39, %41
%43 = or i64 %38, 1
%44 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %43
%45 = load double, double* %44
%46 = fadd double %42, %45
%47 = or i64 %38, 2
%48 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %47
%49 = load double, double* %48
%50 = fadd double %46, %49
%51 = or i64 %38, 3
%52 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %51
%53 = load double, double* %52
%54 = fadd double %50, %53
%55 = or i64 %38, 4
%56 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %55
%57 = load double, double* %56
%58 = fadd double %54, %57
%59 = or i64 %38, 5
%60 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %59
%61 = load double, double* %60
%62 = fadd double %58, %61
%63 = or i64 %38, 6
%64 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %63
%65 = load double, double* %64
%66 = fadd double %62, %65
%67 = or i64 %38, 7
%68 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %67
%69 = load double, double* %68
%70 = fadd double %66, %69
%71 = add nuw nsw i64 %38, 8
%72 = icmp eq i64 %71, 1000
br i1 %72, label %73, label %37
73: ; preds = %37
%74 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), double %70)
%75 = tail call i32 @exit(i32 0)
unreachable
}