#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*/ printf(char *, int, ...);
int main() {
  int i, np;
  int x = 1234;
#pragma omp parallel private(np, i)
  {
    np = omp_get_thread_num();
    printf("Soy el thread %d, antes de actualizar, con x=%d \n", np, x);
#pragma omp for lastprivate(x) schedule(dynamic)
    for (i = 0; i < 11; i++) {
      x = np * i;
      printf("\tSoy el thread %d, actualizando en for, i=%d x=%d\n", np, i, x);
    }
    printf("\t\tSoy el thread %d, despues de actualizar, con x=%d \n", np, x);
  }
  printf("\n Despues de pragma parallel x=%d \n\n", x);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4d2,-0x10(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xb,-0x8(%rbp)
jge    1194 <main+0x74>
mov    -0xc(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115b <main+0x3b>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xee9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebx
lea    0xec9(%rip),%rdi
mov    %eax,%esi
mov    $0x4d2,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee6(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%rbx,%rbx,1),%r15d
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x2,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%rbx,%rbx,2),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x0(,%rbx,4),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%rbx,%rbx,4),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x5,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%r15,%r15,2),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x6,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x0(,%rbx,8),%ebp
mov    %ebp,%ecx
sub    %ebx,%ecx
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x7,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x8,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%rbx,%rbx,8),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x9,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%r15,%r15,4),%ebp
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0xa,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe28(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Soy el thread %d, antes de actualizar, con x=%d \0A\00"
@.str.1 = [51 x i8] c"\09Soy el thread %d, actualizando en for, i=%d x=%d\0A\00"
@.str.2 = [54 x i8] c"\09\09Soy el thread %d, despues de actualizar, con x=%d \0A\00"
@.str.3 = [37 x i8] c"\0A Despues de pragma parallel x=%d \0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1234, i32* %4
%5 = call i32 (...) @omp_get_thread_num()
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = load i32, i32* %4
%8 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
store i32 0, i32* %2
br label %9
9: ; preds = %20, %0
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 11
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = mul nsw i32 %13, %14
store i32 %15, i32* %4
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = load i32, i32* %4
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17, i32 %18)
br label %20
20: ; preds = %12
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %9
23: ; preds = %9
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %25)
%27 = load i32, i32* %4
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [50 x i8] c"Soy el thread %d, antes de actualizar, con x=%d \0A\00"
@.str.1 = [51 x i8] c"\09Soy el thread %d, actualizando en for, i=%d x=%d\0A\00"
@.str.2 = [54 x i8] c"\09\09Soy el thread %d, despues de actualizar, con x=%d \0A\00"
@.str.3 = [37 x i8] c"\0A Despues de pragma parallel x=%d \0A\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @omp_get_thread_num()
%2 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %1, i32 1234)
%3 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 0, i32 0)
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 1, i32 %1)
%5 = shl nsw i32 %1, 1
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 2, i32 %5)
%7 = mul nsw i32 %1, 3
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 3, i32 %7)
%9 = shl nsw i32 %1, 2
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 4, i32 %9)
%11 = mul nsw i32 %1, 5
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 5, i32 %11)
%13 = mul nsw i32 %1, 6
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 6, i32 %13)
%15 = mul nsw i32 %1, 7
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 7, i32 %15)
%17 = shl nsw i32 %1, 3
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 8, i32 %17)
%19 = mul nsw i32 %1, 9
%20 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 9, i32 %19)
%21 = mul nsw i32 %1, 10
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 10, i32 %21)
%23 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %1, i32 %21)
%24 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %21)
ret i32 0
}