#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*/ getenv(char *);
int omp_get_thread_num();
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int main() {
  int i;
  int block = 1;
  int tid;
  int throttling = strcmp(getenv("KMP_ENABLE_TASK_THROTTLING"), "1") == 0;
  int enqueued = 0;
  int failed = -1;
#pragma omp parallel num_threads(2)
#pragma omp master
  {
    for (i = 0; i < 2000; i++) {
      enqueued++;
#pragma omp task
      {
        tid = omp_get_thread_num();
        if (tid == 0) {
          if (failed < 0)
            failed = throttling ? enqueued == 2000 : enqueued < 2000;
          block = 0;
        }
        while (block)
          ;
      }
    }
    block = 0;
  }
  return failed;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
lea    0xeb3(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
lea    0xec0(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x7d0,-0x8(%rbp)
jge    121f <main+0xef>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <omp_get_thread_num@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11f8 <main+0xc8>
cmpl   $0x0,-0x1c(%rbp)
jge    11f1 <main+0xc1>
cmpl   $0x0,-0x14(%rbp)
je     11d9 <main+0xa9>
cmpl   $0x7d0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
jmp    11eb <main+0xbb>
cmpl   $0x7d0,-0x18(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0xc(%rbp)
jmp    11fd <main+0xcd>
cmpl   $0x0,-0xc(%rbp)
je     120c <main+0xdc>
jmp    11fd <main+0xcd>
jmp    1211 <main+0xe1>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1184 <main+0x54>
movl   $0x0,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%rdi
call   1030 <getenv@plt>
lea    0xed1(%rip),%rsi
mov    %eax,%edi
call   1050 <strcmp@plt>
mov    %rax,%r14
mov    $0xffffffff,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1174 <main+0x44>
test   $0x1,%bpl
je     11a0 <main+0x70>
add    $0x1,%ebx
mov    $0x1,%bpl
cmp    $0x7d0,%ebx
je     11a2 <main+0x72>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
test   %eax,%eax
jne    1160 <main+0x30>
test   %r15d,%r15d
jns    1166 <main+0x36>
xor    %eax,%eax
xor    %ecx,%ecx
cmp    $0x7cf,%ebx
sete   %al
setb   %cl
test   %r14,%r14
cmove  %eax,%ecx
movzbl %cl,%r15d
jmp    1166 <main+0x36>
jmp    11a0 <main+0x70>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"KMP_ENABLE_TASK_THROTTLING\00"
@.str.1 = [2 x i8] c"1\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %3
%8 = call i32 @getenv(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = call i64 @strcmp(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
store i32 %11, i32* %5
store i32 0, i32* %6
store i32 -1, i32* %7
store i32 0, i32* %2
br label %12
12: ; preds = %44, %0
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 2000
br i1 %14, label %15, label %47
15: ; preds = %12
%16 = load i32, i32* %6
%17 = add nsw i32 %16, 1
store i32 %17, i32* %6
%18 = call i32 (...) @omp_get_thread_num()
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %38
21: ; preds = %15
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %37
24: ; preds = %21
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 2000
%30 = zext i1 %29 to i32
br label %35
31: ; preds = %24
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 2000
%34 = zext i1 %33 to i32
br label %35
35: ; preds = %31, %27
%36 = phi i32 [ %30, %27 ], [ %34, %31 ]
store i32 %36, i32* %7
br label %37
37: ; preds = %35, %21
store i32 0, i32* %3
br label %38
38: ; preds = %37, %15
br label %39
39: ; preds = %42, %38
%40 = load i32, i32* %3
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %39
br label %39
43: ; preds = %39
br label %44
44: ; preds = %43
%45 = load i32, i32* %2
%46 = add nsw i32 %45, 1
store i32 %46, i32* %2
br label %12
47: ; preds = %12
store i32 0, i32* %3
%48 = load i32, i32* %7
ret i32 %48
}

LLVM IR (-O2):
@.str = [27 x i8] c"KMP_ENABLE_TASK_THROTTLING\00"
@.str.1 = [2 x i8] c"1\00"
define i32 @main() {
%1 = tail call i32 @getenv(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @strcmp(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br label %7
4: ; preds = %14, %16, %21
%5 = phi i32 [ %8, %21 ], [ %8, %14 ], [ %20, %16 ]
%6 = icmp eq i32 %11, 2000
br i1 %6, label %23, label %7
7: ; preds = %0, %4
%8 = phi i32 [ -1, %0 ], [ %5, %4 ]
%9 = phi i32 [ 0, %0 ], [ %11, %4 ]
%10 = phi i1 [ false, %0 ], [ true, %4 ]
%11 = add nuw nsw i32 %9, 1
%12 = tail call i32 (...) @omp_get_thread_num()
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %7
%15 = icmp slt i32 %8, 0
br i1 %15, label %16, label %4
16: ; preds = %14
%17 = icmp eq i32 %11, 2000
%18 = icmp ult i32 %9, 1999
%19 = select i1 %3, i1 %17, i1 %18
%20 = zext i1 %19 to i32
br label %4
21: ; preds = %7
br i1 %10, label %4, label %22
22: ; preds = %21, %22
br label %22
23: ; preds = %4
ret i32 %5
}