#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_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
int *malloc(int const);
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ process(int);
int main(void) {
  const int slow_down = 10;
  const int array_size = 1000;
  int *array = malloc(array_size * sizeof(int));
  if (array == NULL) {
    exit(EXIT_FAILURE);
  }
  for (int i = 0; i < array_size; i++) {
    array[i] = slow_down * i;
  }
  double t;
  printf("// for \n");
  t = omp_get_wtime();
#pragma omp parallel
  {
#pragma omp for
    for (int i = 0; i < array_size; i++) {
      process(array[i]);
    }
  }
  t = omp_get_wtime() - t;
  printf("%d %lf\n", array_size, t);
  printf("// for schedule(dynamic)\n");
  t = omp_get_wtime();
#pragma omp parallel
  {
#pragma omp for schedule(dynamic)
    for (int i = 0; i < array_size; i++) {
      process(array[i]);
    }
  }
  t = omp_get_wtime() - t;
  printf("%d %lf\n", array_size, t);
  printf("// single + task\n");
  t = omp_get_wtime();
#pragma omp parallel
  {
#pragma omp single
    for (int i = 0; i < array_size; i++) {
#pragma omp task
      process(array[i]);
    }
  }
  t = omp_get_wtime() - t;
  printf("%d %lf\n", array_size, t);
  free(array);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
movl   $0x3e8,-0xc(%rbp)
mov    $0xfa0,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a4 <main+0x44>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    11d5 <main+0x75>
imul   $0xa,-0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ab <main+0x4b>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3e8,-0x2c(%rbp)
jge    1221 <main+0xc1>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1060 <process@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f6 <main+0x96>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xdcb(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x3e8,-0x30(%rbp)
jge    1296 <main+0x136>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1060 <process@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    126b <main+0x10b>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xd56(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x3e8,-0x34(%rbp)
jge    130b <main+0x1ab>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1060 <process@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12e0 <main+0x180>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xce1(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0xfa0,%edi
call   1080 <malloc@plt>
test   %rax,%rax
jne    1191 <main+0x21>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %rax,%r14
movdqa 0xe64(%rip),%xmm0
mov    $0xc,%eax
movdqa 0xe67(%rip),%xmm1
movdqa 0xe6f(%rip),%xmm2
movdqa 0xe77(%rip),%xmm3
movdqa 0xe7f(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm5
pmuludq %xmm1,%xmm5
pshufd $0xe8,%xmm5,%xmm5
pshufd $0xf5,%xmm0,%xmm6
pmuludq %xmm1,%xmm6
pshufd $0xe8,%xmm6,%xmm6
punpckldq %xmm6,%xmm5
movdqu %xmm5,-0x30(%r14,%rax,4)
paddd  %xmm2,%xmm5
movdqu %xmm5,-0x20(%r14,%rax,4)
cmp    $0x3ec,%rax
je     1247 <main+0xd7>
movdqa %xmm0,%xmm5
paddd  %xmm3,%xmm5
pshufd $0xf5,%xmm5,%xmm6
pmuludq %xmm1,%xmm5
pshufd $0xe8,%xmm5,%xmm5
pmuludq %xmm1,%xmm6
pshufd $0xe8,%xmm6,%xmm6
punpckldq %xmm6,%xmm5
movdqu %xmm5,-0x10(%r14,%rax,4)
paddd  %xmm2,%xmm5
movdqu %xmm5,(%r14,%rax,4)
paddd  %xmm4,%xmm0
add    $0x10,%rax
jmp    11d0 <main+0x60>
lea    0xe0a(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <omp_get_wtime@plt>
movq   %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%edi
call   1070 <process@plt>
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1270 <main+0x100>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <omp_get_wtime@plt>
subsd  (%rsp),%xmm0
lea    0xdb5(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xdb2(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <omp_get_wtime@plt>
movsd  %xmm0,(%rsp)
nop
mov    (%r14,%rbx,4),%edi
call   1070 <process@plt>
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    12c0 <main+0x150>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <omp_get_wtime@plt>
subsd  (%rsp),%xmm0
lea    0xd65(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xd7b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <omp_get_wtime@plt>
movsd  %xmm0,(%rsp)
nop
mov    (%r14,%rbx,4),%edi
call   1070 <process@plt>
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1310 <main+0x1a0>
xor    %eax,%eax
call   1050 <omp_get_wtime@plt>
subsd  (%rsp),%xmm0
lea    0xd17(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [9 x i8] c"// for \0A\00"
@.str.1 = [8 x i8] c"%d %lf\0A\00"
@.str.2 = [26 x i8] c"// for schedule(dynamic)\0A\00"
@.str.3 = [18 x i8] c"// single + task\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 10, i32* %2
store i32 1000, i32* %3
%10 = call i32* @malloc(i32 4000)
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
store i32 0, i32* %5
br label %17
17: ; preds = %27, %16
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 1000
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = load i32, i32* %5
%22 = mul nsw i32 10, %21
%23 = load i32*, i32** %4
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
store i32 %22, i32* %26
br label %27
27: ; preds = %20
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %17
30: ; preds = %17
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%32 = call double (...) @omp_get_wtime()
store double %32, double* %6
store i32 0, i32* %7
br label %33
33: ; preds = %43, %30
%34 = load i32, i32* %7
%35 = icmp slt i32 %34, 1000
br i1 %35, label %36, label %46
36: ; preds = %33
%37 = load i32*, i32** %4
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = call i32 @process(i32 %41)
br label %43
43: ; preds = %36
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %33
46: ; preds = %33
%47 = call double (...) @omp_get_wtime()
%48 = load double, double* %6
%49 = fsub double %47, %48
store double %49, double* %6
%50 = load double, double* %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1000, double %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%53 = call double (...) @omp_get_wtime()
store double %53, double* %6
store i32 0, i32* %8
br label %54
54: ; preds = %64, %46
%55 = load i32, i32* %8
%56 = icmp slt i32 %55, 1000
br i1 %56, label %57, label %67
57: ; preds = %54
%58 = load i32*, i32** %4
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %58, i64 %60
%62 = load i32, i32* %61
%63 = call i32 @process(i32 %62)
br label %64
64: ; preds = %57
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
br label %54
67: ; preds = %54
%68 = call double (...) @omp_get_wtime()
%69 = load double, double* %6
%70 = fsub double %68, %69
store double %70, double* %6
%71 = load double, double* %6
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1000, double %71)
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%74 = call double (...) @omp_get_wtime()
store double %74, double* %6
store i32 0, i32* %9
br label %75
75: ; preds = %85, %67
%76 = load i32, i32* %9
%77 = icmp slt i32 %76, 1000
br i1 %77, label %78, label %88
78: ; preds = %75
%79 = load i32*, i32** %4
%80 = load i32, i32* %9
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %79, i64 %81
%83 = load i32, i32* %82
%84 = call i32 @process(i32 %83)
br label %85
85: ; preds = %78
%86 = load i32, i32* %9
%87 = add nsw i32 %86, 1
store i32 %87, i32* %9
br label %75
88: ; preds = %75
%89 = call double (...) @omp_get_wtime()
%90 = load double, double* %6
%91 = fsub double %89, %90
store double %91, double* %6
%92 = load double, double* %6
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1000, double %92)
%94 = load i32*, i32** %4
%95 = call i32 @free(i32* %94)
%96 = load i32, i32* @EXIT_SUCCESS
%97 = call i32 @exit(i32 %96)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [8 x i8] c"%d %lf\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [8 x i8] c"// for \00"
@str.4 = [25 x i8] c"// for schedule(dynamic)\00"
@str.5 = [17 x i8] c"// single + task\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 4000)
%2 = icmp eq i32* %1, null
br i1 %2, label %26, label %3
3: ; preds = %0, %16
%4 = phi i64 [ %24, %16 ], [ 0, %0 ]
%5 = phi <4 x i32> [ %25, %16 ], [ <i32 0, i32 1, i32 2, i32 3>, %0 ]
%6 = getelementptr inbounds i32, i32* %1, i64 %4
%7 = mul <4 x i32> %5, <i32 10, i32 10, i32 10, i32 10>
%8 = mul <4 x i32> %5, <i32 10, i32 10, i32 10, i32 10>
%9 = add <4 x i32> %8, <i32 40, i32 40, i32 40, i32 40>
%10 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> %7, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %6, i64 4
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> %9, <4 x i32>* %12
%13 = or i64 %4, 8
%14 = add <4 x i32> %5, <i32 8, i32 8, i32 8, i32 8>
%15 = icmp eq i64 %13, 1000
br i1 %15, label %29, label %16
16: ; preds = %3
%17 = getelementptr inbounds i32, i32* %1, i64 %13
%18 = mul <4 x i32> %14, <i32 10, i32 10, i32 10, i32 10>
%19 = mul <4 x i32> %14, <i32 10, i32 10, i32 10, i32 10>
%20 = add <4 x i32> %19, <i32 40, i32 40, i32 40, i32 40>
%21 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> %18, <4 x i32>* %21
%22 = getelementptr inbounds i32, i32* %17, i64 4
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> %20, <4 x i32>* %23
%24 = add nuw nsw i64 %4, 16
%25 = add <4 x i32> %5, <i32 16, i32 16, i32 16, i32 16>
br label %3
26: ; preds = %0
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %3
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%31 = tail call double (...) @omp_get_wtime()
br label %38
32: ; preds = %38
%33 = tail call double (...) @omp_get_wtime()
%34 = fsub double %33, %31
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1000, double %34)
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.4, i64 0, i64 0))
%37 = tail call double (...) @omp_get_wtime()
br label %51
38: ; preds = %29, %38
%39 = phi i64 [ 0, %29 ], [ %43, %38 ]
%40 = getelementptr inbounds i32, i32* %1, i64 %39
%41 = load i32, i32* %40
%42 = tail call i32 @process(i32 %41)
%43 = add nuw nsw i64 %39, 1
%44 = icmp eq i64 %43, 1000
br i1 %44, label %32, label %38
45: ; preds = %51
%46 = tail call double (...) @omp_get_wtime()
%47 = fsub double %46, %37
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1000, double %47)
%49 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
%50 = tail call double (...) @omp_get_wtime()
br label %65
51: ; preds = %32, %51
%52 = phi i64 [ 0, %32 ], [ %56, %51 ]
%53 = getelementptr inbounds i32, i32* %1, i64 %52
%54 = load i32, i32* %53
%55 = tail call i32 @process(i32 %54)
%56 = add nuw nsw i64 %52, 1
%57 = icmp eq i64 %56, 1000
br i1 %57, label %45, label %51
58: ; preds = %65
%59 = tail call double (...) @omp_get_wtime()
%60 = fsub double %59, %50
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1000, double %60)
%62 = tail call i32 @free(i32* %1)
%63 = load i32, i32* @EXIT_SUCCESS
%64 = tail call i32 @exit(i32 %63)
unreachable
65: ; preds = %45, %65
%66 = phi i64 [ 0, %45 ], [ %70, %65 ]
%67 = getelementptr inbounds i32, i32* %1, i64 %66
%68 = load i32, i32* %67
%69 = tail call i32 @process(i32 %68)
%70 = add nuw nsw i64 %66, 1
%71 = icmp eq i64 %70, 1000
br i1 %71, label %58, label %65
}