#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 /*<<< orphan*/ free(int *);
int *malloc(int);
double omp_get_wtime();
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, double);
int main() {
  int N = 10000000;
  int *a = malloc(N * sizeof(int));
  for (int i = 0; i < N; i++) {
    a[i] = 5;
  }
  int cont = 0;
  int valueToFind = -1;
  omp_set_num_threads(4);
  double startTime = omp_get_wtime();
  for (int i = 0; i < N; i++) {
    if (a[i] == valueToFind)
      cont++;
  }
  double endTime = omp_get_wtime();
  free(a);
  if (cont != 0)
    printf("TROVATO %d volte\n", cont);
  printf("TIME : %16.g\n", endTime - startTime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x989680,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a9 <main+0x59>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1180 <main+0x30>
movl   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    $0x4,%edi
call   1070 <omp_set_num_threads@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1210 <main+0xc0>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x1c(%rbp),%eax
jne    11fd <main+0xad>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1202 <main+0xb2>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d4 <main+0x84>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x18(%rbp)
je     1240 <main+0xf0>
cvtsi2sdl -0x18(%rbp),%xmm0
lea    0xdc5(%rip),%rdi
call   1050 <printf@plt>
movsd  -0x38(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
lea    0xdc1(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    $0x2625a00,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x3c,%eax
movdqa 0xe90(%rip),%xmm0
movdqu %xmm0,-0xf0(%rbx,%rax,4)
ff ff
movdqu %xmm0,-0xe0(%rbx,%rax,4)
ff ff
movdqu %xmm0,-0xd0(%rbx,%rax,4)
ff ff
movdqu %xmm0,-0xc0(%rbx,%rax,4)
ff ff
movdqu %xmm0,-0xb0(%rbx,%rax,4)
ff ff
movdqu %xmm0,-0xa0(%rbx,%rax,4)
ff ff
movdqu %xmm0,-0x90(%rbx,%rax,4)
ff ff
movdqu %xmm0,-0x80(%rbx,%rax,4)
movdqu %xmm0,-0x70(%rbx,%rax,4)
movdqu %xmm0,-0x60(%rbx,%rax,4)
movdqu %xmm0,-0x50(%rbx,%rax,4)
movdqu %xmm0,-0x40(%rbx,%rax,4)
movdqu %xmm0,-0x30(%rbx,%rax,4)
movdqu %xmm0,-0x20(%rbx,%rax,4)
movdqu %xmm0,-0x10(%rbx,%rax,4)
movdqu %xmm0,(%rbx,%rax,4)
add    $0x40,%rax
cmp    $0x9896bc,%rax
jne    1170 <main+0x20>
mov    $0x4,%edi
call   1070 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movq   %xmm0,0x10(%rsp)
pxor   %xmm0,%xmm0
mov    $0xc,%eax
pcmpeqd %xmm2,%xmm2
pxor   %xmm1,%xmm1
nopl   0x0(%rax,%rax,1)
movdqu -0x30(%rbx,%rax,4),%xmm3
movdqu -0x20(%rbx,%rax,4),%xmm4
movdqu -0x10(%rbx,%rax,4),%xmm5
movdqu (%rbx,%rax,4),%xmm6
pcmpeqd %xmm2,%xmm3
psubd  %xmm3,%xmm0
pcmpeqd %xmm2,%xmm4
psubd  %xmm4,%xmm1
pcmpeqd %xmm2,%xmm5
psubd  %xmm5,%xmm0
pcmpeqd %xmm2,%xmm6
psubd  %xmm6,%xmm1
add    $0x10,%rax
cmp    $0x98968c,%rax
jne    1220 <main+0xd0>
paddd  %xmm0,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%ebp
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movq   %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     12a9 <main+0x159>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
lea    0xd6c(%rip),%rdi
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
lea    0xd66(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"TROVATO %d volte\0A\00"
@.str.1 = [14 x i8] c"TIME : %16.g\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca double
store i32 0, i32* %1
store i32 10000000, i32* %2
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = call i32* @malloc(i32 %13)
store i32* %14, i32** %3
store i32 0, i32* %4
br label %15
15: ; preds = %24, %0
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i32*, i32** %3
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
store i32 5, i32* %23
br label %24
24: ; preds = %19
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %15
27: ; preds = %15
store i32 0, i32* %5
store i32 -1, i32* %6
%28 = call i32 @omp_set_num_threads(i32 4)
%29 = call double (...) @omp_get_wtime()
store double %29, double* %7
store i32 0, i32* %8
br label %30
30: ; preds = %46, %27
%31 = load i32, i32* %8
%32 = load i32, i32* %2
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %49
34: ; preds = %30
%35 = load i32*, i32** %3
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = load i32, i32* %6
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %34
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %45
45: ; preds = %42, %34
br label %46
46: ; preds = %45
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %30
49: ; preds = %30
%50 = call double (...) @omp_get_wtime()
store double %50, double* %9
%51 = load i32*, i32** %3
%52 = call i32 @free(i32* %51)
%53 = load i32, i32* %5
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %49
%56 = load i32, i32* %5
%57 = sitofp i32 %56 to double
%58 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %57)
br label %59
59: ; preds = %55, %49
%60 = load double, double* %9
%61 = load double, double* %7
%62 = fsub double %60, %61
%63 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %62)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"TROVATO %d volte\0A\00"
@.str.1 = [14 x i8] c"TIME : %16.g\0A\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 40000000)
br label %2
2: ; preds = %2, %0
%3 = phi i64 [ 0, %0 ], [ %43, %2 ]
%4 = getelementptr inbounds i32, i32* %1, i64 %3
%5 = bitcast i32* %4 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %5
%6 = getelementptr inbounds i32, i32* %4, i64 4
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %7
%8 = or i64 %3, 8
%9 = getelementptr inbounds i32, i32* %1, i64 %8
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %9, i64 4
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %12
%13 = or i64 %3, 16
%14 = getelementptr inbounds i32, i32* %1, i64 %13
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %15
%16 = getelementptr inbounds i32, i32* %14, i64 4
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %17
%18 = or i64 %3, 24
%19 = getelementptr inbounds i32, i32* %1, i64 %18
%20 = bitcast i32* %19 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %20
%21 = getelementptr inbounds i32, i32* %19, i64 4
%22 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %22
%23 = or i64 %3, 32
%24 = getelementptr inbounds i32, i32* %1, i64 %23
%25 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %25
%26 = getelementptr inbounds i32, i32* %24, i64 4
%27 = bitcast i32* %26 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %27
%28 = or i64 %3, 40
%29 = getelementptr inbounds i32, i32* %1, i64 %28
%30 = bitcast i32* %29 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %30
%31 = getelementptr inbounds i32, i32* %29, i64 4
%32 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %32
%33 = or i64 %3, 48
%34 = getelementptr inbounds i32, i32* %1, i64 %33
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %35
%36 = getelementptr inbounds i32, i32* %34, i64 4
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %37
%38 = or i64 %3, 56
%39 = getelementptr inbounds i32, i32* %1, i64 %38
%40 = bitcast i32* %39 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %40
%41 = getelementptr inbounds i32, i32* %39, i64 4
%42 = bitcast i32* %41 to <4 x i32>*
store <4 x i32> <i32 5, i32 5, i32 5, i32 5>, <4 x i32>* %42
%43 = add nuw nsw i64 %3, 64
%44 = icmp eq i64 %43, 10000000
br i1 %44, label %45, label %2
45: ; preds = %2
%46 = tail call i32 @omp_set_num_threads(i32 4)
%47 = tail call double (...) @omp_get_wtime()
br label %48
48: ; preds = %48, %45
%49 = phi i64 [ 0, %45 ], [ %77, %48 ]
%50 = phi <4 x i32> [ zeroinitializer, %45 ], [ %75, %48 ]
%51 = phi <4 x i32> [ zeroinitializer, %45 ], [ %76, %48 ]
%52 = getelementptr inbounds i32, i32* %1, i64 %49
%53 = bitcast i32* %52 to <4 x i32>*
%54 = load <4 x i32>, <4 x i32>* %53
%55 = getelementptr inbounds i32, i32* %52, i64 4
%56 = bitcast i32* %55 to <4 x i32>*
%57 = load <4 x i32>, <4 x i32>* %56
%58 = icmp eq <4 x i32> %54, <i32 -1, i32 -1, i32 -1, i32 -1>
%59 = icmp eq <4 x i32> %57, <i32 -1, i32 -1, i32 -1, i32 -1>
%60 = zext <4 x i1> %58 to <4 x i32>
%61 = zext <4 x i1> %59 to <4 x i32>
%62 = add <4 x i32> %50, %60
%63 = add <4 x i32> %51, %61
%64 = or i64 %49, 8
%65 = getelementptr inbounds i32, i32* %1, i64 %64
%66 = bitcast i32* %65 to <4 x i32>*
%67 = load <4 x i32>, <4 x i32>* %66
%68 = getelementptr inbounds i32, i32* %65, i64 4
%69 = bitcast i32* %68 to <4 x i32>*
%70 = load <4 x i32>, <4 x i32>* %69
%71 = icmp eq <4 x i32> %67, <i32 -1, i32 -1, i32 -1, i32 -1>
%72 = icmp eq <4 x i32> %70, <i32 -1, i32 -1, i32 -1, i32 -1>
%73 = zext <4 x i1> %71 to <4 x i32>
%74 = zext <4 x i1> %72 to <4 x i32>
%75 = add <4 x i32> %62, %73
%76 = add <4 x i32> %63, %74
%77 = add nuw nsw i64 %49, 16
%78 = icmp eq i64 %77, 10000000
br i1 %78, label %79, label %48
79: ; preds = %48
%80 = add <4 x i32> %76, %75
%81 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %80)
%82 = tail call double (...) @omp_get_wtime()
%83 = tail call i32 @free(i32* %1)
%84 = icmp eq i32 %81, 0
br i1 %84, label %88, label %85
85: ; preds = %79
%86 = sitofp i32 %81 to double
%87 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %86)
br label %88
88: ; preds = %85, %79
%89 = fsub double %82, %47
%90 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %89)
ret i32 0
}