#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_num_threads();
int omp_get_thread_num();
int /*<<< orphan*/ omp_set_dynamic(int);
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, int, ...);
int run() {
  int i, nthreads, tid;
  float a[500000], b[500000], c[500000], d[500000];
  omp_set_dynamic(1);
  omp_set_num_threads(5);
  for (i = 0; i < 500000; i++) {
    a[i] = i * 1.5;
    b[i] = i + 22.35;
    c[i] = d[i] = 0.0;
  }
#pragma omp parallel shared(a, b, c, d, nthreads) private(i, tid)
  {
    tid = omp_get_thread_num();
    if (tid == 0) {
      nthreads = omp_get_num_threads();
      printf("Number of threads = %d\n", nthreads);
    }
    printf("Thread %d starting...\n", tid);
#pragma omp sections nowait
    {
#pragma omp section
      {
        printf("Thread %d doing section 1\n", tid);
        for (i = 0; i < 500000; i++) {
          c[i] = a[i] + b[i];
          printf("Thread %d: c[%d]= %f\n", tid, i, c[i]);
        }
      }
#pragma omp section
      {
        printf("Thread %d doing section 2\n", tid);
        for (i = 0; i < 500000; i++) {
          d[i] = a[i] * b[i];
          printf("Thread %d: d[%d]= %f\n", tid, i, d[i]);
        }
      }
    }
    printf("Thread %d done.\n", tid);
  }
  return 0;
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7a1210,%rsp
mov    $0x1,%edi
call   1060 <omp_set_dynamic@plt>
mov    $0x5,%edi
call   1070 <omp_set_num_threads@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x7a120,-0x4(%rbp)
jge    11f5 <run+0xa5>
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xe78(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movslq -0x4(%rbp),%rax
movss  %xmm0,-0x1e8490(%rbp,%rax,4)
e1 ff
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xe4e(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movslq -0x4(%rbp),%rax
movss  %xmm0,-0x3d0910(%rbp,%rax,4)
c2 ff
movslq -0x4(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,-0x7a1210(%rbp,%rax,4)
85 ff
movslq -0x4(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,-0x5b8d90(%rbp,%rax,4)
a4 ff
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1176 <run+0x26>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1224 <run+0xd4>
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x7a120,-0x4(%rbp)
jge    12b4 <run+0x164>
movslq -0x4(%rbp),%rax
movss  -0x1e8490(%rbp,%rax,4),%xmm0
e1 ff
movslq -0x4(%rbp),%rax
addss  -0x3d0910(%rbp,%rax,4),%xmm0
c2 ff
movslq -0x4(%rbp),%rax
movss  %xmm0,-0x5b8d90(%rbp,%rax,4)
a4 ff
mov    -0xc(%rbp),%esi
mov    -0x4(%rbp),%edx
movslq -0x4(%rbp),%rax
movss  -0x5b8d90(%rbp,%rax,4),%xmm0
a4 ff
cvtss2sd %xmm0,%xmm0
lea    0xdbb(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    124d <run+0xfd>
mov    -0xc(%rbp),%esi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x7a120,-0x4(%rbp)
jge    1333 <run+0x1e3>
movslq -0x4(%rbp),%rax
movss  -0x1e8490(%rbp,%rax,4),%xmm0
e1 ff
movslq -0x4(%rbp),%rax
mulss  -0x3d0910(%rbp,%rax,4),%xmm0
c2 ff
movslq -0x4(%rbp),%rax
movss  %xmm0,-0x7a1210(%rbp,%rax,4)
85 ff
mov    -0xc(%rbp),%esi
mov    -0x4(%rbp),%edx
movslq -0x4(%rbp),%rax
movss  -0x7a1210(%rbp,%rax,4),%xmm0
85 ff
cvtss2sd %xmm0,%xmm0
lea    0xd6d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    12cc <run+0x17c>
mov    -0xc(%rbp),%esi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x7a1210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3d0900,%rsp
mov    $0x1,%edi
call   1060 <omp_set_dynamic@plt>
mov    $0x5,%edi
call   1070 <omp_set_num_threads@plt>
movdqa 0xe89(%rip),%xmm0
mov    $0x4,%eax
movapd 0xe8c(%rip),%xmm1
movapd 0xe94(%rip),%xmm2
movdqa 0xe9b(%rip),%xmm8
movdqa 0xea3(%rip),%xmm4
nopl   (%rax)
cvtdq2pd %xmm0,%xmm3
pshufd $0xee,%xmm0,%xmm6
cvtdq2pd %xmm6,%xmm6
movapd %xmm6,%xmm7
mulpd  %xmm1,%xmm7
movapd %xmm3,%xmm5
mulpd  %xmm1,%xmm5
cvtpd2ps %xmm5,%xmm5
cvtpd2ps %xmm7,%xmm7
unpcklpd %xmm7,%xmm5
addpd  %xmm2,%xmm6
addpd  %xmm2,%xmm3
cvtpd2ps %xmm3,%xmm3
cvtpd2ps %xmm6,%xmm6
movapd %xmm5,0x1e8470(%rsp,%rax,4)
movdqa %xmm0,%xmm5
paddd  %xmm8,%xmm5
cvtdq2pd %xmm5,%xmm7
unpcklpd %xmm6,%xmm3
pshufd $0xee,%xmm5,%xmm5
cvtdq2pd %xmm5,%xmm5
movapd %xmm3,-0x10(%rsp,%rax,4)
movapd %xmm5,%xmm3
movapd %xmm7,%xmm6
mulpd  %xmm1,%xmm6
cvtpd2ps %xmm6,%xmm6
mulpd  %xmm1,%xmm3
cvtpd2ps %xmm3,%xmm3
unpcklpd %xmm3,%xmm6
movapd %xmm6,0x1e8480(%rsp,%rax,4)
addpd  %xmm2,%xmm7
cvtpd2ps %xmm7,%xmm3
addpd  %xmm2,%xmm5
cvtpd2ps %xmm5,%xmm5
unpcklpd %xmm5,%xmm3
movapd %xmm3,(%rsp,%rax,4)
paddd  %xmm4,%xmm0
add    $0x8,%rax
cmp    $0x7a124,%rax
jne    11a0 <run+0x50>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1278 <run+0x128>
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
lea    0xde1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xde9(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdee(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdf9(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  0x1e8480(%rsp,%rbx,4),%xmm0
addss  (%rsp,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x7a120,%rbx
jne    12b0 <run+0x160>
lea    0xdcc(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdd5(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
movss  0x1e8480(%rsp,%rbx,4),%xmm0
mulss  (%rsp,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x7a120,%rbx
jne    1300 <run+0x1b0>
lea    0xdad(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x3d0900,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Number of threads = %d\0A\00"
@.str.1 = [23 x i8] c"Thread %d starting...\0A\00"
@.str.2 = [27 x i8] c"Thread %d doing section 1\0A\00"
@.str.3 = [22 x i8] c"Thread %d: c[%d]= %f\0A\00"
@.str.4 = [27 x i8] c"Thread %d doing section 2\0A\00"
@.str.5 = [22 x i8] c"Thread %d: d[%d]= %f\0A\00"
@.str.6 = [17 x i8] c"Thread %d done.\0A\00"
define i32 @run() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [500000 x float]
%5 = alloca [500000 x float]
%6 = alloca [500000 x float]
%7 = alloca [500000 x float]
%8 = call i32 @omp_set_dynamic(i32 1)
%9 = call i32 @omp_set_num_threads(i32 5)
store i32 0, i32* %1
br label %10
10: ; preds = %34, %0
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 500000
br i1 %12, label %13, label %37
13: ; preds = %10
%14 = load i32, i32* %1
%15 = sitofp i32 %14 to double
%16 = fmul double %15, 1.500000e+00
%17 = fptrunc double %16 to float
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [500000 x float], [500000 x float]* %4, i64 0, i64 %19
store float %17, float* %20
%21 = load i32, i32* %1
%22 = sitofp i32 %21 to double
%23 = fadd double %22, 2.235000e+01
%24 = fptrunc double %23 to float
%25 = load i32, i32* %1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [500000 x float], [500000 x float]* %5, i64 0, i64 %26
store float %24, float* %27
%28 = load i32, i32* %1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [500000 x float], [500000 x float]* %7, i64 0, i64 %29
store float 0.000000e+00, float* %30
%31 = load i32, i32* %1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [500000 x float], [500000 x float]* %6, i64 0, i64 %32
store float 0.000000e+00, float* %33
br label %34
34: ; preds = %13
%35 = load i32, i32* %1
%36 = add nsw i32 %35, 1
store i32 %36, i32* %1
br label %10
37: ; preds = %10
%38 = call i32 (...) @omp_get_thread_num()
store i32 %38, i32* %3
%39 = load i32, i32* %3
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = call i32 (...) @omp_get_num_threads()
store i32 %42, i32* %2
%43 = load i32, i32* %2
%44 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %41, %37
%46 = load i32, i32* %3
%47 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %3
%49 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %48)
store i32 0, i32* %1
br label %50
50: ; preds = %74, %45
%51 = load i32, i32* %1
%52 = icmp slt i32 %51, 500000
br i1 %52, label %53, label %77
53: ; preds = %50
%54 = load i32, i32* %1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [500000 x float], [500000 x float]* %4, i64 0, i64 %55
%57 = load float, float* %56
%58 = load i32, i32* %1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [500000 x float], [500000 x float]* %5, i64 0, i64 %59
%61 = load float, float* %60
%62 = fadd float %57, %61
%63 = load i32, i32* %1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [500000 x float], [500000 x float]* %6, i64 0, i64 %64
store float %62, float* %65
%66 = load i32, i32* %3
%67 = load i32, i32* %1
%68 = load i32, i32* %1
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [500000 x float], [500000 x float]* %6, i64 0, i64 %69
%71 = load float, float* %70
%72 = fpext float %71 to double
%73 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %66, i32 %67, double %72)
br label %74
74: ; preds = %53
%75 = load i32, i32* %1
%76 = add nsw i32 %75, 1
store i32 %76, i32* %1
br label %50
77: ; preds = %50
%78 = load i32, i32* %3
%79 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %78)
store i32 0, i32* %1
br label %80
80: ; preds = %104, %77
%81 = load i32, i32* %1
%82 = icmp slt i32 %81, 500000
br i1 %82, label %83, label %107
83: ; preds = %80
%84 = load i32, i32* %1
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [500000 x float], [500000 x float]* %4, i64 0, i64 %85
%87 = load float, float* %86
%88 = load i32, i32* %1
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [500000 x float], [500000 x float]* %5, i64 0, i64 %89
%91 = load float, float* %90
%92 = fmul float %87, %91
%93 = load i32, i32* %1
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [500000 x float], [500000 x float]* %7, i64 0, i64 %94
store float %92, float* %95
%96 = load i32, i32* %3
%97 = load i32, i32* %1
%98 = load i32, i32* %1
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [500000 x float], [500000 x float]* %7, i64 0, i64 %99
%101 = load float, float* %100
%102 = fpext float %101 to double
%103 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %96, i32 %97, double %102)
br label %104
104: ; preds = %83
%105 = load i32, i32* %1
%106 = add nsw i32 %105, 1
store i32 %106, i32* %1
br label %80
107: ; preds = %80
%108 = load i32, i32* %3
%109 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %108)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Number of threads = %d\0A\00"
@.str.1 = [23 x i8] c"Thread %d starting...\0A\00"
@.str.2 = [27 x i8] c"Thread %d doing section 1\0A\00"
@.str.3 = [22 x i8] c"Thread %d: c[%d]= %f\0A\00"
@.str.4 = [27 x i8] c"Thread %d doing section 2\0A\00"
@.str.5 = [22 x i8] c"Thread %d: d[%d]= %f\0A\00"
@.str.6 = [17 x i8] c"Thread %d done.\0A\00"
define i32 @run() {
%1 = alloca [500000 x float]
%2 = alloca [500000 x float]
%3 = bitcast [500000 x float]* %1 to i8*
%4 = bitcast [500000 x float]* %2 to i8*
%5 = tail call i32 @omp_set_dynamic(i32 1)
%6 = tail call i32 @omp_set_num_threads(i32 5)
br label %7
7: ; preds = %7, %0
%8 = phi i64 [ 0, %0 ], [ %30, %7 ]
%9 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %31, %7 ]
%10 = sitofp <4 x i32> %9 to <4 x double>
%11 = fmul <4 x double> %10, <double 1.500000e+00, double 1.500000e+00, double 1.500000e+00, double 1.500000e+00>
%12 = fptrunc <4 x double> %11 to <4 x float>
%13 = getelementptr inbounds [500000 x float], [500000 x float]* %1, i64 0, i64 %8
%14 = bitcast float* %13 to <4 x float>*
store <4 x float> %12, <4 x float>* %14
%15 = fadd <4 x double> %10, <double 2.235000e+01, double 2.235000e+01, double 2.235000e+01, double 2.235000e+01>
%16 = fptrunc <4 x double> %15 to <4 x float>
%17 = getelementptr inbounds [500000 x float], [500000 x float]* %2, i64 0, i64 %8
%18 = bitcast float* %17 to <4 x float>*
store <4 x float> %16, <4 x float>* %18
%19 = or i64 %8, 4
%20 = add <4 x i32> %9, <i32 4, i32 4, i32 4, i32 4>
%21 = sitofp <4 x i32> %20 to <4 x double>
%22 = fmul <4 x double> %21, <double 1.500000e+00, double 1.500000e+00, double 1.500000e+00, double 1.500000e+00>
%23 = fptrunc <4 x double> %22 to <4 x float>
%24 = getelementptr inbounds [500000 x float], [500000 x float]* %1, i64 0, i64 %19
%25 = bitcast float* %24 to <4 x float>*
store <4 x float> %23, <4 x float>* %25
%26 = fadd <4 x double> %21, <double 2.235000e+01, double 2.235000e+01, double 2.235000e+01, double 2.235000e+01>
%27 = fptrunc <4 x double> %26 to <4 x float>
%28 = getelementptr inbounds [500000 x float], [500000 x float]* %2, i64 0, i64 %19
%29 = bitcast float* %28 to <4 x float>*
store <4 x float> %27, <4 x float>* %29
%30 = add nuw nsw i64 %8, 8
%31 = add <4 x i32> %9, <i32 8, i32 8, i32 8, i32 8>
%32 = icmp eq i64 %30, 500000
br i1 %32, label %33, label %7
33: ; preds = %7
%34 = tail call i32 (...) @omp_get_thread_num()
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = tail call i32 (...) @omp_get_num_threads()
%38 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %33
%40 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%41 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %42
42: ; preds = %39, %42
%43 = phi i64 [ 0, %39 ], [ %52, %42 ]
%44 = getelementptr inbounds [500000 x float], [500000 x float]* %1, i64 0, i64 %43
%45 = load float, float* %44
%46 = getelementptr inbounds [500000 x float], [500000 x float]* %2, i64 0, i64 %43
%47 = load float, float* %46
%48 = fadd float %45, %47
%49 = fpext float %48 to double
%50 = trunc i64 %43 to i32
%51 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %50, double %49)
%52 = add nuw nsw i64 %43, 1
%53 = icmp eq i64 %52, 500000
br i1 %53, label %54, label %42
54: ; preds = %42
%55 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %34)
br label %56
56: ; preds = %54, %56
%57 = phi i64 [ 0, %54 ], [ %66, %56 ]
%58 = getelementptr inbounds [500000 x float], [500000 x float]* %1, i64 0, i64 %57
%59 = load float, float* %58
%60 = getelementptr inbounds [500000 x float], [500000 x float]* %2, i64 0, i64 %57
%61 = load float, float* %60
%62 = fmul float %59, %61
%63 = fpext float %62 to double
%64 = trunc i64 %57 to i32
%65 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %34, i32 %64, double %63)
%66 = add nuw nsw i64 %57, 1
%67 = icmp eq i64 %66, 500000
br i1 %67, label %68, label %56
68: ; preds = %56
%69 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %34)
ret i32 0
}