#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int omp_get_num_threads();
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, double);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int i, a, con = 100000000;
  clock_t start, end;
  double cpu_time_used;
  srand(time(NULL));
  start = clock();
  for (i = 0; i < con; i++) {
    a = a + i * rand();
    a = a * a;
  }
  printf("%d \t", a);
  end = clock();
  cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
  printf("Tempo senza parellelizzazione: %f \n", cpu_time_used);
  omp_set_num_threads(4);
  printf("Numero di Threads attivi: %d \n", omp_get_num_threads());
  start = clock();
#pragma omp parallel
#pragma omp for schedule(static)
  for (i = 0; i < con; i++) {
    a = a = a + i * rand();
    a = a * a;
  }
  end = clock();
  printf("%d \t", a);
  cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
  printf("Tempo con parellelizzazione: %f \n", cpu_time_used);
  return 0;
}


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)
movl   $0x5f5e100,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f6 <main+0x86>
mov    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
mov    -0x40(%rbp),%ecx
mov    %eax,%edx
mov    -0x3c(%rbp),%eax
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11af <main+0x3f>
cvtsi2sdl -0x18(%rbp),%xmm0
lea    0xdfe(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2dc2(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xdca(%rip),%rdi
call   1040 <printf@plt>
mov    $0x4,%edi
call   1080 <omp_set_num_threads@plt>
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
cvtsi2sd %eax,%xmm0
lea    0xdcd(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12bd <main+0x14d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
mov    -0x48(%rbp),%ecx
mov    %eax,%edx
mov    -0x44(%rbp),%eax
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1273 <main+0x103>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
lea    0xd2c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2cfb(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xd46(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <rand@plt>
imul   %ebx,%eax
add    %eax,%ebp
imul   %ebp,%ebp
add    $0x1,%ebx
cmp    $0x5f5e100,%ebx
jne    11a0 <main+0x30>
cvtsi2sd %ebp,%xmm0
lea    0xe3b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2e05(%rip),%r15
divsd  (%r15),%xmm0
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
mov    $0x4,%edi
call   1080 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <rand@plt>
imul   %ebx,%eax
add    %eax,%ebp
imul   %ebp,%ebp
add    $0x1,%ebx
cmp    $0x5f5e100,%ebx
jne    1230 <main+0xc0>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
lea    0xd9e(%rip),%rdi
call   1040 <printf@plt>
sub    %r14,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
divsd  (%r15),%xmm0
lea    0xdca(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d \09\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [36 x i8] c"Tempo senza parellelizzazione: %f \0A\00"
@.str.2 = [31 x i8] c"Numero di Threads attivi: %d \0A\00"
@.str.3 = [34 x i8] c"Tempo con parellelizzazione: %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 i64
%10 = alloca i64
%11 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 100000000, i32* %8
%12 = call i32 @time(i32* null)
%13 = call i32 @srand(i32 %12)
%14 = call i64 (...) @clock()
store i64 %14, i64* %9
store i32 0, i32* %6
br label %15
15: ; preds = %28, %2
%16 = load i32, i32* %6
%17 = load i32, i32* %8
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = load i32, i32* %7
%21 = load i32, i32* %6
%22 = call i32 (...) @rand()
%23 = mul nsw i32 %21, %22
%24 = add nsw i32 %20, %23
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = load i32, i32* %7
%27 = mul nsw i32 %25, %26
store i32 %27, i32* %7
br label %28
28: ; preds = %19
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %15
31: ; preds = %15
%32 = load i32, i32* %7
%33 = sitofp i32 %32 to double
%34 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %33)
%35 = call i64 (...) @clock()
store i64 %35, i64* %10
%36 = load i64, i64* %10
%37 = load i64, i64* %9
%38 = sub nsw i64 %36, %37
%39 = sitofp i64 %38 to double
%40 = load double, double* @CLOCKS_PER_SEC
%41 = fdiv double %39, %40
store double %41, double* %11
%42 = load double, double* %11
%43 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), double %42)
%44 = call i32 @omp_set_num_threads(i32 4)
%45 = call i32 (...) @omp_get_num_threads()
%46 = sitofp i32 %45 to double
%47 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), double %46)
%48 = call i64 (...) @clock()
store i64 %48, i64* %9
store i32 0, i32* %6
br label %49
49: ; preds = %62, %31
%50 = load i32, i32* %6
%51 = load i32, i32* %8
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %65
53: ; preds = %49
%54 = load i32, i32* %7
%55 = load i32, i32* %6
%56 = call i32 (...) @rand()
%57 = mul nsw i32 %55, %56
%58 = add nsw i32 %54, %57
store i32 %58, i32* %7
store i32 %58, i32* %7
%59 = load i32, i32* %7
%60 = load i32, i32* %7
%61 = mul nsw i32 %59, %60
store i32 %61, i32* %7
br label %62
62: ; preds = %53
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %49
65: ; preds = %49
%66 = call i64 (...) @clock()
store i64 %66, i64* %10
%67 = load i32, i32* %7
%68 = sitofp i32 %67 to double
%69 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %68)
%70 = load i64, i64* %10
%71 = load i64, i64* %9
%72 = sub nsw i64 %70, %71
%73 = sitofp i64 %72 to double
%74 = load double, double* @CLOCKS_PER_SEC
%75 = fdiv double %73, %74
store double %75, double* %11
%76 = load double, double* %11
%77 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), double %76)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d \09\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [36 x i8] c"Tempo senza parellelizzazione: %f \0A\00"
@.str.2 = [31 x i8] c"Numero di Threads attivi: %d \0A\00"
@.str.3 = [34 x i8] c"Tempo con parellelizzazione: %f \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i64 (...) @clock()
br label %6
6: ; preds = %2, %6
%7 = phi i32 [ 0, %2 ], [ %13, %6 ]
%8 = phi i32 [ undef, %2 ], [ %12, %6 ]
%9 = tail call i32 (...) @rand()
%10 = mul nsw i32 %9, %7
%11 = add nsw i32 %10, %8
%12 = mul nsw i32 %11, %11
%13 = add nuw nsw i32 %7, 1
%14 = icmp eq i32 %13, 100000000
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = sitofp i32 %12 to double
%17 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %16)
%18 = tail call i64 (...) @clock()
%19 = sub nsw i64 %18, %5
%20 = sitofp i64 %19 to double
%21 = load double, double* @CLOCKS_PER_SEC
%22 = fdiv double %20, %21
%23 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), double %22)
%24 = tail call i32 @omp_set_num_threads(i32 4)
%25 = tail call i32 (...) @omp_get_num_threads()
%26 = sitofp i32 %25 to double
%27 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), double %26)
%28 = tail call i64 (...) @clock()
br label %29
29: ; preds = %15, %29
%30 = phi i32 [ 0, %15 ], [ %36, %29 ]
%31 = phi i32 [ %12, %15 ], [ %35, %29 ]
%32 = tail call i32 (...) @rand()
%33 = mul nsw i32 %32, %30
%34 = add nsw i32 %33, %31
%35 = mul nsw i32 %34, %34
%36 = add nuw nsw i32 %30, 1
%37 = icmp eq i32 %36, 100000000
br i1 %37, label %38, label %29
38: ; preds = %29
%39 = tail call i64 (...) @clock()
%40 = sitofp i32 %35 to double
%41 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %40)
%42 = sub nsw i64 %39, %28
%43 = sitofp i64 %42 to double
%44 = load double, double* @CLOCKS_PER_SEC
%45 = fdiv double %43, %44
%46 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), double %45)
ret i32 0
}