#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 */
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, int, double);
int main() {
  int A[50000];
  int B[50000];
  int seq_sum[50000];
  int par_sum[50000];
  int i;
  for (i = 0; i < 50000; i++) {
    A[i] = 1;
    B[i] = 2;
  }
  double t_start = omp_get_wtime();
  for (i = 0; i < 50000; i++) {
    seq_sum[i] = A[i] + B[i];
  }
  double t_end = omp_get_wtime();
  printf("Total time taken for sequential sum of %d elements: %f s\n", 50000,
         (t_end - t_start));
  t_start = omp_get_wtime();
#pragma omp parallel for
  for (i = 0; i < 50000; i++) {
    par_sum[i] = A[i] + B[i];
  }
  t_end = omp_get_wtime();
  printf("Total time taken for parallel sum of %d elements: %f s\n", 50000,
         (t_end - t_start));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc3530,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc3514(%rbp)
cmpl   $0xc350,-0xc3514(%rbp)
jge    1184 <main+0x64>
movslq -0xc3514(%rbp),%rax
movl   $0x1,-0x30d50(%rbp,%rax,4)
movslq -0xc3514(%rbp),%rax
movl   $0x2,-0x61a90(%rbp,%rax,4)
mov    -0xc3514(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc3514(%rbp)
jmp    113c <main+0x1c>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0xc3520(%rbp)
ff
movl   $0x0,-0xc3514(%rbp)
cmpl   $0xc350,-0xc3514(%rbp)
jge    11eb <main+0xcb>
movslq -0xc3514(%rbp),%rax
mov    -0x30d50(%rbp,%rax,4),%ecx
movslq -0xc3514(%rbp),%rax
add    -0x61a90(%rbp,%rax,4),%ecx
movslq -0xc3514(%rbp),%rax
mov    %ecx,-0x927d0(%rbp,%rax,4)
mov    -0xc3514(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc3514(%rbp)
jmp    119d <main+0x7d>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0xc3528(%rbp)
ff
movsd  -0xc3528(%rbp),%xmm0
ff
subsd  -0xc3520(%rbp),%xmm0
ff
lea    0xdef(%rip),%rdi
mov    $0xc350,%esi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0xc3520(%rbp)
ff
movl   $0x0,-0xc3514(%rbp)
cmpl   $0xc350,-0xc3514(%rbp)
jge    1282 <main+0x162>
movslq -0xc3514(%rbp),%rax
mov    -0x30d50(%rbp,%rax,4),%ecx
movslq -0xc3514(%rbp),%rax
add    -0x61a90(%rbp,%rax,4),%ecx
movslq -0xc3514(%rbp),%rax
mov    %ecx,-0xc3510(%rbp,%rax,4)
mov    -0xc3514(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc3514(%rbp)
jmp    1234 <main+0x114>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0xc3528(%rbp)
ff
movsd  -0xc3528(%rbp),%xmm0
ff
subsd  -0xc3520(%rbp),%xmm0
ff
lea    0xd92(%rip),%rdi
mov    $0xc350,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xc3530,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
subsd  (%rsp),%xmm0
lea    0xec0(%rip),%rdi
mov    $0xc350,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
subsd  (%rsp),%xmm0
lea    0xed1(%rip),%rdi
mov    $0xc350,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [58 x i8] c"Total time taken for sequential sum of %d elements: %f s\0A\00"
@.str.1 = [56 x i8] c"Total time taken for parallel sum of %d elements: %f s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50000 x i32]
%3 = alloca [50000 x i32]
%4 = alloca [50000 x i32]
%5 = alloca [50000 x i32]
%6 = alloca i32
%7 = alloca double
%8 = alloca double
store i32 0, i32* %1
store i32 0, i32* %6
br label %9
9: ; preds = %19, %0
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 50000
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [50000 x i32], [50000 x i32]* %2, i64 0, i64 %14
store i32 1, i32* %15
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [50000 x i32], [50000 x i32]* %3, i64 0, i64 %17
store i32 2, i32* %18
br label %19
19: ; preds = %12
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %9
22: ; preds = %9
%23 = call double (...) @omp_get_wtime()
store double %23, double* %7
store i32 0, i32* %6
br label %24
24: ; preds = %40, %22
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 50000
br i1 %26, label %27, label %43
27: ; preds = %24
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [50000 x i32], [50000 x i32]* %2, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [50000 x i32], [50000 x i32]* %3, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = add nsw i32 %31, %35
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [50000 x i32], [50000 x i32]* %4, i64 0, i64 %38
store i32 %36, i32* %39
br label %40
40: ; preds = %27
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %24
43: ; preds = %24
%44 = call double (...) @omp_get_wtime()
store double %44, double* %8
%45 = load double, double* %8
%46 = load double, double* %7
%47 = fsub double %45, %46
%48 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 50000, double %47)
%49 = call double (...) @omp_get_wtime()
store double %49, double* %7
store i32 0, i32* %6
br label %50
50: ; preds = %66, %43
%51 = load i32, i32* %6
%52 = icmp slt i32 %51, 50000
br i1 %52, label %53, label %69
53: ; preds = %50
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [50000 x i32], [50000 x i32]* %2, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = load i32, i32* %6
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [50000 x i32], [50000 x i32]* %3, i64 0, i64 %59
%61 = load i32, i32* %60
%62 = add nsw i32 %57, %61
%63 = load i32, i32* %6
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [50000 x i32], [50000 x i32]* %5, i64 0, i64 %64
store i32 %62, i32* %65
br label %66
66: ; preds = %53
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %50
69: ; preds = %50
%70 = call double (...) @omp_get_wtime()
store double %70, double* %8
%71 = load double, double* %8
%72 = load double, double* %7
%73 = fsub double %71, %72
%74 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 50000, double %73)
ret i32 0
}

LLVM IR (-O2):
@.str = [58 x i8] c"Total time taken for sequential sum of %d elements: %f s\0A\00"
@.str.1 = [56 x i8] c"Total time taken for parallel sum of %d elements: %f s\0A\00"
define i32 @main() {
%1 = tail call double (...) @omp_get_wtime()
%2 = tail call double (...) @omp_get_wtime()
%3 = fsub double %2, %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 50000, double %3)
%5 = tail call double (...) @omp_get_wtime()
%6 = tail call double (...) @omp_get_wtime()
%7 = fsub double %6, %5
%8 = tail call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 50000, double %7)
ret i32 0
}