#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 atoi(char *);
int omp_get_num_threads();
int omp_get_thread_num();
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  int def_nthreads, nthreads, tid;
  if (argc > 1) {
    def_nthreads = atoi(argv[1]);
  } else {
    def_nthreads = 10;
  }
  omp_set_num_threads(def_nthreads);
#pragma omp parallel private(nthreads, tid)
  {
    tid = omp_get_thread_num();
    printf("Hello World from thread = %d\n", tid);
    if (tid == 0) {
      nthreads = omp_get_num_threads();
      printf("Number of threads = %d\n", nthreads);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1185 <main+0x35>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    118c <main+0x3c>
movl   $0xa,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <omp_set_num_threads@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe58(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11d0 <main+0x80>
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %edi,%eax
mov    $0xa,%edi
cmp    $0x2,%eax
jl     1168 <main+0x18>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1060 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebx
lea    0xe83(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
test   %ebx,%ebx
jne    119d <main+0x4d>
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
lea    0xe88(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Hello World from thread = %d\0A\00"
@.str.1 = [24 x i8] c"Number of threads = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6
br label %17
16: ; preds = %2
store i32 10, i32* %6
br label %17
17: ; preds = %16, %11
%18 = load i32, i32* %6
%19 = call i32 @omp_set_num_threads(i32 %18)
%20 = call i32 (...) @omp_get_thread_num()
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %8
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %17
%26 = call i32 (...) @omp_get_num_threads()
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %25, %17
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"Hello World from thread = %d\0A\00"
@.str.1 = [24 x i8] c"Number of threads = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %2, %4
%9 = phi i32 [ %7, %4 ], [ 10, %2 ]
%10 = tail call i32 @omp_set_num_threads(i32 %9)
%11 = tail call i32 (...) @omp_get_thread_num()
%12 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp eq i32 %11, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = tail call i32 (...) @omp_get_num_threads()
%16 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %8
ret i32 0
}