; LLVM IR from simbody/simbody :: SimTKmath/Optimizers/src/IpOpt (IpLapackSolverInterface)

; 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.SimTKIpopt::LapackSolverInterface" = type <{ %"class.SimTKIpopt::SparseSymLinearSolverInterface.base", [3 x i8], i32, i32, [4 x i8], ptr, ptr, ptr, ptr, i32, [4 x i8], ptr, i8, [7 x i8] }>
%"class.SimTKIpopt::SparseSymLinearSolverInterface.base" = type { %"class.SimTKIpopt::AlgorithmStrategyObject.base" }
%"class.SimTKIpopt::AlgorithmStrategyObject.base" = type <{ %"class.SimTKIpopt::ReferencedObject.base", [4 x i8], %"class.SimTKIpopt::SmartPtr.6", %"class.SimTKIpopt::SmartPtr.7", %"class.SimTKIpopt::SmartPtr.8", %"class.SimTKIpopt::SmartPtr.9", i8 }>
%"class.SimTKIpopt::ReferencedObject.base" = type <{ ptr, i32 }>
%"class.SimTKIpopt::SmartPtr.6" = type { ptr }
%"class.SimTKIpopt::SmartPtr.7" = type { ptr }
%"class.SimTKIpopt::SmartPtr.8" = type { ptr }
%"class.SimTKIpopt::SmartPtr.9" = type { ptr }

; 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: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10SimTKIpopt21LapackSolverInterface19InitializeStructureEiiPKiS2_(ptr noundef nonnull align 8 dereferenceable(113) %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) unnamed_addr #4 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !11
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 2
  store i32 %14, ptr %15, align 4, !tbaa !13
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 3
  store i32 %16, ptr %17, align 8, !tbaa !23
  %18 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 5
  %19 = load ptr, ptr %18, align 8, !tbaa !24
  %20 = icmp eq ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %5
  call void @_ZdaPv(ptr noundef %19) #6
  br label %22

22:                                               ; preds = %21, %5
  %23 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 7
  %24 = load ptr, ptr %23, align 8, !tbaa !25
  %25 = icmp eq ptr %24, null
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @_ZdaPv(ptr noundef %24) #6
  br label %27

27:                                               ; preds = %26, %22
  %28 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 8
  %29 = load ptr, ptr %28, align 8, !tbaa !26
  %30 = icmp eq ptr %29, null
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  call void @_ZdaPv(ptr noundef %29) #6
  br label %32

32:                                               ; preds = %31, %27
  %33 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 11
  store ptr null, ptr %33, align 8, !tbaa !27
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = mul nsw i32 %34, %35
  %37 = sext i32 %36 to i64
  %38 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %37, i64 8)
  %39 = extractvalue { i64, i1 } %38, 1
  %40 = extractvalue { i64, i1 } %38, 0
  %41 = select i1 %39, i64 -1, i64 %40
  %42 = call noalias noundef nonnull ptr @_Znam(i64 noundef %41) #7
  %43 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 5
  store ptr %42, ptr %43, align 8, !tbaa !24
  %44 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 3
  %45 = load i32, ptr %44, align 8, !tbaa !23
  %46 = sext i32 %45 to i64
  %47 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %46, i64 4)
  %48 = extractvalue { i64, i1 } %47, 1
  %49 = extractvalue { i64, i1 } %47, 0
  %50 = select i1 %48, i64 -1, i64 %49
  %51 = call noalias noundef nonnull ptr @_Znam(i64 noundef %50) #7
  %52 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 7
  store ptr %51, ptr %52, align 8, !tbaa !25
  %53 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 3
  %54 = load i32, ptr %53, align 8, !tbaa !23
  %55 = sext i32 %54 to i64
  %56 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %55, i64 4)
  %57 = extractvalue { i64, i1 } %56, 1
  %58 = extractvalue { i64, i1 } %56, 0
  %59 = select i1 %57, i64 -1, i64 %58
  %60 = call noalias noundef nonnull ptr @_Znam(i64 noundef %59) #7
  %61 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 8
  store ptr %60, ptr %61, align 8, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %89, %32
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 3
  %65 = load i32, ptr %64, align 8, !tbaa !23
  %66 = icmp slt i32 %63, %65
  br i1 %66, label %68, label %67

67:                                               ; preds = %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %92

68:                                               ; preds = %62
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = load i32, ptr %12, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i32, ptr %69, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 7
  %75 = load ptr, ptr %74, align 8, !tbaa !25
  %76 = load i32, ptr %12, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i32, ptr %75, i64 %77
  store i32 %73, ptr %78, align 4, !tbaa !9
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = load i32, ptr %12, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds i32, ptr %79, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !9
  %84 = getelementptr inbounds %"class.SimTKIpopt::LapackSolverInterface", ptr %13, i32 0, i32 8
  %85 = load ptr, ptr %84, align 8, !tbaa !26
  %86 = load i32, ptr %12, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i32, ptr %85, i64 %87
  store i32 %83, ptr %88, align 4, !tbaa !9
  br label %89

89:                                               ; preds = %68
  %90 = load i32, ptr %12, align 4, !tbaa !9
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %12, align 4, !tbaa !9
  br label %62, !llvm.loop !28

