#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();
scalar_t__ omp_get_cancellation();
int omp_get_thread_num();
int /*<<< orphan*/ usleep(int);
void foo(int *x) {
#pragma omp parallel firstprivate(x) num_threads(32)
  {
    int thr = omp_get_thread_num();
    switch (x[thr]) {
    case 4:;
#pragma omp cancel parallel
      break;
    case 3:
#pragma omp task
      usleep(1000);
#pragma omp task
      usleep(2000);
#pragma omp task
      usleep(4000);
      break;
    case 2:
      usleep(1000);
    case 1:;
#pragma omp cancellation point parallel
      break;
    }
#pragma omp barrier
    if (omp_get_cancellation())
      abort();
  }
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     11be <foo+0x7e>
mov    -0x18(%rbp),%rax
lea    0xe82(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    11be <foo+0x7e>
mov    $0x3e8,%edi
call   1060 <usleep@plt>
mov    $0x7d0,%edi
call   1060 <usleep@plt>
mov    $0xfa0,%edi
call   1060 <usleep@plt>
jmp    11be <foo+0x7e>
mov    $0x3e8,%edi
call   1060 <usleep@plt>
jmp    11be <foo+0x7e>
mov    $0x0,%al
call   1050 <omp_get_cancellation@plt>
cmp    $0x0,%rax
je     11d6 <foo+0x96>
mov    $0x0,%al
call   1030 <abort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
cltq
mov    (%rbx,%rax,4),%eax
cmp    $0x2,%eax
je     1175 <foo+0x35>
cmp    $0x3,%eax
jne    117f <foo+0x3f>
mov    $0x3e8,%edi
call   1060 <usleep@plt>
mov    $0x7d0,%edi
call   1060 <usleep@plt>
mov    $0xfa0,%edi
jmp    117a <foo+0x3a>
mov    $0x3e8,%edi
call   1060 <usleep@plt>
xor    %eax,%eax
call   1050 <omp_get_cancellation@plt>
test   %rax,%rax
jne    118d <foo+0x4d>
pop    %rbx
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define void @foo(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = call i32 (...) @omp_get_thread_num()
store i32 %4, i32* %3
%5 = load i32*, i32** %2
%6 = load i32, i32* %3
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i32, i32* %5, i64 %7
%9 = load i32, i32* %8
switch i32 %9, label %18 [
i32 4, label %10
i32 3, label %11
i32 2, label %15
i32 1, label %17
]
10: ; preds = %1
br label %18
11: ; preds = %1
%12 = call i32 @usleep(i32 1000)
%13 = call i32 @usleep(i32 2000)
%14 = call i32 @usleep(i32 4000)
br label %18
15: ; preds = %1
%16 = call i32 @usleep(i32 1000)
br label %17
17: ; preds = %1, %15
br label %18
18: ; preds = %1, %17, %11, %10
%19 = call i64 (...) @omp_get_cancellation()
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %18
ret void
}

LLVM IR (-O2):
define void @foo(i32* nocapture %0) {
%2 = tail call i32 (...) @omp_get_thread_num()
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i32, i32* %0, i64 %3
%5 = load i32, i32* %4
switch i32 %5, label %12 [
i32 2, label %9
i32 3, label %6
]
6: ; preds = %1
%7 = tail call i32 @usleep(i32 1000)
%8 = tail call i32 @usleep(i32 2000)
br label %9
9: ; preds = %1, %6
%10 = phi i32 [ 4000, %6 ], [ 1000, %1 ]
%11 = tail call i32 @usleep(i32 %10)
br label %12
12: ; preds = %9, %1
%13 = tail call i64 (...) @omp_get_cancellation()
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 (...) @abort()
unreachable
17: ; preds = %12
ret void
}