#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, tid, i, j;
  double a[10][10];
#pragma omp parallel shared(nthreads) private(i, j, tid, a)
  {
    tid = omp_get_thread_num();
    if (tid == 0) {
      nthreads = omp_get_num_threads();
      printf("Number of threads = %d\n", nthreads);
    }
    printf("Thread %d starting...\n", tid);
    for (i = 0; i < 10; i++)
      for (j = 0; j < 10; j++)
        a[i][j] = tid + i + j;
    printf("Thread %d done. Last element= %f\n", tid, a[10 - 1][10 - 1]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%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,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1178 <main+0x48>
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    11f4 <main+0xc4>
movl   $0x0,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jge    11e1 <main+0xb1>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
cvtsi2sd %eax,%xmm0
movslq -0x1c(%rbp),%rcx
lea    -0x340(%rbp),%rax
imul   $0x50,%rcx,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a1 <main+0x71>
jmp    11e6 <main+0xb6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1190 <main+0x60>
mov    -0x18(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
lea    0xe2c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x328,%rsp
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    115d <main+0x2d>
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
lea    0xeec(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xef4(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movdqa 0xe89(%rip),%xmm0
movdqa 0xe91(%rip),%xmm1
movdqa 0xe99(%rip),%xmm2
movdqa 0xea1(%rip),%xmm3
mov    %ebp,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm4,%xmm4
cvtsi2sd %eax,%xmm4
movsd  %xmm4,(%rsp,%rbx,1)
movd   %eax,%xmm4
pshufd $0x50,%xmm4,%xmm4
movdqa %xmm4,%xmm5
paddd  %xmm0,%xmm5
cvtdq2pd %xmm5,%xmm5
movups %xmm5,0x8(%rsp,%rbx,1)
movdqa %xmm4,%xmm5
paddd  %xmm1,%xmm5
cvtdq2pd %xmm5,%xmm5
movups %xmm5,0x18(%rsp,%rbx,1)
movdqa %xmm4,%xmm5
paddd  %xmm2,%xmm5
cvtdq2pd %xmm5,%xmm5
movups %xmm5,0x28(%rsp,%rbx,1)
paddd  %xmm3,%xmm4
cvtdq2pd %xmm4,%xmm4
movups %xmm4,0x38(%rsp,%rbx,1)
lea    0x9(%rax),%ecx
xorps  %xmm4,%xmm4
cvtsi2sd %ecx,%xmm4
movsd  %xmm4,0x48(%rsp,%rbx,1)
add    $0x1,%eax
add    $0x50,%rbx
cmp    $0x320,%rbx
jne    11a0 <main+0x70>
movsd  0x318(%rsp),%xmm0
lea    0xe4a(%rip),%rdi
mov    %ebp,%esi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x328,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Number of threads = %d\0A\00"
@.str.1 = [23 x i8] c"Thread %d starting...\0A\00"
@.str.2 = [34 x i8] c"Thread %d done. Last element= %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 i32
%10 = alloca [10 x [10 x double]]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (...) @omp_get_thread_num()
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = call i32 (...) @omp_get_num_threads()
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %14, %2
%19 = load i32, i32* %7
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 0, i32* %8
br label %21
21: ; preds = %45, %18
%22 = load i32, i32* %8
%23 = icmp slt i32 %22, 10
br i1 %23, label %24, label %48
24: ; preds = %21
store i32 0, i32* %9
br label %25
25: ; preds = %41, %24
%26 = load i32, i32* %9
%27 = icmp slt i32 %26, 10
br i1 %27, label %28, label %44
28: ; preds = %25
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = add nsw i32 %29, %30
%32 = load i32, i32* %9
%33 = add nsw i32 %31, %32
%34 = sitofp i32 %33 to double
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10 x [10 x double]], [10 x [10 x double]]* %10, i64 0, i64 %36
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [10 x double], [10 x double]* %37, i64 0, i64 %39
store double %34, double* %40
br label %41
41: ; preds = %28
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %25
44: ; preds = %25
br label %45
45: ; preds = %44
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %21
48: ; preds = %21
%49 = load i32, i32* %7
%50 = getelementptr inbounds [10 x [10 x double]], [10 x [10 x double]]* %10, i64 0, i64 9
%51 = getelementptr inbounds [10 x double], [10 x double]* %50, i64 0, i64 9
%52 = load double, double* %51
%53 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %49, double %52)
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [24 x i8] c"Number of threads = %d\0A\00"
@.str.1 = [23 x i8] c"Thread %d starting...\0A\00"
@.str.2 = [34 x i8] c"Thread %d done. Last element= %f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x [10 x double]]
%4 = bitcast [10 x [10 x double]]* %3 to i8*
%5 = tail call i32 (...) @omp_get_thread_num()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 (...) @omp_get_num_threads()
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %7, %2
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %39, %12 ]
%14 = trunc i64 %13 to i32
%15 = add nsw i32 %5, %14
%16 = sitofp i32 %15 to double
%17 = getelementptr inbounds [10 x [10 x double]], [10 x [10 x double]]* %3, i64 0, i64 %13, i64 0
store double %16, double* %17
%18 = getelementptr inbounds [10 x [10 x double]], [10 x [10 x double]]* %3, i64 0, i64 %13, i64 1
%19 = insertelement <2 x i32> poison, i32 %15, i64 0
%20 = shufflevector <2 x i32> %19, <2 x i32> poison, <2 x i32> zeroinitializer
%21 = add nsw <2 x i32> %20, <i32 1, i32 2>
%22 = sitofp <2 x i32> %21 to <2 x double>
%23 = bitcast double* %18 to <2 x double>*
store <2 x double> %22, <2 x double>* %23
%24 = getelementptr inbounds [10 x [10 x double]], [10 x [10 x double]]* %3, i64 0, i64 %13, i64 3
%25 = add nsw <2 x i32> %20, <i32 3, i32 4>
%26 = sitofp <2 x i32> %25 to <2 x double>
%27 = bitcast double* %24 to <2 x double>*
store <2 x double> %26, <2 x double>* %27
%28 = getelementptr inbounds [10 x [10 x double]], [10 x [10 x double]]* %3, i64 0, i64 %13, i64 5
%29 = add nsw <2 x i32> %20, <i32 5, i32 6>
%30 = sitofp <2 x i32> %29 to <2 x double>
%31 = bitcast double* %28 to <2 x double>*
store <2 x double> %30, <2 x double>* %31
%32 = getelementptr inbounds [10 x [10 x double]], [10 x [10 x double]]* %3, i64 0, i64 %13, i64 7
%33 = add nsw <2 x i32> %20, <i32 7, i32 8>
%34 = sitofp <2 x i32> %33 to <2 x double>
%35 = bitcast double* %32 to <2 x double>*
store <2 x double> %34, <2 x double>* %35
%36 = add nsw i32 %15, 9
%37 = sitofp i32 %36 to double
%38 = getelementptr inbounds [10 x [10 x double]], [10 x [10 x double]]* %3, i64 0, i64 %13, i64 9
store double %37, double* %38
%39 = add nuw nsw i64 %13, 1
%40 = icmp eq i64 %39, 10
br i1 %40, label %41, label %12
41: ; preds = %12
%42 = getelementptr inbounds [10 x [10 x double]], [10 x [10 x double]]* %3, i64 0, i64 9, i64 9
%43 = load double, double* %42
%44 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %5, double %43)
ret i32 0
}