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

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

%struct._DlsMat = type { i32, i32, i32, i32, i32, i32, i32, ptr, i32, ptr }

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

11:                                               ; preds = %2
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = icmp sle i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %94

15:                                               ; preds = %11
  store ptr null, ptr %6, align 8, !tbaa !9
  %16 = call noalias ptr @malloc(i64 noundef 56) #5
  store ptr %16, ptr %6, align 8, !tbaa !9
  %17 = load ptr, ptr %6, align 8, !tbaa !9
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %94

20:                                               ; preds = %15
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = mul nsw i32 %21, %22
  %24 = sext i32 %23 to i64
  %25 = mul i64 %24, 8
  %26 = call noalias ptr @malloc(i64 noundef %25) #5
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct._DlsMat, ptr %27, i32 0, i32 7
  store ptr %26, ptr %28, align 8, !tbaa !11
  %29 = load ptr, ptr %6, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct._DlsMat, ptr %29, i32 0, i32 7
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %35

33:                                               ; preds = %20
  %34 = load ptr, ptr %6, align 8, !tbaa !9
  call void @free(ptr noundef %34) #4
  store ptr null, ptr %6, align 8, !tbaa !9
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %94

35:                                               ; preds = %20
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = mul i64 %37, 8
  %39 = call noalias ptr @malloc(i64 noundef %38) #5
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct._DlsMat, ptr %40, i32 0, i32 9
  store ptr %39, ptr %41, align 8, !tbaa !13
  %42 = load ptr, ptr %6, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct._DlsMat, ptr %42, i32 0, i32 9
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  %45 = icmp eq ptr %44, null
  br i1 %45, label %46, label %53

46:                                               ; preds = %35
  %47 = load ptr, ptr %6, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct._DlsMat, ptr %47, i32 0, i32 7
  %49 = load ptr, ptr %48, align 8, !tbaa !11
  call void @free(ptr noundef %49) #4
  %50 = load ptr, ptr %6, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct._DlsMat, ptr %50, i32 0, i32 7
  store ptr null, ptr %51, align 8, !tbaa !11
  %52 = load ptr, ptr %6, align 8, !tbaa !9
  call void @free(ptr noundef %52) #4
  store ptr null, ptr %6, align 8, !tbaa !9
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %94

53:                                               ; preds = %35
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %73, %53
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = icmp slt i32 %55, %56
  br i1 %57, label %58, label %76

58:                                               ; preds = %54
  %59 = load ptr, ptr %6, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct._DlsMat, ptr %59, i32 0, i32 7
  %61 = load ptr, ptr %60, align 8, !tbaa !11
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = mul nsw i32 %62, %63
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds double, ptr %61, i64 %65
  %67 = load ptr, ptr %6, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct._DlsMat, ptr %67, i32 0, i32 9
  %69 = load ptr, ptr %68, align 8, !tbaa !13
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds ptr, ptr %69, i64 %71
  store ptr %66, ptr %72, align 8, !tbaa !9
  br label %73

73:                                               ; preds = %58
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %7, align 4, !tbaa !5
  br label %54, !llvm.loop !14

76:                                               ; preds = %54
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct._DlsMat, ptr %78, i32 0, i32 1
  store i32 %77, ptr %79, align 4, !tbaa !16
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = load ptr, ptr %6, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct._DlsMat, ptr %81, i32 0, i32 2
  store i32 %80, ptr %82, align 8, !tbaa !17
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = load ptr, ptr %6, align 8, !tbaa !9
  %85 = getelementptr inbounds %struct._DlsMat, ptr %84, i32 0, i32 3
  store i32 %83, ptr %85, align 4, !tbaa !18
  %86 = load i32, ptr %4, align 4, !tbaa !5
  %87 = load i32, ptr %5, align 4, !tbaa !5
  %88 = mul nsw i32 %86, %87
  %89 = load ptr, ptr %6, align 8, !tbaa !9
  %90 = getelementptr inbounds %struct._DlsMat, ptr %89, i32 0, i32 8
  store i32 %88, ptr %90, align 8, !tbaa !19
  %91 = load ptr, ptr %6, align 8, !tbaa !9
  %92 = getelementptr inbounds %struct._DlsMat, ptr %91, i32 0, i32 0
  store i32 1, ptr %92, align 8, !tbaa !20
  %93 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %93, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %94

94:                                               ; preds = %76, %46, %33, %19, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %95 = load ptr, ptr %3, align 8
  ret ptr %95
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; 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 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 #3 = { 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 #4 = { nounwind }
attributes #5 = { nounwind 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"_DlsMat", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !10, i64 32, !6, i64 40, !10, i64 48}
!13 = !{!12, !10, i64 48}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!12, !6, i64 4}
!17 = !{!12, !6, i64 8}
!18 = !{!12, !6, i64 12}
!19 = !{!12, !6, i64 40}
!20 = !{!12, !6, i64 0}


