#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 omp_get_num_threads();
int foo() {
  int A[2000];
  int i, nthreads;
  int res = 0;
#pragma omp parallel shared(A, nthreads)
  {
#pragma omp master
    nthreads = omp_get_num_threads();
#pragma omp for
    for (i = 0; i < 2000; i++)
      A[i] = 0;
#pragma omp critical(crit1)
    for (i = 0; i < 2000; i++)
      A[i]++;
  }
  for (i = 0; i < 2000; i++)
    if (A[i] != nthreads)
      res = 1;
  return res;
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f50,%rsp
movl   $0x0,-0x1f4c(%rbp)
mov    $0x0,%al
call   1030 <omp_get_num_threads@plt>
mov    %eax,-0x1f48(%rbp)
movl   $0x0,-0x1f44(%rbp)
cmpl   $0x7d0,-0x1f44(%rbp)
jge    1172 <foo+0x62>
movslq -0x1f44(%rbp),%rax
movl   $0x0,-0x1f40(%rbp,%rax,4)
mov    -0x1f44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f44(%rbp)
jmp    113c <foo+0x2c>
movl   $0x0,-0x1f44(%rbp)
cmpl   $0x7d0,-0x1f44(%rbp)
jge    11b8 <foo+0xa8>
movslq -0x1f44(%rbp),%rax
mov    -0x1f40(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1f40(%rbp,%rax,4)
mov    -0x1f44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f44(%rbp)
jmp    117c <foo+0x6c>
movl   $0x0,-0x1f44(%rbp)
cmpl   $0x7d0,-0x1f44(%rbp)
jge    120f <foo+0xff>
movslq -0x1f44(%rbp),%rax
mov    -0x1f40(%rbp,%rax,4),%eax
cmp    -0x1f48(%rbp),%eax
je     11f6 <foo+0xe6>
movl   $0x1,-0x1f4c(%rbp)
jmp    11fb <foo+0xeb>
mov    -0x1f44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f44(%rbp)
jmp    11c2 <foo+0xb2>
mov    -0x1f4c(%rbp),%eax
add    $0x1f50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbx
sub    $0x1f40,%rsp
xor    %eax,%eax
call   1040 <omp_get_num_threads@plt>
mov    %eax,%ebx
mov    %rsp,%rdi
mov    $0x1f40,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    $0xc,%eax
pcmpeqd %xmm0,%xmm0
nopl   0x0(%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    1150 <foo+0x30>
movd   %ebx,%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    11c0 <foo+0xa0>
pxor   %xmm2,%xmm2
movdqa %xmm0,%xmm3
pcmpeqd %xmm2,%xmm3
pand   %xmm3,%xmm1
pandn  %xmm0,%xmm3
por    %xmm1,%xmm3
pcmpeqd %xmm2,%xmm3
movmskps %xmm3,%ecx
xor    %eax,%eax
cmp    $0xf,%ecx
setne  %al
add    $0x1f40,%rsp
pop    %rbx
ret

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

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