#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() != 9)
    return 0;
  omp_set_dynamic(0);
#pragma omp parallel num_threads(8)
  if (omp_get_num_threads() != 8)
    abort();
#pragma omp parallel num_threads(16)
  if (omp_get_num_threads() > 9)
    abort();
#pragma omp target if (0)
#pragma omp teams thread_limit(6)
  {
    if (omp_get_thread_limit() > 6)
      abort();
    if (omp_get_thread_limit() == 6) {
      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    $0x9,%eax
je     118b <main+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    1292 <main+0x132>
xor    %edi,%edi
call   1060 <omp_set_dynamic@plt>
mov    $0x0,%al
call   1040 <omp_get_num_threads@plt>
cmp    $0x8,%eax
je     11a9 <main+0x49>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   1040 <omp_get_num_threads@plt>
cmp    $0x9,%eax
jle    11c0 <main+0x60>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   1050 <omp_get_thread_limit@plt>
cmp    $0x6,%eax
jle    11d7 <main+0x77>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   1050 <omp_get_thread_limit@plt>
cmp    $0x6,%eax
jne    128b <main+0x12b>
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     120f <main+0xaf>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   1040 <omp_get_num_threads@plt>
cmp    $0x3,%eax
je     1226 <main+0xc6>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   1040 <omp_get_num_threads@plt>
cmp    $0x6,%eax
jle    123d <main+0xdd>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   1040 <omp_get_num_threads@plt>
cmp    $0x6,%eax
je     1254 <main+0xf4>
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    1278 <main+0x118>
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    $0x9,%eax
jne    11f3 <main+0x93>
xor    %edi,%edi
call   1060 <omp_set_dynamic@plt>
xor    %eax,%eax
call   1040 <omp_get_num_threads@plt>
cmp    $0x8,%eax
jne    11f7 <main+0x97>
xor    %eax,%eax
call   1040 <omp_get_num_threads@plt>
cmp    $0xa,%eax
jge    11f7 <main+0x97>
xor    %eax,%eax
call   1050 <omp_get_thread_limit@plt>
cmp    $0x7,%eax
jge    11f7 <main+0x97>
xor    %eax,%eax
call   1050 <omp_get_thread_limit@plt>
cmp    $0x6,%eax
jne    11f3 <main+0x93>
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    11f7 <main+0x97>
xor    %eax,%eax
call   1040 <omp_get_num_threads@plt>
cmp    $0x3,%eax
jne    11f7 <main+0x97>
xor    %eax,%eax
call   1040 <omp_get_num_threads@plt>
cmp    $0x7,%eax
jge    11f7 <main+0x97>
xor    %eax,%eax
call   1040 <omp_get_num_threads@plt>
cmp    $0x6,%eax
jne    11f7 <main+0x97>
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, 9
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 0, i32* %1
br label %60
7: ; preds = %0
%8 = call i32 @omp_set_dynamic(i32 0)
%9 = call i32 (...) @omp_get_num_threads()
%10 = icmp ne i32 %9, 8
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 (...) @abort()
unreachable
13: ; preds = %7
%14 = call i32 (...) @omp_get_num_threads()
%15 = icmp sgt i32 %14, 9
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %13
%19 = call i32 (...) @omp_get_thread_limit()
%20 = icmp sgt i32 %19, 6
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %18
%24 = call i32 (...) @omp_get_thread_limit()
%25 = icmp eq i32 %24, 6
br i1 %25, label %26, label %59
26: ; preds = %23
%27 = call i32 @omp_set_dynamic(i32 0)
%28 = call i32 @omp_set_nested(i32 1)
%29 = call i32 (...) @omp_get_num_threads()
%30 = icmp ne i32 %29, 3
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 (...) @abort()
unreachable
33: ; preds = %26
%34 = call i32 (...) @omp_get_num_threads()
%35 = icmp ne i32 %34, 3
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 (...) @abort()
unreachable
38: ; preds = %33
%39 = call i32 (...) @omp_get_num_threads()
%40 = icmp sgt i32 %39, 6
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 (...) @abort()
unreachable
43: ; preds = %38
%44 = call i32 (...) @omp_get_num_threads()
%45 = icmp ne i32 %44, 6
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 (...) @abort()
unreachable
48: ; preds = %43
store i32 0, i32* %2
%49 = load i32, i32* %2
%50 = add nsw i32 %49, 1
store i32 %50, i32* %2
store i32 %50, i32* %3
%51 = load i32, i32* %3
%52 = icmp sgt i32 %51, 6
br i1 %52, label %53, label %55
53: ; preds = %48
%54 = call i32 (...) @abort()
unreachable
55: ; preds = %48
%56 = call i32 @usleep(i32 10000)
%57 = load i32, i32* %2
%58 = add nsw i32 %57, -1
store i32 %58, i32* %2
br label %59
59: ; preds = %55, %23
store i32 0, i32* %1
br label %60
60: ; preds = %59, %6
%61 = load i32, i32* %1
ret i32 %61
}

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