#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 */
scalar_t__ cos(double);
int /*<<< orphan*/ dtime(double *);
int omp_get_num_procs();
int omp_get_num_threads();
int omp_get_thread_num();
int /*<<< orphan*/ printf(char *, double, ...);
scalar_t__ sin(double);
int main(int argc, char *argv[]) {
  int i, id, Nthrds, Nprocs, N, k, kp;
  double sum[100], tsum;
  double stime, etime;
  dtime(&stime);
  N = 30000000;
  k = 0;
#pragma omp parallel shared(k, sum) private(i, id, kp, tsum)
  {
    id = omp_get_thread_num();
    Nthrds = omp_get_num_threads();
    Nprocs = omp_get_num_procs();
    printf("Nprocs=%2d Nthrds=%2d id=%d\n", Nprocs, Nthrds, id);
    kp = id;
    k = Nthrds - 1;
    do {
      sum[kp] = 0.0;
      for (i = 0; i < N; i++) {
        sum[kp] += sin((double)(i + kp)) + cos((double)(i + 2 * kp));
      }
      printf("id=%2d kp=%2d sum=%15.12f\n", id, kp, sum[kp]);
#pragma omp critical
      kp = ++k;
    } while (k < 20);
#pragma omp barrier
    {
      tsum = 0.0;
      for (i = 0; i < 20; i++) {
        tsum += sum[i];
      }
    }
    printf("tsum=%15.12f\n", tsum);
  }
  dtime(&etime);
  printf("Elapsed time (s)=%15.12f\n", etime - stime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x370,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x360(%rbp),%rdi
call   1080 <dtime@plt>
movl   $0x1c9c380,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <omp_get_num_procs@plt>
mov    %eax,-0x20(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm0
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe2d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
movslq -0x2c(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x350(%rbp,%rax,8)
ff ff
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    126c <main+0xfc>
mov    -0x14(%rbp),%eax
add    -0x2c(%rbp),%eax
cvtsi2sd %eax,%xmm0
call   1060 <sin@plt>
mov    %rax,-0x370(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x2c(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
call   1090 <cos@plt>
mov    %rax,%rcx
mov    -0x370(%rbp),%rax
add    %rcx,%rax
cvtsi2sd %rax,%xmm0
movslq -0x2c(%rbp),%rax
addsd  -0x350(%rbp,%rax,8),%xmm0
ff ff
movsd  %xmm0,-0x350(%rbp,%rax,8)
ff ff
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1200 <main+0x90>
cvtsi2sdl -0x18(%rbp),%xmm0
mov    -0x2c(%rbp),%esi
movslq -0x2c(%rbp),%rax
movsd  -0x350(%rbp,%rax,8),%xmm1
ff ff
lea    0xd95(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    %eax,-0x2c(%rbp)
cmpl   $0x14,-0x28(%rbp)
jl     11e9 <main+0x79>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x358(%rbp)
ff
movl   $0x0,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jge    12ec <main+0x17c>
movslq -0x14(%rbp),%rax
movsd  -0x350(%rbp,%rax,8),%xmm0
ff ff
addsd  -0x358(%rbp),%xmm0
ff
movsd  %xmm0,-0x358(%rbp)
ff
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12b7 <main+0x147>
movsd  -0x358(%rbp),%xmm0
ff
lea    0xd3d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    -0x368(%rbp),%rdi
call   1080 <dtime@plt>
movsd  -0x368(%rbp),%xmm0
ff
subsd  -0x360(%rbp),%xmm0
ff
lea    0xd21(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x370,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x348,%rsp
lea    0x18(%rsp),%rdi
call   1080 <dtime@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <omp_get_num_procs@plt>
cvtsi2sd %eax,%xmm0
lea    0xe50(%rip),%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    $0x1,%al
call   1040 <printf@plt>
add    $0xffffffff,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm0
movsd  %xmm0,(%rsp)
nopl   0x0(%rax)
mov    %rbx,0x8(%rsp)
movslq %r12d,%r13
movq   $0x0,0x20(%rsp,%r13,8)
lea    0x0(%r13,%r13,1),%ebp
mov    $0x1c9c380,%r15d
mov    %r12d,%r14d
nop
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
call   1060 <sin@plt>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
call   1090 <cos@plt>
add    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x20(%rsp,%r13,8),%xmm0
movsd  %xmm0,0x20(%rsp,%r13,8)
lea    0x1(%r14),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1060 <sin@plt>
mov    %rax,%rbx
lea    0x1(%rbp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1090 <cos@plt>
add    %rbx,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  0x20(%rsp,%r13,8),%xmm1
movsd  %xmm1,0x20(%rsp,%r13,8)
add    $0x2,%r14d
add    $0x2,%ebp
add    $0xfffffffe,%r15d
jne    11f0 <main+0x80>
lea    0xda9(%rip),%rdi
movsd  (%rsp),%xmm0
mov    %r12d,%esi
mov    $0x2,%al
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
lea    0x1(%rax),%r12d
cmp    $0x13,%eax
mov    %r12d,%ebx
jl     11d0 <main+0x60>
xorpd  %xmm0,%xmm0
addsd  0x20(%rsp),%xmm0
addsd  0x28(%rsp),%xmm0
addsd  0x30(%rsp),%xmm0
addsd  0x38(%rsp),%xmm0
addsd  0x40(%rsp),%xmm0
addsd  0x48(%rsp),%xmm0
addsd  0x50(%rsp),%xmm0
addsd  0x58(%rsp),%xmm0
addsd  0x60(%rsp),%xmm0
addsd  0x68(%rsp),%xmm0
addsd  0x70(%rsp),%xmm0
addsd  0x78(%rsp),%xmm0
addsd  0x80(%rsp),%xmm0
addsd  0x88(%rsp),%xmm0
addsd  0x90(%rsp),%xmm0
addsd  0x98(%rsp),%xmm0
addsd  0xa0(%rsp),%xmm0
addsd  0xa8(%rsp),%xmm0
addsd  0xb0(%rsp),%xmm0
addsd  0xb8(%rsp),%xmm0
lea    0xd05(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0x10(%rsp),%rdi
call   1080 <dtime@plt>
movsd  0x10(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
lea    0xcef(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x348,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Nprocs=%2d Nthrds=%2d id=%d\0A\00"
@.str.1 = [27 x i8] c"id=%2d kp=%2d sum=%15.12f\0A\00"
@.str.2 = [14 x i8] c"tsum=%15.12f\0A\00"
@.str.3 = [26 x i8] c"Elapsed time (s)=%15.12f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [100 x double]
%14 = alloca double
%15 = alloca double
%16 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = call i32 @dtime(double* %15)
store i32 30000000, i32* %10
store i32 0, i32* %11
%18 = call i32 (...) @omp_get_thread_num()
store i32 %18, i32* %7
%19 = call i32 (...) @omp_get_num_threads()
store i32 %19, i32* %8
%20 = call i32 (...) @omp_get_num_procs()
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = sitofp i32 %21 to double
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), double %22, i32 %23, i32 %24)
%26 = load i32, i32* %7
store i32 %26, i32* %12
%27 = load i32, i32* %8
%28 = sub nsw i32 %27, 1
store i32 %28, i32* %11
br label %29
29: ; preds = %70, %2
%30 = load i32, i32* %12
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [100 x double], [100 x double]* %13, i64 0, i64 %31
store double 0.000000e+00, double* %32
store i32 0, i32* %6
br label %33
33: ; preds = %56, %29
%34 = load i32, i32* %6
%35 = load i32, i32* %10
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %59
37: ; preds = %33
%38 = load i32, i32* %6
%39 = load i32, i32* %12
%40 = add nsw i32 %38, %39
%41 = sitofp i32 %40 to double
%42 = call i64 @sin(double %41)
%43 = load i32, i32* %6
%44 = load i32, i32* %12
%45 = mul nsw i32 2, %44
%46 = add nsw i32 %43, %45
%47 = sitofp i32 %46 to double
%48 = call i64 @cos(double %47)
%49 = add nsw i64 %42, %48
%50 = sitofp i64 %49 to double
%51 = load i32, i32* %12
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [100 x double], [100 x double]* %13, i64 0, i64 %52
%54 = load double, double* %53
%55 = fadd double %54, %50
store double %55, double* %53
br label %56
56: ; preds = %37
%57 = load i32, i32* %6
%58 = add nsw i32 %57, 1
store i32 %58, i32* %6
br label %33
59: ; preds = %33
%60 = load i32, i32* %7
%61 = sitofp i32 %60 to double
%62 = load i32, i32* %12
%63 = load i32, i32* %12
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [100 x double], [100 x double]* %13, i64 0, i64 %64
%66 = load double, double* %65
%67 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double %61, i32 %62, double %66)
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
store i32 %69, i32* %11
store i32 %69, i32* %12
br label %70
70: ; preds = %59
%71 = load i32, i32* %11
%72 = icmp slt i32 %71, 20
br i1 %72, label %29, label %73
73: ; preds = %70
store double 0.000000e+00, double* %14
store i32 0, i32* %6
br label %74
74: ; preds = %84, %73
%75 = load i32, i32* %6
%76 = icmp slt i32 %75, 20
br i1 %76, label %77, label %87
77: ; preds = %74
%78 = load i32, i32* %6
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [100 x double], [100 x double]* %13, i64 0, i64 %79
%81 = load double, double* %80
%82 = load double, double* %14
%83 = fadd double %82, %81
store double %83, double* %14
br label %84
84: ; preds = %77
%85 = load i32, i32* %6
%86 = add nsw i32 %85, 1
store i32 %86, i32* %6
br label %74
87: ; preds = %74
%88 = load double, double* %14
%89 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %88)
%90 = call i32 @dtime(double* %16)
%91 = load double, double* %16
%92 = load double, double* %15
%93 = fsub double %91, %92
%94 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), double %93)
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"Nprocs=%2d Nthrds=%2d id=%d\0A\00"
@.str.1 = [27 x i8] c"id=%2d kp=%2d sum=%15.12f\0A\00"
@.str.2 = [14 x i8] c"tsum=%15.12f\0A\00"
@.str.3 = [26 x i8] c"Elapsed time (s)=%15.12f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x double]
%4 = alloca double
%5 = alloca double
%6 = bitcast [100 x double]* %3 to i8*
%7 = bitcast double* %4 to i8*
%8 = bitcast double* %5 to i8*
%9 = call i32 @dtime(double* %4)
%10 = call i32 (...) @omp_get_thread_num()
%11 = call i32 (...) @omp_get_num_threads()
%12 = call i32 (...) @omp_get_num_procs()
%13 = sitofp i32 %12 to double
%14 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), double %13, i32 %11, i32 %10)
%15 = add nsw i32 %11, -1
%16 = sitofp i32 %10 to double
br label %17
17: ; preds = %48, %2
%18 = phi i32 [ %15, %2 ], [ %50, %48 ]
%19 = phi i32 [ %10, %2 ], [ %50, %48 ]
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 %20
store double 0.000000e+00, double* %21
%22 = shl nsw i32 %19, 1
br label %23
23: ; preds = %23, %17
%24 = phi i32 [ 0, %17 ], [ %46, %23 ]
%25 = add nsw i32 %24, %19
%26 = sitofp i32 %25 to double
%27 = call i64 @sin(double %26)
%28 = add nsw i32 %24, %22
%29 = sitofp i32 %28 to double
%30 = call i64 @cos(double %29)
%31 = add nsw i64 %30, %27
%32 = sitofp i64 %31 to double
%33 = load double, double* %21
%34 = fadd double %33, %32
store double %34, double* %21
%35 = or i32 %24, 1
%36 = add nsw i32 %35, %19
%37 = sitofp i32 %36 to double
%38 = call i64 @sin(double %37)
%39 = add nsw i32 %35, %22
%40 = sitofp i32 %39 to double
%41 = call i64 @cos(double %40)
%42 = add nsw i64 %41, %38
%43 = sitofp i64 %42 to double
%44 = load double, double* %21
%45 = fadd double %44, %43
store double %45, double* %21
%46 = add nuw nsw i32 %24, 2
%47 = icmp eq i32 %46, 30000000
br i1 %47, label %48, label %23
48: ; preds = %23
%49 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double %16, i32 %19, double %45)
%50 = add nsw i32 %18, 1
%51 = icmp slt i32 %18, 19
br i1 %51, label %17, label %52
52: ; preds = %48
%53 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 0
%54 = load double, double* %53
%55 = fadd double %54, 0.000000e+00
%56 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 1
%57 = load double, double* %56
%58 = fadd double %55, %57
%59 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 2
%60 = load double, double* %59
%61 = fadd double %58, %60
%62 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 3
%63 = load double, double* %62
%64 = fadd double %61, %63
%65 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 4
%66 = load double, double* %65
%67 = fadd double %64, %66
%68 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 5
%69 = load double, double* %68
%70 = fadd double %67, %69
%71 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 6
%72 = load double, double* %71
%73 = fadd double %70, %72
%74 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 7
%75 = load double, double* %74
%76 = fadd double %73, %75
%77 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 8
%78 = load double, double* %77
%79 = fadd double %76, %78
%80 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 9
%81 = load double, double* %80
%82 = fadd double %79, %81
%83 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 10
%84 = load double, double* %83
%85 = fadd double %82, %84
%86 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 11
%87 = load double, double* %86
%88 = fadd double %85, %87
%89 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 12
%90 = load double, double* %89
%91 = fadd double %88, %90
%92 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 13
%93 = load double, double* %92
%94 = fadd double %91, %93
%95 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 14
%96 = load double, double* %95
%97 = fadd double %94, %96
%98 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 15
%99 = load double, double* %98
%100 = fadd double %97, %99
%101 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 16
%102 = load double, double* %101
%103 = fadd double %100, %102
%104 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 17
%105 = load double, double* %104
%106 = fadd double %103, %105
%107 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 18
%108 = load double, double* %107
%109 = fadd double %106, %108
%110 = getelementptr inbounds [100 x double], [100 x double]* %3, i64 0, i64 19
%111 = load double, double* %110
%112 = fadd double %109, %111
%113 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %112)
%114 = call i32 @dtime(double* %5)
%115 = load double, double* %5
%116 = load double, double* %4
%117 = fsub double %115, %116
%118 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), double %117)
ret i32 0
}