#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 omp_get_thread_num();
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int numberOfThreads, threadID;
  printf("Setting a fixed number of threads. In this case 8\n");
  omp_set_num_threads(8);
  numberOfThreads = omp_get_num_threads();
  printf("The total number of threads is %d\n", numberOfThreads);
#pragma omp parallel private(threadID)
  {
    threadID = omp_get_thread_num();
    printf("Hello! my ID is %d\n", threadID);
    if (threadID == 0) {
      numberOfThreads = omp_get_num_threads();
      printf("I am the thread 0 and the total numer is %d\n", numberOfThreads);
    }
  }
  printf("Now we use 5 threads\n");
  omp_set_num_threads(5);
  numberOfThreads = omp_get_num_threads();
  printf("Total number of threads %d\n", numberOfThreads);
#pragma omp parallel
  {
    threadID = omp_get_thread_num();
    printf("Hello! my ID is %d\n", threadID);
    if (threadID == 0) {
      numberOfThreads = omp_get_num_threads();
      printf("I am the thread 0 and the total numer is %d\n", numberOfThreads);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x8,%edi
call   1060 <omp_set_num_threads@plt>
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jne    11c2 <main+0x82>
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x5,%edi
call   1060 <omp_set_num_threads@plt>
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1235 <main+0xf5>
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xf28(%rip),%rdi
call   1030 <puts@plt>
mov    $0x8,%edi
call   1070 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1060 <omp_get_num_threads@plt>
lea    0xe8b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %eax,%ebx
lea    0xe95(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
jne    11b2 <main+0x62>
xor    %eax,%eax
call   1060 <omp_get_num_threads@plt>
lea    0xe8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xef9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   1070 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1060 <omp_get_num_threads@plt>
lea    0xe8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %eax,%ebx
lea    0xe34(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
jne    1213 <main+0xc3>
xor    %eax,%eax
call   1060 <omp_get_num_threads@plt>
lea    0xe2d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [51 x i8] c"Setting a fixed number of threads. In this case 8\0A\00"
@.str.1 = [35 x i8] c"The total number of threads is %d\0A\00"
@.str.2 = [20 x i8] c"Hello! my ID is %d\0A\00"
@.str.3 = [45 x i8] c"I am the thread 0 and the total numer is %d\0A\00"
@.str.4 = [22 x i8] c"Now we use 5 threads\0A\00"
@.str.5 = [28 x i8] c"Total number of threads %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @omp_set_num_threads(i32 8)
%6 = call i32 (...) @omp_get_num_threads()
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i32 (...) @omp_get_thread_num()
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = call i32 (...) @omp_get_num_threads()
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %14, %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @omp_set_num_threads(i32 5)
%21 = call i32 (...) @omp_get_num_threads()
store i32 %21, i32* %2
%22 = load i32, i32* %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %22)
%24 = call i32 (...) @omp_get_thread_num()
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %3
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %18
%30 = call i32 (...) @omp_get_num_threads()
store i32 %30, i32* %2
%31 = load i32, i32* %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %29, %18
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [35 x i8] c"The total number of threads is %d\0A\00"
@.str.2 = [20 x i8] c"Hello! my ID is %d\0A\00"
@.str.3 = [45 x i8] c"I am the thread 0 and the total numer is %d\0A\00"
@.str.5 = [28 x i8] c"Total number of threads %d\0A\00"
@str = [50 x i8] c"Setting a fixed number of threads. In this case 8\00"
@str.6 = [21 x i8] c"Now we use 5 threads\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @omp_set_num_threads(i32 8)
%3 = tail call i32 (...) @omp_get_num_threads()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = tail call i32 (...) @omp_get_thread_num()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %5, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 (...) @omp_get_num_threads()
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %8, %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0))
%13 = tail call i32 @omp_set_num_threads(i32 5)
%14 = tail call i32 (...) @omp_get_num_threads()
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %14)
%16 = tail call i32 (...) @omp_get_thread_num()
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = icmp eq i32 %16, 0
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = tail call i32 (...) @omp_get_num_threads()
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19, %11
ret i32 0
}