; LLVM IR from ERGO-Code/HiGHS :: src/ipm/ipx/sparse_matrix.ll (ZNK3ipx12SparseMatrix8IsSortedEv)

; 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK3ipx12SparseMatrix8IsSortedEv(ptr noundef nonnull align 8 dereferenceable(128) %0) #1 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %38, %1
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = call noundef i32 @_ZNK3ipx12SparseMatrix4colsEv(ptr noundef nonnull align 8 dereferenceable(128) %7)
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  store i32 2, ptr %5, align 4
  br label %41

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = call noundef i32 @_ZNK3ipx12SparseMatrix5beginEi(ptr noundef nonnull align 8 dereferenceable(128) %7, i32 noundef %14)
  store i32 %15, ptr %6, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %32, %13
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = call noundef i32 @_ZNK3ipx12SparseMatrix3endEi(ptr noundef nonnull align 8 dereferenceable(128) %7, i32 noundef %18)
  %20 = sub nsw i32 %19, 1
  %21 = icmp slt i32 %17, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  store i32 5, ptr %5, align 4
  br label %35

23:                                               ; preds = %16
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = call noundef i32 @_ZNK3ipx12SparseMatrix5indexEi(ptr noundef nonnull align 8 dereferenceable(128) %7, i32 noundef %24)
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  %28 = call noundef i32 @_ZNK3ipx12SparseMatrix5indexEi(ptr noundef nonnull align 8 dereferenceable(128) %7, i32 noundef %27)
  %29 = icmp sgt i32 %25, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %23
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %35

31:                                               ; preds = %23
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %6, align 4, !tbaa !9
  br label %16, !llvm.loop !11

35:                                               ; preds = %30, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %36 = load i32, ptr %5, align 4
  switch i32 %36, label %41 [
    i32 5, label %37
  ]

37:                                               ; preds = %35
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %4, align 4, !tbaa !9
  br label %8, !llvm.loop !13

41:                                               ; preds = %35, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %42 = load i32, ptr %5, align 4
  switch i32 %42, label %46 [
    i32 2, label %43
    i32 1, label %44
  ]

43:                                               ; preds = %41
  store i1 true, ptr %2, align 1
  br label %44

44:                                               ; preds = %43, %41
  %45 = load i1, ptr %2, align 1
  ret i1 %45

46:                                               ; preds = %41
  unreachable
}

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

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

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

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

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


; 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: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZNK3ipx12SparseMatrix8IsSortedEv(ptr noundef nonnull align 8 dereferenceable(128) %0) local_unnamed_addr #0 align 2 {
  %2 = tail call noundef i32 @_ZNK3ipx12SparseMatrix4colsEv(ptr noundef nonnull align 8 dereferenceable(128) %0)
  %3 = icmp slt i32 %2, 1
  br i1 %3, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %1, %13
  %.01218 = phi i32 [ %14, %13 ], [ 0, %1 ]
  %4 = tail call noundef i32 @_ZNK3ipx12SparseMatrix5beginEi(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %.01218)
  br label %5

5:                                                ; preds = %8, %.lr.ph
  %.0 = phi i32 [ %4, %.lr.ph ], [ %10, %8 ]
  %6 = tail call noundef i32 @_ZNK3ipx12SparseMatrix3endEi(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %.01218)
  %7 = add nsw i32 %6, -1
  %.not = icmp slt i32 %.0, %7
  br i1 %.not, label %8, label %13

8:                                                ; preds = %5
  %9 = tail call noundef i32 @_ZNK3ipx12SparseMatrix5indexEi(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %.0)
  %10 = add nsw i32 %.0, 1
  %11 = tail call noundef i32 @_ZNK3ipx12SparseMatrix5indexEi(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %10)
  %12 = icmp sgt i32 %9, %11
  br i1 %12, label %.thread, label %5, !llvm.loop !5

13:                                               ; preds = %5
  %14 = add nuw nsw i32 %.01218, 1
  %15 = tail call noundef i32 @_ZNK3ipx12SparseMatrix4colsEv(ptr noundef nonnull align 8 dereferenceable(128) %0)
  %.not22 = icmp slt i32 %14, %15
  br i1 %.not22, label %.lr.ph, label %.thread, !llvm.loop !7

.thread:                                          ; preds = %13, %8, %1
  %16 = phi i1 [ true, %1 ], [ false, %8 ], [ true, %13 ]
  ret i1 %16
}

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

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

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

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

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

!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 = distinct !{!7, !6}


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