; 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_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
define dso_local double @matrix_sum(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
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  store i64 0, ptr %3, align 8, !tbaa !11
  br label %7

7:                                                ; preds = %33, %1
  %8 = load i64, ptr %3, align 8, !tbaa !11
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = call i64 @matrix_rows(ptr noundef %9)
  %11 = icmp ult i64 %8, %10
  br i1 %11, label %12, label %36

12:                                               ; preds = %7
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = load i64, ptr %3, align 8, !tbaa !11
  %15 = call ptr @matrix_crow(ptr noundef %13, i64 noundef %14)
  store ptr %15, ptr %5, align 8, !tbaa !5
  store i64 0, ptr %4, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %27, %12
  %17 = load i64, ptr %4, align 8, !tbaa !11
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = call i64 @matrix_cols(ptr noundef %18)
  %20 = icmp ult i64 %17, %19
  br i1 %20, label %21, label %32

21:                                               ; preds = %16
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load float, ptr %22, align 4, !tbaa !13
  %24 = fpext float %23 to double
  %25 = load double, ptr %6, align 8, !tbaa !9
  %26 = fadd double %25, %24
  store double %26, ptr %6, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %21
  %28 = load i64, ptr %4, align 8, !tbaa !11
  %29 = add i64 %28, 1
  store i64 %29, ptr %4, align 8, !tbaa !11
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds float, ptr %30, i32 1
  store ptr %31, ptr %5, align 8, !tbaa !5
  br label %16, !llvm.loop !15

32:                                               ; preds = %16
  br label %33

33:                                               ; preds = %32
  %34 = load i64, ptr %3, align 8, !tbaa !11
  %35 = add i64 %34, 1
  store i64 %35, ptr %3, align 8, !tbaa !11
  br label %7, !llvm.loop !17

36:                                               ; preds = %7
  %37 = load double, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret double %37
}

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 }

!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_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
define dso_local double @matrix_sum(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call i64 @matrix_rows(ptr noundef %0)
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge21, label %.lr.ph20

.lr.ph20:                                         ; preds = %1, %._crit_edge
  %.018 = phi double [ %.1.lcssa, %._crit_edge ], [ 0.000000e+00, %1 ]
  %.01317 = phi i64 [ %12, %._crit_edge ], [ 0, %1 ]
  %3 = tail call ptr @matrix_crow(ptr noundef %0, i64 noundef %.01317)
  %4 = tail call i64 @matrix_cols(ptr noundef %0)
  %.not23 = icmp eq i64 %4, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph20, %.lr.ph
  %.116 = phi double [ %7, %.lr.ph ], [ %.018, %.lr.ph20 ]
  %.01115 = phi ptr [ %9, %.lr.ph ], [ %3, %.lr.ph20 ]
  %.01214 = phi i64 [ %8, %.lr.ph ], [ 0, %.lr.ph20 ]
  %5 = load float, ptr %.01115, align 4, !tbaa !5
  %6 = fpext float %5 to double
  %7 = fadd double %.116, %6
  %8 = add nuw i64 %.01214, 1
  %9 = getelementptr inbounds i8, ptr %.01115, i64 4
  %10 = tail call i64 @matrix_cols(ptr noundef %0)
  %11 = icmp ult i64 %8, %10
  br i1 %11, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph20
  %.1.lcssa = phi double [ %.018, %.lr.ph20 ], [ %7, %.lr.ph ]
  %12 = add nuw i64 %.01317, 1
  %13 = tail call i64 @matrix_rows(ptr noundef %0)
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %.lr.ph20, label %._crit_edge21, !llvm.loop !11

._crit_edge21:                                    ; preds = %._crit_edge, %1
  %.0.lcssa = phi double [ 0.000000e+00, %1 ], [ %.1.lcssa, %._crit_edge ]
  ret double %.0.lcssa
}

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