#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_thread_num();
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int v[5], i, suma;
  for (i = 0; i < 5; i++) {
    v[i] = i;
  }
  omp_set_num_threads(4);
  printf("Private\n");
#pragma omp parallel private(suma)
  {
    suma = 0;
    for (i = 0; i < 5; i++) {
      suma += v[i];
    }
    printf("Hilo %d. Suma %d\n", omp_get_thread_num(), suma);
  }
  printf("\nShared\n");
#pragma omp parallel shared(suma)
  {
    for (i = 0; i < 5; i++) {
      suma += v[i];
    }
    printf("Hilo %d. Suma %d\n", omp_get_thread_num(), suma);
  }
  printf("\nIf\n");
#pragma omp parallel if (suma < 10)
  {
    for (i = 0; i < 5; i++) {
      suma += v[i];
    }
    printf("Hilo %d. Suma %d\n", omp_get_thread_num(), suma);
  }
  printf("\nFirstprivate\n");
#pragma omp parallel firstprivate(suma)
  {
    for (i = 0; i < 5; i++) {
      suma += v[i];
    }
    printf("Hilo %d. Suma %d\n", omp_get_thread_num(), suma);
  }
  printf("\nParallel reduction\n");
#pragma omp parallel
  {
#pragma omp for reduction(+ : suma)
    for (i = 0; i < 5; i++) {
      suma += v[i];
    }
    printf("Hilo %d. Suma %d\n", omp_get_thread_num(), suma);
  }
  printf("\nParallel for con nowait\n");
#pragma omp parallel shared(suma)
  {
#pragma omp for nowait
    for (i = 0; i < 5; i++) {
      suma += v[i];
    }
    printf("Hilo %d. Suma %d\n", omp_get_thread_num(), suma);
  }
  printf("\nParallel for sin nowait\n");
#pragma omp parallel shared(suma)
  {
#pragma omp for
    for (i = 0; i < 5; i++) {
      suma += v[i];
    }
    printf("Hilo %d. Suma %d\n", omp_get_thread_num(), suma);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x5,-0x34(%rbp)
jge    1170 <main+0x40>
mov    -0x34(%rbp),%ecx
movslq -0x34(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    114d <main+0x1d>
mov    $0x4,%edi
call   1050 <omp_set_num_threads@plt>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x5,-0x34(%rbp)
jge    11bc <main+0x8c>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1196 <main+0x66>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    -0x38(%rbp),%edx
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x5,-0x34(%rbp)
jge    1211 <main+0xe1>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11eb <main+0xbb>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    -0x38(%rbp),%edx
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x5,-0x34(%rbp)
jge    1266 <main+0x136>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1240 <main+0x110>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    -0x38(%rbp),%edx
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x5,-0x34(%rbp)
jge    12bb <main+0x18b>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1295 <main+0x165>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    -0x38(%rbp),%edx
lea    0xd3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x5,-0x34(%rbp)
jge    1310 <main+0x1e0>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12ea <main+0x1ba>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    -0x38(%rbp),%edx
lea    0xce6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x5,-0x34(%rbp)
jge    1365 <main+0x235>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    133f <main+0x20f>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    -0x38(%rbp),%edx
lea    0xc91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xce1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x5,-0x34(%rbp)
jge    13ba <main+0x28a>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1394 <main+0x264>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    -0x38(%rbp),%edx
lea    0xc3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x4,%edi
call   1060 <omp_set_num_threads@plt>
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
lea    0xe9b(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0xa,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x14,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1e,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x28,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x32,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x3c,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x46,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"Private\0A\00"
@.str.1 = [18 x i8] c"Hilo %d. Suma %d\0A\00"
@.str.2 = [9 x i8] c"\0AShared\0A\00"
@.str.3 = [5 x i8] c"\0AIf\0A\00"
@.str.4 = [15 x i8] c"\0AFirstprivate\0A\00"
@.str.5 = [21 x i8] c"\0AParallel reduction\0A\00"
@.str.6 = [26 x i8] c"\0AParallel for con nowait\0A\00"
@.str.7 = [26 x i8] c"\0AParallel for sin nowait\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [5 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %9
9: ; preds = %17, %2
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 5
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32, i32* %7
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %15
store i32 %13, i32* %16
br label %17
17: ; preds = %12
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
store i32 %19, i32* %7
br label %9
20: ; preds = %9
%21 = call i32 @omp_set_num_threads(i32 4)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
store i32 0, i32* %7
br label %23
23: ; preds = %33, %20
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 5
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = load i32, i32* %8
%32 = add nsw i32 %31, %30
store i32 %32, i32* %8
br label %33
33: ; preds = %26
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %23
36: ; preds = %23
%37 = call i32 (...) @omp_get_thread_num()
%38 = load i32, i32* %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %37, i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %7
br label %41
41: ; preds = %51, %36
%42 = load i32, i32* %7
%43 = icmp slt i32 %42, 5
br i1 %43, label %44, label %54
44: ; preds = %41
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = load i32, i32* %8
%50 = add nsw i32 %49, %48
store i32 %50, i32* %8
br label %51
51: ; preds = %44
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %41
54: ; preds = %41
%55 = call i32 (...) @omp_get_thread_num()
%56 = load i32, i32* %8
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %55, i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %7
br label %59
59: ; preds = %69, %54
%60 = load i32, i32* %7
%61 = icmp slt i32 %60, 5
br i1 %61, label %62, label %72
62: ; preds = %59
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %64
%66 = load i32, i32* %65
%67 = load i32, i32* %8
%68 = add nsw i32 %67, %66
store i32 %68, i32* %8
br label %69
69: ; preds = %62
%70 = load i32, i32* %7
%71 = add nsw i32 %70, 1
store i32 %71, i32* %7
br label %59
72: ; preds = %59
%73 = call i32 (...) @omp_get_thread_num()
%74 = load i32, i32* %8
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %73, i32 %74)
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %7
br label %77
77: ; preds = %87, %72
%78 = load i32, i32* %7
%79 = icmp slt i32 %78, 5
br i1 %79, label %80, label %90
80: ; preds = %77
%81 = load i32, i32* %7
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %82
%84 = load i32, i32* %83
%85 = load i32, i32* %8
%86 = add nsw i32 %85, %84
store i32 %86, i32* %8
br label %87
87: ; preds = %80
%88 = load i32, i32* %7
%89 = add nsw i32 %88, 1
store i32 %89, i32* %7
br label %77
90: ; preds = %77
%91 = call i32 (...) @omp_get_thread_num()
%92 = load i32, i32* %8
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %91, i32 %92)
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %7
br label %95
95: ; preds = %105, %90
%96 = load i32, i32* %7
%97 = icmp slt i32 %96, 5
br i1 %97, label %98, label %108
98: ; preds = %95
%99 = load i32, i32* %7
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %100
%102 = load i32, i32* %101
%103 = load i32, i32* %8
%104 = add nsw i32 %103, %102
store i32 %104, i32* %8
br label %105
105: ; preds = %98
%106 = load i32, i32* %7
%107 = add nsw i32 %106, 1
store i32 %107, i32* %7
br label %95
108: ; preds = %95
%109 = call i32 (...) @omp_get_thread_num()
%110 = load i32, i32* %8
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %109, i32 %110)
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %7
br label %113
113: ; preds = %123, %108
%114 = load i32, i32* %7
%115 = icmp slt i32 %114, 5
br i1 %115, label %116, label %126
116: ; preds = %113
%117 = load i32, i32* %7
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %118
%120 = load i32, i32* %119
%121 = load i32, i32* %8
%122 = add nsw i32 %121, %120
store i32 %122, i32* %8
br label %123
123: ; preds = %116
%124 = load i32, i32* %7
%125 = add nsw i32 %124, 1
store i32 %125, i32* %7
br label %113
126: ; preds = %113
%127 = call i32 (...) @omp_get_thread_num()
%128 = load i32, i32* %8
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %127, i32 %128)
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %7
br label %131
131: ; preds = %141, %126
%132 = load i32, i32* %7
%133 = icmp slt i32 %132, 5
br i1 %133, label %134, label %144
134: ; preds = %131
%135 = load i32, i32* %7
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %136
%138 = load i32, i32* %137
%139 = load i32, i32* %8
%140 = add nsw i32 %139, %138
store i32 %140, i32* %8
br label %141
141: ; preds = %134
%142 = load i32, i32* %7
%143 = add nsw i32 %142, 1
store i32 %143, i32* %7
br label %131
144: ; preds = %131
%145 = call i32 (...) @omp_get_thread_num()
%146 = load i32, i32* %8
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %145, i32 %146)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"Hilo %d. Suma %d\0A\00"
@str = [8 x i8] c"Private\00"
@str.8 = [8 x i8] c"\0AShared\00"
@str.9 = [4 x i8] c"\0AIf\00"
@str.10 = [14 x i8] c"\0AFirstprivate\00"
@str.11 = [20 x i8] c"\0AParallel reduction\00"
@str.12 = [25 x i8] c"\0AParallel for con nowait\00"
@str.13 = [25 x i8] c"\0AParallel for sin nowait\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @omp_set_num_threads(i32 4)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 (...) @omp_get_thread_num()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 10)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.8, i64 0, i64 0))
%8 = tail call i32 (...) @omp_get_thread_num()
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 20)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.9, i64 0, i64 0))
%11 = tail call i32 (...) @omp_get_thread_num()
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 30)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.10, i64 0, i64 0))
%14 = tail call i32 (...) @omp_get_thread_num()
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 40)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.11, i64 0, i64 0))
%17 = tail call i32 (...) @omp_get_thread_num()
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 50)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
%20 = tail call i32 (...) @omp_get_thread_num()
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 60)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.13, i64 0, i64 0))
%23 = tail call i32 (...) @omp_get_thread_num()
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 70)
ret i32 0
}