#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_max_threads();
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, int);
int main(int argc, char **argv) {
  omp_set_nested(1);
  omp_set_dynamic(0);
  int num = 0;
  int threads = 0;
  int max = 0;
  num = omp_get_thread_num();
  threads = omp_get_num_threads();
  max = omp_get_max_threads();
  printf("Master : Thread %d of %d (%d Max)\n\n", num, threads, max);
#pragma omp parallel num_threads(8)
  {
    num = omp_get_thread_num();
    threads = omp_get_num_threads();
    max = omp_get_max_threads();
    printf("Outer  : Thread %d of %d (%d Max)\n\n", num, threads, max);
#pragma omp parallel num_threads(4)
    {
      num = omp_get_thread_num();
      threads = omp_get_num_threads();
      max = omp_get_max_threads();
      printf("Inner  : Thread %d of %d (%d Max)\n", num, threads, max);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1070 <omp_set_nested@plt>
xor    %edi,%edi
call   1060 <omp_set_dynamic@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <omp_get_max_threads@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <omp_get_max_threads@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe27(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <omp_get_max_threads@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe18(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
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>
mov    %eax,%ebp
xor    %eax,%eax
call   1080 <omp_get_max_threads@plt>
lea    0xe6c(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1080 <omp_get_max_threads@plt>
lea    0xe65(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1080 <omp_get_max_threads@plt>
lea    0xe5e(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Master : Thread %d of %d (%d Max)\0A\0A\00"
@.str.1 = [36 x i8] c"Outer : Thread %d of %d (%d Max)\0A\0A\00"
@.str.2 = [35 x i8] c"Inner : Thread %d of %d (%d Max)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @omp_set_nested(i32 1)
%10 = call i32 @omp_set_dynamic(i32 0)
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%11 = call i32 (...) @omp_get_thread_num()
store i32 %11, i32* %6
%12 = call i32 (...) @omp_get_num_threads()
store i32 %12, i32* %7
%13 = call i32 (...) @omp_get_max_threads()
store i32 %13, i32* %8
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = load i32, i32* %8
%17 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15, i32 %16)
%18 = call i32 (...) @omp_get_thread_num()
store i32 %18, i32* %6
%19 = call i32 (...) @omp_get_num_threads()
store i32 %19, i32* %7
%20 = call i32 (...) @omp_get_max_threads()
store i32 %20, i32* %8
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22, i32 %23)
%25 = call i32 (...) @omp_get_thread_num()
store i32 %25, i32* %6
%26 = call i32 (...) @omp_get_num_threads()
store i32 %26, i32* %7
%27 = call i32 (...) @omp_get_max_threads()
store i32 %27, i32* %8
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %29, i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"Master : Thread %d of %d (%d Max)\0A\0A\00"
@.str.1 = [36 x i8] c"Outer : Thread %d of %d (%d Max)\0A\0A\00"
@.str.2 = [35 x i8] c"Inner : Thread %d of %d (%d Max)\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @omp_set_nested(i32 1)
%4 = tail call i32 @omp_set_dynamic(i32 0)
%5 = tail call i32 (...) @omp_get_thread_num()
%6 = tail call i32 (...) @omp_get_num_threads()
%7 = tail call i32 (...) @omp_get_max_threads()
%8 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6, i32 %7)
%9 = tail call i32 (...) @omp_get_thread_num()
%10 = tail call i32 (...) @omp_get_num_threads()
%11 = tail call i32 (...) @omp_get_max_threads()
%12 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %10, i32 %11)
%13 = tail call i32 (...) @omp_get_thread_num()
%14 = tail call i32 (...) @omp_get_num_threads()
%15 = tail call i32 (...) @omp_get_max_threads()
%16 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14, i32 %15)
ret i32 0
}