; LLVM IR from AlgoGenesis/C :: Mathematical Algorithms/real-time-anomaly-detection (anomaly_detection)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = external hidden unnamed_addr constant [68 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @calculateRollingZScore(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store double 0.000000e+00, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store double 0.000000e+00, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store double 0.000000e+00, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %102, %2
  %14 = load i32, ptr %10, align 4, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %105

18:                                               ; preds = %13
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds double, ptr %19, i64 %21
  %23 = load double, ptr %22, align 8, !tbaa !11
  %24 = load double, ptr %5, align 8, !tbaa !11
  %25 = fadd double %24, %23
  store double %25, ptr %5, align 8, !tbaa !11
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = icmp sge i32 %26, 3
  br i1 %27, label %28, label %37

28:                                               ; preds = %18
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = sub nsw i32 %30, 3
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds double, ptr %29, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !11
  %35 = load double, ptr %5, align 8, !tbaa !11
  %36 = fsub double %35, %34
  store double %36, ptr %5, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %28, %18
  %38 = load i32, ptr %10, align 4, !tbaa !9
  %39 = icmp sge i32 %38, 2
  br i1 %39, label %40, label %101

40:                                               ; preds = %37
  %41 = load double, ptr %5, align 8, !tbaa !11
  %42 = fdiv double %41, 3.000000e+00
  store double %42, ptr %6, align 8, !tbaa !11
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = sub nsw i32 %43, 3
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %12, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %62, %40
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %65

51:                                               ; preds = %46
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = load i32, ptr %12, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds double, ptr %52, i64 %54
  %56 = load double, ptr %55, align 8, !tbaa !11
  %57 = load double, ptr %6, align 8, !tbaa !11
  %58 = fsub double %56, %57
  %59 = call double @pow(double noundef %58, double noundef 2.000000e+00) #5
  %60 = load double, ptr %7, align 8, !tbaa !11
  %61 = fadd double %60, %59
  store double %61, ptr %7, align 8, !tbaa !11
  br label %62

62:                                               ; preds = %51
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %12, align 4, !tbaa !9
  br label %46, !llvm.loop !13

65:                                               ; preds = %50
  %66 = load double, ptr %7, align 8, !tbaa !11
  %67 = fdiv double %66, 3.000000e+00
  %68 = call double @sqrt(double noundef %67) #5
  store double %68, ptr %8, align 8, !tbaa !11
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds double, ptr %69, i64 %71
  %73 = load double, ptr %72, align 8, !tbaa !11
  %74 = load double, ptr %6, align 8, !tbaa !11
  %75 = fsub double %73, %74
  %76 = load double, ptr %8, align 8, !tbaa !11
  %77 = fdiv double %75, %76
  store double %77, ptr %9, align 8, !tbaa !11
  %78 = load i32, ptr %10, align 4, !tbaa !9
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = load i32, ptr %10, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds double, ptr %79, i64 %81
  %83 = load double, ptr %82, align 8, !tbaa !11
  %84 = load double, ptr %6, align 8, !tbaa !11
  %85 = load double, ptr %8, align 8, !tbaa !11
  %86 = load double, ptr %9, align 8, !tbaa !11
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %78, double noundef %83, double noundef %84, double noundef %85, double noundef %86)
  %88 = load double, ptr %9, align 8, !tbaa !11
  %89 = call double @llvm.fabs.f64(double %88)
  %90 = fcmp ogt double %89, 1.500000e+00
  br i1 %90, label %91, label %100

91:                                               ; preds = %65
  %92 = load i32, ptr %10, align 4, !tbaa !9
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = load i32, ptr %10, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds double, ptr %93, i64 %95
  %97 = load double, ptr %96, align 8, !tbaa !11
  %98 = load double, ptr %9, align 8, !tbaa !11
  %99 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %92, double noundef %97, double noundef %98)
  br label %100

100:                                              ; preds = %91, %65
  br label %101

101:                                              ; preds = %100, %37
  br label %102

102:                                              ; preds = %101
  %103 = load i32, ptr %10, align 4, !tbaa !9
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %10, align 4, !tbaa !9
  br label %13, !llvm.loop !15

105:                                              ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #4

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = external hidden unnamed_addr constant [68 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @calculateRollingZScore(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 0
  br i1 %3, label %4, label %._crit_edge

4:                                                ; preds = %2
  %wide.trip.count = zext nneg i32 %1 to i64
  %switch = icmp ult i32 %1, 3
  br i1 %switch, label %._crit_edge, label %5

5:                                                ; preds = %4
  %6 = load double, ptr %0, align 8, !tbaa !5
  %7 = fadd double %6, 0.000000e+00
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = fadd double %7, %9
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = fadd double %10, %12
  %14 = fdiv double %13, 3.000000e+00
  %15 = fsub double %9, %14
  %square.1.peel72 = fmul double %15, %15
  %16 = insertelement <2 x double> poison, double %6, i64 0
  %17 = insertelement <2 x double> %16, double %12, i64 1
  %18 = insertelement <2 x double> poison, double %14, i64 0
  %19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
  %20 = fsub <2 x double> %17, %19
  %21 = fmul <2 x double> %20, %20
  %22 = extractelement <2 x double> %21, i64 0
  %23 = fadd double %22, %square.1.peel72
  %24 = extractelement <2 x double> %21, i64 1
  %25 = fadd double %23, %24
  %26 = fdiv double %25, 3.000000e+00
  %27 = tail call double @sqrt(double noundef %26) #4
  %28 = load double, ptr %11, align 8, !tbaa !5
  %29 = fsub double %28, %14
  %30 = fdiv double %29, %27
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 2, double noundef %28, double noundef %14, double noundef %27, double noundef %30)
  %32 = tail call double @llvm.fabs.f64(double %30)
  %33 = fcmp ogt double %32, 1.500000e+00
  br i1 %33, label %34, label %37

34:                                               ; preds = %5
  %35 = load double, ptr %11, align 8, !tbaa !5
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef 2, double noundef %35, double noundef %30)
  br label %37

37:                                               ; preds = %34, %5
  %exitcond.peel78.not = icmp eq i32 %1, 3
  br i1 %exitcond.peel78.not, label %._crit_edge, label %.lr.ph.peel.next66

.lr.ph.peel.next66:                               ; preds = %37
  %invariant.gep = getelementptr inbounds i8, ptr %0, i64 8
  %invariant.gep88 = getelementptr inbounds i8, ptr %0, i64 16
  br label %38

._crit_edge:                                      ; preds = %74, %4, %37, %2
  ret void

38:                                               ; preds = %.lr.ph.peel.next66, %74
  %indvars.iv50 = phi i64 [ 3, %.lr.ph.peel.next66 ], [ %indvars.iv.next51, %74 ]
  %indvars.iv = phi i32 [ 1, %.lr.ph.peel.next66 ], [ %indvars.iv.next, %74 ]
  %.03643 = phi double [ %13, %.lr.ph.peel.next66 ], [ %45, %74 ]
  %39 = zext nneg i32 %indvars.iv to i64
  %40 = getelementptr inbounds double, ptr %0, i64 %indvars.iv50
  %41 = load double, ptr %40, align 8, !tbaa !5
  %42 = fadd double %.03643, %41
  %43 = getelementptr i8, ptr %40, i64 -24
  %44 = load double, ptr %43, align 8, !tbaa !5
  %45 = fsub double %42, %44
  %46 = fdiv double %45, 3.000000e+00
  %47 = getelementptr inbounds double, ptr %0, i64 %39
  %48 = load double, ptr %47, align 8, !tbaa !5
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %39
  %49 = load double, ptr %gep, align 8, !tbaa !5
  %50 = fsub double %49, %46
  %square.1 = fmul double %50, %50
  %gep89 = getelementptr inbounds double, ptr %invariant.gep88, i64 %39
  %51 = load double, ptr %gep89, align 8, !tbaa !5
  %52 = insertelement <2 x double> poison, double %48, i64 0
  %53 = insertelement <2 x double> %52, double %51, i64 1
  %54 = insertelement <2 x double> poison, double %46, i64 0
  %55 = shufflevector <2 x double> %54, <2 x double> poison, <2 x i32> zeroinitializer
  %56 = fsub <2 x double> %53, %55
  %57 = fmul <2 x double> %56, %56
  %58 = extractelement <2 x double> %57, i64 0
  %59 = fadd double %58, %square.1
  %60 = extractelement <2 x double> %57, i64 1
  %61 = fadd double %59, %60
  %62 = fdiv double %61, 3.000000e+00
  %63 = tail call double @sqrt(double noundef %62) #4
  %64 = load double, ptr %40, align 8, !tbaa !5
  %65 = fsub double %64, %46
  %66 = fdiv double %65, %63
  %67 = trunc nuw nsw i64 %indvars.iv50 to i32
  %68 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %67, double noundef %64, double noundef %46, double noundef %63, double noundef %66)
  %69 = tail call double @llvm.fabs.f64(double %66)
  %70 = fcmp ogt double %69, 1.500000e+00
  br i1 %70, label %71, label %74

71:                                               ; preds = %38
  %72 = load double, ptr %40, align 8, !tbaa !5
  %73 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %67, double noundef %72, double noundef %66)
  br label %74

74:                                               ; preds = %71, %38
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next51, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %38, !llvm.loop !9
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #3

attributes #0 = { nofree nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 3}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass