#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_team_num();
scalar_t__ omp_is_initial_device();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int A[(992)], B[(992)], C[(992)], D[(992)], E[(992)];
  int fail = 0;
  for (int i = 0; i < (992); i++) {
    A[i] = 0;
    C[i] = 1;
    D[i] = i;
    E[i] = (-1) * i;
  }
  int num_teams = omp_is_initial_device() ? 128 : 512;
  printf("Using num_teams = %d\n", num_teams);
  for (int t = 0; t < (1); t++) {
#pragma omp target
#pragma omp teams num_teams(num_teams)
    { A[omp_get_team_num()] += omp_get_team_num(); }
  }
  for (int i = 0; i < num_teams; i++)
    if (A[i] != i * (1)) {
      printf("Error at %d, h = %d, d = %d\n", i, i * (1), A[i]);
      fail = 1;
    }
  if (fail)
    printf("Failed\n");
  else
    printf("Succeeded\n");
  return fail;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4db0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x4d94(%rbp)
movl   $0x0,-0x4d98(%rbp)
cmpl   $0x3e0,-0x4d98(%rbp)
jge    11ca <main+0x9a>
movslq -0x4d98(%rbp),%rax
movl   $0x0,-0xf90(%rbp,%rax,4)
movslq -0x4d98(%rbp),%rax
movl   $0x1,-0x2e90(%rbp,%rax,4)
mov    -0x4d98(%rbp),%ecx
movslq -0x4d98(%rbp),%rax
mov    %ecx,-0x3e10(%rbp,%rax,4)
imul   $0xffffffff,-0x4d98(%rbp),%ecx
ff ff ff
movslq -0x4d98(%rbp),%rax
mov    %ecx,-0x4d90(%rbp,%rax,4)
mov    -0x4d98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4d98(%rbp)
jmp    1156 <main+0x26>
mov    $0x0,%al
call   1050 <omp_is_initial_device@plt>
mov    %rax,%rdx
mov    $0x200,%eax
mov    $0x80,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4d9c(%rbp)
mov    -0x4d9c(%rbp),%esi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4da0(%rbp)
cmpl   $0x1,-0x4da0(%rbp)
jge    1254 <main+0x124>
mov    $0x0,%al
call   1040 <omp_get_team_num@plt>
mov    %eax,-0x4da8(%rbp)
mov    $0x0,%al
call   1040 <omp_get_team_num@plt>
mov    -0x4da8(%rbp),%ecx
cltq
add    -0xf90(%rbp,%rax,4),%ecx
mov    %ecx,-0xf90(%rbp,%rax,4)
mov    -0x4da0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4da0(%rbp)
jmp    1209 <main+0xd9>
movl   $0x0,-0x4da4(%rbp)
mov    -0x4da4(%rbp),%eax
cmp    -0x4d9c(%rbp),%eax
jge    12dd <main+0x1ad>
movslq -0x4da4(%rbp),%rax
mov    -0xf90(%rbp,%rax,4),%eax
mov    -0x4da4(%rbp),%ecx
shl    $0x0,%ecx
cmp    %ecx,%eax
je     12c4 <main+0x194>
mov    -0x4da4(%rbp),%esi
mov    -0x4da4(%rbp),%edx
shl    $0x0,%edx
movslq -0x4da4(%rbp),%rax
mov    -0xf90(%rbp,%rax,4),%ecx
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4d94(%rbp)
jmp    12c9 <main+0x199>
mov    -0x4da4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4da4(%rbp)
jmp    125e <main+0x12e>
cmpl   $0x0,-0x4d94(%rbp)
je     12fd <main+0x1cd>
lea    0xd42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    130b <main+0x1db>
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4d94(%rbp),%eax
add    $0x4db0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf88,%rsp
mov    %rsp,%rdi
xor    %ebp,%ebp
mov    $0xf80,%edx
xor    %esi,%esi
call   1050 <memset@plt>
xor    %eax,%eax
call   1070 <omp_is_initial_device@plt>
test   %rax,%rax
mov    $0x200,%eax
mov    $0x80,%ebx
cmove  %eax,%ebx
lea    0xe70(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <omp_get_team_num@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1060 <omp_get_team_num@plt>
cltq
add    %r14d,(%rsp,%rax,4)
neg    %rbx
mov    $0x1,%r13b
lea    0xe59(%rip),%r15
lea    0xe79(%rip),%r14
xor    %r12d,%r12d
add    $0x1,%rbp
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbp),%rax
mov    -0x4(%rsp,%rbp,4),%ecx
cmp    %rcx,%rax
jne    1200 <main+0xb0>
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbp
cmp    $0x1,%rax
jne    11d0 <main+0x80>
jmp    1222 <main+0xd2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbp),%edx
xor    %r13d,%r13d
mov    %r15,%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r12d
mov    %rbx,%rax
add    %rbp,%rax
jne    11c7 <main+0x77>
jmp    123e <main+0xee>
lea    0xe0a(%rip),%rax
lea    0xe0d(%rip),%r14
xor    %ecx,%ecx
test   $0x1,%r13b
cmovne %rax,%r14
cmovne %ecx,%r12d
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r12d,%eax
add    $0xf88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Using num_teams = %d\0A\00"
@.str.1 = [29 x i8] c"Error at %d, h = %d, d = %d\0A\00"
@.str.2 = [8 x i8] c"Failed\0A\00"
@.str.3 = [11 x i8] c"Succeeded\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [992 x i32]
%3 = alloca [992 x i32]
%4 = alloca [992 x i32]
%5 = alloca [992 x i32]
%6 = alloca [992 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %7
store i32 0, i32* %8
br label %12
12: ; preds = %31, %0
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 992
br i1 %14, label %15, label %34
15: ; preds = %12
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [992 x i32], [992 x i32]* %2, i64 0, i64 %17
store i32 0, i32* %18
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [992 x i32], [992 x i32]* %4, i64 0, i64 %20
store i32 1, i32* %21
%22 = load i32, i32* %8
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [992 x i32], [992 x i32]* %5, i64 0, i64 %24
store i32 %22, i32* %25
%26 = load i32, i32* %8
%27 = mul nsw i32 -1, %26
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [992 x i32], [992 x i32]* %6, i64 0, i64 %29
store i32 %27, i32* %30
br label %31
31: ; preds = %15
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %12
34: ; preds = %12
%35 = call i64 (...) @omp_is_initial_device()
%36 = icmp ne i64 %35, 0
%37 = zext i1 %36 to i64
%38 = select i1 %36, i32 128, i32 512
store i32 %38, i32* %9
%39 = load i32, i32* %9
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %39)
store i32 0, i32* %10
br label %41
41: ; preds = %51, %34
%42 = load i32, i32* %10
%43 = icmp slt i32 %42, 1
br i1 %43, label %44, label %54
44: ; preds = %41
%45 = call i32 (...) @omp_get_team_num()
%46 = call i32 (...) @omp_get_team_num()
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [992 x i32], [992 x i32]* %2, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = add nsw i32 %49, %45
store i32 %50, i32* %48
br label %51
51: ; preds = %44
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %41
54: ; preds = %41
store i32 0, i32* %11
br label %55
55: ; preds = %77, %54
%56 = load i32, i32* %11
%57 = load i32, i32* %9
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %80
59: ; preds = %55
%60 = load i32, i32* %11
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [992 x i32], [992 x i32]* %2, i64 0, i64 %61
%63 = load i32, i32* %62
%64 = load i32, i32* %11
%65 = mul nsw i32 %64, 1
%66 = icmp ne i32 %63, %65
br i1 %66, label %67, label %76
67: ; preds = %59
%68 = load i32, i32* %11
%69 = load i32, i32* %11
%70 = mul nsw i32 %69, 1
%71 = load i32, i32* %11
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [992 x i32], [992 x i32]* %2, i64 0, i64 %72
%74 = load i32, i32* %73
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %68, i32 %70, i32 %74)
store i32 1, i32* %7
br label %76
76: ; preds = %67, %59
br label %77
77: ; preds = %76
%78 = load i32, i32* %11
%79 = add nsw i32 %78, 1
store i32 %79, i32* %11
br label %55
80: ; preds = %55
%81 = load i32, i32* %7
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %80
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %87
85: ; preds = %80
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %87
87: ; preds = %85, %83
%88 = load i32, i32* %7
ret i32 %88
}

