#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 */
char EOF;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ gethostname(char *, int);
char getopt(int, char **, char *);
int omp_get_num_threads();
int omp_get_thread_num();
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ print_usage(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int nthreads, tid;
  int T = 2;
  char c;
  char name[50];
  if (argc <= 1) {
    print_usage(argv[0]);
  } else {
    while ((c = getopt(argc, argv, "ht:")) != EOF) {
      switch (c) {
      case 'h':
        print_usage(argv[0]);
      case 't':
        T = atoi(optarg);
        break;
      default:
        print_usage(argv[0]);
      }
    }
  }
#pragma omp parallel private(nthreads, tid) num_threads(T)
  {
    tid = omp_get_thread_num();
    printf("Hello World from thread = %d\n", tid);
    if (tid == 0) {
      nthreads = omp_get_num_threads();
      gethostname(name, 50);
      printf("Number of threads on node %s = %d\n", name, nthreads);
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11b8 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <print_usage@plt>
jmp    1246 <main+0xc6>
jmp    11bd <main+0x3d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe35(%rip),%rdx
call   1060 <getopt@plt>
mov    %al,-0x1d(%rbp)
movsbl %al,%eax
mov    0x2e03(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1241 <main+0xc1>
movsbl -0x1d(%rbp),%eax
mov    %eax,-0x54(%rbp)
sub    $0x68,%eax
je     120e <main+0x8e>
jmp    11fd <main+0x7d>
mov    -0x54(%rbp),%eax
sub    $0x74,%eax
je     121a <main+0x9a>
jmp    1230 <main+0xb0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <print_usage@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    123c <main+0xbc>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <print_usage@plt>
jmp    11bd <main+0x3d>
jmp    1246 <main+0xc6>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1298 <main+0x118>
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x14(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x32,%esi
call   1080 <gethostname@plt>
lea    -0x50(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jge    119e <main+0x1e>
mov    (%rbx),%rdi
call   10a0 <print_usage@plt>
jmp    11bb <main+0x3b>
mov    %edi,%ebp
lea    0xe59(%rip),%rdx
mov    %rbx,%rsi
call   1060 <getopt@plt>
mov    0x2e2a(%rip),%r15
cmp    (%r15),%al
jne    120b <main+0x8b>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebx
lea    0xe39(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jne    1204 <main+0x84>
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %eax,%ebx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x32,%esi
call   1080 <gethostname@plt>
lea    0xe2a(%rip),%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2de6(%rip),%r12
lea    0xde7(%rip),%r14
jmp    1247 <main+0xc7>
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rdi
call   10a0 <print_usage@plt>
mov    (%r12),%edi
call   1070 <atoi@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <getopt@plt>
cmp    (%r15),%al
je     11bb <main+0x3b>
movsbl %al,%eax
cmp    $0x74,%eax
je     1228 <main+0xa8>
cmp    $0x68,%eax
je     1220 <main+0xa0>
mov    (%rbx),%rdi
call   10a0 <print_usage@plt>
jmp    1231 <main+0xb1>

LLVM IR (-O0):
@.str = [4 x i8] c"ht:\00"
@EOF = global i8 0
@optarg = global i32 0
@.str.1 = [30 x i8] c"Hello World from thread = %d\0A\00"
@.str.2 = [35 x i8] c"Number of threads on node %s = %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
%9 = alloca i8
%10 = alloca [50 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2, i32* %8
%11 = load i32, i32* %4
%12 = icmp sle i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @print_usage(i8* %16)
br label %45
18: ; preds = %2
br label %19
19: ; preds = %43, %18
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call signext i8 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8 %22, i8* %9
%23 = sext i8 %22 to i32
%24 = load i8, i8* @EOF
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %23, %25
br i1 %26, label %27, label %44
27: ; preds = %19
%28 = load i8, i8* %9
%29 = sext i8 %28 to i32
switch i32 %29, label %38 [
i32 104, label %30
i32 116, label %35
]
30: ; preds = %27
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @print_usage(i8* %33)
br label %35
35: ; preds = %27, %30
%36 = load i32, i32* @optarg
%37 = call i32 @atoi(i32 %36)
store i32 %37, i32* %8
br label %43
38: ; preds = %27
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = call i32 @print_usage(i8* %41)
br label %43
43: ; preds = %38, %35
br label %19
44: ; preds = %19
br label %45
45: ; preds = %44, %13
%46 = call i32 (...) @omp_get_thread_num()
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %7
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %58
51: ; preds = %45
%52 = call i32 (...) @omp_get_num_threads()
store i32 %52, i32* %6
%53 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%54 = call i32 @gethostname(i8* %53, i32 50)
%55 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%56 = load i32, i32* %6
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %55, i32 %56)
br label %58
58: ; preds = %51, %45
%59 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [4 x i8] c"ht:\00"
@EOF = global i8 0
@optarg = global i32 0
@.str.1 = [30 x i8] c"Hello World from thread = %d\0A\00"
@.str.2 = [35 x i8] c"Number of threads on node %s = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [50 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %29, label %13
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 @print_usage(i8* %11)
br label %29
13: ; preds = %6, %25
%14 = phi i8 [ %26, %25 ], [ %7, %6 ]
%15 = sext i8 %14 to i32
switch i32 %15, label %22 [
i32 104, label %16
i32 116, label %19
]
16: ; preds = %13
%17 = load i8*, i8** %1
%18 = tail call i32 @print_usage(i8* %17)
br label %19
19: ; preds = %13, %16
%20 = load i32, i32* @optarg
%21 = tail call i32 @atoi(i32 %20)
br label %25
22: ; preds = %13
%23 = load i8*, i8** %1
%24 = tail call i32 @print_usage(i8* %23)
br label %25
25: ; preds = %22, %19
%26 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%27 = load i8, i8* @EOF
%28 = icmp eq i8 %26, %27
br i1 %28, label %29, label %13
29: ; preds = %25, %6, %10
%30 = tail call i32 (...) @omp_get_thread_num()
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = icmp eq i32 %30, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = tail call i32 (...) @omp_get_num_threads()
%35 = call i32 @gethostname(i8* %4, i32 50)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 %34)
br label %37
37: ; preds = %33, %29
%38 = call i32 @exit(i32 0)
unreachable
}