; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @NewBandMat(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %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 i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = icmp sle i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %111

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

21:                                               ; preds = %17
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %111

22:                                               ; preds = %17
  %23 = load i32, ptr %9, align 4, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = add nsw i32 %23, %24
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %12, align 4, !tbaa !5
  %27 = load ptr, ptr %10, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct._DlsMat, ptr %27, i32 0, i32 7
  store ptr null, ptr %28, align 8, !tbaa !11
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = load i32, ptr %12, align 4, !tbaa !5
  %31 = mul nsw i32 %29, %30
  %32 = sext i32 %31 to i64
  %33 = mul i64 %32, 8
  %34 = call noalias ptr @malloc(i64 noundef %33) #5
  %35 = load ptr, ptr %10, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct._DlsMat, ptr %35, i32 0, i32 7
  store ptr %34, ptr %36, align 8, !tbaa !11
  %37 = load ptr, ptr %10, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct._DlsMat, ptr %37, i32 0, i32 7
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %43

41:                                               ; preds = %22
  %42 = load ptr, ptr %10, align 8, !tbaa !9
  call void @free(ptr noundef %42) #4
  store ptr null, ptr %10, align 8, !tbaa !9
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %111

43:                                               ; preds = %22
  %44 = load ptr, ptr %10, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct._DlsMat, ptr %44, i32 0, i32 9
  store ptr null, ptr %45, align 8, !tbaa !13
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = mul i64 %47, 8
  %49 = call noalias ptr @malloc(i64 noundef %48) #5
  %50 = load ptr, ptr %10, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct._DlsMat, ptr %50, i32 0, i32 9
  store ptr %49, ptr %51, align 8, !tbaa !13
  %52 = load ptr, ptr %10, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct._DlsMat, ptr %52, i32 0, i32 9
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  %55 = icmp eq ptr %54, null
  br i1 %55, label %56, label %61

56:                                               ; preds = %43
  %57 = load ptr, ptr %10, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct._DlsMat, ptr %57, i32 0, i32 7
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  call void @free(ptr noundef %59) #4
  %60 = load ptr, ptr %10, align 8, !tbaa !9
  call void @free(ptr noundef %60) #4
  store ptr null, ptr %10, align 8, !tbaa !9
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %111

61:                                               ; preds = %43
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %81, %61
  %63 = load i32, ptr %11, align 4, !tbaa !5
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = icmp slt i32 %63, %64
  br i1 %65, label %66, label %84

66:                                               ; preds = %62
  %67 = load ptr, ptr %10, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct._DlsMat, ptr %67, i32 0, i32 7
  %69 = load ptr, ptr %68, align 8, !tbaa !11
  %70 = load i32, ptr %11, align 4, !tbaa !5
  %71 = load i32, ptr %12, align 4, !tbaa !5
  %72 = mul nsw i32 %70, %71
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds double, ptr %69, i64 %73
  %75 = load ptr, ptr %10, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct._DlsMat, ptr %75, i32 0, i32 9
  %77 = load ptr, ptr %76, align 8, !tbaa !13
  %78 = load i32, ptr %11, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds ptr, ptr %77, i64 %79
  store ptr %74, ptr %80, align 8, !tbaa !9
  br label %81

81:                                               ; preds = %66
  %82 = load i32, ptr %11, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %11, align 4, !tbaa !5
  br label %62, !llvm.loop !14

84:                                               ; preds = %62
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = load ptr, ptr %10, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct._DlsMat, ptr %86, i32 0, i32 1
  store i32 %85, ptr %87, align 4, !tbaa !16
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = load ptr, ptr %10, align 8, !tbaa !9
  %90 = getelementptr inbounds %struct._DlsMat, ptr %89, i32 0, i32 2
  store i32 %88, ptr %90, align 8, !tbaa !17
  %91 = load i32, ptr %7, align 4, !tbaa !5
  %92 = load ptr, ptr %10, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct._DlsMat, ptr %92, i32 0, i32 4
  store i32 %91, ptr %93, align 8, !tbaa !18
  %94 = load i32, ptr %8, align 4, !tbaa !5
  %95 = load ptr, ptr %10, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct._DlsMat, ptr %95, i32 0, i32 5
  store i32 %94, ptr %96, align 4, !tbaa !19
  %97 = load i32, ptr %9, align 4, !tbaa !5
  %98 = load ptr, ptr %10, align 8, !tbaa !9
  %99 = getelementptr inbounds %struct._DlsMat, ptr %98, i32 0, i32 6
  store i32 %97, ptr %99, align 8, !tbaa !20
  %100 = load i32, ptr %12, align 4, !tbaa !5
  %101 = load ptr, ptr %10, align 8, !tbaa !9
  %102 = getelementptr inbounds %struct._DlsMat, ptr %101, i32 0, i32 3
  store i32 %100, ptr %102, align 4, !tbaa !21
  %103 = load i32, ptr %6, align 4, !tbaa !5
  %104 = load i32, ptr %12, align 4, !tbaa !5
  %105 = mul nsw i32 %103, %104
  %106 = load ptr, ptr %10, align 8, !tbaa !9
  %107 = getelementptr inbounds %struct._DlsMat, ptr %106, i32 0, i32 8
  store i32 %105, ptr %107, align 8, !tbaa !22
  %108 = load ptr, ptr %10, align 8, !tbaa !9
  %109 = getelementptr inbounds %struct._DlsMat, ptr %108, i32 0, i32 0
  store i32 2, ptr %109, align 8, !tbaa !23
  %110 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %110, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %111

111:                                              ; preds = %84, %56, %41, %21, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %112 = load ptr, ptr %5, align 8
  ret ptr %112
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 #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 16}
!19 = !{!12, !6, i64 20}
!20 = !{!12, !6, i64 24}
!21 = !{!12, !6, i64 12}
!22 = !{!12, !6, i64 40}
!23 = !{!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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind memory(readwrite, argmem: none) uwtable
define dso_local noalias noundef ptr @NewBandMat(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = icmp slt i32 %0, 1
  br i1 %5, label %50, label %6

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

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

18:                                               ; preds = %9
  tail call void @free(ptr noundef nonnull %7) #4
  br label %50

19:                                               ; preds = %9
  %20 = getelementptr inbounds i8, ptr %7, i64 48
  %21 = zext nneg i32 %0 to i64
  %22 = shl nuw nsw i64 %21, 3
  %23 = tail call noalias ptr @malloc(i64 noundef %22) #3
  store ptr %23, ptr %20, align 8, !tbaa !11
  %24 = icmp eq ptr %23, null
  br i1 %24, label %27, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %19
  %25 = sext i32 %11 to i64
  %xtraiter = and i64 %21, 3
  %26 = icmp ult i32 %0, 4
  br i1 %26, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

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

27:                                               ; preds = %19
  tail call void @free(ptr noundef nonnull %16) #4
  tail call void @free(ptr noundef nonnull %7) #4
  br label %50

.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 ]
  %28 = mul nsw i64 %indvars.iv, %25
  %29 = getelementptr inbounds double, ptr %16, i64 %28
  %30 = getelementptr inbounds ptr, ptr %23, i64 %indvars.iv
  store ptr %29, ptr %30, align 8, !tbaa !12
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %31 = mul nsw i64 %indvars.iv.next, %25
  %32 = getelementptr inbounds double, ptr %16, i64 %31
  %33 = getelementptr inbounds ptr, ptr %23, i64 %indvars.iv.next
  store ptr %32, ptr %33, align 8, !tbaa !12
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %34 = mul nsw i64 %indvars.iv.next.1, %25
  %35 = getelementptr inbounds double, ptr %16, i64 %34
  %36 = getelementptr inbounds ptr, ptr %23, i64 %indvars.iv.next.1
  store ptr %35, ptr %36, align 8, !tbaa !12
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %37 = mul nsw i64 %indvars.iv.next.2, %25
  %38 = getelementptr inbounds double, ptr %16, i64 %37
  %39 = getelementptr inbounds ptr, ptr %23, i64 %indvars.iv.next.2
  store ptr %38, ptr %39, 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 ]
  %40 = mul nsw i64 %indvars.iv.epil, %25
  %41 = getelementptr inbounds double, ptr %16, i64 %40
  %42 = getelementptr inbounds ptr, ptr %23, i64 %indvars.iv.epil
  store ptr %41, ptr %42, 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
  %43 = getelementptr inbounds i8, ptr %7, i64 4
  store i32 %0, ptr %43, align 4, !tbaa !17
  %44 = getelementptr inbounds i8, ptr %7, i64 8
  store i32 %0, ptr %44, align 8, !tbaa !18
  %45 = getelementptr inbounds i8, ptr %7, i64 16
  store i32 %1, ptr %45, align 8, !tbaa !19
  %46 = getelementptr inbounds i8, ptr %7, i64 20
  store i32 %2, ptr %46, align 4, !tbaa !20
  %47 = getelementptr inbounds i8, ptr %7, i64 24
  store i32 %3, ptr %47, align 8, !tbaa !21
  %48 = getelementptr inbounds i8, ptr %7, i64 12
  store i32 %11, ptr %48, align 4, !tbaa !22
  %49 = getelementptr inbounds i8, ptr %7, i64 40
  store i32 %13, ptr %49, align 8, !tbaa !23
  store i32 2, ptr %7, align 8, !tbaa !24
  br label %50

50:                                               ; preds = %6, %4, %._crit_edge, %27, %18
  %.0 = phi ptr [ null, %18 ], [ null, %27 ], [ %7, %._crit_edge ], [ null, %4 ], [ null, %6 ]
  ret ptr %.0
}

attributes #0 = { 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 #1 = { 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 #2 = { 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 #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 16}
!20 = !{!6, !7, i64 20}
!21 = !{!6, !7, i64 24}
!22 = !{!6, !7, i64 12}
!23 = !{!6, !7, i64 40}
!24 = !{!6, !7, i64 0}


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