; LLVM IR from clunietp/libgmsd :: src (matrix)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @matrix_size(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @matrix_cols(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @matrix_rows(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @matrix_crow(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local double @matrix_sum(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local double @matrix_variance_p(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i64, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call i64 @matrix_size(ptr noundef %10)
  store i64 %11, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call double @matrix_sum(ptr noundef %12)
  store double %13, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %14 = load double, ptr %8, align 8, !tbaa !9
  %15 = load i64, ptr %7, align 8, !tbaa !11
  %16 = uitofp i64 %15 to double
  %17 = fdiv double %14, %16
  store double %17, ptr %9, align 8, !tbaa !9
  store i64 0, ptr %3, align 8, !tbaa !11
  br label %18

18:                                               ; preds = %47, %1
  %19 = load i64, ptr %3, align 8, !tbaa !11
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = call i64 @matrix_rows(ptr noundef %20)
  %22 = icmp ult i64 %19, %21
  br i1 %22, label %23, label %50

23:                                               ; preds = %18
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = load i64, ptr %3, align 8, !tbaa !11
  %26 = call ptr @matrix_crow(ptr noundef %24, i64 noundef %25)
  store ptr %26, ptr %5, align 8, !tbaa !5
  store i64 0, ptr %4, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %41, %23
  %28 = load i64, ptr %4, align 8, !tbaa !11
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = call i64 @matrix_cols(ptr noundef %29)
  %31 = icmp ult i64 %28, %30
  br i1 %31, label %32, label %46

32:                                               ; preds = %27
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load float, ptr %33, align 4, !tbaa !13
  %35 = fpext float %34 to double
  %36 = load double, ptr %9, align 8, !tbaa !9
  %37 = fsub double %35, %36
  %38 = call double @pow(double noundef %37, double noundef 2.000000e+00) #4
  %39 = load double, ptr %6, align 8, !tbaa !9
  %40 = fadd double %39, %38
  store double %40, ptr %6, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %32
  %42 = load i64, ptr %4, align 8, !tbaa !11
  %43 = add i64 %42, 1
  store i64 %43, ptr %4, align 8, !tbaa !11
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds float, ptr %44, i32 1
  store ptr %45, ptr %5, align 8, !tbaa !5
  br label %27, !llvm.loop !15

46:                                               ; preds = %27
  br label %47

47:                                               ; preds = %46
  %48 = load i64, ptr %3, align 8, !tbaa !11
  %49 = add i64 %48, 1
  store i64 %49, ptr %3, align 8, !tbaa !11
  br label %18, !llvm.loop !17

50:                                               ; preds = %18
  %51 = load double, ptr %6, align 8, !tbaa !9
  %52 = load i64, ptr %7, align 8, !tbaa !11
  %53 = sub i64 %52, 1
  %54 = uitofp i64 %53 to double
  %55 = fdiv double %51, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret double %55
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 #3 = { 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 #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 = !{!"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 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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: inlinehint nounwind uwtable
declare hidden i64 @matrix_size(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @matrix_cols(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @matrix_rows(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @matrix_crow(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local double @matrix_sum(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local double @matrix_variance_p(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call i64 @matrix_size(ptr noundef %0)
  %3 = tail call double @matrix_sum(ptr noundef %0)
  %4 = uitofp i64 %2 to double
  %5 = fdiv double %3, %4
  %6 = tail call i64 @matrix_rows(ptr noundef %0)
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %._crit_edge27, label %.lr.ph26

.lr.ph26:                                         ; preds = %1, %._crit_edge
  %.024 = phi i64 [ %17, %._crit_edge ], [ 0, %1 ]
  %.01923 = phi double [ %.1.lcssa, %._crit_edge ], [ 0.000000e+00, %1 ]
  %7 = tail call ptr @matrix_crow(ptr noundef %0, i64 noundef %.024)
  %8 = tail call i64 @matrix_cols(ptr noundef %0)
  %.not29 = icmp eq i64 %8, 0
  br i1 %.not29, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph26, %.lr.ph
  %.01722 = phi i64 [ %13, %.lr.ph ], [ 0, %.lr.ph26 ]
  %.01821 = phi ptr [ %14, %.lr.ph ], [ %7, %.lr.ph26 ]
  %.120 = phi double [ %12, %.lr.ph ], [ %.01923, %.lr.ph26 ]
  %9 = load float, ptr %.01821, align 4, !tbaa !5
  %10 = fpext float %9 to double
  %11 = fsub double %10, %5
  %square = fmul double %11, %11
  %12 = fadd double %.120, %square
  %13 = add nuw i64 %.01722, 1
  %14 = getelementptr inbounds i8, ptr %.01821, i64 4
  %15 = tail call i64 @matrix_cols(ptr noundef %0)
  %16 = icmp ult i64 %13, %15
  br i1 %16, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph26
  %.1.lcssa = phi double [ %.01923, %.lr.ph26 ], [ %12, %.lr.ph ]
  %17 = add nuw i64 %.024, 1
  %18 = tail call i64 @matrix_rows(ptr noundef %0)
  %19 = icmp ult i64 %17, %18
  br i1 %19, label %.lr.ph26, label %._crit_edge27, !llvm.loop !11

._crit_edge27:                                    ; preds = %._crit_edge, %1
  %.019.lcssa = phi double [ 0.000000e+00, %1 ], [ %.1.lcssa, %._crit_edge ]
  %20 = add i64 %2, -1
  %21 = uitofp i64 %20 to double
  %22 = fdiv double %.019.lcssa, %21
  ret double %22
}

attributes #0 = { inlinehint 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 = { 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" }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass