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

; 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::TripletToDenseConverter" = 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 @_ZN10SimTKIpopt23TripletToDenseConverter13ConvertValuesEiPKdiPd(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
  %13 = 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
  %14 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %37, %5
  %16 = load i32, ptr %11, align 4, !tbaa !9
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %40

19:                                               ; preds = %15
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %33, %19
  %21 = load i32, ptr %12, align 4, !tbaa !9
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %36

24:                                               ; preds = %20
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = mul nsw i32 %26, %27
  %29 = load i32, ptr %12, align 4, !tbaa !9
  %30 = add nsw i32 %28, %29
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds double, ptr %25, i64 %31
  store double 0.000000e+00, ptr %32, align 8, !tbaa !11
  br label %33

33:                                               ; preds = %24
  %34 = load i32, ptr %12, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %12, align 4, !tbaa !9
  br label %20, !llvm.loop !13

36:                                               ; preds = %20
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %11, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %11, align 4, !tbaa !9
  br label %15, !llvm.loop !15

40:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %112, %40
  %42 = load i32, ptr %13, align 4, !tbaa !9
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %115

46:                                               ; preds = %41
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %13, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds double, ptr %47, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !11
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds %"class.SimTKIpopt::TripletToDenseConverter", ptr %14, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = load i32, ptr %13, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = mul nsw i32 %58, %59
  %61 = getelementptr inbounds %"class.SimTKIpopt::TripletToDenseConverter", ptr %14, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !20
  %63 = load i32, ptr %13, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i32, ptr %62, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = add nsw i32 %60, %66
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds double, ptr %52, i64 %68
  %70 = load double, ptr %69, align 8, !tbaa !11
  %71 = fadd double %70, %51
  store double %71, ptr %69, align 8, !tbaa !11
  %72 = getelementptr inbounds %"class.SimTKIpopt::TripletToDenseConverter", ptr %14, i32 0, i32 2
  %73 = load ptr, ptr %72, align 8, !tbaa !20
  %74 = load i32, ptr %13, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i32, ptr %73, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !9
  %78 = getelementptr inbounds %"class.SimTKIpopt::TripletToDenseConverter", ptr %14, i32 0, i32 3
  %79 = load ptr, ptr %78, align 8, !tbaa !16
  %80 = load i32, ptr %13, 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 = icmp ne i32 %77, %83
  br i1 %84, label %85, label %111

85:                                               ; preds = %46
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = load i32, ptr %13, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds double, ptr %86, i64 %88
  %90 = load double, ptr %89, align 8, !tbaa !11
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  %92 = getelementptr inbounds %"class.SimTKIpopt::TripletToDenseConverter", ptr %14, i32 0, i32 2
  %93 = load ptr, ptr %92, align 8, !tbaa !20
  %94 = load i32, ptr %13, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds i32, ptr %93, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !9
  %98 = load i32, ptr %9, align 4, !tbaa !9
  %99 = mul nsw i32 %97, %98
  %100 = getelementptr inbounds %"class.SimTKIpopt::TripletToDenseConverter", ptr %14, i32 0, i32 3
  %101 = load ptr, ptr %100, align 8, !tbaa !16
  %102 = load i32, ptr %13, align 4, !tbaa !9
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds i32, ptr %101, i64 %103
  %105 = load i32, ptr %104, align 4, !tbaa !9
  %106 = add nsw i32 %99, %105
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds double, ptr %91, i64 %107
  %109 = load double, ptr %108, align 8, !tbaa !11
  %110 = fadd double %109, %90
  store double %110, ptr %108, align 8, !tbaa !11
  br label %111

111:                                              ; preds = %85, %46
  br label %112

112:                                              ; preds = %111
  %113 = load i32, ptr %13, align 4, !tbaa !9
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %13, align 4, !tbaa !9
  br label %41, !llvm.loop !21

115:                                              ; preds = %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{!17, !6, i64 24}
!17 = !{!"_ZTSN10SimTKIpopt23TripletToDenseConverterE", !18, i64 0, !10, i64 12, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !19, i64 44, !6, i64 48, !6, i64 56, !6, i64 64}
!18 = !{!"_ZTSN10SimTKIpopt16ReferencedObjectE", !10, i64 8}
!19 = !{!"bool", !7, i64 0}
!20 = !{!17, !6, i64 16}
!21 = distinct !{!21, !14}


; 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 @_ZN10SimTKIpopt23TripletToDenseConverter13ConvertValuesEiPKdiPd(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 = icmp sgt i32 %3, 0
  br i1 %6, label %.preheader32.us.preheader, label %.preheader

.preheader32.us.preheader:                        ; preds = %5
  %7 = zext nneg i32 %3 to i64
  %8 = mul nuw nsw i64 %7, %7
  %9 = shl i64 %8, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %4, i8 0, i64 %9, i1 false), !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader32.us.preheader, %5
  %10 = icmp sgt i32 %1, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

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

._crit_edge:                                      ; preds = %36, %.preheader
  ret void

15:                                               ; preds = %.lr.ph, %36
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %36 ]
  %16 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv
  %19 = load i32, ptr %18, align 4, !tbaa !16
  %20 = mul nsw i32 %19, %3
  %21 = getelementptr inbounds i32, ptr %14, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !16
  %23 = add nsw i32 %22, %20
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %4, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = fadd double %17, %26
  store double %27, ptr %25, align 8, !tbaa !5
  %.not = icmp eq i32 %22, %19
  br i1 %.not, label %36, label %28

28:                                               ; preds = %15
  %29 = load double, ptr %16, align 8, !tbaa !5
  %30 = mul nsw i32 %22, %3
  %31 = add nsw i32 %30, %19
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds double, ptr %4, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = fadd double %29, %34
  store double %35, ptr %33, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %15, %28
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %15, !llvm.loop !17
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !13, i64 24}
!10 = !{!"_ZTSN10SimTKIpopt23TripletToDenseConverterE", !11, i64 0, !12, i64 12, !13, i64 16, !13, i64 24, !12, i64 32, !12, i64 36, !12, i64 40, !14, i64 44, !13, i64 48, !13, i64 56, !13, i64 64}
!11 = !{!"_ZTSN10SimTKIpopt16ReferencedObjectE", !12, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!10, !13, i64 16}
!16 = !{!12, !12, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass