#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 /*<<< orphan*/ exit(int);
int omp_get_thread_num();
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int x, numThreads;
  if (argc != 2) {
    printf("\t\t Very Few Arguments\n ");
    printf("\t\t Syntax : exec  <No. of Threads>\n");
    exit(-1);
  }
  numThreads = atoi(argv[1]);
  x = 2;
  omp_set_num_threads(numThreads);
#pragma omp parallel shared(x)
  {
    if (omp_get_thread_num() == 0) {
      x = 5;
    } else {
      printf("\n\t\t 1: Thread# %d: x = %d\n", omp_get_thread_num(), x);
    }
#pragma omp barrier
    if (omp_get_thread_num() == 0) {
      printf("\n\t\t 2: Thread# %d: x = %d\n", omp_get_thread_num(), x);
    } else {
      printf("\n\t\t 3: Thread# %d: x = %d\n", omp_get_thread_num(), x);
    }
  }
  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   $0x2,-0x8(%rbp)
je     1196 <main+0x46>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
movl   $0x2,-0x14(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <omp_set_num_threads@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
cmp    $0x0,%eax
jne    11d1 <main+0x81>
movl   $0x5,-0x14(%rbp)
jmp    11eb <main+0x9b>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
cmp    $0x0,%eax
jne    121a <main+0xca>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1234 <main+0xe4>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11e3 <main+0x83>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1060 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
test   %eax,%eax
je     11a6 <main+0x46>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
lea    0xe87(%rip),%rdi
mov    $0x2,%ebx
mov    %eax,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11ab <main+0x4b>
mov    $0x5,%ebx
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
test   %ebp,%ebp
lea    0xe6f(%rip),%rcx
lea    0xe83(%rip),%rdi
cmove  %rcx,%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"\09\09 Very Few Arguments\0A \00"
@.str.1 = [36 x i8] c"\09\09 Syntax : exec <No. of Threads>\0A\00"
@.str.2 = [27 x i8] c"\0A\09\09 1: Thread# %d: x = %d\0A\00"
@.str.3 = [27 x i8] c"\0A\09\09 2: Thread# %d: x = %d\0A\00"
@.str.4 = [27 x i8] c"\0A\09\09 3: Thread# %d: x = %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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %7
store i32 2, i32* %6
%19 = load i32, i32* %7
%20 = call i32 @omp_set_num_threads(i32 %19)
%21 = call i32 (...) @omp_get_thread_num()
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %14
store i32 5, i32* %6
br label %28
24: ; preds = %14
%25 = call i32 (...) @omp_get_thread_num()
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 %26)
br label %28
28: ; preds = %24, %23
%29 = call i32 (...) @omp_get_thread_num()
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = call i32 (...) @omp_get_thread_num()
%33 = load i32, i32* %6
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %33)
br label %39
35: ; preds = %28
%36 = call i32 (...) @omp_get_thread_num()
%37 = load i32, i32* %6
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %36, i32 %37)
br label %39
39: ; preds = %35, %31
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"\09\09 Very Few Arguments\0A \00"
@.str.2 = [27 x i8] c"\0A\09\09 1: Thread# %d: x = %d\0A\00"
@.str.3 = [27 x i8] c"\0A\09\09 2: Thread# %d: x = %d\0A\00"
@.str.4 = [27 x i8] c"\0A\09\09 3: Thread# %d: x = %d\0A\00"
@str = [35 x i8] c"\09\09 Syntax : exec <No. of Threads>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = tail call i32 @omp_set_num_threads(i32 %11)
%13 = tail call i32 (...) @omp_get_thread_num()
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %8
%16 = tail call i32 (...) @omp_get_thread_num()
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 2)
br label %18
18: ; preds = %8, %15
%19 = phi i32 [ 2, %15 ], [ 5, %8 ]
%20 = tail call i32 (...) @omp_get_thread_num()
%21 = icmp eq i32 %20, 0
%22 = tail call i32 (...) @omp_get_thread_num()
%23 = select i1 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %23, i32 %22, i32 %19)
ret i32 0
}