#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 */
scalar_t__ omp_get_num_teams();
scalar_t__ omp_get_num_threads();
scalar_t__ omp_get_team_num();
scalar_t__ omp_get_thread_num();
int /*<<< orphan*/ printf(char *, ...);
void foo() {
  int x = 123;
  int i;
#pragma omp target teams distribute num_teams(7)
  for (i = 0; i < 36; i++) {
    printf("team %d thread %d doing iteration %d and x is %d num_threads %d "
           "num_teams is %d\n",
           (int)omp_get_team_num(), (int)omp_get_thread_num(), i, x,
           (int)omp_get_num_threads(), (int)omp_get_num_teams());
  }
  printf("end of function foo\n");
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x7b,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x24,-0x8(%rbp)
jge    11d1 <foo+0x81>
mov    $0x0,%al
call   1060 <omp_get_team_num@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1070 <omp_get_num_teams@plt>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0xc(%rbp),%r9d
lea    0xe47(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1166 <foo+0x16>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe8d(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1070 <omp_get_team_num@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1060 <omp_get_num_threads@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <omp_get_num_teams@plt>
mov    %eax,(%rsp)
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %ebp,%ecx
mov    $0x7b,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    $0x24,%ebp
jne    1180 <foo+0x20>
lea    0xe7f(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [81 x i8] c"team %d thread %d doing iteration %d and x is %d num_threads %d num_teams is %d\0A\00"
@.str.1 = [21 x i8] c"end of function foo\0A\00"
define void @foo() {
%1 = alloca i32
%2 = alloca i32
store i32 123, i32* %1
store i32 0, i32* %2
br label %3
3: ; preds = %18, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 36
br i1 %5, label %6, label %21
6: ; preds = %3
%7 = call i64 (...) @omp_get_team_num()
%8 = trunc i64 %7 to i32
%9 = call i64 (...) @omp_get_thread_num()
%10 = trunc i64 %9 to i32
%11 = load i32, i32* %2
%12 = load i32, i32* %1
%13 = call i64 (...) @omp_get_num_threads()
%14 = trunc i64 %13 to i32
%15 = call i64 (...) @omp_get_num_teams()
%16 = trunc i64 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %10, i32 %11, i32 %12, i32 %14, i32 %16)
br label %18
18: ; preds = %6
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %3
21: ; preds = %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [81 x i8] c"team %d thread %d doing iteration %d and x is %d num_threads %d num_teams is %d\0A\00"
@str = [20 x i8] c"end of function foo\00"
define void @foo() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 0, %0 ], [ %12, %1 ]
%3 = tail call i64 (...) @omp_get_team_num()
%4 = trunc i64 %3 to i32
%5 = tail call i64 (...) @omp_get_thread_num()
%6 = trunc i64 %5 to i32
%7 = tail call i64 (...) @omp_get_num_threads()
%8 = trunc i64 %7 to i32
%9 = tail call i64 (...) @omp_get_num_teams()
%10 = trunc i64 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %6, i32 %2, i32 123, i32 %8, i32 %10)
%12 = add nuw nsw i32 %2, 1
%13 = icmp eq i32 %12, 36
br i1 %13, label %14, label %1
14: ; preds = %1
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
ret void
}