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

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

13:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %63

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

15:                                               ; preds = %59, %14
  %16 = load i32, ptr %4, align 4, !tbaa !13
  %17 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 1
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = icmp slt i32 %16, %18
  br i1 %19, label %20, label %62

20:                                               ; preds = %15
  store i32 0, ptr %5, align 4, !tbaa !13
  br label %21

21:                                               ; preds = %55, %20
  %22 = load i32, ptr %5, align 4, !tbaa !13
  %23 = load i32, ptr %4, align 4, !tbaa !13
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %58

25:                                               ; preds = %21
  %26 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 4
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = load i32, ptr %4, align 4, !tbaa !13
  %29 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 3
  %30 = load i32, ptr %29, align 8, !tbaa !15
  %31 = mul nsw i32 %28, %30
  %32 = load i32, ptr %5, align 4, !tbaa !13
  %33 = add nsw i32 %31, %32
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds double, ptr %27, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !16
  %37 = call noundef double @_ZN7qpOASES6getAbsEd(double noundef %36)
  %38 = fcmp ogt double %37, 2.221000e-16
  br i1 %38, label %53, label %39

39:                                               ; preds = %25
  %40 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = load i32, ptr %5, align 4, !tbaa !13
  %43 = getelementptr inbounds %"class.qpOASES::DenseMatrix", ptr %7, i32 0, i32 3
  %44 = load i32, ptr %43, align 8, !tbaa !15
  %45 = mul nsw i32 %42, %44
  %46 = load i32, ptr %4, align 4, !tbaa !13
  %47 = add nsw i32 %45, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %41, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !16
  %51 = call noundef double @_ZN7qpOASES6getAbsEd(double noundef %50)
  %52 = fcmp ogt double %51, 2.221000e-16
  br i1 %52, label %53, label %54

53:                                               ; preds = %39, %25
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %63

54:                                               ; preds = %39
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %5, align 4, !tbaa !13
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %5, align 4, !tbaa !13
  br label %21, !llvm.loop !18

58:                                               ; preds = %21
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %4, align 4, !tbaa !13
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %4, align 4, !tbaa !13
  br label %15, !llvm.loop !20

62:                                               ; preds = %15
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %63

63:                                               ; preds = %62, %53, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %64 = load i32, ptr %2, align 4
  ret i32 %64
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN7qpOASES6getAbsEd(double noundef) #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 = { 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 = { 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 8}
!10 = !{!"_ZTSN7qpOASES11DenseMatrixE", !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 12}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 24}
!15 = !{!10, !11, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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 range(i32 0, 2) i32 @_ZNK7qpOASES11DenseMatrix6isDiagEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = load i32, ptr %4, align 4, !tbaa !11
  %.not = icmp eq i32 %3, %5
  br i1 %.not, label %.preheader12, label %.loopexit

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

.preheader.lr.ph:                                 ; preds = %.preheader12
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %9 = phi i32 [ %3, %.preheader.lr.ph ], [ %31, %._crit_edge ]
  %.01015 = phi i32 [ 0, %.preheader.lr.ph ], [ %32, %._crit_edge ]
  %.not16 = icmp eq i32 %.01015, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph

10:                                               ; preds = %21
  %11 = add nuw nsw i32 %.014, 1
  %exitcond.not = icmp eq i32 %11, %.01015
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !12

.lr.ph:                                           ; preds = %.preheader, %10
  %.014 = phi i32 [ %11, %10 ], [ 0, %.preheader ]
  %12 = load ptr, ptr %7, align 8, !tbaa !14
  %13 = load i32, ptr %8, align 8, !tbaa !15
  %14 = mul nsw i32 %13, %.01015
  %15 = add nsw i32 %14, %.014
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds double, ptr %12, i64 %16
  %18 = load double, ptr %17, align 8, !tbaa !16
  %19 = tail call noundef double @_ZN7qpOASES6getAbsEd(double noundef %18)
  %20 = fcmp ogt double %19, 2.221000e-16
  br i1 %20, label %.loopexit, label %21

21:                                               ; preds = %.lr.ph
  %22 = load ptr, ptr %7, align 8, !tbaa !14
  %23 = load i32, ptr %8, align 8, !tbaa !15
  %24 = mul nsw i32 %23, %.014
  %25 = add nsw i32 %24, %.01015
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds double, ptr %22, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !16
  %29 = tail call noundef double @_ZN7qpOASES6getAbsEd(double noundef %28)
  %30 = fcmp ogt double %29, 2.221000e-16
  br i1 %30, label %.loopexit, label %10

._crit_edge.loopexit:                             ; preds = %10
  %.pre = load i32, ptr %2, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %31 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %9, %.preheader ]
  %32 = add nuw nsw i32 %.01015, 1
  %33 = icmp slt i32 %32, %31
  br i1 %33, label %.preheader, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %._crit_edge, %.lr.ph, %21, %.preheader12, %1
  %.011 = phi i32 [ 0, %1 ], [ 1, %.preheader12 ], [ 0, %21 ], [ 0, %.lr.ph ], [ 1, %._crit_edge ]
  ret i32 %.011
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN7qpOASES6getAbsEd(double noundef) local_unnamed_addr #1

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

!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 8}
!6 = !{!"_ZTSN7qpOASES11DenseMatrixE", !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 24}
!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 12}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !10, i64 24}
!15 = !{!6, !7, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !8, i64 0}
!18 = distinct !{!18, !13}


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