#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*/ printf(char *, int, ...);
int main(int argc, char *argv[]) {
  int nthreads, i, tid;
  float total;
#pragma omp parallel private(tid) shared(total)
  {
    tid = omp_get_thread_num();
    if (tid == 0) {
      nthreads = omp_get_num_threads();
      printf("Number of threads = %d\n", nthreads);
    }
    printf("Thread %d is starting...\n", tid);
    total = 0.0;
#pragma omp barrier
#pragma omp for schedule(dynamic, 10)
    for (i = 0; i < 10; i++)
      total = total + i * 1.0;
    printf("Thread %d is done! Total= %f\n", tid, total);
  }
}


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)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1175 <main+0x45>
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    11c8 <main+0x98>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
cvtsi2sdl -0x18(%rbp),%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1195 <main+0x65>
mov    -0x1c(%rbp),%esi
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe57(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1155 <main+0x25>
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
lea    0xebc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec4(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
movsd  0xe8c(%rip),%xmm0
mov    %ebx,%esi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Number of threads = %d\0A\00"
@.str.1 = [26 x i8] c"Thread %d is starting...\0A\00"
@.str.2 = [30 x i8] c"Thread %d is done! Total= %f\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 float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (...) @omp_get_thread_num()
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 (...) @omp_get_num_threads()
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %13, %2
%18 = load i32, i32* %8
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %18)
store float 0.000000e+00, float* %9
store i32 0, i32* %7
br label %20
20: ; preds = %30, %17
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 10
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = load float, float* %9
%25 = fpext float %24 to double
%26 = load i32, i32* %7
%27 = sitofp i32 %26 to double
%28 = call double @llvm.fmuladd.f64(double %27, double 1.000000e+00, double %25)
%29 = fptrunc double %28 to float
store float %29, float* %9
br label %30
30: ; preds = %23
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %20
33: ; preds = %20
%34 = load i32, i32* %8
%35 = load float, float* %9
%36 = fpext float %35 to double
%37 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %34, double %36)
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [24 x i8] c"Number of threads = %d\0A\00"
@.str.1 = [26 x i8] c"Thread %d is starting...\0A\00"
@.str.2 = [30 x i8] c"Thread %d is done! Total= %f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @omp_get_thread_num()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 (...) @omp_get_num_threads()
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %8
8: ; preds = %5, %2
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %3, double 4.500000e+01)
ret i32 0
}