; LLVM IR from stan-dev/math :: lib/sundials_6.1.1/src/sunlinsol/band (sunlinsol_band)

; 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._generic_SUNLinearSolver = type { ptr, ptr, ptr }
%struct._SUNLinearSolverContent_Band = type { i64, ptr, i64 }
%struct._generic_SUNMatrix = type { ptr, ptr, ptr }
%struct._SUNMatrixContent_Band = type { i64, i64, i64, i64, i64, i64, ptr, i64, 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 uwtable
define dso_local i32 @SUNLinSolSolve_Band(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, double noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store double %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %27, label %18

18:                                               ; preds = %5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %27, label %21

21:                                               ; preds = %18
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %27, label %24

24:                                               ; preds = %21
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %24, %21, %18, %5
  store i32 -801, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %76

28:                                               ; preds = %24
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  call void @N_VScale(double noundef 1.000000e+00, ptr noundef %29, ptr noundef %30)
  store ptr null, ptr %12, align 8, !tbaa !5
  store ptr null, ptr %13, align 8, !tbaa !5
  store ptr null, ptr %14, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = call ptr @SUNBandMatrix_Cols(ptr noundef %31)
  store ptr %32, ptr %12, align 8, !tbaa !5
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = call ptr @N_VGetArrayPointer(ptr noundef %33)
  store ptr %34, ptr %13, align 8, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._generic_SUNLinearSolver, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct._SUNLinearSolverContent_Band, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  store ptr %39, ptr %14, align 8, !tbaa !5
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %48, label %42

42:                                               ; preds = %28
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = icmp eq ptr %43, null
  br i1 %44, label %48, label %45

45:                                               ; preds = %42
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  %47 = icmp eq ptr %46, null
  br i1 %47, label %48, label %53

48:                                               ; preds = %45, %42, %28
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._generic_SUNLinearSolver, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  %52 = getelementptr inbounds %struct._SUNLinearSolverContent_Band, ptr %51, i32 0, i32 2
  store i64 -803, ptr %52, align 8, !tbaa !16
  store i32 -803, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %76

53:                                               ; preds = %45
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  %58 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !19
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !17
  %63 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %62, i32 0, i32 5
  %64 = load i64, ptr %63, align 8, !tbaa !21
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !17
  %68 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %67, i32 0, i32 4
  %69 = load i64, ptr %68, align 8, !tbaa !22
  %70 = load ptr, ptr %14, align 8, !tbaa !5
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  call void @SUNDlsMat_bandGBTRS(ptr noundef %54, i64 noundef %59, i64 noundef %64, i64 noundef %69, ptr noundef %70, ptr noundef %71)
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._generic_SUNLinearSolver, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  %75 = getelementptr inbounds %struct._SUNLinearSolverContent_Band, ptr %74, i32 0, i32 2
  store i64 0, ptr %75, align 8, !tbaa !16
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %76

76:                                               ; preds = %53, %48, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %77 = load i32, ptr %6, align 4
  ret i32 %77
}

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

declare void @N_VScale(double noundef, ptr noundef, ptr noundef) #2

declare ptr @SUNBandMatrix_Cols(ptr noundef) #2

declare ptr @N_VGetArrayPointer(ptr noundef) #2

declare void @SUNDlsMat_bandGBTRS(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) #2

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

!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 = !{!12, !6, i64 0}
!12 = !{!"_generic_SUNLinearSolver", !6, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!14, !6, i64 8}
!14 = !{!"_SUNLinearSolverContent_Band", !15, i64 0, !6, i64 8, !15, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !15, i64 16}
!17 = !{!18, !6, i64 0}
!18 = !{!"_generic_SUNMatrix", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!20, !15, i64 8}
!20 = !{!"_SUNMatrixContent_Band", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !15, i64 32, !15, i64 40, !6, i64 48, !15, i64 56, !6, i64 64}
!21 = !{!20, !15, i64 40}
!22 = !{!20, !15, i64 32}


; 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 uwtable
define dso_local range(i32 -803, 1) i32 @SUNLinSolSolve_Band(ptr noundef readonly %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, double noundef %4) local_unnamed_addr #0 {
  %6 = insertelement <4 x ptr> poison, ptr %0, i64 0
  %7 = insertelement <4 x ptr> %6, ptr %1, i64 1
  %8 = insertelement <4 x ptr> %7, ptr %2, i64 2
  %9 = insertelement <4 x ptr> %8, ptr %3, i64 3
  %10 = icmp eq <4 x ptr> %9, zeroinitializer
  %11 = bitcast <4 x i1> %10 to i4
  %.not = icmp eq i4 %11, 0
  br i1 %.not, label %12, label %31

12:                                               ; preds = %5
  tail call void @N_VScale(double noundef 1.000000e+00, ptr noundef nonnull %3, ptr noundef nonnull %2) #2
  %13 = tail call ptr @SUNBandMatrix_Cols(ptr noundef nonnull %1) #2
  %14 = tail call ptr @N_VGetArrayPointer(ptr noundef nonnull %2) #2
  %15 = load ptr, ptr %0, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !10
  %18 = icmp eq ptr %13, null
  %19 = icmp eq ptr %14, null
  %or.cond7 = select i1 %18, i1 true, i1 %19
  %20 = icmp eq ptr %17, null
  %or.cond9 = select i1 %or.cond7, i1 true, i1 %20
  br i1 %or.cond9, label %.sink.split, label %21

21:                                               ; preds = %12
  %22 = load ptr, ptr %1, align 8, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %22, i64 40
  %26 = load i64, ptr %25, align 8, !tbaa !17
  %27 = getelementptr inbounds i8, ptr %22, i64 32
  %28 = load i64, ptr %27, align 8, !tbaa !18
  tail call void @SUNDlsMat_bandGBTRS(ptr noundef nonnull %13, i64 noundef %24, i64 noundef %26, i64 noundef %28, ptr noundef nonnull %17, ptr noundef nonnull %14) #2
  %29 = load ptr, ptr %0, align 8, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %12, %21
  %.sink37 = phi ptr [ %29, %21 ], [ %15, %12 ]
  %.sink = phi i64 [ 0, %21 ], [ -803, %12 ]
  %.0.ph = phi i32 [ 0, %21 ], [ -803, %12 ]
  %30 = getelementptr inbounds i8, ptr %.sink37, i64 16
  store i64 %.sink, ptr %30, align 8, !tbaa !19
  br label %31

31:                                               ; preds = %.sink.split, %5
  %.0 = phi i32 [ -801, %5 ], [ %.0.ph, %.sink.split ]
  ret i32 %.0
}

declare void @N_VScale(double noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @SUNBandMatrix_Cols(ptr noundef) local_unnamed_addr #1

declare ptr @N_VGetArrayPointer(ptr noundef) local_unnamed_addr #1

declare void @SUNDlsMat_bandGBTRS(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 = { "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, !7, i64 0}
!6 = !{!"_generic_SUNLinearSolver", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 8}
!11 = !{!"_SUNLinearSolverContent_Band", !12, i64 0, !7, i64 8, !12, i64 16}
!12 = !{!"long", !8, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"_generic_SUNMatrix", !7, i64 0, !7, i64 8, !7, i64 16}
!15 = !{!16, !12, i64 8}
!16 = !{!"_SUNMatrixContent_Band", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !7, i64 48, !12, i64 56, !7, i64 64}
!17 = !{!16, !12, i64 40}
!18 = !{!16, !12, i64 32}
!19 = !{!11, !12, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass