#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 /*<<< orphan*/);
int /*<<< orphan*/ omp_set_nested(int);
int /*<<< orphan*/ printf(char *, int, int, ...);
void nested_parallel(void) {
  int i = 1, j = 2;
  int l = -1;
  omp_set_nested(1);
  omp_set_dynamic(0);
#pragma omp parallel num_threads(2) private(l)
  {
    int num = omp_get_thread_num();
    int nthr = omp_get_num_threads();
    int off = num * nthr;
    int k = off + 101;
    l = off + 102;
#pragma omp parallel num_threads(2) shared(num)
    {
      int inner_num = omp_get_thread_num();
#pragma omp critical
      printf("nested_parallel (inner threads): outer thread num = %d, thread "
             "num = %d\n",
             num, inner_num);
    }
#pragma omp critical
    printf("nested_parallel (outer threads) %d: k = %d, l = %d\n", num, k, l);
  }
}


x86 assembly (clang, -O0):
<nested_parallel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    $0x1,%edi
call   1070 <omp_set_nested@plt>
xor    %edi,%edi
call   1060 <omp_set_dynamic@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x65,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x66,%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nested_parallel>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%edi
call   1070 <omp_set_nested@plt>
xor    %edi,%edi
call   1060 <omp_set_dynamic@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
imul   %ebx,%eax
lea    0x65(%rax),%r14d
lea    0x66(%rax),%ebp
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
lea    0xe73(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeaa(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [73 x i8] c"nested_parallel (inner threads): outer thread num = %d, thread num = %d\0A\00"
@.str.1 = [52 x i8] c"nested_parallel (outer threads) %d: k = %d, l = %d\0A\00"
define void @nested_parallel() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 1, i32* %1
store i32 2, i32* %2
store i32 -1, i32* %3
%9 = call i32 @omp_set_nested(i32 1)
%10 = call i32 @omp_set_dynamic(i32 0)
%11 = call i32 (...) @omp_get_thread_num()
store i32 %11, i32* %4
%12 = call i32 (...) @omp_get_num_threads()
store i32 %12, i32* %5
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = mul nsw i32 %13, %14
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = add nsw i32 %16, 101
store i32 %17, i32* %7
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 102
store i32 %19, i32* %3
%20 = call i32 (...) @omp_get_thread_num()
store i32 %20, i32* %8
%21 = load i32, i32* %4
%22 = load i32, i32* %8
%23 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22)
%24 = load i32, i32* %4
%25 = load i32, i32* %7
%26 = load i32, i32* %3
%27 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25, i32 %26)
ret void
}

LLVM IR (-O2):
@.str = [73 x i8] c"nested_parallel (inner threads): outer thread num = %d, thread num = %d\0A\00"
@.str.1 = [52 x i8] c"nested_parallel (outer threads) %d: k = %d, l = %d\0A\00"
define void @nested_parallel() {
%1 = tail call i32 @omp_set_nested(i32 1)
%2 = tail call i32 @omp_set_dynamic(i32 0)
%3 = tail call i32 (...) @omp_get_thread_num()
%4 = tail call i32 (...) @omp_get_num_threads()
%5 = mul nsw i32 %4, %3
%6 = add nsw i32 %5, 101
%7 = add nsw i32 %5, 102
%8 = tail call i32 (...) @omp_get_thread_num()
%9 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %8)
%10 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %6, i32 %7)
ret void
}