; LLVM IR from Tencent-RoboticsX/jbdl :: src/jbdl/experimental/qpoases/src/Matrices.ll (ZNK7qpOASES12SparseMatrix6isDiagEv)

; 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.qpOASES::SparseMatrix" = type { ptr, i32, i32, ptr, ptr, ptr, ptr, %"class.qpOASES::Matrix.base" }
%"class.qpOASES::Matrix.base" = type <{ ptr, i32 }>

; 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 nounwind uwtable
define dso_local noundef i32 @_ZNK7qpOASES12SparseMatrix6isDiagEv(ptr noundef nonnull align 8 dereferenceable(48) %0) unnamed_addr #1 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %7 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %6, i32 0, i32 2
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %6, i32 0, i32 1
  %10 = load i32, ptr %9, align 8, !tbaa !12
  %11 = icmp ne i32 %8, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %72

13:                                               ; preds = %1
  store i32 0, ptr %4, align 4, !tbaa !13
  br label %14

14:                                               ; preds = %68, %13
  %15 = load i32, ptr %4, align 4, !tbaa !13
  %16 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %6, i32 0, i32 2
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = icmp slt i32 %15, %17
  br i1 %18, label %19, label %71

19:                                               ; preds = %14
  %20 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %6, i32 0, i32 4
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = load i32, ptr %4, align 4, !tbaa !13
  %23 = add nsw i32 %22, 1
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i32, ptr %21, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %6, i32 0, i32 4
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load i32, ptr %4, align 4, !tbaa !13
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %28, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !13
  %33 = add nsw i32 %32, 1
  %34 = icmp sgt i32 %26, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %19
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %72

36:                                               ; preds = %19
  %37 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %6, i32 0, i32 4
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = load i32, ptr %4, align 4, !tbaa !13
  %40 = add nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %38, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !13
  %44 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %6, i32 0, i32 4
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = load i32, ptr %4, align 4, !tbaa !13
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i32, ptr %45, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !13
  %50 = add nsw i32 %49, 1
  %51 = icmp eq i32 %43, %50
  br i1 %51, label %52, label %67

52:                                               ; preds = %36
  %53 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %6, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %6, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !14
  %57 = load i32, ptr %4, align 4, !tbaa !13
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr %56, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !13
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr %54, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !13
  %64 = load i32, ptr %4, align 4, !tbaa !13
  %65 = icmp ne i32 %63, %64
  br i1 %65, label %66, label %67

66:                                               ; preds = %52
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %72

67:                                               ; preds = %52, %36
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %4, align 4, !tbaa !13
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %4, align 4, !tbaa !13
  br label %14, !llvm.loop !16

71:                                               ; preds = %14
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %72

72:                                               ; preds = %71, %66, %35, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %73 = load i32, ptr %2, align 4
  ret i32 %73
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !11, i64 12}
!10 = !{!"_ZTSN7qpOASES12SparseMatrixE", !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 24}
!15 = !{!10, !6, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZNK7qpOASES12SparseMatrix6isDiagEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(48) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 12
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !11
  %.not = icmp eq i32 %3, %5
  br i1 %.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %1
  %6 = icmp sgt i32 %3, 0
  br i1 %6, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = load ptr, ptr %7, align 8
  %wide.trip.count = zext nneg i32 %3 to i64
  %.pre = load i32, ptr %9, align 4, !tbaa !13
  br label %11

11:                                               ; preds = %.lr.ph, %24
  %12 = phi i32 [ %.pre, %.lr.ph ], [ %14, %24 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %24 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv.next
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = add nsw i32 %12, 1
  %16 = icmp sgt i32 %14, %15
  br i1 %16, label %.loopexit, label %17

17:                                               ; preds = %11
  %18 = icmp eq i32 %14, %15
  br i1 %18, label %19, label %24

19:                                               ; preds = %17
  %20 = sext i32 %12 to i64
  %21 = getelementptr inbounds i32, ptr %10, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = zext i32 %22 to i64
  %.not12 = icmp eq i64 %indvars.iv, %23
  br i1 %.not12, label %24, label %.loopexit

24:                                               ; preds = %17, %19
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %11, !llvm.loop !14

.loopexit:                                        ; preds = %11, %19, %24, %.preheader, %1
  %.09 = phi i32 [ 0, %1 ], [ 1, %.preheader ], [ 0, %11 ], [ 0, %19 ], [ 1, %24 ]
  ret i32 %.09
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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, !7, i64 12}
!6 = !{!"_ZTSN7qpOASES12SparseMatrixE", !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!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 8}
!12 = !{!6, !10, i64 24}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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