#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, int, int, ...);
void fun() {
  int a = 100;
  int b = 200;
  int c = 300;
  int d = 400;
  static int sum = 0;
  printf("Before parallel: a = %d, b = %d, c = %d, d = %d\n", a, b, c, d);
#pragma omp parallel private(a) firstprivate(b) num_threads(2)
  {
    int tid = omp_get_thread_num();
    printf("Thread %d: a = %d, b = %d, c = %d, d = %d\n", tid, a, b, c, d);
    a = 1;
    b = 2;
#pragma omp threadprivate(sum)
    sum++;
#pragma omp for lastprivate(c)
    for (int i = 0; i < 100; i++)
      c = i;
#pragma omp sections lastprivate(d)
    {
#pragma omp section
      { d = 1; }
#pragma omp section
      { d = 2; }
    }
  }
  printf("After parallel: a = %d, b = %d, c = %d, d = %d\n", a, b, c, d);
}


x86 assembly (clang, -O0):
<fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x64,-0x4(%rbp)
movl   $0xc8,-0x8(%rbp)
movl   $0x12c,-0xc(%rbp)
movl   $0x190,-0x10(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
mov    0x2e98(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e8f(%rip)
movl   $0x0,-0x18(%rbp)
cmpl   $0x64,-0x18(%rbp)
jge    11ca <fun+0xaa>
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ac <fun+0x8c>
movl   $0x1,-0x10(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun>:
push   %rax
lea    0xed8(%rip),%rdi
mov    $0x64,%esi
mov    $0xc8,%edx
mov    $0x12c,%ecx
mov    $0x190,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
lea    0xedf(%rip),%rdi
mov    %eax,%esi
mov    $0x64,%edx
mov    $0xc8,%ecx
mov    $0x12c,%r8d
mov    $0x190,%r9d
xor    %eax,%eax
call   1040 <printf@plt>
addl   $0x1,0x2ebc(%rip)
lea    0xedd(%rip),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    $0x63,%ecx
mov    $0x2,%r8d
xor    %eax,%eax
pop    %r9
jmp    1040 <printf@plt>

LLVM IR (-O0):
@fun.sum = internal global i32 0
@.str = [49 x i8] c"Before parallel: a = %d, b = %d, c = %d, d = %d\0A\00"
@.str.1 = [43 x i8] c"Thread %d: a = %d, b = %d, c = %d, d = %d\0A\00"
@.str.2 = [48 x i8] c"After parallel: a = %d, b = %d, c = %d, d = %d\0A\00"
define void @fun() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 100, i32* %1
store i32 200, i32* %2
store i32 300, i32* %3
store i32 400, i32* %4
%7 = load i32, i32* %1
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = call i32 (i8*, i32, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8, i32 %9, i32 %10)
%12 = call i32 (...) @omp_get_thread_num()
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = load i32, i32* %1
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = call i32 (i8*, i32, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14, i32 %15, i32 %16, i32 %17)
store i32 1, i32* %1
store i32 2, i32* %2
%19 = load i32, i32* @fun.sum
%20 = add nsw i32 %19, 1
store i32 %20, i32* @fun.sum
store i32 0, i32* %6
br label %21
21: ; preds = %26, %0
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 100
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i32, i32* %6
store i32 %25, i32* %3
br label %26
26: ; preds = %24
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %21
29: ; preds = %21
store i32 1, i32* %4
store i32 2, i32* %4
%30 = load i32, i32* %1
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = call i32 (i8*, i32, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %31, i32 %32, i32 %33)
ret void
}

LLVM IR (-O2):
@fun.sum = internal unnamed_addr global i32 0
@.str = [49 x i8] c"Before parallel: a = %d, b = %d, c = %d, d = %d\0A\00"
@.str.1 = [43 x i8] c"Thread %d: a = %d, b = %d, c = %d, d = %d\0A\00"
@.str.2 = [48 x i8] c"After parallel: a = %d, b = %d, c = %d, d = %d\0A\00"
define void @fun() {
%1 = tail call i32 (i8*, i32, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 100, i32 200, i32 300, i32 400)
%2 = tail call i32 (...) @omp_get_thread_num()
%3 = tail call i32 (i8*, i32, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 100, i32 200, i32 300, i32 400)
%4 = load i32, i32* @fun.sum
%5 = add nsw i32 %4, 1
store i32 %5, i32* @fun.sum
%6 = tail call i32 (i8*, i32, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 2, i32 99, i32 2)
ret void
}