#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*/ do_lots_of_stuff(int);
int /*<<< orphan*/ omp_get_num_procs();
int omp_get_num_threads();
int omp_get_thread_num();
int /*<<< orphan*/ omp_set_dynamic(int /*<<< orphan*/);
int /*<<< orphan*/ omp_set_num_threads(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int main(void) {
  int num_threads;
  omp_set_dynamic(0);
  omp_set_num_threads(omp_get_num_procs());
#pragma omp parallel
  {
    int id = omp_get_thread_num();
#pragma omp single
    {
      num_threads = omp_get_num_threads();
      printf("[%d] We have %d threads working here.\n", id, num_threads);
    }
    do_lots_of_stuff(id);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1070 <omp_set_dynamic@plt>
mov    $0x0,%al
call   1080 <omp_get_num_procs@plt>
mov    %eax,%edi
call   1090 <omp_set_num_threads@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1060 <omp_get_num_threads@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <do_lots_of_stuff@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %edi,%edi
call   1070 <omp_set_dynamic@plt>
xor    %eax,%eax
call   1080 <omp_get_num_procs@plt>
mov    %eax,%edi
call   1090 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <omp_get_num_threads@plt>
lea    0xe63(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <do_lots_of_stuff@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [39 x i8] c"[%d] We have %d threads working here.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @omp_set_dynamic(i32 0)
%5 = call i32 (...) @omp_get_num_procs()
%6 = call i32 @omp_set_num_threads(i32 %5)
%7 = call i32 (...) @omp_get_thread_num()
store i32 %7, i32* %3
%8 = call i32 (...) @omp_get_num_threads()
store i32 %8, i32* %2
%9 = load i32, i32* %3
%10 = load i32, i32* %2
%11 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = load i32, i32* %3
%13 = call i32 @do_lots_of_stuff(i32 %12)
ret i32 0
}

LLVM IR (-O2):
@.str = [39 x i8] c"[%d] We have %d threads working here.\0A\00"
define i32 @main() {
%1 = tail call i32 @omp_set_dynamic(i32 0)
%2 = tail call i32 (...) @omp_get_num_procs()
%3 = tail call i32 @omp_set_num_threads(i32 %2)
%4 = tail call i32 (...) @omp_get_thread_num()
%5 = tail call i32 (...) @omp_get_num_threads()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
%7 = tail call i32 @do_lots_of_stuff(i32 %4)
ret i32 0
}