; LLVM IR from simbody/simbody :: SimTKmath/Integrators/src/CPodes/sundials/src/sundials (sundials_dense)

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

; Function Attrs: nounwind uwtable
define dso_local void @denseZero(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %33, %3
  %11 = load i32, ptr %8, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %36

14:                                               ; preds = %10
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds ptr, ptr %15, i64 %17
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  store ptr %19, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %29, %14
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %32

24:                                               ; preds = %20
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds double, ptr %25, i64 %27
  store double 0.000000e+00, ptr %28, align 8, !tbaa !11
  br label %29

29:                                               ; preds = %24
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %7, align 4, !tbaa !9
  br label %20, !llvm.loop !13

32:                                               ; preds = %20
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %8, align 4, !tbaa !9
  br label %10, !llvm.loop !15

36:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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/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}


; 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: nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @denseZero(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %2, 0
  %5 = icmp sgt i32 %1, 0
  %or.cond = and i1 %4, %5
  br i1 %or.cond, label %.lr.ph.us.preheader, label %._crit_edge14

.lr.ph.us.preheader:                              ; preds = %3
  %6 = zext nneg i32 %1 to i64
  %7 = shl nuw nsw i64 %6, 3
  %wide.trip.count = zext nneg i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 7
  %8 = icmp ult i32 %2, 8
  br i1 %8, label %._crit_edge14.loopexit.unr-lcssa, label %.lr.ph.us.preheader.new

.lr.ph.us.preheader.new:                          ; preds = %.lr.ph.us.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483640
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us, %.lr.ph.us.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.us.preheader.new ], [ %indvars.iv.next.7, %.lr.ph.us ]
  %niter = phi i64 [ 0, %.lr.ph.us.preheader.new ], [ %niter.next.7, %.lr.ph.us ]
  %9 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 8 %10, i8 0, i64 %7, i1 false), !tbaa !9
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %11 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 8 %12, i8 0, i64 %7, i1 false), !tbaa !9
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %13 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next.1
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 8 %14, i8 0, i64 %7, i1 false), !tbaa !9
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %15 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next.2
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 8 %16, i8 0, i64 %7, i1 false), !tbaa !9
  %indvars.iv.next.3 = or disjoint i64 %indvars.iv, 4
  %17 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next.3
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 8 %18, i8 0, i64 %7, i1 false), !tbaa !9
  %indvars.iv.next.4 = or disjoint i64 %indvars.iv, 5
  %19 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next.4
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 8 %20, i8 0, i64 %7, i1 false), !tbaa !9
  %indvars.iv.next.5 = or disjoint i64 %indvars.iv, 6
  %21 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next.5
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 8 %22, i8 0, i64 %7, i1 false), !tbaa !9
  %indvars.iv.next.6 = or disjoint i64 %indvars.iv, 7
  %23 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next.6
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 8 %24, i8 0, i64 %7, i1 false), !tbaa !9
  %indvars.iv.next.7 = add nuw nsw i64 %indvars.iv, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge14.loopexit.unr-lcssa, label %.lr.ph.us, !llvm.loop !11

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

.lr.ph.us.epil:                                   ; preds = %._crit_edge14.loopexit.unr-lcssa, %.lr.ph.us.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.us.epil ], [ %indvars.iv.unr, %._crit_edge14.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.us.epil ], [ 0, %._crit_edge14.loopexit.unr-lcssa ]
  %25 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.epil
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 8 %26, i8 0, i64 %7, i1 false), !tbaa !9
  %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 %._crit_edge14, label %.lr.ph.us.epil, !llvm.loop !13

._crit_edge14:                                    ; preds = %._crit_edge14.loopexit.unr-lcssa, %.lr.ph.us.epil, %3
  ret void
}

; 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 = { nofree norecurse nosync nounwind memory(write, 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass