; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/st (libst)

; 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"

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

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

9:                                                ; preds = %21, %3
  %10 = load i32, ptr %7, align 4, !tbaa !11
  %11 = icmp slt i32 %10, 100
  br i1 %11, label %12, label %24

12:                                               ; preds = %9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i32, ptr %7, align 4, !tbaa !11
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds double, ptr %13, i64 %15
  %17 = load double, ptr %16, align 8, !tbaa !9
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load double, ptr %18, align 8, !tbaa !9
  %20 = fadd double %19, %17
  store double %20, ptr %18, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %12
  %22 = load i32, ptr %7, align 4, !tbaa !11
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %7, align 4, !tbaa !11
  br label %9, !llvm.loop !13

24:                                               ; preds = %9
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = fdiv double %26, 1.000000e+02
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  store double %27, ptr %28, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @Calc_Sum_Mean(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  store double 0.000000e+00, ptr %1, align 8, !tbaa !5
  %invariant.gep = getelementptr inbounds i8, ptr %0, i64 8
  %invariant.gep9 = getelementptr inbounds i8, ptr %0, i64 16
  %invariant.gep11 = getelementptr inbounds i8, ptr %0, i64 24
  %invariant.gep13 = getelementptr inbounds i8, ptr %0, i64 32
  br label %4

4:                                                ; preds = %4, %3
  %indvars.iv = phi i64 [ 0, %3 ], [ %indvars.iv.next.4, %4 ]
  %5 = phi double [ 0.000000e+00, %3 ], [ %16, %4 ]
  %6 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = fadd double %7, %5
  store double %8, ptr %1, align 8, !tbaa !5
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %indvars.iv
  %9 = load double, ptr %gep, align 8, !tbaa !5
  %10 = fadd double %9, %8
  store double %10, ptr %1, align 8, !tbaa !5
  %gep10 = getelementptr inbounds double, ptr %invariant.gep9, i64 %indvars.iv
  %11 = load double, ptr %gep10, align 8, !tbaa !5
  %12 = fadd double %11, %10
  store double %12, ptr %1, align 8, !tbaa !5
  %gep12 = getelementptr inbounds double, ptr %invariant.gep11, i64 %indvars.iv
  %13 = load double, ptr %gep12, align 8, !tbaa !5
  %14 = fadd double %13, %12
  store double %14, ptr %1, align 8, !tbaa !5
  %gep14 = getelementptr inbounds double, ptr %invariant.gep13, i64 %indvars.iv
  %15 = load double, ptr %gep14, align 8, !tbaa !5
  %16 = fadd double %15, %14
  store double %16, ptr %1, align 8, !tbaa !5
  %indvars.iv.next.4 = add nuw nsw i64 %indvars.iv, 5
  %exitcond.not.4 = icmp eq i64 %indvars.iv.next.4, 100
  br i1 %exitcond.not.4, label %17, label %4, !llvm.loop !9

17:                                               ; preds = %4
  %18 = fdiv double %16, 1.000000e+02
  store double %18, ptr %2, align 8, !tbaa !5
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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" }

!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}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass