; LLVM IR from ERGO-Code/HiGHS :: src/ipm/ipx (sparse_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"

@.str.12 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [21 x i8], align 1
@__PRETTY_FUNCTION__._ZN3ipx16AddNormalProductERKNS_12SparseMatrixEPKdRKSt8valarrayIdERS6_ = external hidden unnamed_addr constant [91 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 @_ZNK3ipx12SparseMatrix4rowsEv(ptr noundef nonnull align 8 dereferenceable(128)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3ipx12SparseMatrix4colsEv(ptr noundef nonnull align 8 dereferenceable(128)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt8valarrayIdE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3ipx9DotColumnERKNS_12SparseMatrixEiRKSt8valarrayIdE(ptr noundef nonnull align 8 dereferenceable(128), i32 noundef, ptr noundef nonnull align 8 dereferenceable(16)) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3ipx13ScatterColumnERKNS_12SparseMatrixEidRSt8valarrayIdE(ptr noundef nonnull align 8 dereferenceable(128), i32 noundef, double noundef, ptr noundef nonnull align 8 dereferenceable(16)) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3ipx16AddNormalProductERKNS_12SparseMatrixEPKdRKSt8valarrayIdERS6_(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(16) %3) #4 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call noundef i32 @_ZNK3ipx12SparseMatrix4rowsEv(ptr noundef nonnull align 8 dereferenceable(128) %13)
  store i32 %14, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call noundef i32 @_ZNK3ipx12SparseMatrix4colsEv(ptr noundef nonnull align 8 dereferenceable(128) %15)
  store i32 %16, ptr %10, align 4, !tbaa !9
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call noundef i64 @_ZNKSt8valarrayIdE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %17)
  %19 = trunc i64 %18 to i32
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = icmp eq i32 %19, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %4
  br label %25

23:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.16, ptr noundef @.str.12, i32 noundef 214, ptr noundef @__PRETTY_FUNCTION__._ZN3ipx16AddNormalProductERKNS_12SparseMatrixEPKdRKSt8valarrayIdERS6_) #6
  unreachable

24:                                               ; No predecessors!
  br label %25

25:                                               ; preds = %24, %22
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = call noundef i64 @_ZNKSt8valarrayIdE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %26)
  %28 = trunc i64 %27 to i32
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = icmp eq i32 %28, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %25
  br label %34

32:                                               ; preds = %25
  call void @__assert_fail(ptr noundef @.str.19, ptr noundef @.str.12, i32 noundef 215, ptr noundef @__PRETTY_FUNCTION__._ZN3ipx16AddNormalProductERKNS_12SparseMatrixEPKdRKSt8valarrayIdERS6_) #6
  unreachable

33:                                               ; No predecessors!
  br label %34

34:                                               ; preds = %33, %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %66, %34
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %69

40:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = call noundef double @_ZN3ipx9DotColumnERKNS_12SparseMatrixEiRKSt8valarrayIdE(ptr noundef nonnull align 8 dereferenceable(128) %41, i32 noundef %42, ptr noundef nonnull align 8 dereferenceable(16) %43)
  store double %44, ptr %12, align 8, !tbaa !11
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %61

47:                                               ; preds = %40
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %48, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !11
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds double, ptr %53, i64 %55
  %57 = load double, ptr %56, align 8, !tbaa !11
  %58 = fmul double %52, %57
  %59 = load double, ptr %12, align 8, !tbaa !11
  %60 = fmul double %59, %58
  store double %60, ptr %12, align 8, !tbaa !11
  br label %61

61:                                               ; preds = %47, %40
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = load double, ptr %12, align 8, !tbaa !11
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN3ipx13ScatterColumnERKNS_12SparseMatrixEidRSt8valarrayIdE(ptr noundef nonnull align 8 dereferenceable(128) %62, i32 noundef %63, double noundef %64, ptr noundef nonnull align 8 dereferenceable(16) %65)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %66

66:                                               ; preds = %61
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %11, align 4, !tbaa !9
  br label %35, !llvm.loop !13

69:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret void
}

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 = { inlinehint 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 #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 = { nounwind }
attributes #6 = { 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, !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, !12, i64 0}
!12 = !{!"double", !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"

@.str.12 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [21 x i8], align 1
@__PRETTY_FUNCTION__._ZN3ipx16AddNormalProductERKNS_12SparseMatrixEPKdRKSt8valarrayIdERS6_ = external hidden unnamed_addr constant [91 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 @_ZNK3ipx12SparseMatrix4rowsEv(ptr noundef nonnull align 8 dereferenceable(128)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3ipx12SparseMatrix4colsEv(ptr noundef nonnull align 8 dereferenceable(128)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt8valarrayIdE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3ipx9DotColumnERKNS_12SparseMatrixEiRKSt8valarrayIdE(ptr noundef nonnull align 8 dereferenceable(128), i32 noundef, ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3ipx13ScatterColumnERKNS_12SparseMatrixEidRSt8valarrayIdE(ptr noundef nonnull align 8 dereferenceable(128), i32 noundef, double noundef, ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3ipx16AddNormalProductERKNS_12SparseMatrixEPKdRKSt8valarrayIdERS6_(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef readonly %1, ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(16) %3) local_unnamed_addr #1 {
  %5 = tail call noundef i32 @_ZNK3ipx12SparseMatrix4rowsEv(ptr noundef nonnull align 8 dereferenceable(128) %0)
  %6 = tail call noundef i32 @_ZNK3ipx12SparseMatrix4colsEv(ptr noundef nonnull align 8 dereferenceable(128) %0)
  %7 = tail call noundef i64 @_ZNKSt8valarrayIdE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  %8 = trunc i64 %7 to i32
  %9 = icmp eq i32 %5, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.16, ptr noundef nonnull @.str.12, i32 noundef 214, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN3ipx16AddNormalProductERKNS_12SparseMatrixEPKdRKSt8valarrayIdERS6_) #3
  unreachable

11:                                               ; preds = %4
  %12 = tail call noundef i64 @_ZNKSt8valarrayIdE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %3)
  %13 = trunc i64 %12 to i32
  %14 = icmp eq i32 %5, %13
  br i1 %14, label %.preheader, label %18

.preheader:                                       ; preds = %11
  %15 = icmp sgt i32 %6, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %.lr.ph.split.us, label %.lr.ph.split.preheader

.lr.ph.split.preheader:                           ; preds = %.lr.ph
  %wide.trip.count = zext nneg i32 %6 to i64
  br label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %.02124.us = phi i32 [ %17, %.lr.ph.split.us ], [ 0, %.lr.ph ]
  %16 = tail call noundef double @_ZN3ipx9DotColumnERKNS_12SparseMatrixEiRKSt8valarrayIdE(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %.02124.us, ptr noundef nonnull align 8 dereferenceable(16) %2)
  tail call void @_ZN3ipx13ScatterColumnERKNS_12SparseMatrixEidRSt8valarrayIdE(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %.02124.us, double noundef %16, ptr noundef nonnull align 8 dereferenceable(16) %3)
  %17 = add nuw nsw i32 %.02124.us, 1
  %exitcond27.not = icmp eq i32 %17, %6
  br i1 %exitcond27.not, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !5

18:                                               ; preds = %11
  tail call void @__assert_fail(ptr noundef nonnull @.str.19, ptr noundef nonnull @.str.12, i32 noundef 215, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN3ipx16AddNormalProductERKNS_12SparseMatrixEPKdRKSt8valarrayIdERS6_) #3
  unreachable

._crit_edge:                                      ; preds = %.lr.ph.split, %.lr.ph.split.us, %.preheader
  ret void

.lr.ph.split:                                     ; preds = %.lr.ph.split.preheader, %.lr.ph.split
  %indvars.iv = phi i64 [ 0, %.lr.ph.split.preheader ], [ %indvars.iv.next, %.lr.ph.split ]
  %19 = trunc nuw nsw i64 %indvars.iv to i32
  %20 = tail call noundef double @_ZN3ipx9DotColumnERKNS_12SparseMatrixEiRKSt8valarrayIdE(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %19, ptr noundef nonnull align 8 dereferenceable(16) %2)
  %21 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %22 = load double, ptr %21, align 8, !tbaa !7
  %23 = fmul double %22, %22
  %24 = fmul double %20, %23
  tail call void @_ZN3ipx13ScatterColumnERKNS_12SparseMatrixEidRSt8valarrayIdE(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %19, double noundef %24, ptr noundef nonnull align 8 dereferenceable(16) %3)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !5
}

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


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