#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 log(int);
int omp_get_num_threads();
int omp_get_thread_num();
int /*<<< orphan*/ omp_set_dynamic(int /*<<< orphan*/);
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  omp_set_dynamic(0);
  omp_set_num_threads(1);
#pragma omp parallel
  {
    int j;
    for (int i = 0; i < 1000000; i++) {
      for (int k = 0; k < 1000; k++) {
        j = log(i + 1);
      }
    }
    printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(),
           omp_get_num_threads());
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1060 <omp_set_dynamic@plt>
mov    $0x1,%edi
call   1070 <omp_set_num_threads@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xf4240,-0xc(%rbp)
jge    11d7 <main+0x77>
movl   $0x0,-0x10(%rbp)
cmpl   $0x3e8,-0x10(%rbp)
jge    11c4 <main+0x64>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1080 <log@plt>
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119b <main+0x3b>
jmp    11c9 <main+0x69>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1187 <main+0x27>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <omp_set_dynamic@plt>
mov    $0x1,%edi
call   1070 <omp_set_num_threads@plt>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    $0x3e8,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1080 <log@plt>
add    $0xffffffff,%ebp
jne    1190 <main+0x30>
cmp    $0xf4240,%ebx
jne    1180 <main+0x20>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
lea    0xe45(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [35 x i8] c"Hello from thread %d, nthreads %d\0A\00"
define i32 @main() {
%1 = tail call i32 @omp_set_dynamic(i32 0)
%2 = tail call i32 @omp_set_num_threads(i32 1)
br label %3
3: ; preds = %0, %10
%4 = phi i32 [ 0, %0 ], [ %5, %10 ]
%5 = add nuw nsw i32 %4, 1
br label %12
6: ; preds = %10
%7 = tail call i32 (...) @omp_get_thread_num()
%8 = tail call i32 (...) @omp_get_num_threads()
%9 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
ret i32 0
10: ; preds = %12
%11 = icmp eq i32 %5, 1000000
br i1 %11, label %6, label %3
12: ; preds = %3, %12
%13 = phi i32 [ 0, %3 ], [ %15, %12 ]
%14 = tail call i32 @log(i32 %5)
%15 = add nuw nsw i32 %13, 1
%16 = icmp eq i32 %15, 1000
br i1 %16, label %10, label %12
}