92:                                               ; preds = %67
  %93 = load i32, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  ret i32 %93
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nobuiltin allocsize(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 = { builtin nounwind }
attributes #7 = { builtin allocsize(0) }

!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 = !{!"_ZTSN10SimTKIpopt16ESymSolverStatusE", !7, i64 0}
!13 = !{!14, !10, i64 52}
!14 = !{!"_ZTSN10SimTKIpopt21LapackSolverInterfaceE", !15, i64 0, !10, i64 52, !10, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !10, i64 96, !6, i64 104, !22, i64 112}
!15 = !{!"_ZTSN10SimTKIpopt30SparseSymLinearSolverInterfaceE", !16, i64 0}
!16 = !{!"_ZTSN10SimTKIpopt23AlgorithmStrategyObjectE", !17, i64 0, !18, i64 16, !19, i64 24, !20, i64 32, !21, i64 40, !22, i64 48}
!17 = !{!"_ZTSN10SimTKIpopt16ReferencedObjectE", !10, i64 8}
!18 = !{!"_ZTSN10SimTKIpopt8SmartPtrIKNS_10JournalistEEE", !6, i64 0}
!19 = !{!"_ZTSN10SimTKIpopt8SmartPtrINS_8IpoptNLPEEE", !6, i64 0}
!20 = !{!"_ZTSN10SimTKIpopt8SmartPtrINS_9IpoptDataEEE", !6, i64 0}
!21 = !{!"_ZTSN10SimTKIpopt8SmartPtrINS_25IpoptCalculatedQuantitiesEEE", !6, i64 0}
!22 = !{!"bool", !7, i64 0}
!23 = !{!14, !10, i64 56}
!24 = !{!14, !6, i64 64}
!25 = !{!14, !6, i64 80}
!26 = !{!14, !6, i64 88}
!27 = !{!14, !6, i64 104}
!28 = distinct !{!28, !29}
!29 = !{!"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: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #0

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10SimTKIpopt21LapackSolverInterface19InitializeStructureEiiPKiS2_(ptr nocapture noundef nonnull align 8 dereferenceable(113) %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4) unnamed_addr #2 align 2 {
  %6 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 %1, ptr %6, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 %2, ptr %7, align 8, !tbaa !19
  %8 = getelementptr inbounds i8, ptr %0, i64 64
  %9 = load ptr, ptr %8, align 8, !tbaa !20
  %10 = icmp eq ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %5
  tail call void @_ZdaPv(ptr noundef nonnull %9) #4
  br label %12

12:                                               ; preds = %11, %5
  %13 = getelementptr inbounds i8, ptr %0, i64 80
  %14 = load ptr, ptr %13, align 8, !tbaa !21
  %15 = icmp eq ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  tail call void @_ZdaPv(ptr noundef nonnull %14) #4
  br label %17

17:                                               ; preds = %16, %12
  %18 = getelementptr inbounds i8, ptr %0, i64 88
  %19 = load ptr, ptr %18, align 8, !tbaa !22
  %20 = icmp eq ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  tail call void @_ZdaPv(ptr noundef nonnull %19) #4
  br label %22

22:                                               ; preds = %21, %17
  %23 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr null, ptr %23, align 8, !tbaa !23
  %24 = mul nsw i32 %1, %1
  %25 = zext nneg i32 %24 to i64
  %26 = shl nuw nsw i64 %25, 3
  %27 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %26) #5
  store ptr %27, ptr %8, align 8, !tbaa !20
  %28 = load i32, ptr %7, align 8, !tbaa !19
  %29 = sext i32 %28 to i64
  %30 = icmp slt i32 %28, 0
  %31 = shl nsw i64 %29, 2
  %32 = select i1 %30, i64 -1, i64 %31
  %33 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %32) #5
  store ptr %33, ptr %13, align 8, !tbaa !21
  %34 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %32) #5
  store ptr %34, ptr %18, align 8, !tbaa !22
  %35 = icmp sgt i32 %28, 0
  br i1 %35, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %22
  %36 = zext nneg i32 %28 to i64
  %37 = shl nuw nsw i64 %36, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %33, ptr align 4 %3, i64 %37, i1 false), !tbaa !24
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %34, ptr align 4 %4, i64 %37, i1 false), !tbaa !24
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %22
  ret i32 0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { nobuiltin 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 = { nobuiltin allocsize(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" }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { builtin nounwind }
attributes #5 = { builtin allocsize(0) }

!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 52}
!6 = !{!"_ZTSN10SimTKIpopt21LapackSolverInterfaceE", !7, i64 0, !10, i64 52, !10, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !14, i64 88, !10, i64 96, !14, i64 104, !18, i64 112}
!7 = !{!"_ZTSN10SimTKIpopt30SparseSymLinearSolverInterfaceE", !8, i64 0}
!8 = !{!"_ZTSN10SimTKIpopt23AlgorithmStrategyObjectE", !9, i64 0, !13, i64 16, !15, i64 24, !16, i64 32, !17, i64 40, !18, i64 48}
!9 = !{!"_ZTSN10SimTKIpopt16ReferencedObjectE", !10, i64 8}
!10 = !{!"int", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"_ZTSN10SimTKIpopt8SmartPtrIKNS_10JournalistEEE", !14, i64 0}
!14 = !{!"any pointer", !11, i64 0}
!15 = !{!"_ZTSN10SimTKIpopt8SmartPtrINS_8IpoptNLPEEE", !14, i64 0}
!16 = !{!"_ZTSN10SimTKIpopt8SmartPtrINS_9IpoptDataEEE", !14, i64 0}
!17 = !{!"_ZTSN10SimTKIpopt8SmartPtrINS_25IpoptCalculatedQuantitiesEEE", !14, i64 0}
!18 = !{!"bool", !11, i64 0}
!19 = !{!6, !10, i64 56}
!20 = !{!6, !14, i64 64}
!21 = !{!6, !14, i64 80}
!22 = !{!6, !14, i64 88}
!23 = !{!6, !14, i64 104}
!24 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass