#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 */
struct timespec {
  scalar_t__ tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ bruteFindMaxSubarray(int *, int *, int *);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, double);
int rand();
int /*<<< orphan*/ recFindMaxSubarray(int *, int *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  srand(time(NULL));
  int *arr, n = 1, tst = 0;
  int low = 0, high = 0;
  double avg = 0;
  struct timespec start, end;
  double time_bf, time_rec;
  arr = (int *)malloc(sizeof(int) * 1000000);
  for (int i = 0; i < 1000000; i++) {
    arr[i] = rand() % 201 - 100;
  }
  while (tst < 1000000) {
    low = 0;
    high = n;
    clock_gettime(CLOCK_MONOTONIC, &start);
    bruteFindMaxSubarray(arr, &low, &high);
    clock_gettime(CLOCK_MONOTONIC, &end);
    time_bf = (double)(end.tv_sec - start.tv_sec) * 1.0e9 +
              (double)(end.tv_nsec - start.tv_nsec);
    low = 0;
    high = n;
    clock_gettime(CLOCK_MONOTONIC, &start);
    recFindMaxSubarray(arr, &low, &high);
    clock_gettime(CLOCK_MONOTONIC, &end);
    time_rec = (double)(end.tv_sec - start.tv_sec) * 1.0e9 +
               (double)(end.tv_nsec - start.tv_nsec);
    if (time_bf > time_rec) {
      tst++;
      avg += n + 1;
      n = 1;
      continue;
    }
    n++;
  }
  printf("Average Crossover point : "
         "\x1B[33m"
         "%lf\n"
         "\x1B[0m",
         avg / 1000000);
  free(arr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x3d0900,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0xf4240,-0x64(%rbp)
jge    1227 <main+0x97>
mov    $0x0,%al
call   10b0 <rand@plt>
mov    $0xc9,%ecx
cltd
idiv   %ecx
sub    $0x64,%edx
mov    -0x18(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11ef <main+0x5f>
jmp    122c <main+0x9c>
cmpl   $0xf4240,-0x20(%rbp)
jge    1362 <main+0x1d2>
movl   $0x0,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x18(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   10a0 <bruteFindMaxSubarray@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x48(%rbp),%rax
sub    -0x38(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    -0x50(%rbp),%rax
sub    -0x40(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  0xd6b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x18(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1090 <recFindMaxSubarray@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x48(%rbp),%rax
sub    -0x38(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    -0x50(%rbp),%rax
sub    -0x40(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  0xcfa(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
ucomisd -0x60(%rbp),%xmm0
jbe    1354 <main+0x1c4>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    122c <main+0x9c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    122c <main+0x9c>
movsd  -0x30(%rbp),%xmm0
movsd  0xc91(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xc96(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x3d0900,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10b0 <rand@plt>
cltq
imul   $0x28c1979,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
imul   $0xc9,%ecx,%ecx
neg    %ecx
add    %ecx,%eax
add    $0xffffff9c,%eax
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    $0xf4240,%rbp
jne    11c0 <main+0x30>
mov    %rbx,0x28(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
xor    %eax,%eax
mov    %rax,0x20(%rsp)
movb   $0x1,0xf(%rsp)
mov    0x28(%rsp),%r13
mov    $0x2,%r15d
lea    -0x1(%r15),%r12d
movl   $0x0,0x14(%rsp)
mov    %r12d,0x10(%rsp)
mov    0x2db0(%rip),%rbx
mov    (%rbx),%edi
lea    0x40(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    %r13,%rdi
lea    0x14(%rsp),%r14
mov    %r14,%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdx
call   10a0 <bruteFindMaxSubarray@plt>
mov    (%rbx),%edi
lea    0x30(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    0x30(%rsp),%rax
mov    0x38(%rsp),%rcx
sub    0x48(%rsp),%rcx
xorps  %xmm2,%xmm2
cvtsi2sd %rcx,%xmm2
sub    0x40(%rsp),%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0xd6c(%rip),%xmm1
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,0x50(%rsp)
movl   $0x0,0x14(%rsp)
mov    %r12d,0x10(%rsp)
mov    (%rbx),%edi
lea    0x40(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1090 <recFindMaxSubarray@plt>
mov    (%rbx),%edi
lea    0x30(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    0x30(%rsp),%rax
mov    0x38(%rsp),%rcx
sub    0x48(%rsp),%rcx
xorps  %xmm0,%xmm0
cvtsi2sd %rcx,%xmm0
sub    0x40(%rsp),%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mulsd  0xcff(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  0x50(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     1322 <main+0x192>
add    $0x1,%r15d
testb  $0x1,0xf(%rsp)
jne    1220 <main+0x90>
jmp    1365 <main+0x1d5>
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
mov    0x20(%rsp),%rax
cmp    $0xf423f,%eax
lea    0x1(%rax),%eax
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
setb   0xf(%rsp)
mov    %eax,%ecx
mov    %rcx,0x20(%rsp)
cmp    $0xf4240,%eax
je     1365 <main+0x1d5>
mov    $0x2,%r15d
jmp    1220 <main+0x90>
movsd  0x18(%rsp),%xmm0
divsd  0xc95(%rip),%xmm0
lea    0xc96(%rip),%rdi
call   1050 <printf@plt>
mov    0x28(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC = global i32 0
@.str = [40 x i8] c"Average Crossover point : \1B[33m%lf\0A\1B[0m\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 i32
%11 = alloca double
%12 = alloca %struct.timespec
%13 = alloca %struct.timespec
%14 = alloca double
%15 = alloca double
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = call i32 @time(i32* null)
%18 = call i32 @srand(i32 %17)
store i32 1, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store double 0.000000e+00, double* %11
%19 = call i64 @malloc(i32 4000000)
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %6
store i32 0, i32* %16
br label %21
21: ; preds = %32, %2
%22 = load i32, i32* %16
%23 = icmp slt i32 %22, 1000000
br i1 %23, label %24, label %35
24: ; preds = %21
%25 = call i32 (...) @rand()
%26 = srem i32 %25, 201
%27 = sub nsw i32 %26, 100
%28 = load i32*, i32** %6
%29 = load i32, i32* %16
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 %27, i32* %31
br label %32
32: ; preds = %24
%33 = load i32, i32* %16
%34 = add nsw i32 %33, 1
store i32 %34, i32* %16
br label %21
35: ; preds = %21
br label %36
36: ; preds = %91, %83, %35
%37 = load i32, i32* %8
%38 = icmp slt i32 %37, 1000000
br i1 %38, label %39, label %94
39: ; preds = %36
store i32 0, i32* %9
%40 = load i32, i32* %7
store i32 %40, i32* %10
%41 = load i32, i32* @CLOCK_MONOTONIC
%42 = call i32 @clock_gettime(i32 %41, %struct.timespec* %12)
%43 = load i32*, i32** %6
%44 = call i32 @bruteFindMaxSubarray(i32* %43, i32* %9, i32* %10)
%45 = load i32, i32* @CLOCK_MONOTONIC
%46 = call i32 @clock_gettime(i32 %45, %struct.timespec* %13)
%47 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 1
%48 = load i64, i64* %47
%49 = getelementptr inbounds %struct.timespec, %struct.timespec* %12, i32 0, i32 1
%50 = load i64, i64* %49
%51 = sub nsw i64 %48, %50
%52 = sitofp i64 %51 to double
%53 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 0
%54 = load i64, i64* %53
%55 = getelementptr inbounds %struct.timespec, %struct.timespec* %12, i32 0, i32 0
%56 = load i64, i64* %55
%57 = sub nsw i64 %54, %56
%58 = sitofp i64 %57 to double
%59 = call double @llvm.fmuladd.f64(double %52, double 1.000000e+09, double %58)
store double %59, double* %14
store i32 0, i32* %9
%60 = load i32, i32* %7
store i32 %60, i32* %10
%61 = load i32, i32* @CLOCK_MONOTONIC
%62 = call i32 @clock_gettime(i32 %61, %struct.timespec* %12)
%63 = load i32*, i32** %6
%64 = call i32 @recFindMaxSubarray(i32* %63, i32* %9, i32* %10)
%65 = load i32, i32* @CLOCK_MONOTONIC
%66 = call i32 @clock_gettime(i32 %65, %struct.timespec* %13)
%67 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 1
%68 = load i64, i64* %67
%69 = getelementptr inbounds %struct.timespec, %struct.timespec* %12, i32 0, i32 1
%70 = load i64, i64* %69
%71 = sub nsw i64 %68, %70
%72 = sitofp i64 %71 to double
%73 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 0
%74 = load i64, i64* %73
%75 = getelementptr inbounds %struct.timespec, %struct.timespec* %12, i32 0, i32 0
%76 = load i64, i64* %75
%77 = sub nsw i64 %74, %76
%78 = sitofp i64 %77 to double
%79 = call double @llvm.fmuladd.f64(double %72, double 1.000000e+09, double %78)
store double %79, double* %15
%80 = load double, double* %14
%81 = load double, double* %15
%82 = fcmp ogt double %80, %81
br i1 %82, label %83, label %91
83: ; preds = %39
%84 = load i32, i32* %8
%85 = add nsw i32 %84, 1
store i32 %85, i32* %8
%86 = load i32, i32* %7
%87 = add nsw i32 %86, 1
%88 = sitofp i32 %87 to double
%89 = load double, double* %11
%90 = fadd double %89, %88
store double %90, double* %11
store i32 1, i32* %7
br label %36
91: ; preds = %39
%92 = load i32, i32* %7
%93 = add nsw i32 %92, 1
store i32 %93, i32* %7
br label %36
94: ; preds = %36
%95 = load double, double* %11
%96 = fdiv double %95, 1.000000e+06
%97 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), double %96)
%98 = load i32*, i32** %6
%99 = call i32 @free(i32* %98)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC = global i32 0
@.str = [40 x i8] c"Average Crossover point : \1B[33m%lf\0A\1B[0m\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timespec
%6 = alloca %struct.timespec
%7 = tail call i32 @time(i32* null)
%8 = tail call i32 @srand(i32 %7)
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast %struct.timespec* %5 to i8*
%12 = bitcast %struct.timespec* %6 to i8*
%13 = tail call i64 @malloc(i32 4000000)
%14 = inttoptr i64 %13 to i32*
br label %20
15: ; preds = %20
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 1
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 1
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 0
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 0
br label %66
20: ; preds = %2, %20
%21 = phi i64 [ 0, %2 ], [ %26, %20 ]
%22 = tail call i32 (...) @rand()
%23 = srem i32 %22, 201
%24 = add nsw i32 %23, -100
%25 = getelementptr inbounds i32, i32* %14, i64 %21
store i32 %24, i32* %25
%26 = add nuw nsw i64 %21, 1
%27 = icmp eq i64 %26, 1000000
br i1 %27, label %15, label %20
28: ; preds = %66, %70
%29 = phi i32 [ 1, %66 ], [ %71, %70 ]
store i32 0, i32* %3
store i32 %29, i32* %4
%30 = load i32, i32* @CLOCK_MONOTONIC
%31 = call i32 @clock_gettime(i32 %30, %struct.timespec* %5)
%32 = call i32 @bruteFindMaxSubarray(i32* %14, i32* %3, i32* %4)
%33 = load i32, i32* @CLOCK_MONOTONIC
%34 = call i32 @clock_gettime(i32 %33, %struct.timespec* %6)
%35 = load i64, i64* %16
%36 = load i64, i64* %17
%37 = sub nsw i64 %35, %36
%38 = sitofp i64 %37 to double
%39 = load i64, i64* %18
%40 = load i64, i64* %19
%41 = sub nsw i64 %39, %40
%42 = sitofp i64 %41 to double
%43 = call double @llvm.fmuladd.f64(double %38, double 1.000000e+09, double %42)
store i32 0, i32* %3
store i32 %29, i32* %4
%44 = load i32, i32* @CLOCK_MONOTONIC
%45 = call i32 @clock_gettime(i32 %44, %struct.timespec* %5)
%46 = call i32 @recFindMaxSubarray(i32* %14, i32* %3, i32* %4)
%47 = load i32, i32* @CLOCK_MONOTONIC
%48 = call i32 @clock_gettime(i32 %47, %struct.timespec* %6)
%49 = load i64, i64* %16
%50 = load i64, i64* %17
%51 = sub nsw i64 %49, %50
%52 = sitofp i64 %51 to double
%53 = load i64, i64* %18
%54 = load i64, i64* %19
%55 = sub nsw i64 %53, %54
%56 = sitofp i64 %55 to double
%57 = call double @llvm.fmuladd.f64(double %52, double 1.000000e+09, double %56)
%58 = fcmp ogt double %43, %57
br i1 %58, label %59, label %70
59: ; preds = %28
%60 = add nuw nsw i32 %68, 1
%61 = add nuw nsw i32 %29, 1
%62 = sitofp i32 %61 to double
%63 = fadd double %69, %62
%64 = icmp ult i32 %68, 999999
%65 = icmp eq i32 %60, 1000000
br i1 %65, label %72, label %66
66: ; preds = %15, %59
%67 = phi i1 [ true, %15 ], [ %64, %59 ]
%68 = phi i32 [ 0, %15 ], [ %60, %59 ]
%69 = phi double [ 0.000000e+00, %15 ], [ %63, %59 ]
br label %28
70: ; preds = %28
%71 = add nuw nsw i32 %29, 1
br i1 %67, label %28, label %72
72: ; preds = %59, %70
%73 = phi double [ %69, %70 ], [ %63, %59 ]
%74 = fdiv double %73, 1.000000e+06
%75 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), double %74)
%76 = call i32 @free(i32* %14)
ret i32 0
}