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

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

@.str = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [103 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

declare noundef ptr @_ZN7qpOASES23getGlobalMessageHandlerEv() #1

declare noundef i32 @_ZN7qpOASES15MessageHandling10throwErrorENS_11returnValueEPKcS3_S3_mNS_16VisibilityStatusE(ptr noundef nonnull align 8 dereferenceable(28), i32 noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, i32 noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7qpOASES6isZeroEdd(double noundef, double noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7qpOASES12SparseMatrix9addToDiagEd(ptr noundef nonnull align 8 dereferenceable(48) %0, double noundef %1) unnamed_addr #3 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %9 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %8, i32 0, i32 5
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %2
  %13 = call noundef ptr @_ZN7qpOASES23getGlobalMessageHandlerEv()
  %14 = call noundef i32 @_ZN7qpOASES15MessageHandling10throwErrorENS_11returnValueEPKcS3_S3_mNS_16VisibilityStatusE(ptr noundef nonnull align 8 dereferenceable(28) %13, i32 noundef 140, ptr noundef null, ptr noundef @.str, ptr noundef @.str.1, i64 noundef 1347, i32 noundef 1)
  store i32 %14, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %68

15:                                               ; preds = %2
  %16 = load double, ptr %5, align 8, !tbaa !9
  %17 = call noundef i32 @_ZN7qpOASES6isZeroEdd(double noundef %16, double noundef 1.000000e-25)
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %67

19:                                               ; preds = %15
  store i64 0, ptr %6, align 8, !tbaa !14
  br label %20

20:                                               ; preds = %63, %19
  %21 = load i64, ptr %6, align 8, !tbaa !14
  %22 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %8, i32 0, i32 1
  %23 = load i32, ptr %22, align 8, !tbaa !16
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %21, %24
  br i1 %25, label %26, label %32

26:                                               ; preds = %20
  %27 = load i64, ptr %6, align 8, !tbaa !14
  %28 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %8, i32 0, i32 2
  %29 = load i32, ptr %28, align 4, !tbaa !17
  %30 = sext i32 %29 to i64
  %31 = icmp slt i64 %27, %30
  br label %32

32:                                               ; preds = %26, %20
  %33 = phi i1 [ false, %20 ], [ %31, %26 ]
  br i1 %33, label %34, label %66

34:                                               ; preds = %32
  %35 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %8, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  %37 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %8, i32 0, i32 5
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = load i64, ptr %6, align 8, !tbaa !14
  %40 = getelementptr inbounds i32, ptr %38, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !19
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %36, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !19
  %45 = sext i32 %44 to i64
  %46 = load i64, ptr %6, align 8, !tbaa !14
  %47 = icmp eq i64 %45, %46
  br i1 %47, label %48, label %61

48:                                               ; preds = %34
  %49 = load double, ptr %5, align 8, !tbaa !9
  %50 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %8, i32 0, i32 6
  %51 = load ptr, ptr %50, align 8, !tbaa !20
  %52 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %8, i32 0, i32 5
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = load i64, ptr %6, align 8, !tbaa !14
  %55 = getelementptr inbounds i32, ptr %53, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !19
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds double, ptr %51, i64 %57
  %59 = load double, ptr %58, align 8, !tbaa !9
  %60 = fadd double %59, %49
  store double %60, ptr %58, align 8, !tbaa !9
  br label %62

61:                                               ; preds = %34
  store i32 139, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %68

62:                                               ; preds = %48
  br label %63

63:                                               ; preds = %62
  %64 = load i64, ptr %6, align 8, !tbaa !14
  %65 = add nsw i64 %64, 1
  store i64 %65, ptr %6, align 8, !tbaa !14
  br label %20, !llvm.loop !21

66:                                               ; preds = %32
  br label %67

67:                                               ; preds = %66, %15
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %68

68:                                               ; preds = %67, %61, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %69 = load i32, ptr %3, align 4
  ret i32 %69
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #4 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !6, i64 32}
!12 = !{!"_ZTSN7qpOASES12SparseMatrixE", !13, i64 8, !13, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !13, i64 8}
!17 = !{!12, !13, i64 12}
!18 = !{!12, !6, i64 16}
!19 = !{!13, !13, i64 0}
!20 = !{!12, !6, i64 40}
!21 = distinct !{!21, !22}
!22 = !{!"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 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [103 x i8], align 1

declare noundef ptr @_ZN7qpOASES23getGlobalMessageHandlerEv() local_unnamed_addr #0

declare noundef i32 @_ZN7qpOASES15MessageHandling10throwErrorENS_11returnValueEPKcS3_S3_mNS_16VisibilityStatusE(ptr noundef nonnull align 8 dereferenceable(28), i32 noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7qpOASES12SparseMatrix9addToDiagEd(ptr nocapture noundef nonnull readonly align 8 dereferenceable(48) %0, double noundef %1) unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %9

6:                                                ; preds = %2
  %7 = tail call noundef ptr @_ZN7qpOASES23getGlobalMessageHandlerEv()
  %8 = tail call noundef i32 @_ZN7qpOASES15MessageHandling10throwErrorENS_11returnValueEPKcS3_S3_mNS_16VisibilityStatusE(ptr noundef nonnull align 8 dereferenceable(28) %7, i32 noundef 140, ptr noundef null, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 1347, i32 noundef 1)
  br label %.critedge

9:                                                ; preds = %2
  %10 = tail call noundef i32 @_ZN7qpOASES6isZeroEdd(double noundef %1, double noundef 1.000000e-25)
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %.preheader, label %.critedge

.preheader:                                       ; preds = %9
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %0, i64 12
  %16 = icmp sgt i32 %13, 0
  %17 = load i32, ptr %15, align 4
  %18 = icmp sgt i32 %17, 0
  %or.cond13 = select i1 %16, i1 %18, i1 false
  br i1 %or.cond13, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.preheader
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %0, i64 40
  %23 = load ptr, ptr %22, align 8
  br label %24

24:                                               ; preds = %.lr.ph, %32
  %.014 = phi i64 [ 0, %.lr.ph ], [ %36, %32 ]
  %25 = getelementptr inbounds i32, ptr %21, i64 %.014
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr %20, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = sext i32 %29 to i64
  %31 = icmp eq i64 %.014, %30
  br i1 %31, label %32, label %.critedge

32:                                               ; preds = %24
  %33 = getelementptr inbounds double, ptr %23, i64 %27
  %34 = load double, ptr %33, align 8, !tbaa !14
  %35 = fadd double %34, %1
  store double %35, ptr %33, align 8, !tbaa !14
  %36 = add nuw nsw i64 %.014, 1
  %37 = icmp slt i64 %36, %14
  %38 = load i32, ptr %15, align 4
  %39 = sext i32 %38 to i64
  %40 = icmp slt i64 %36, %39
  %or.cond = select i1 %37, i1 %40, i1 false
  br i1 %or.cond, label %24, label %.critedge, !llvm.loop !16

.critedge:                                        ; preds = %24, %32, %.preheader, %9, %6
  %.09 = phi i32 [ %8, %6 ], [ 0, %9 ], [ 0, %.preheader ], [ 139, %24 ], [ 0, %32 ]
  ret i32 %.09
}

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

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


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