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

; 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_LapackBand = type { i64, ptr, i64 }

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

declare i32 @SUNMatGetID(ptr noundef) #1

declare i64 @SUNBandMatrix_Rows(ptr noundef) #1

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

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14, %2
  store i32 -801, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %56

18:                                               ; preds = %14
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i32 @SUNMatGetID(ptr noundef %19)
  %21 = icmp ne i32 %20, 3
  br i1 %21, label %22, label %27

22:                                               ; preds = %18
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._generic_SUNLinearSolver, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct._SUNLinearSolverContent_LapackBand, ptr %25, i32 0, i32 2
  store i64 -802, ptr %26, align 8, !tbaa !11
  store i32 -802, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %56

27:                                               ; preds = %18
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call i64 @SUNBandMatrix_Rows(ptr noundef %28)
  store i64 %29, ptr %6, align 8, !tbaa !14
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call i64 @SUNBandMatrix_LowerBandwidth(ptr noundef %30)
  store i64 %31, ptr %7, align 8, !tbaa !14
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = call i64 @SUNBandMatrix_UpperBandwidth(ptr noundef %32)
  store i64 %33, ptr %8, align 8, !tbaa !14
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = call i64 @SUNBandMatrix_LDim(ptr noundef %34)
  store i64 %35, ptr %9, align 8, !tbaa !14
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call ptr @SUNBandMatrix_Data(ptr noundef %36)
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._generic_SUNLinearSolver, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct._SUNLinearSolverContent_LapackBand, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  call void @dgbtrf_(ptr noundef %6, ptr noundef %6, ptr noundef %7, ptr noundef %8, ptr noundef %37, ptr noundef %9, ptr noundef %42, ptr noundef %10)
  %43 = load i64, ptr %10, align 8, !tbaa !14
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._generic_SUNLinearSolver, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct._SUNLinearSolverContent_LapackBand, ptr %46, i32 0, i32 2
  store i64 %43, ptr %47, align 8, !tbaa !11
  %48 = load i64, ptr %10, align 8, !tbaa !14
  %49 = icmp sgt i64 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %27
  store i32 808, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %56

51:                                               ; preds = %27
  %52 = load i64, ptr %10, align 8, !tbaa !14
  %53 = icmp slt i64 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %51
  store i32 -809, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %56

55:                                               ; preds = %51
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %56

56:                                               ; preds = %55, %54, %50, %22, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %57 = load i32, ptr %3, align 4
  ret i32 %57
}

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

declare i64 @SUNBandMatrix_LowerBandwidth(ptr noundef) #1

declare i64 @SUNBandMatrix_UpperBandwidth(ptr noundef) #1

declare i64 @SUNBandMatrix_LDim(ptr noundef) #1

declare void @dgbtrf_(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare ptr @SUNBandMatrix_Data(ptr noundef) #1

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

!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, !6, i64 0}
!10 = !{!"_generic_SUNLinearSolver", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!12, !13, i64 16}
!12 = !{!"_SUNLinearSolverContent_LapackBand", !13, i64 0, !6, i64 8, !13, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !6, i64 8}


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

declare i32 @SUNMatGetID(ptr noundef) local_unnamed_addr #1

declare i64 @SUNBandMatrix_Rows(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -809, 809) i32 @SUNLinSolSetup_LapackBand(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  %8 = icmp eq ptr %1, null
  %9 = icmp eq ptr %0, null
  %or.cond = or i1 %9, %8
  br i1 %or.cond, label %29, label %10

10:                                               ; preds = %2
  %11 = tail call i32 @SUNMatGetID(ptr noundef nonnull %1) #3
  %.not = icmp eq i32 %11, 3
  br i1 %.not, label %15, label %12

12:                                               ; preds = %10
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  store i64 -802, ptr %14, align 8, !tbaa !10
  br label %29

15:                                               ; preds = %10
  %16 = tail call i64 @SUNBandMatrix_Rows(ptr noundef nonnull %1) #3
  store i64 %16, ptr %3, align 8, !tbaa !13
  %17 = tail call i64 @SUNBandMatrix_LowerBandwidth(ptr noundef nonnull %1) #3
  store i64 %17, ptr %4, align 8, !tbaa !13
  %18 = tail call i64 @SUNBandMatrix_UpperBandwidth(ptr noundef nonnull %1) #3
  store i64 %18, ptr %5, align 8, !tbaa !13
  %19 = tail call i64 @SUNBandMatrix_LDim(ptr noundef nonnull %1) #3
  store i64 %19, ptr %6, align 8, !tbaa !13
  %20 = tail call ptr @SUNBandMatrix_Data(ptr noundef nonnull %1) #3
  %21 = load ptr, ptr %0, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  call void @dgbtrf_(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef %20, ptr noundef nonnull %6, ptr noundef %23, ptr noundef nonnull %7) #3
  %24 = load i64, ptr %7, align 8, !tbaa !13
  %25 = load ptr, ptr %0, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  store i64 %24, ptr %26, align 8, !tbaa !10
  %27 = icmp sgt i64 %24, 0
  br i1 %27, label %29, label %28

28:                                               ; preds = %15
  %.not15 = icmp eq i64 %24, 0
  %. = select i1 %.not15, i32 0, i32 -809
  br label %29

29:                                               ; preds = %28, %15, %2, %12
  %.0 = phi i32 [ -802, %12 ], [ -801, %2 ], [ 808, %15 ], [ %., %28 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i32 %.0
}

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

declare i64 @SUNBandMatrix_LowerBandwidth(ptr noundef) local_unnamed_addr #1

declare i64 @SUNBandMatrix_UpperBandwidth(ptr noundef) local_unnamed_addr #1

declare i64 @SUNBandMatrix_LDim(ptr noundef) local_unnamed_addr #1

declare void @dgbtrf_(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @SUNBandMatrix_Data(ptr noundef) local_unnamed_addr #1

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

!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, !12, i64 16}
!11 = !{!"_SUNLinearSolverContent_LapackBand", !12, i64 0, !7, i64 8, !12, i64 16}
!12 = !{!"long", !8, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!11, !7, i64 8}


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