; 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: nounwind memory(readwrite, argmem: none) uwtable
define dso_local noalias noundef ptr @NewDenseMat(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp slt i32 %0, 1
  %4 = icmp slt i32 %1, 1
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %45, label %5

5:                                                ; preds = %2
  %6 = tail call noalias dereferenceable_or_null(56) ptr @malloc(i64 noundef 56) #3
  %7 = icmp eq ptr %6, null
  br i1 %7, label %45, label %8

8:                                                ; preds = %5
  %9 = mul nuw nsw i32 %1, %0
  %10 = zext nneg i32 %9 to i64
  %11 = shl nuw nsw i64 %10, 3
  %12 = tail call noalias ptr @malloc(i64 noundef %11) #3
  %13 = getelementptr inbounds i8, ptr %6, i64 32
  store ptr %12, ptr %13, align 8, !tbaa !5
  %14 = icmp eq ptr %12, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %8
  tail call void @free(ptr noundef nonnull %6) #4
  br label %45

16:                                               ; preds = %8
  %17 = zext nneg i32 %1 to i64
  %18 = shl nuw nsw i64 %17, 3
  %19 = tail call noalias ptr @malloc(i64 noundef %18) #3
  %20 = getelementptr inbounds i8, ptr %6, i64 48
  store ptr %19, ptr %20, align 8, !tbaa !11
  %21 = icmp eq ptr %19, null
  br i1 %21, label %25, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %16
  %22 = zext nneg i32 %0 to i64
  %23 = add nsw i64 %17, -1
  %xtraiter = and i64 %17, 3
  %24 = icmp ult i64 %23, 3
  br i1 %24, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %17, 2147483644
  br label %.lr.ph

25:                                               ; preds = %16
  tail call void @free(ptr noundef nonnull %12) #4
  tail call void @free(ptr noundef nonnull %6) #4
  br label %45

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %26 = mul nuw nsw i64 %indvars.iv, %22
  %27 = getelementptr inbounds double, ptr %12, i64 %26
  %28 = getelementptr inbounds ptr, ptr %19, i64 %indvars.iv
  store ptr %27, ptr %28, align 8, !tbaa !12
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %29 = mul nuw nsw i64 %indvars.iv.next, %22
  %30 = getelementptr inbounds double, ptr %12, i64 %29
  %31 = getelementptr inbounds ptr, ptr %19, i64 %indvars.iv.next
  store ptr %30, ptr %31, align 8, !tbaa !12
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %32 = mul nuw nsw i64 %indvars.iv.next.1, %22
  %33 = getelementptr inbounds double, ptr %12, i64 %32
  %34 = getelementptr inbounds ptr, ptr %19, i64 %indvars.iv.next.1
  store ptr %33, ptr %34, align 8, !tbaa !12
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %35 = mul nuw nsw i64 %indvars.iv.next.2, %22
  %36 = getelementptr inbounds double, ptr %12, i64 %35
  %37 = getelementptr inbounds ptr, ptr %19, i64 %indvars.iv.next.2
  store ptr %36, ptr %37, align 8, !tbaa !12
  %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 %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !13

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

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.unr-lcssa ]
  %38 = mul nuw nsw i64 %indvars.iv.epil, %22
  %39 = getelementptr inbounds double, ptr %12, i64 %38
  %40 = getelementptr inbounds ptr, ptr %19, i64 %indvars.iv.epil
  store ptr %39, ptr %40, align 8, !tbaa !12
  %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_edge, label %.lr.ph.epil, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.unr-lcssa
  %41 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %0, ptr %41, align 4, !tbaa !17
  %42 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 %1, ptr %42, align 8, !tbaa !18
  %43 = getelementptr inbounds i8, ptr %6, i64 12
  store i32 %0, ptr %43, align 4, !tbaa !19
  %44 = getelementptr inbounds i8, ptr %6, i64 40
  store i32 %9, ptr %44, align 8, !tbaa !20
  store i32 1, ptr %6, align 8, !tbaa !21
  br label %45

45:                                               ; preds = %5, %2, %._crit_edge, %25, %15
  %.034 = phi ptr [ null, %15 ], [ null, %25 ], [ %6, %._crit_edge ], [ null, %2 ], [ null, %5 ]
  ret ptr %.034
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { nounwind memory(readwrite, argmem: 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind allocsize(0) }
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, !10, i64 32}
!6 = !{!"_DlsMat", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !10, i64 32, !7, i64 40, !10, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 48}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = !{!6, !7, i64 4}
!18 = !{!6, !7, i64 8}
!19 = !{!6, !7, i64 12}
!20 = !{!6, !7, i64 40}
!21 = !{!6, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass