; LLVM IR from Slingshot-Physics/slingshot-community :: common/math/src/heap_matrix.ll (ZNK10HeapMatrix18innerProductColVecEjRS_)

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

%class.HeapMatrix = type { i32, i32, i32, i32, i32, [12 x i8], ptr, [8 x i8] }

@.str.1 = external hidden unnamed_addr constant [103 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__._ZNK10HeapMatrix18innerProductColVecEjRS_ = external hidden unnamed_addr constant [71 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [25 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK10HeapMatrix5indexEjj(ptr noundef nonnull align 16 dereferenceable(40), i32 noundef, i32 noundef) #2 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZNK10HeapMatrix18innerProductColVecEjRS_(ptr noundef nonnull align 16 dereferenceable(40) %0, i32 noundef %1, ptr noundef nonnull align 16 dereferenceable(40) %2) #4 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = getelementptr inbounds %class.HeapMatrix, ptr %9, i32 0, i32 1
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = icmp ult i32 %10, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  br label %17

15:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 180, ptr noundef @__PRETTY_FUNCTION__._ZNK10HeapMatrix18innerProductColVecEjRS_) #5
  unreachable

16:                                               ; No predecessors!
  br label %17

17:                                               ; preds = %16, %14
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %class.HeapMatrix, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  br label %25

23:                                               ; preds = %17
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 181, ptr noundef @__PRETTY_FUNCTION__._ZNK10HeapMatrix18innerProductColVecEjRS_) #5
  unreachable

24:                                               ; No predecessors!
  br label %25

25:                                               ; preds = %24, %22
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %class.HeapMatrix, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 16, !tbaa !13
  %29 = getelementptr inbounds %class.HeapMatrix, ptr %9, i32 0, i32 0
  %30 = load i32, ptr %29, align 16, !tbaa !13
  %31 = icmp eq i32 %28, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %25
  br label %35

33:                                               ; preds = %25
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 182, ptr noundef @__PRETTY_FUNCTION__._ZNK10HeapMatrix18innerProductColVecEjRS_) #5
  unreachable

34:                                               ; No predecessors!
  br label %35

35:                                               ; preds = %34, %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store float 0.000000e+00, ptr %7, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %60, %35
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = getelementptr inbounds %class.HeapMatrix, ptr %9, i32 0, i32 0
  %39 = load i32, ptr %38, align 16, !tbaa !13
  %40 = icmp ult i32 %37, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %63

42:                                               ; preds = %36
  %43 = getelementptr inbounds %class.HeapMatrix, ptr %9, i32 0, i32 6
  %44 = load ptr, ptr %43, align 16, !tbaa !16
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = call noundef i32 @_ZNK10HeapMatrix5indexEjj(ptr noundef nonnull align 16 dereferenceable(40) %9, i32 noundef %45, i32 noundef %46)
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds float, ptr %44, i64 %48
  %50 = load float, ptr %49, align 4, !tbaa !14
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %class.HeapMatrix, ptr %51, i32 0, i32 6
  %53 = load ptr, ptr %52, align 16, !tbaa !16
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds float, ptr %53, i64 %55
  %57 = load float, ptr %56, align 4, !tbaa !14
  %58 = load float, ptr %7, align 4, !tbaa !14
  %59 = call float @llvm.fmuladd.f32(float %50, float %57, float %58)
  store float %59, ptr %7, align 4, !tbaa !14
  br label %60

60:                                               ; preds = %42
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = add i32 %61, 1
  store i32 %62, ptr %8, align 4, !tbaa !9
  br label %36, !llvm.loop !17

63:                                               ; preds = %41
  %64 = load float, ptr %7, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  ret float %64
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #2 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { mustprogress 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 #5 = { noreturn nounwind }
attributes #6 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTS10HeapMatrix", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 32}
!13 = !{!12, !10, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!12, !6, i64 32}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [103 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__._ZNK10HeapMatrix18innerProductColVecEjRS_ = external hidden unnamed_addr constant [71 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK10HeapMatrix5indexEjj(ptr noundef nonnull align 16 dereferenceable(40), i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_ZNK10HeapMatrix18innerProductColVecEjRS_(ptr noundef nonnull align 16 dereferenceable(40) %0, i32 noundef %1, ptr nocapture noundef nonnull readonly align 16 dereferenceable(40) %2) local_unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp ugt i32 %5, %1
  br i1 %6, label %8, label %7

7:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 180, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK10HeapMatrix18innerProductColVecEjRS_) #3
  unreachable

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %2, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 181, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK10HeapMatrix18innerProductColVecEjRS_) #3
  unreachable

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 16, !tbaa !11
  %15 = load i32, ptr %0, align 16, !tbaa !11
  %16 = icmp eq i32 %14, %15
  br i1 %16, label %.preheader, label %19

.preheader:                                       ; preds = %13
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  %18 = getelementptr inbounds i8, ptr %2, i64 32
  br label %20

19:                                               ; preds = %13
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i32 noundef 182, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK10HeapMatrix18innerProductColVecEjRS_) #3
  unreachable

._crit_edge:                                      ; preds = %20, %.preheader
  %.011.lcssa = phi float [ 0.000000e+00, %.preheader ], [ %30, %20 ]
  ret float %.011.lcssa

20:                                               ; preds = %.lr.ph, %20
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %.01113 = phi float [ 0.000000e+00, %.lr.ph ], [ %30, %20 ]
  %21 = load ptr, ptr %17, align 16, !tbaa !12
  %22 = trunc nuw i64 %indvars.iv to i32
  %23 = tail call noundef i32 @_ZNK10HeapMatrix5indexEjj(ptr noundef nonnull align 16 dereferenceable(40) %0, i32 noundef %22, i32 noundef %1)
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds float, ptr %21, i64 %24
  %26 = load float, ptr %25, align 4, !tbaa !13
  %27 = load ptr, ptr %18, align 16, !tbaa !12
  %28 = getelementptr inbounds float, ptr %27, i64 %indvars.iv
  %29 = load float, ptr %28, align 4, !tbaa !13
  %30 = tail call float @llvm.fmuladd.f32(float %26, float %29, float %.01113)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load i32, ptr %0, align 16, !tbaa !11
  %32 = zext i32 %31 to i64
  %33 = icmp ult i64 %indvars.iv.next, %32
  br i1 %33, label %20, label %._crit_edge, !llvm.loop !15
}

attributes #0 = { noreturn 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 #1 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { noreturn 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, !7, i64 4}
!6 = !{!"_ZTS10HeapMatrix", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 32}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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