#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_nested(int);
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char *argv[]) {
  int i;
  omp_set_nested(2);
#pragma omp parallel num_threads(2) private(i)
  {
    int iam = omp_get_thread_num();
    printf("init %d\n", iam);
#pragma omp for private(i)
    for (i = 0; i < 8; i++) {
      printf(" %d doing %d\n", iam, i);
    }
#pragma omp parallel for num_threads(4) private(i) shared(iam)
    for (i = 0; i < 8; i++) {
      int iam2 = omp_get_thread_num();
      printf(" %d/%d/%d doing %d\n", iam, iam2, omp_get_num_threads(), i);
    }
    printf(" %d doing %d\n", iam, omp_get_thread_num());
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x2,%edi
call   1060 <omp_set_nested@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    11ae <main+0x6e>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <main+0x42>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    1204 <main+0xc4>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    %eax,%ecx
mov    -0x14(%rbp),%r8d
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b5 <main+0x75>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    -0x28(%rbp),%esi
mov    %eax,%edx
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x2,%edi
call   1060 <omp_set_nested@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebx
lea    0xe9f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe98(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x5,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x6,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x7,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
lea    0xe0a(%rip),%r15
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
mov    $0x1,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
mov    $0x2,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
mov    $0x3,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
mov    $0x4,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
mov    $0x5,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
mov    $0x6,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
mov    $0x7,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
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 = [9 x i8] c"init %d\0A\00"
@.str.1 = [14 x i8] c" %d doing %d\0A\00"
@.str.2 = [20 x i8] c" %d/%d/%d doing %d\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 2)
%10 = call i32 (...) @omp_get_thread_num()
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 0, i32* %6
br label %13
13: ; preds = %20, %2
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 8
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18)
br label %20
20: ; preds = %16
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %13
23: ; preds = %13
store i32 0, i32* %6
br label %24
24: ; preds = %34, %23
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 8
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = call i32 (...) @omp_get_thread_num()
store i32 %28, i32* %8
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = call i32 (...) @omp_get_num_threads()
%32 = load i32, i32* %6
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %30, i32 %31, i32 %32)
br label %34
34: ; preds = %27
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %24
37: ; preds = %24
%38 = load i32, i32* %7
%39 = call i32 (...) @omp_get_thread_num()
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"init %d\0A\00"
@.str.1 = [14 x i8] c" %d doing %d\0A\00"
@.str.2 = [20 x i8] c" %d/%d/%d doing %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @omp_set_nested(i32 2)
%4 = tail call i32 (...) @omp_get_thread_num()
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 0)
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 1)
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 2)
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 3)
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 4)
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 5)
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 6)
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 7)
%14 = tail call i32 (...) @omp_get_thread_num()
%15 = tail call i32 (...) @omp_get_num_threads()
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %14, i32 %15, i32 0)
%17 = tail call i32 (...) @omp_get_thread_num()
%18 = tail call i32 (...) @omp_get_num_threads()
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %17, i32 %18, i32 1)
%20 = tail call i32 (...) @omp_get_thread_num()
%21 = tail call i32 (...) @omp_get_num_threads()
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %20, i32 %21, i32 2)
%23 = tail call i32 (...) @omp_get_thread_num()
%24 = tail call i32 (...) @omp_get_num_threads()
%25 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %23, i32 %24, i32 3)
%26 = tail call i32 (...) @omp_get_thread_num()
%27 = tail call i32 (...) @omp_get_num_threads()
%28 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %26, i32 %27, i32 4)
%29 = tail call i32 (...) @omp_get_thread_num()
%30 = tail call i32 (...) @omp_get_num_threads()
%31 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %29, i32 %30, i32 5)
%32 = tail call i32 (...) @omp_get_thread_num()
%33 = tail call i32 (...) @omp_get_num_threads()
%34 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %32, i32 %33, i32 6)
%35 = tail call i32 (...) @omp_get_thread_num()
%36 = tail call i32 (...) @omp_get_num_threads()
%37 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %35, i32 %36, i32 7)
%38 = tail call i32 (...) @omp_get_thread_num()
%39 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 %38)
ret i32 0
}