#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, ...);
main(int argc, char **argv) {
  double *Array, *Array1, *Check, serial_sum, sum;
  int array_size, i, threadid, tval, Noofthreads;
  printf("\n\t\t---------------------------------------------------------------"
         "------------");
  printf("\n\t\t Email : RarchK");
  printf("\n\t\t---------------------------------------------------------------"
         "------------");
  printf("\n\t\t Objective :Find the Sum of elements of one-dimensional real "
         "array.  ");
  printf("\n\t\t OpenMP Parallel for directive and Critical Section are used ");
  printf("\n\t\t..............................................................."
         "...........\n");
  if (argc != 3) {
    printf("\t\t Very Few Arguments\n ");
    printf("\t\t Syntax : exec <Threads> <array-size>\n");
    exit(-1);
  }
  Noofthreads = atoi(argv[1]);
  if ((Noofthreads != 1) && (Noofthreads != 2) && (Noofthreads != 4) &&
      (Noofthreads != 8) && (Noofthreads != 16)) {
    printf("\n Number of threads should be 1,2,4,8 or 16 for the execution of "
           "program. \n\n");
    exit(-1);
  }
  array_size = atoi(argv[2]);
  if (array_size <= 0) {
    printf("\n\t\t Array Size Should Be Of Positive Value ");
    exit(1);
  }
  printf("\n\t\t Threads     : %d ", Noofthreads);
  printf("\n\t\t Array Size  : %d ", array_size);
  Array = (double *)malloc(sizeof(double) * array_size);
  Check = (double *)malloc(sizeof(double) * array_size);
  for (i = 0; i < array_size; i++) {
    Array[i] = i * 5;
    Check[i] = Array[i];
  }
  sum = 0.0;
  omp_set_num_threads(Noofthreads);
#pragma omp parallel for
  for (i = 0; i < array_size; i++) {
#pragma omp critical
    sum = sum + Array[i];
  }
  serial_sum = 0.0;
  for (i = 0; i < array_size; i++)
    serial_sum = serial_sum + Check[i];
  if (serial_sum == sum)
    printf("\n\n\t\t The Serial And Parallel Sums Are Equal\n");
  else {
    printf("\n\\nt\t The Serial And Parallel Sums Are UnEqual\n");
    exit(1);
  }
  free(Check);
  free(Array);
  printf(
      "\n\t\t The SumOfElements Of The Array Using OpenMP Directives Is %lf\n",
      sum);
  printf("\t\t The SumOfElements Of The Array By Serial Calculation Is %lf\n\n",
         serial_sum);
  printf("\n\t\t..............................................................."
         "...........\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xef6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
je     11fa <main+0x9a>
lea    0xf60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x1,-0x4c(%rbp)
je     1254 <main+0xf4>
cmpl   $0x2,-0x4c(%rbp)
je     1254 <main+0xf4>
cmpl   $0x4,-0x4c(%rbp)
je     1254 <main+0xf4>
cmpl   $0x8,-0x4c(%rbp)
je     1254 <main+0xf4>
cmpl   $0x10,-0x4c(%rbp)
je     1254 <main+0xf4>
lea    0xf39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jg     1286 <main+0x126>
lea    0xf54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x4c(%rbp),%esi
lea    0xf65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x3c(%rbp),%esi
lea    0xf6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    131e <main+0x1be>
imul   $0x5,-0x40(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12d5 <main+0x175>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x4c(%rbp),%edi
call   1060 <omp_set_num_threads@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    1366 <main+0x206>
movsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1335 <main+0x1d5>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    13a6 <main+0x246>
movsd  -0x30(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x40(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1375 <main+0x215>
movsd  -0x30(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jne    13cf <main+0x26f>
jp     13cf <main+0x26f>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13e7 <main+0x287>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x38(%rbp),%xmm0
lea    0xe79(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x30(%rbp),%xmm0
lea    0xea9(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xcc6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xeb5(%rip),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xef3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeee(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf29(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10ab(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x3,%r14d
jne    15b3 <main+0x443>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
cmp    $0x10,%eax
ja     1605 <main+0x495>
mov    %eax,%r12d
mov    $0x10116,%eax
bt     %r12d,%eax
jae    1605 <main+0x495>
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
test   %eax,%eax
jle    15d7 <main+0x467>
mov    %eax,%r15d
lea    0xf52(%rip),%rdi
xor    %ebp,%ebp
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf55(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x0(,%r15,8),%r14d
mov    %r14d,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r14d,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %r15d,%r13d
cmp    $0x4,%r15d
jb     1381 <main+0x211>
lea    (%r14,%r13,8),%rax
cmp    %rax,%rbx
jae    127f <main+0x10f>
lea    (%rbx,%r13,8),%rax
cmp    %rax,%r14
jae    127f <main+0x10f>
xor    %ebp,%ebp
jmp    1381 <main+0x211>
mov    %r13d,%ebp
and    $0xfffffffc,%ebp
lea    -0x4(%rbp),%rax
mov    %rax,%rcx
shr    $0x2,%rcx
add    $0x1,%rcx
test   %rax,%rax
je     159b <main+0x42b>
mov    %rcx,%rdx
and    $0xfffffffffffffffe,%rdx
movdqa 0xd54(%rip),%xmm0
xor    %eax,%eax
movdqa 0xd5a(%rip),%xmm1
movdqa 0xd62(%rip),%xmm2
movdqa 0xd6a(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
movdqa %xmm0,%xmm4
pslld  $0x2,%xmm4
paddd  %xmm0,%xmm4
cvtdq2pd %xmm4,%xmm5
paddd  %xmm1,%xmm4
cvtdq2pd %xmm4,%xmm4
movups %xmm5,(%rbx,%rax,8)
movups %xmm4,0x10(%rbx,%rax,8)
movdqa %xmm0,%xmm6
paddd  %xmm2,%xmm6
movdqa %xmm6,%xmm7
pslld  $0x2,%xmm7
paddd  %xmm6,%xmm7
cvtdq2pd %xmm7,%xmm6
movups %xmm5,(%r14,%rax,8)
paddd  %xmm1,%xmm7
cvtdq2pd %xmm7,%xmm5
movups %xmm4,0x10(%r14,%rax,8)
movups %xmm6,0x20(%rbx,%rax,8)
movups %xmm5,0x30(%rbx,%rax,8)
movups %xmm6,0x20(%r14,%rax,8)
movups %xmm5,0x30(%r14,%rax,8)
add    $0x8,%rax
paddd  %xmm3,%xmm0
add    $0xfffffffffffffffe,%rdx
jne    12d0 <main+0x160>
test   $0x1,%cl
je     137c <main+0x20c>
movdqa %xmm0,%xmm1
pslld  $0x2,%xmm1
paddd  %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm0
paddd  0xcb0(%rip),%xmm1
cvtdq2pd %xmm1,%xmm1
movdqu %xmm0,(%rbx,%rax,8)
movdqu %xmm1,0x10(%rbx,%rax,8)
movdqu %xmm0,(%r14,%rax,8)
movdqu %xmm1,0x10(%r14,%rax,8)
cmp    %r13,%rbp
je     13e5 <main+0x275>
mov    %rbp,%rax
not    %rax
test   $0x1,%r13b
je     13a7 <main+0x237>
lea    0x0(%rbp,%rbp,4),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
movsd  %xmm0,(%r14,%rbp,8)
or     $0x1,%rbp
add    %r13,%rax
je     13e5 <main+0x275>
lea    0x0(%rbp,%rbp,4),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
movsd  %xmm0,(%r14,%rbp,8)
lea    0x5(%rax),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,0x8(%rbx,%rbp,8)
movsd  %xmm0,0x8(%r14,%rbp,8)
add    $0x2,%rbp
add    $0xa,%eax
cmp    %rbp,%r13
jne    13b0 <main+0x240>
mov    %r12d,%edi
call   1070 <omp_set_num_threads@plt>
test   %r15d,%r15d
jle    140a <main+0x29a>
lea    -0x1(%r13),%rax
mov    %r13d,%ecx
and    $0x7,%ecx
cmp    $0x7,%rax
jae    1423 <main+0x2b3>
pxor   %xmm0,%xmm0
xor    %edx,%edx
jmp    1468 <main+0x2f8>
pxor   %xmm0,%xmm0
movq   %xmm0,0x10(%rsp)
pxor   %xmm0,%xmm0
movq   %xmm0,0x8(%rsp)
jmp    153a <main+0x3ca>
mov    %r13d,%esi
and    $0xfffffff8,%esi
pxor   %xmm0,%xmm0
xor    %edx,%edx
nop
addsd  (%rbx,%rdx,8),%xmm0
addsd  0x8(%rbx,%rdx,8),%xmm0
addsd  0x10(%rbx,%rdx,8),%xmm0
addsd  0x18(%rbx,%rdx,8),%xmm0
addsd  0x20(%rbx,%rdx,8),%xmm0
addsd  0x28(%rbx,%rdx,8),%xmm0
addsd  0x30(%rbx,%rdx,8),%xmm0
addsd  0x38(%rbx,%rdx,8),%xmm0
add    $0x8,%rdx
cmp    %rdx,%rsi
jne    1430 <main+0x2c0>
test   %rcx,%rcx
je     148e <main+0x31e>
lea    (%rbx,%rdx,8),%rdx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addsd  (%rdx,%rsi,8),%xmm0
add    $0x1,%rsi
cmp    %rsi,%rcx
jne    1480 <main+0x310>
test   %r15d,%r15d
jle    14a7 <main+0x337>
mov    %r13d,%ecx
and    $0x7,%ecx
cmp    $0x7,%rax
jae    14ad <main+0x33d>
pxor   %xmm1,%xmm1
xor    %eax,%eax
jmp    1500 <main+0x390>
pxor   %xmm1,%xmm1
jmp    151e <main+0x3ae>
and    $0xfffffff8,%r13d
pxor   %xmm1,%xmm1
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
addsd  (%r14,%rax,8),%xmm1
addsd  0x8(%r14,%rax,8),%xmm1
addsd  0x10(%r14,%rax,8),%xmm1
addsd  0x18(%r14,%rax,8),%xmm1
addsd  0x20(%r14,%rax,8),%xmm1
addsd  0x28(%r14,%rax,8),%xmm1
addsd  0x30(%r14,%rax,8),%xmm1
addsd  0x38(%r14,%rax,8),%xmm1
add    $0x8,%rax
cmp    %rax,%r13
jne    14c0 <main+0x350>
test   %rcx,%rcx
je     151e <main+0x3ae>
lea    (%r14,%rax,8),%rax
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
addsd  (%rax,%rdx,8),%xmm1
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1510 <main+0x3a0>
movsd  %xmm1,0x10(%rsp)
ucomisd %xmm0,%xmm1
movsd  %xmm0,0x8(%rsp)
jne    15ef <main+0x47f>
jp     15ef <main+0x47f>
lea    0xd0e(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xc3f(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xc6e(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xcf6(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movdqa 0xa5d(%rip),%xmm0
xor    %eax,%eax
test   $0x1,%cl
jne    1347 <main+0x1d7>
jmp    137c <main+0x20c>
lea    0xb72(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd4d(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    0xb66(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xc2a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xcbd(%rip),%rdi
jmp    15c8 <main+0x458>

LLVM IR (-O0):
@.str = [79 x i8] c"\0A\09\09---------------------------------------------------------------------------\00"
@.str.1 = [19 x i8] c"\0A\09\09 Email : RarchK\00"
@.str.2 = [73 x i8] c"\0A\09\09 Objective :Find the Sum of elements of one-dimensional real array. \00"
@.str.3 = [65 x i8] c"\0A\09\09 OpenMP Parallel for directive and Critical Section are used \00"
@.str.4 = [79 x i8] c"\0A\09\09..........................................................................\0A\00"
@.str.5 = [24 x i8] c"\09\09 Very Few Arguments\0A \00"
@.str.6 = [41 x i8] c"\09\09 Syntax : exec <Threads> <array-size>\0A\00"
@.str.7 = [77 x i8] c"\0A Number of threads should be 1,2,4,8 or 16 for the execution of program. \0A\0A\00"
@.str.8 = [44 x i8] c"\0A\09\09 Array Size Should Be Of Positive Value \00"
@.str.9 = [22 x i8] c"\0A\09\09 Threads : %d \00"
@.str.10 = [22 x i8] c"\0A\09\09 Array Size : %d \00"
@.str.11 = [45 x i8] c"\0A\0A\09\09 The Serial And Parallel Sums Are Equal\0A\00"
@.str.12 = [48 x i8] c"\0A\\nt\09 The Serial And Parallel Sums Are UnEqual\0A\00"
@.str.13 = [67 x i8] c"\0A\09\09 The SumOfElements Of The Array Using OpenMP Directives Is %lf\0A\00"
@.str.14 = [65 x i8] c"\09\09 The SumOfElements Of The Array By Serial Calculation Is %lf\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.4, i64 0, i64 0))
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 3
br i1 %23, label %24, label %28
24: ; preds = %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %15
%33 = load i32, i32* %15
%34 = icmp ne i32 %33, 1
br i1 %34, label %35, label %50
35: ; preds = %28
%36 = load i32, i32* %15
%37 = icmp ne i32 %36, 2
br i1 %37, label %38, label %50
38: ; preds = %35
%39 = load i32, i32* %15
%40 = icmp ne i32 %39, 4
br i1 %40, label %41, label %50
41: ; preds = %38
%42 = load i32, i32* %15
%43 = icmp ne i32 %42, 8
br i1 %43, label %44, label %50
44: ; preds = %41
%45 = load i32, i32* %15
%46 = icmp ne i32 %45, 16
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.7, i64 0, i64 0))
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %44, %41, %38, %35, %28
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = call i32 @atoi(i8* %53)
store i32 %54, i32* %11
%55 = load i32, i32* %11
%56 = icmp sle i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %50
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %50
%61 = load i32, i32* %15
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %61)
%63 = load i32, i32* %11
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i32 %63)
%65 = load i32, i32* %11
%66 = sext i32 %65 to i64
%67 = mul i64 8, %66
%68 = trunc i64 %67 to i32
%69 = call i64 @malloc(i32 %68)
%70 = inttoptr i64 %69 to double*
store double* %70, double** %6
%71 = load i32, i32* %11
%72 = sext i32 %71 to i64
%73 = mul i64 8, %72
%74 = trunc i64 %73 to i32
%75 = call i64 @malloc(i32 %74)
%76 = inttoptr i64 %75 to double*
store double* %76, double** %8
store i32 0, i32* %12
br label %77
77: ; preds = %98, %60
%78 = load i32, i32* %12
%79 = load i32, i32* %11
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %101
81: ; preds = %77
%82 = load i32, i32* %12
%83 = mul nsw i32 %82, 5
%84 = sitofp i32 %83 to double
%85 = load double*, double** %6
%86 = load i32, i32* %12
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds double, double* %85, i64 %87
store double %84, double* %88
%89 = load double*, double** %6
%90 = load i32, i32* %12
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds double, double* %89, i64 %91
%93 = load double, double* %92
%94 = load double*, double** %8
%95 = load i32, i32* %12
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds double, double* %94, i64 %96
store double %93, double* %97
br label %98
98: ; preds = %81
%99 = load i32, i32* %12
%100 = add nsw i32 %99, 1
store i32 %100, i32* %12
br label %77
101: ; preds = %77
store double 0.000000e+00, double* %10
%102 = load i32, i32* %15
%103 = call i32 @omp_set_num_threads(i32 %102)
store i32 0, i32* %12
br label %104
104: ; preds = %116, %101
%105 = load i32, i32* %12
%106 = load i32, i32* %11
%107 = icmp slt i32 %105, %106
br i1 %107, label %108, label %119
108: ; preds = %104
%109 = load double, double* %10
%110 = load double*, double** %6
%111 = load i32, i32* %12
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds double, double* %110, i64 %112
%114 = load double, double* %113
%115 = fadd double %109, %114
store double %115, double* %10
br label %116
116: ; preds = %108
%117 = load i32, i32* %12
%118 = add nsw i32 %117, 1
store i32 %118, i32* %12
br label %104
119: ; preds = %104
store double 0.000000e+00, double* %9
store i32 0, i32* %12
br label %120
120: ; preds = %132, %119
%121 = load i32, i32* %12
%122 = load i32, i32* %11
%123 = icmp slt i32 %121, %122
br i1 %123, label %124, label %135
124: ; preds = %120
%125 = load double, double* %9
%126 = load double*, double** %8
%127 = load i32, i32* %12
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds double, double* %126, i64 %128
%130 = load double, double* %129
%131 = fadd double %125, %130
store double %131, double* %9
br label %132
132: ; preds = %124
%133 = load i32, i32* %12
%134 = add nsw i32 %133, 1
store i32 %134, i32* %12
br label %120
135: ; preds = %120
%136 = load double, double* %9
%137 = load double, double* %10
%138 = fcmp oeq double %136, %137
br i1 %138, label %139, label %141
139: ; preds = %135
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.11, i64 0, i64 0))
br label %144
141: ; preds = %135
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.12, i64 0, i64 0))
%143 = call i32 @exit(i32 1)
unreachable
144: ; preds = %139
%145 = load double*, double** %8
%146 = call i32 @free(double* %145)
%147 = load double*, double** %6
%148 = call i32 @free(double* %147)
%149 = load double, double* %10
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.13, i64 0, i64 0), double %149)
%151 = load double, double* %9
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.14, i64 0, i64 0), double %151)
%153 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.4, i64 0, i64 0))
%154 = load i32, i32* %3
ret i32 %154
}

LLVM IR (-O2):
@.str = [79 x i8] c"\0A\09\09---------------------------------------------------------------------------\00"
@.str.1 = [19 x i8] c"\0A\09\09 Email : RarchK\00"
@.str.2 = [73 x i8] c"\0A\09\09 Objective :Find the Sum of elements of one-dimensional real array. \00"
@.str.3 = [65 x i8] c"\0A\09\09 OpenMP Parallel for directive and Critical Section are used \00"
@.str.5 = [24 x i8] c"\09\09 Very Few Arguments\0A \00"
@.str.8 = [44 x i8] c"\0A\09\09 Array Size Should Be Of Positive Value \00"
@.str.9 = [22 x i8] c"\0A\09\09 Threads : %d \00"
@.str.10 = [22 x i8] c"\0A\09\09 Array Size : %d \00"
@.str.13 = [67 x i8] c"\0A\09\09 The SumOfElements Of The Array Using OpenMP Directives Is %lf\0A\00"
@.str.14 = [65 x i8] c"\09\09 The SumOfElements Of The Array By Serial Calculation Is %lf\0A\0A\00"
@str.15 = [47 x i8] c"\0A\\nt\09 The Serial And Parallel Sums Are UnEqual\00"
@str.16 = [44 x i8] c"\0A\0A\09\09 The Serial And Parallel Sums Are Equal\00"
@str.17 = [78 x i8] c"\0A\09\09..........................................................................\00"
@str.18 = [76 x i8] c"\0A Number of threads should be 1,2,4,8 or 16 for the execution of program. \0A\00"
@str.19 = [40 x i8] c"\09\09 Syntax : exec <Threads> <array-size>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str.17, i64 0, i64 0))
%9 = icmp eq i32 %0, 3
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.19, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
switch i32 %17, label %18 [
i32 16, label %21
i32 8, label %21
i32 4, label %21
i32 2, label %21
i32 1, label %21
]
18: ; preds = %14
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str.18, i64 0, i64 0))
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %14, %14, %14, %14, %14
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
%25 = icmp slt i32 %24, 1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %17)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i32 %24)
%32 = shl i32 %24, 3
%33 = tail call i64 @malloc(i32 %32)
%34 = inttoptr i64 %33 to double*
%35 = tail call i64 @malloc(i32 %32)
%36 = inttoptr i64 %35 to double*
%37 = zext i32 %24 to i64
%38 = icmp ult i32 %24, 4
br i1 %38, label %114, label %39
39: ; preds = %29
%40 = inttoptr i64 %35 to i8*
%41 = inttoptr i64 %33 to i8*
%42 = getelementptr double, double* %34, i64 %37
%43 = bitcast double* %42 to i8*
%44 = getelementptr double, double* %36, i64 %37
%45 = bitcast double* %44 to i8*
%46 = icmp ult i8* %41, %45
%47 = icmp ult i8* %40, %43
%48 = and i1 %46, %47
br i1 %48, label %114, label %49
49: ; preds = %39
%50 = and i64 %37, 4294967292
%51 = add nsw i64 %50, -4
%52 = lshr exact i64 %51, 2
%53 = add nuw nsw i64 %52, 1
%54 = and i64 %53, 1
%55 = icmp eq i64 %51, 0
br i1 %55, label %94, label %56
56: ; preds = %49
%57 = and i64 %53, 9223372036854775806
br label %58
58: ; preds = %58, %56
%59 = phi i64 [ 0, %56 ], [ %90, %58 ]
%60 = phi <2 x i32> [ <i32 0, i32 1>, %56 ], [ %91, %58 ]
%61 = phi i64 [ 0, %56 ], [ %92, %58 ]
%62 = mul nsw <2 x i32> %60, <i32 5, i32 5>
%63 = mul <2 x i32> %60, <i32 5, i32 5>
%64 = add <2 x i32> %63, <i32 10, i32 10>
%65 = sitofp <2 x i32> %62 to <2 x double>
%66 = sitofp <2 x i32> %64 to <2 x double>
%67 = getelementptr inbounds double, double* %34, i64 %59
%68 = bitcast double* %67 to <2 x double>*
store <2 x double> %65, <2 x double>* %68
%69 = getelementptr inbounds double, double* %67, i64 2
%70 = bitcast double* %69 to <2 x double>*
store <2 x double> %66, <2 x double>* %70
%71 = getelementptr inbounds double, double* %36, i64 %59
%72 = bitcast double* %71 to <2 x double>*
store <2 x double> %65, <2 x double>* %72
%73 = getelementptr inbounds double, double* %71, i64 2
%74 = bitcast double* %73 to <2 x double>*
store <2 x double> %66, <2 x double>* %74
%75 = or i64 %59, 4
%76 = add <2 x i32> %60, <i32 4, i32 4>
%77 = mul nsw <2 x i32> %76, <i32 5, i32 5>
%78 = mul <2 x i32> %76, <i32 5, i32 5>
%79 = add <2 x i32> %78, <i32 10, i32 10>
%80 = sitofp <2 x i32> %77 to <2 x double>
%81 = sitofp <2 x i32> %79 to <2 x double>
%82 = getelementptr inbounds double, double* %34, i64 %75
%83 = bitcast double* %82 to <2 x double>*
store <2 x double> %80, <2 x double>* %83
%84 = getelementptr inbounds double, double* %82, i64 2
%85 = bitcast double* %84 to <2 x double>*
store <2 x double> %81, <2 x double>* %85
%86 = getelementptr inbounds double, double* %36, i64 %75
%87 = bitcast double* %86 to <2 x double>*
store <2 x double> %80, <2 x double>* %87
%88 = getelementptr inbounds double, double* %86, i64 2
%89 = bitcast double* %88 to <2 x double>*
store <2 x double> %81, <2 x double>* %89
%90 = add nuw i64 %59, 8
%91 = add <2 x i32> %60, <i32 8, i32 8>
%92 = add i64 %61, 2
%93 = icmp eq i64 %92, %57
br i1 %93, label %94, label %58
94: ; preds = %58, %49
%95 = phi i64 [ 0, %49 ], [ %90, %58 ]
%96 = phi <2 x i32> [ <i32 0, i32 1>, %49 ], [ %91, %58 ]
%97 = icmp eq i64 %54, 0
br i1 %97, label %112, label %98
98: ; preds = %94
%99 = mul nsw <2 x i32> %96, <i32 5, i32 5>
%100 = mul <2 x i32> %96, <i32 5, i32 5>
%101 = add <2 x i32> %100, <i32 10, i32 10>
%102 = sitofp <2 x i32> %99 to <2 x double>
%103 = sitofp <2 x i32> %101 to <2 x double>
%104 = getelementptr inbounds double, double* %34, i64 %95
%105 = bitcast double* %104 to <2 x double>*
store <2 x double> %102, <2 x double>* %105
%106 = getelementptr inbounds double, double* %104, i64 2
%107 = bitcast double* %106 to <2 x double>*
store <2 x double> %103, <2 x double>* %107
%108 = getelementptr inbounds double, double* %36, i64 %95
%109 = bitcast double* %108 to <2 x double>*
store <2 x double> %102, <2 x double>* %109
%110 = getelementptr inbounds double, double* %108, i64 2
%111 = bitcast double* %110 to <2 x double>*
store <2 x double> %103, <2 x double>* %111
br label %112
112: ; preds = %94, %98
%113 = icmp eq i64 %50, %37
br i1 %113, label %145, label %114
114: ; preds = %39, %29, %112
%115 = phi i64 [ 0, %39 ], [ 0, %29 ], [ %50, %112 ]
%116 = xor i64 %115, -1
%117 = and i64 %37, 1
%118 = icmp eq i64 %117, 0
br i1 %118, label %126, label %119
119: ; preds = %114
%120 = trunc i64 %115 to i32
%121 = mul nsw i32 %120, 5
%122 = sitofp i32 %121 to double
%123 = getelementptr inbounds double, double* %34, i64 %115
store double %122, double* %123
%124 = getelementptr inbounds double, double* %36, i64 %115
store double %122, double* %124
%125 = or i64 %115, 1
br label %126
126: ; preds = %119, %114
%127 = phi i64 [ %115, %114 ], [ %125, %119 ]
%128 = sub nsw i64 0, %37
%129 = icmp eq i64 %116, %128
br i1 %129, label %145, label %130
130: ; preds = %126, %130
%131 = phi i64 [ %143, %130 ], [ %127, %126 ]
%132 = trunc i64 %131 to i32
%133 = mul nsw i32 %132, 5
%134 = sitofp i32 %133 to double
%135 = getelementptr inbounds double, double* %34, i64 %131
store double %134, double* %135
%136 = getelementptr inbounds double, double* %36, i64 %131
store double %134, double* %136
%137 = add nuw nsw i64 %131, 1
%138 = trunc i64 %137 to i32
%139 = mul nsw i32 %138, 5
%140 = sitofp i32 %139 to double
%141 = getelementptr inbounds double, double* %34, i64 %137
store double %140, double* %141
%142 = getelementptr inbounds double, double* %36, i64 %137
store double %140, double* %142
%143 = add nuw nsw i64 %131, 2
%144 = icmp eq i64 %143, %37
br i1 %144, label %145, label %130
145: ; preds = %126, %130, %112
%146 = tail call i32 @omp_set_num_threads(i32 %17)
%147 = icmp sgt i32 %24, 0
br i1 %147, label %148, label %270
148: ; preds = %145
%149 = add nsw i64 %37, -1
%150 = and i64 %37, 7
%151 = icmp ult i64 %149, 7
br i1 %151, label %154, label %152
152: ; preds = %148
%153 = and i64 %37, 4294967288
br label %176
154: ; preds = %176, %148
%155 = phi double [ undef, %148 ], [ %210, %176 ]
%156 = phi i64 [ 0, %148 ], [ %211, %176 ]
%157 = phi double [ 0.000000e+00, %148 ], [ %210, %176 ]
%158 = icmp eq i64 %150, 0
br i1 %158, label %169, label %159
159: ; preds = %154, %159
%160 = phi i64 [ %166, %159 ], [ %156, %154 ]
%161 = phi double [ %165, %159 ], [ %157, %154 ]
%162 = phi i64 [ %167, %159 ], [ 0, %154 ]
%163 = getelementptr inbounds double, double* %34, i64 %160
%164 = load double, double* %163
%165 = fadd double %161, %164
%166 = add nuw nsw i64 %160, 1
%167 = add i64 %162, 1
%168 = icmp eq i64 %167, %150
br i1 %168, label %169, label %159
169: ; preds = %159, %154
%170 = phi double [ %155, %154 ], [ %165, %159 ]
br i1 %147, label %171, label %267
171: ; preds = %169
%172 = and i64 %37, 7
%173 = icmp ult i64 %149, 7
br i1 %173, label %252, label %174
174: ; preds = %171
%175 = and i64 %37, 4294967288
br label %214
176: ; preds = %176, %152
%177 = phi i64 [ 0, %152 ], [ %211, %176 ]
%178 = phi double [ 0.000000e+00, %152 ], [ %210, %176 ]
%179 = phi i64 [ 0, %152 ], [ %212, %176 ]
%180 = getelementptr inbounds double, double* %34, i64 %177
%181 = load double, double* %180
%182 = fadd double %178, %181
%183 = or i64 %177, 1
%184 = getelementptr inbounds double, double* %34, i64 %183
%185 = load double, double* %184
%186 = fadd double %182, %185
%187 = or i64 %177, 2
%188 = getelementptr inbounds double, double* %34, i64 %187
%189 = load double, double* %188
%190 = fadd double %186, %189
%191 = or i64 %177, 3
%192 = getelementptr inbounds double, double* %34, i64 %191
%193 = load double, double* %192
%194 = fadd double %190, %193
%195 = or i64 %177, 4
%196 = getelementptr inbounds double, double* %34, i64 %195
%197 = load double, double* %196
%198 = fadd double %194, %197
%199 = or i64 %177, 5
%200 = getelementptr inbounds double, double* %34, i64 %199
%201 = load double, double* %200
%202 = fadd double %198, %201
%203 = or i64 %177, 6
%204 = getelementptr inbounds double, double* %34, i64 %203
%205 = load double, double* %204
%206 = fadd double %202, %205
%207 = or i64 %177, 7
%208 = getelementptr inbounds double, double* %34, i64 %207
%209 = load double, double* %208
%210 = fadd double %206, %209
%211 = add nuw nsw i64 %177, 8
%212 = add i64 %179, 8
%213 = icmp eq i64 %212, %153
br i1 %213, label %154, label %176
214: ; preds = %214, %174
%215 = phi i64 [ 0, %174 ], [ %249, %214 ]
%216 = phi double [ 0.000000e+00, %174 ], [ %248, %214 ]
%217 = phi i64 [ 0, %174 ], [ %250, %214 ]
%218 = getelementptr inbounds double, double* %36, i64 %215
%219 = load double, double* %218
%220 = fadd double %216, %219
%221 = or i64 %215, 1
%222 = getelementptr inbounds double, double* %36, i64 %221
%223 = load double, double* %222
%224 = fadd double %220, %223
%225 = or i64 %215, 2
%226 = getelementptr inbounds double, double* %36, i64 %225
%227 = load double, double* %226
%228 = fadd double %224, %227
%229 = or i64 %215, 3
%230 = getelementptr inbounds double, double* %36, i64 %229
%231 = load double, double* %230
%232 = fadd double %228, %231
%233 = or i64 %215, 4
%234 = getelementptr inbounds double, double* %36, i64 %233
%235 = load double, double* %234
%236 = fadd double %232, %235
%237 = or i64 %215, 5
%238 = getelementptr inbounds double, double* %36, i64 %237
%239 = load double, double* %238
%240 = fadd double %236, %239
%241 = or i64 %215, 6
%242 = getelementptr inbounds double, double* %36, i64 %241
%243 = load double, double* %242
%244 = fadd double %240, %243
%245 = or i64 %215, 7
%246 = getelementptr inbounds double, double* %36, i64 %245
%247 = load double, double* %246
%248 = fadd double %244, %247
%249 = add nuw nsw i64 %215, 8
%250 = add i64 %217, 8
%251 = icmp eq i64 %250, %175
br i1 %251, label %252, label %214
252: ; preds = %214, %171
%253 = phi double [ undef, %171 ], [ %248, %214 ]
%254 = phi i64 [ 0, %171 ], [ %249, %214 ]
%255 = phi double [ 0.000000e+00, %171 ], [ %248, %214 ]
%256 = icmp eq i64 %172, 0
br i1 %256, label %267, label %257
257: ; preds = %252, %257
%258 = phi i64 [ %264, %257 ], [ %254, %252 ]
%259 = phi double [ %263, %257 ], [ %255, %252 ]
%260 = phi i64 [ %265, %257 ], [ 0, %252 ]
%261 = getelementptr inbounds double, double* %36, i64 %258
%262 = load double, double* %261
%263 = fadd double %259, %262
%264 = add nuw nsw i64 %258, 1
%265 = add i64 %260, 1
%266 = icmp eq i64 %265, %172
br i1 %266, label %267, label %257
267: ; preds = %252, %257, %169
%268 = phi double [ 0.000000e+00, %169 ], [ %253, %252 ], [ %263, %257 ]
%269 = fcmp oeq double %268, %170
br i1 %269, label %270, label %279
270: ; preds = %145, %267
%271 = phi double [ %268, %267 ], [ 0.000000e+00, %145 ]
%272 = phi double [ %170, %267 ], [ 0.000000e+00, %145 ]
%273 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.16, i64 0, i64 0))
%274 = tail call i32 @free(double* %36)
%275 = tail call i32 @free(double* %34)
%276 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str.13, i64 0, i64 0), double %272)
%277 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.14, i64 0, i64 0), double %271)
%278 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str.17, i64 0, i64 0))
ret i32 0
279: ; preds = %267
%280 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.15, i64 0, i64 0))
%281 = tail call i32 @exit(i32 1)
unreachable
}