#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 foo();
int omp_get_num_threads();
int main() {
  int res1, res2;
#pragma omp target map(from : res1, res2)
  {
    int B[2000];
    int i, nthreads;
    res1 = foo();
#pragma omp parallel shared(B, nthreads)
    {
#pragma omp master
      nthreads = omp_get_num_threads();
#pragma omp for
      for (i = 0; i < 2000; i++)
        B[i] = 0;
#pragma omp critical(crit2)
      for (i = 0; i < 2000; i++)
        B[i]++;
    }
    res2 = 0;
    for (i = 0; i < 2000; i++)
      if (B[i] != nthreads)
        res2 = 1;
  }
  if (res1 || res2)
    abort();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f60,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <foo@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <omp_get_num_threads@plt>
mov    %eax,-0x1f58(%rbp)
movl   $0x0,-0x1f54(%rbp)
cmpl   $0x7d0,-0x1f54(%rbp)
jge    1199 <main+0x69>
movslq -0x1f54(%rbp),%rax
movl   $0x0,-0x1f50(%rbp,%rax,4)
mov    -0x1f54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f54(%rbp)
jmp    1163 <main+0x33>
movl   $0x0,-0x1f54(%rbp)
cmpl   $0x7d0,-0x1f54(%rbp)
jge    11df <main+0xaf>
movslq -0x1f54(%rbp),%rax
mov    -0x1f50(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1f50(%rbp,%rax,4)
mov    -0x1f54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f54(%rbp)
jmp    11a3 <main+0x73>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x1f54(%rbp)
cmpl   $0x7d0,-0x1f54(%rbp)
jge    123a <main+0x10a>
movslq -0x1f54(%rbp),%rax
mov    -0x1f50(%rbp,%rax,4),%eax
cmp    -0x1f58(%rbp),%eax
je     1221 <main+0xf1>
movl   $0x1,-0xc(%rbp)
jmp    1226 <main+0xf6>
mov    -0x1f54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f54(%rbp)
jmp    11f0 <main+0xc0>
cmpl   $0x0,-0x8(%rbp)
jne    124e <main+0x11e>
cmpl   $0x0,-0xc(%rbp)
je     1255 <main+0x125>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %eax,%eax
add    $0x1f60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x1f48,%rsp
xor    %eax,%eax
call   1060 <foo@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %eax,%ebp
mov    %rsp,%rdi
mov    $0x1f40,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0xc,%eax
pcmpeqd %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movdqa -0x30(%rsp,%rax,4),%xmm1
movdqa -0x20(%rsp,%rax,4),%xmm2
movdqa -0x10(%rsp,%rax,4),%xmm3
movdqa (%rsp,%rax,4),%xmm4
psubd  %xmm0,%xmm1
psubd  %xmm0,%xmm2
movdqa %xmm1,-0x30(%rsp,%rax,4)
movdqa %xmm2,-0x20(%rsp,%rax,4)
psubd  %xmm0,%xmm3
psubd  %xmm0,%xmm4
movdqa %xmm3,-0x10(%rsp,%rax,4)
movdqa %xmm4,(%rsp,%rax,4)
add    $0x10,%rax
cmp    $0x7dc,%rax
jne    1180 <main+0x40>
movd   %ebp,%xmm0
pshufd $0x0,%xmm0,%xmm2
pxor   %xmm0,%xmm0
mov    $0xc,%eax
pcmpeqd %xmm3,%xmm3
pxor   %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqa -0x30(%rsp,%rax,4),%xmm4
pcmpeqd %xmm2,%xmm4
movdqa -0x20(%rsp,%rax,4),%xmm5
pcmpeqd %xmm2,%xmm5
movdqa -0x10(%rsp,%rax,4),%xmm6
pcmpeqd %xmm2,%xmm6
pand   %xmm4,%xmm6
movdqa (%rsp,%rax,4),%xmm4
pcmpeqd %xmm2,%xmm4
pand   %xmm5,%xmm4
pand   %xmm6,%xmm0
paddd  %xmm6,%xmm0
psubd  %xmm3,%xmm0
pand   %xmm4,%xmm1
paddd  %xmm4,%xmm1
psubd  %xmm3,%xmm1
add    $0x10,%rax
cmp    $0x7dc,%rax
jne    11f0 <main+0xb0>
test   %ebx,%ebx
jne    1279 <main+0x139>
pxor   %xmm2,%xmm2
movdqa %xmm0,%xmm3
pcmpeqd %xmm2,%xmm3
pand   %xmm3,%xmm1
pandn  %xmm0,%xmm3
por    %xmm1,%xmm3
pcmpeqd %xmm2,%xmm3
movmskps %xmm3,%eax
xor    $0xf,%eax
test   %al,%al
jne    1279 <main+0x139>
xor    %eax,%eax
add    $0x1f48,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2000 x i32]
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (...) @foo()
store i32 %7, i32* %2
%8 = call i32 (...) @omp_get_num_threads()
store i32 %8, i32* %6
store i32 0, i32* %5
br label %9
9: ; preds = %16, %0
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 2000
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [2000 x i32], [2000 x i32]* %4, i64 0, i64 %14
store i32 0, i32* %15
br label %16
16: ; preds = %12
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
br label %9
19: ; preds = %9
store i32 0, i32* %5
br label %20
20: ; preds = %29, %19
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 2000
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [2000 x i32], [2000 x i32]* %4, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
br label %29
29: ; preds = %23
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %20
32: ; preds = %20
store i32 0, i32* %3
store i32 0, i32* %5
br label %33
33: ; preds = %45, %32
%34 = load i32, i32* %5
%35 = icmp slt i32 %34, 2000
br i1 %35, label %36, label %48
36: ; preds = %33
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [2000 x i32], [2000 x i32]* %4, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %6
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %44
43: ; preds = %36
store i32 1, i32* %3
br label %44
44: ; preds = %43, %36
br label %45
45: ; preds = %44
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %33
48: ; preds = %33
%49 = load i32, i32* %2
%50 = icmp ne i32 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %48
%52 = load i32, i32* %3
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %51, %48
%55 = call i32 (...) @abort()
unreachable
56: ; preds = %51
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [2000 x i32]
%2 = bitcast [2000 x i32]* %1 to i8*
%3 = tail call i32 (...) @foo()
%4 = tail call i32 (...) @omp_get_num_threads()
br label %5
5: ; preds = %5, %0
%6 = phi i64 [ 0, %0 ], [ %28, %5 ]
%7 = getelementptr inbounds [2000 x i32], [2000 x i32]* %1, i64 0, i64 %6
%8 = bitcast i32* %7 to <4 x i32>*
%9 = load <4 x i32>, <4 x i32>* %8
%10 = getelementptr inbounds i32, i32* %7, i64 4
%11 = bitcast i32* %10 to <4 x i32>*
%12 = load <4 x i32>, <4 x i32>* %11
%13 = add nsw <4 x i32> %9, <i32 1, i32 1, i32 1, i32 1>
%14 = add nsw <4 x i32> %12, <i32 1, i32 1, i32 1, i32 1>
%15 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> %13, <4 x i32>* %15
%16 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> %14, <4 x i32>* %16
%17 = or i64 %6, 8
%18 = getelementptr inbounds [2000 x i32], [2000 x i32]* %1, i64 0, i64 %17
%19 = bitcast i32* %18 to <4 x i32>*
%20 = load <4 x i32>, <4 x i32>* %19
%21 = getelementptr inbounds i32, i32* %18, i64 4
%22 = bitcast i32* %21 to <4 x i32>*
%23 = load <4 x i32>, <4 x i32>* %22
%24 = add nsw <4 x i32> %20, <i32 1, i32 1, i32 1, i32 1>
%25 = add nsw <4 x i32> %23, <i32 1, i32 1, i32 1, i32 1>
%26 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> %24, <4 x i32>* %26
%27 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> %25, <4 x i32>* %27
%28 = add nuw nsw i64 %6, 16
%29 = icmp eq i64 %28, 2000
br i1 %29, label %30, label %5
30: ; preds = %5
%31 = insertelement <4 x i32> poison, i32 %4, i64 0
%32 = shufflevector <4 x i32> %31, <4 x i32> poison, <4 x i32> zeroinitializer
%33 = insertelement <4 x i32> poison, i32 %4, i64 0
%34 = shufflevector <4 x i32> %33, <4 x i32> poison, <4 x i32> zeroinitializer
br label %35
35: ; preds = %35, %30
%36 = phi i64 [ 0, %30 ], [ %60, %35 ]
%37 = phi <4 x i32> [ zeroinitializer, %30 ], [ %57, %35 ]
%38 = phi <4 x i32> [ zeroinitializer, %30 ], [ %59, %35 ]
%39 = getelementptr inbounds [2000 x i32], [2000 x i32]* %1, i64 0, i64 %36
%40 = bitcast i32* %39 to <4 x i32>*
%41 = load <4 x i32>, <4 x i32>* %40
%42 = getelementptr inbounds i32, i32* %39, i64 4
%43 = bitcast i32* %42 to <4 x i32>*
%44 = load <4 x i32>, <4 x i32>* %43
%45 = icmp eq <4 x i32> %41, %32
%46 = icmp eq <4 x i32> %44, %34
%47 = or i64 %36, 8
%48 = getelementptr inbounds [2000 x i32], [2000 x i32]* %1, i64 0, i64 %47
%49 = bitcast i32* %48 to <4 x i32>*
%50 = load <4 x i32>, <4 x i32>* %49
%51 = getelementptr inbounds i32, i32* %48, i64 4
%52 = bitcast i32* %51 to <4 x i32>*
%53 = load <4 x i32>, <4 x i32>* %52
%54 = icmp eq <4 x i32> %50, %32
%55 = icmp eq <4 x i32> %53, %34
%56 = select <4 x i1> %54, <4 x i1> %45, <4 x i1> zeroinitializer
%57 = select <4 x i1> %56, <4 x i32> %37, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
%58 = select <4 x i1> %55, <4 x i1> %46, <4 x i1> zeroinitializer
%59 = select <4 x i1> %58, <4 x i32> %38, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
%60 = add nuw nsw i64 %36, 16
%61 = icmp eq i64 %60, 2000
br i1 %61, label %62, label %35
62: ; preds = %35
%63 = icmp eq <4 x i32> %57, zeroinitializer
%64 = select <4 x i1> %63, <4 x i32> %59, <4 x i32> %57
%65 = icmp ne <4 x i32> %64, zeroinitializer
%66 = bitcast <4 x i1> %65 to i4
%67 = icmp ne i4 %66, 0
%68 = icmp ne i32 %3, 0
%69 = select i1 %68, i1 true, i1 %67
br i1 %69, label %70, label %72
70: ; preds = %62
%71 = tail call i32 (...) @abort()
unreachable
72: ; preds = %62
ret i32 0
}