#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 /*<<< orphan*/ abort();
int omp_get_num_threads();
int omp_get_thread_limit();
int /*<<< orphan*/ omp_set_dynamic(int /*<<< orphan*/);
int /*<<< orphan*/ omp_set_nested(int);
int /*<<< orphan*/ usleep(int);
int main() {
  if (omp_get_thread_limit() != 6)
    return 0;
  omp_set_dynamic(0);
  omp_set_nested(1);
#pragma omp parallel num_threads(3)
  if (omp_get_num_threads() != 3)
    abort();
#pragma omp parallel num_threads(3)
  if (omp_get_num_threads() != 3)
    abort();
#pragma omp parallel num_threads(8)
  if (omp_get_num_threads() > 6)
    abort();
#pragma omp parallel num_threads(6)
  if (omp_get_num_threads() != 6)
    abort();
  int cnt = 0;
#pragma omp parallel num_threads(5)
#pragma omp parallel num_threads(5)
#pragma omp parallel num_threads(2)
  {
    int v;
#pragma omp atomic capture
    v = ++cnt;
    if (v > 6)
      abort();
    usleep(10000);
#pragma omp atomic
    --cnt;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <omp_get_thread_limit@plt>
cmp    $0x6,%eax
je     118b <main+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    1236 <main+0xd6>
xor    %edi,%edi
call   1060 <omp_set_dynamic@plt>
mov    $0x1,%edi
call   1070 <omp_set_nested@plt>
mov    $0x0,%al
call   1040 <omp_get_num_threads@plt>
cmp    $0x3,%eax
je     11b3 <main+0x53>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   1040 <omp_get_num_threads@plt>
cmp    $0x3,%eax
je     11ca <main+0x6a>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   1040 <omp_get_num_threads@plt>
cmp    $0x6,%eax
jle    11e1 <main+0x81>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   1040 <omp_get_num_threads@plt>
cmp    $0x6,%eax
je     11f8 <main+0x98>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    %eax,-0xc(%rbp)
cmpl   $0x6,-0xc(%rbp)
jle    121c <main+0xbc>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x2710,%edi
call   1080 <usleep@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1050 <omp_get_thread_limit@plt>
cmp    $0x6,%eax
jne    11b8 <main+0x58>
xor    %edi,%edi
call   1060 <omp_set_dynamic@plt>
mov    $0x1,%edi
call   1070 <omp_set_nested@plt>
xor    %eax,%eax
call   1040 <omp_get_num_threads@plt>
cmp    $0x3,%eax
jne    11bc <main+0x5c>
xor    %eax,%eax
call   1040 <omp_get_num_threads@plt>
cmp    $0x3,%eax
jne    11bc <main+0x5c>
xor    %eax,%eax
call   1040 <omp_get_num_threads@plt>
cmp    $0x7,%eax
jge    11bc <main+0x5c>
xor    %eax,%eax
call   1040 <omp_get_num_threads@plt>
cmp    $0x6,%eax
jne    11bc <main+0x5c>
mov    $0x2710,%edi
call   1080 <usleep@plt>
xor    %eax,%eax
pop    %rcx
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @omp_get_thread_limit()
%5 = icmp ne i32 %4, 6
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 0, i32* %1
br label %40
7: ; preds = %0
%8 = call i32 @omp_set_dynamic(i32 0)
%9 = call i32 @omp_set_nested(i32 1)
%10 = call i32 (...) @omp_get_num_threads()
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %7
%15 = call i32 (...) @omp_get_num_threads()
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %14
%20 = call i32 (...) @omp_get_num_threads()
%21 = icmp sgt i32 %20, 6
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %19
%25 = call i32 (...) @omp_get_num_threads()
%26 = icmp ne i32 %25, 6
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 (...) @abort()
unreachable
29: ; preds = %24
store i32 0, i32* %2
%30 = load i32, i32* %2
%31 = add nsw i32 %30, 1
store i32 %31, i32* %2
store i32 %31, i32* %3
%32 = load i32, i32* %3
%33 = icmp sgt i32 %32, 6
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 (...) @abort()
unreachable
36: ; preds = %29
%37 = call i32 @usleep(i32 10000)
%38 = load i32, i32* %2
%39 = add nsw i32 %38, -1
store i32 %39, i32* %2
store i32 0, i32* %1
br label %40
40: ; preds = %36, %6
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 (...) @omp_get_thread_limit()
%2 = icmp eq i32 %1, 6
br i1 %2, label %3, label %27
3: ; preds = %0
%4 = tail call i32 @omp_set_dynamic(i32 0)
%5 = tail call i32 @omp_set_nested(i32 1)
%6 = tail call i32 (...) @omp_get_num_threads()
%7 = icmp eq i32 %6, 3
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %3
%11 = tail call i32 (...) @omp_get_num_threads()
%12 = icmp eq i32 %11, 3
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 (...) @abort()
unreachable
15: ; preds = %10
%16 = tail call i32 (...) @omp_get_num_threads()
%17 = icmp sgt i32 %16, 6
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 (...) @abort()
unreachable
20: ; preds = %15
%21 = tail call i32 (...) @omp_get_num_threads()
%22 = icmp eq i32 %21, 6
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 (...) @abort()
unreachable
25: ; preds = %20
%26 = tail call i32 @usleep(i32 10000)
br label %27
27: ; preds = %0, %25
ret i32 0
}