#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[1023][1023];
#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 < 1023; i++)
      for (j = 0; j < 1023; j++)
        a[i][j] = tid + i + j;
    printf("Thread %d done. Last element= %f\n", tid, a[1023 - 1][1023 - 1]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7fc030,%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   $0x3ff,-0x1c(%rbp)
jge    11fd <main+0xcd>
movl   $0x0,-0x20(%rbp)
cmpl   $0x3ff,-0x20(%rbp)
jge    11ea <main+0xba>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
cvtsi2sd %eax,%xmm0
movslq -0x1c(%rbp),%rcx
lea    -0x7fc030(%rbp),%rax
imul   $0x1ff8,%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    11a4 <main+0x74>
jmp    11ef <main+0xbf>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1190 <main+0x60>
mov    -0x18(%rbp),%esi
movsd  -0x30(%rbp),%xmm0
lea    0xe23(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x7fc030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x7fc008,%rsp
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%r14d
test   %eax,%eax
jne    115f <main+0x2f>
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
lea    0xeca(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed2(%rip),%rdi
xor    %ebx,%ebx
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rax
movdqa 0xe83(%rip),%xmm0
movdqa 0xe8b(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r14,%rbx,1),%ecx
movd   %ecx,%xmm2
pshufd $0x50,%xmm2,%xmm2
lea    (%r14,%rbx,1),%edx
add    $0x2,%edx
movd   %edx,%xmm3
pshufd $0x50,%xmm3,%xmm3
mov    $0x2,%edx
movdqa %xmm0,%xmm4
cs nopw 0x0(%rax,%rax,1)
movdqa %xmm2,%xmm5
paddd  %xmm4,%xmm5
movdqa %xmm3,%xmm6
cvtdq2pd %xmm5,%xmm5
paddd  %xmm4,%xmm6
cvtdq2pd %xmm6,%xmm6
movups %xmm5,-0x10(%rax,%rdx,8)
movups %xmm6,(%rax,%rdx,8)
paddd  %xmm1,%xmm4
add    $0x4,%rdx
cmp    $0x3fe,%rdx
jne    11c0 <main+0x90>
lea    0x3fc(%rcx),%edx
xorps  %xmm2,%xmm2
cvtsi2sd %edx,%xmm2
imul   $0x1ff8,%rbx,%rdx
movsd  %xmm2,0x1fe0(%rsp,%rdx,1)
lea    0x3fd(%rcx),%esi
xorps  %xmm2,%xmm2
cvtsi2sd %esi,%xmm2
movsd  %xmm2,0x1fe8(%rsp,%rdx,1)
add    $0x3fe,%ecx
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
movsd  %xmm2,0x1ff0(%rsp,%rdx,1)
add    $0x1,%rbx
add    $0x1ff8,%rax
cmp    $0x3ff,%rbx
jne    1190 <main+0x60>
movsd  0x7fc000(%rsp),%xmm0
lea    0xded(%rip),%rdi
mov    %r14d,%esi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x7fc008,%rsp
pop    %rbx
pop    %r14
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 [1023 x [1023 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, 1023
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, 1023
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 [1023 x [1023 x double]], [1023 x [1023 x double]]* %10, i64 0, i64 %36
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1023 x double], [1023 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 [1023 x [1023 x double]], [1023 x [1023 x double]]* %10, i64 0, i64 1022
%51 = getelementptr inbounds [1023 x double], [1023 x double]* %50, i64 0, i64 1022
%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 [1023 x [1023 x double]]
%4 = bitcast [1023 x [1023 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, %35
%13 = phi i64 [ 0, %10 ], [ %45, %35 ]
%14 = trunc i64 %13 to i32
%15 = add nsw i32 %5, %14
%16 = insertelement <2 x i32> poison, i32 %15, i64 0
%17 = shufflevector <2 x i32> %16, <2 x i32> poison, <2 x i32> zeroinitializer
%18 = add i32 %15, 2
%19 = insertelement <2 x i32> poison, i32 %18, i64 0
%20 = shufflevector <2 x i32> %19, <2 x i32> poison, <2 x i32> zeroinitializer
br label %21
21: ; preds = %21, %12
%22 = phi i64 [ 0, %12 ], [ %32, %21 ]
%23 = phi <2 x i32> [ <i32 0, i32 1>, %12 ], [ %33, %21 ]
%24 = add nsw <2 x i32> %17, %23
%25 = add <2 x i32> %20, %23
%26 = sitofp <2 x i32> %24 to <2 x double>
%27 = sitofp <2 x i32> %25 to <2 x double>
%28 = getelementptr inbounds [1023 x [1023 x double]], [1023 x [1023 x double]]* %3, i64 0, i64 %13, i64 %22
%29 = bitcast double* %28 to <2 x double>*
store <2 x double> %26, <2 x double>* %29
%30 = getelementptr inbounds double, double* %28, i64 2
%31 = bitcast double* %30 to <2 x double>*
store <2 x double> %27, <2 x double>* %31
%32 = add nuw i64 %22, 4
%33 = add <2 x i32> %23, <i32 4, i32 4>
%34 = icmp eq i64 %32, 1020
br i1 %34, label %35, label %21
35: ; preds = %21
%36 = add nsw i32 %15, 1020
%37 = sitofp i32 %36 to double
%38 = getelementptr inbounds [1023 x [1023 x double]], [1023 x [1023 x double]]* %3, i64 0, i64 %13, i64 1020
store double %37, double* %38
%39 = add nsw i32 %15, 1021
%40 = sitofp i32 %39 to double
%41 = getelementptr inbounds [1023 x [1023 x double]], [1023 x [1023 x double]]* %3, i64 0, i64 %13, i64 1021
store double %40, double* %41
%42 = add nsw i32 %15, 1022
%43 = sitofp i32 %42 to double
%44 = getelementptr inbounds [1023 x [1023 x double]], [1023 x [1023 x double]]* %3, i64 0, i64 %13, i64 1022
store double %43, double* %44
%45 = add nuw nsw i64 %13, 1
%46 = icmp eq i64 %45, 1023
br i1 %46, label %47, label %12
47: ; preds = %35
%48 = getelementptr inbounds [1023 x [1023 x double]], [1023 x [1023 x double]]* %3, i64 0, i64 1022, i64 1022
%49 = load double, double* %48
%50 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %5, double %49)
ret i32 0
}