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

; 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::TripletToCSRConverter" = type { %"class.SimTKIpopt::ReferencedObject.base", i32, ptr, ptr, i32, i32, i32, i8, ptr, ptr, ptr }
%"class.SimTKIpopt::ReferencedObject.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 void @_ZN10SimTKIpopt21TripletToCSRConverter13ConvertValuesEiPKdiPd(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) #1 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %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 ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  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) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %35, %5
  %15 = load i32, ptr %11, align 4, !tbaa !9
  %16 = getelementptr inbounds %"class.SimTKIpopt::TripletToCSRConverter", ptr %13, i32 0, i32 6
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = icmp slt i32 %15, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %38

20:                                               ; preds = %14
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %"class.SimTKIpopt::TripletToCSRConverter", ptr %13, i32 0, i32 8
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = load i32, ptr %11, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr %23, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds double, ptr %21, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !16
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds double, ptr %31, i64 %33
  store double %30, ptr %34, align 8, !tbaa !16
  br label %35

35:                                               ; preds = %20
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %11, align 4, !tbaa !9
  br label %14, !llvm.loop !18

38:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %70, %38
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = getelementptr inbounds %"class.SimTKIpopt::TripletToCSRConverter", ptr %13, i32 0, i32 5
  %42 = load i32, ptr %41, align 4, !tbaa !20
  %43 = getelementptr inbounds %"class.SimTKIpopt::TripletToCSRConverter", ptr %13, i32 0, i32 6
  %44 = load i32, ptr %43, align 8, !tbaa !11
  %45 = sub nsw i32 %42, %44
  %46 = icmp slt i32 %40, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %73

48:                                               ; preds = %39
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.SimTKIpopt::TripletToCSRConverter", ptr %13, i32 0, i32 9
  %51 = load ptr, ptr %50, align 8, !tbaa !21
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %51, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %49, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !16
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %"class.SimTKIpopt::TripletToCSRConverter", ptr %13, i32 0, i32 10
  %61 = load ptr, ptr %60, align 8, !tbaa !22
  %62 = load i32, ptr %12, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %61, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds double, ptr %59, i64 %66
  %68 = load double, ptr %67, align 8, !tbaa !16
  %69 = fadd double %68, %58
  store double %69, ptr %67, align 8, !tbaa !16
  br label %70

70:                                               ; preds = %48
  %71 = load i32, ptr %12, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %12, align 4, !tbaa !9
  br label %39, !llvm.loop !23

73:                                               ; preds = %47
  ret void
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 40}
!12 = !{!"_ZTSN10SimTKIpopt21TripletToCSRConverterE", !13, i64 0, !10, i64 12, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !14, i64 44, !6, i64 48, !6, i64 56, !6, i64 64}
!13 = !{!"_ZTSN10SimTKIpopt16ReferencedObjectE", !10, i64 8}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !6, i64 48}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!12, !10, i64 36}
!21 = !{!12, !6, i64 56}
!22 = !{!12, !6, i64 64}
!23 = distinct !{!23, !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 nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN10SimTKIpopt21TripletToCSRConverter13ConvertValuesEiPKdiPd(ptr nocapture noundef nonnull readonly align 8 dereferenceable(72) %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, ptr nocapture noundef %4) local_unnamed_addr #0 align 2 {
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %wide.trip.count = zext nneg i32 %7 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %11 = icmp ult i32 %7, 4
  br i1 %11, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %27

.preheader.loopexit.unr-lcssa:                    ; preds = %27, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %27 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.epil.preheader

.epil.preheader:                                  ; preds = %.preheader.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %.preheader.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.preheader.loopexit.unr-lcssa ]
  %12 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.epil
  %13 = load i32, ptr %12, align 4, !tbaa !14
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds double, ptr %2, i64 %14
  %16 = load double, ptr %15, align 8, !tbaa !15
  %17 = getelementptr inbounds double, ptr %4, i64 %indvars.iv.epil
  store double %16, ptr %17, align 8, !tbaa !15
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader, label %.epil.preheader, !llvm.loop !17

.preheader:                                       ; preds = %.preheader.loopexit.unr-lcssa, %.epil.preheader, %5
  %18 = getelementptr inbounds i8, ptr %0, i64 36
  %19 = load i32, ptr %18, align 4, !tbaa !19
  %20 = sub nsw i32 %19, %7
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph15, label %._crit_edge

.lr.ph15:                                         ; preds = %.preheader
  %22 = getelementptr inbounds i8, ptr %0, i64 56
  %23 = load ptr, ptr %22, align 8, !tbaa !20
  %24 = getelementptr inbounds i8, ptr %0, i64 64
  %25 = load ptr, ptr %24, align 8, !tbaa !21
  %wide.trip.count20 = zext nneg i32 %20 to i64
  %xtraiter23 = and i64 %wide.trip.count20, 1
  %26 = icmp eq i32 %20, 1
  br i1 %26, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph15.new

.lr.ph15.new:                                     ; preds = %.lr.ph15
  %unroll_iter26 = and i64 %wide.trip.count20, 2147483646
  br label %63

27:                                               ; preds = %27, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %27 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %27 ]
  %28 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %2, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !15
  %33 = getelementptr inbounds double, ptr %4, i64 %indvars.iv
  store double %32, ptr %33, align 8, !tbaa !15
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %34 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.next
  %35 = load i32, ptr %34, align 4, !tbaa !14
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds double, ptr %2, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !15
  %39 = getelementptr inbounds double, ptr %4, i64 %indvars.iv.next
  store double %38, ptr %39, align 8, !tbaa !15
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %40 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.next.1
  %41 = load i32, ptr %40, align 4, !tbaa !14
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %2, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !15
  %45 = getelementptr inbounds double, ptr %4, i64 %indvars.iv.next.1
  store double %44, ptr %45, align 8, !tbaa !15
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %46 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.next.2
  %47 = load i32, ptr %46, align 4, !tbaa !14
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %2, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !15
  %51 = getelementptr inbounds double, ptr %4, i64 %indvars.iv.next.2
  store double %50, ptr %51, align 8, !tbaa !15
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader.loopexit.unr-lcssa, label %27, !llvm.loop !22

._crit_edge.loopexit.unr-lcssa:                   ; preds = %63, %.lr.ph15
  %indvars.iv17.unr = phi i64 [ 0, %.lr.ph15 ], [ %indvars.iv.next18.1, %63 ]
  %lcmp.mod25.not = icmp eq i64 %xtraiter23, 0
  br i1 %lcmp.mod25.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %52 = getelementptr inbounds i32, ptr %23, i64 %indvars.iv17.unr
  %53 = load i32, ptr %52, align 4, !tbaa !14
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds double, ptr %2, i64 %54
  %56 = load double, ptr %55, align 8, !tbaa !15
  %57 = getelementptr inbounds i32, ptr %25, i64 %indvars.iv17.unr
  %58 = load i32, ptr %57, align 4, !tbaa !14
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds double, ptr %4, i64 %59
  %61 = load double, ptr %60, align 8, !tbaa !15
  %62 = fadd double %56, %61
  store double %62, ptr %60, align 8, !tbaa !15
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %.preheader
  ret void

63:                                               ; preds = %63, %.lr.ph15.new
  %indvars.iv17 = phi i64 [ 0, %.lr.ph15.new ], [ %indvars.iv.next18.1, %63 ]
  %niter27 = phi i64 [ 0, %.lr.ph15.new ], [ %niter27.next.1, %63 ]
  %64 = getelementptr inbounds i32, ptr %23, i64 %indvars.iv17
  %65 = load i32, ptr %64, align 4, !tbaa !14
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds double, ptr %2, i64 %66
  %68 = load double, ptr %67, align 8, !tbaa !15
  %69 = getelementptr inbounds i32, ptr %25, i64 %indvars.iv17
  %70 = load i32, ptr %69, align 4, !tbaa !14
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds double, ptr %4, i64 %71
  %73 = load double, ptr %72, align 8, !tbaa !15
  %74 = fadd double %68, %73
  store double %74, ptr %72, align 8, !tbaa !15
  %indvars.iv.next18 = or disjoint i64 %indvars.iv17, 1
  %75 = getelementptr inbounds i32, ptr %23, i64 %indvars.iv.next18
  %76 = load i32, ptr %75, align 4, !tbaa !14
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds double, ptr %2, i64 %77
  %79 = load double, ptr %78, align 8, !tbaa !15
  %80 = getelementptr inbounds i32, ptr %25, i64 %indvars.iv.next18
  %81 = load i32, ptr %80, align 4, !tbaa !14
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds double, ptr %4, i64 %82
  %84 = load double, ptr %83, align 8, !tbaa !15
  %85 = fadd double %79, %84
  store double %85, ptr %83, align 8, !tbaa !15
  %indvars.iv.next18.1 = add nuw nsw i64 %indvars.iv17, 2
  %niter27.next.1 = add i64 %niter27, 2
  %niter27.ncmp.1 = icmp eq i64 %niter27.next.1, %unroll_iter26
  br i1 %niter27.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %63, !llvm.loop !24
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, 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, !8, i64 40}
!6 = !{!"_ZTSN10SimTKIpopt21TripletToCSRConverterE", !7, i64 0, !8, i64 12, !11, i64 16, !11, i64 24, !8, i64 32, !8, i64 36, !8, i64 40, !12, i64 44, !11, i64 48, !11, i64 56, !11, i64 64}
!7 = !{!"_ZTSN10SimTKIpopt16ReferencedObjectE", !8, i64 8}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"bool", !9, i64 0}
!13 = !{!6, !11, i64 48}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !9, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = !{!6, !8, i64 36}
!20 = !{!6, !11, i64 56}
!21 = !{!6, !11, i64 64}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


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