LLVM IR (-O2):
@.str = [22 x i8] c"Using num_teams = %d\0A\00"
@.str.1 = [29 x i8] c"Error at %d, h = %d, d = %d\0A\00"
@str = [10 x i8] c"Succeeded\00"
@str.4 = [7 x i8] c"Failed\00"
define i32 @main() {
%1 = alloca [992 x i32]
%2 = bitcast [992 x i32]* %1 to i8*
%3 = tail call i64 (...) @omp_is_initial_device()
%4 = icmp eq i64 %3, 0
%5 = select i1 %4, i32 512, i32 128
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 (...) @omp_get_team_num()
%8 = tail call i32 (...) @omp_get_team_num()
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [992 x i32], [992 x i32]* %1, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = add nsw i32 %11, %7
store i32 %12, i32* %10
%13 = zext i32 %5 to i64
br label %14
14: ; preds = %30, %0
%15 = phi i64 [ %33, %30 ], [ 0, %0 ]
%16 = phi i1 [ false, %30 ], [ true, %0 ]
%17 = phi i32 [ 1, %30 ], [ 0, %0 ]
br label %21
18: ; preds = %27
%19 = select i1 %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.4, i64 0, i64 0)
%20 = select i1 %16, i32 0, i32 %17
br label %35
21: ; preds = %14, %27
%22 = phi i64 [ %28, %27 ], [ %15, %14 ]
%23 = getelementptr inbounds [992 x i32], [992 x i32]* %1, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = zext i32 %24 to i64
%26 = icmp eq i64 %22, %25
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = add nuw nsw i64 %22, 1
%29 = icmp eq i64 %28, %13
br i1 %29, label %18, label %21
30: ; preds = %21
%31 = trunc i64 %22 to i32
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %31, i32 %24)
%33 = add nuw nsw i64 %22, 1
%34 = icmp eq i64 %33, %13
br i1 %34, label %35, label %14
35: ; preds = %30, %18
%36 = phi i8* [ %19, %18 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @str.4, i64 0, i64 0), %30 ]
%37 = phi i32 [ %20, %18 ], [ 1, %30 ]
%38 = tail call i32 @puts(i8* dereferenceable(1) %36)
ret i32 %37
}