; 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

declare i32 @SUNMatGetID(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @SUNLinSolSetup_Band(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = 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
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %14, label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

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

15:                                               ; preds = %11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call i32 @SUNMatGetID(ptr noundef %16)
  %18 = icmp ne i32 %17, 3
  br i1 %18, label %19, label %24

19:                                               ; preds = %15
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._generic_SUNLinearSolver, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct._SUNLinearSolverContent_Band, ptr %22, i32 0, i32 2
  store i64 -802, ptr %23, align 8, !tbaa !11
  store i32 -802, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %132

24:                                               ; preds = %15
  store ptr null, ptr %6, align 8, !tbaa !5
  store ptr null, ptr %7, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %27, i32 0, i32 8
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  store ptr %29, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._generic_SUNLinearSolver, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct._SUNLinearSolverContent_Band, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !18
  store ptr %34, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = icmp eq ptr %35, null
  br i1 %36, label %40, label %37

37:                                               ; preds = %24
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %45

40:                                               ; preds = %37, %24
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._generic_SUNLinearSolver, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct._SUNLinearSolverContent_Band, ptr %43, i32 0, i32 2
  store i64 -803, ptr %44, align 8, !tbaa !11
  store i32 -803, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %132

45:                                               ; preds = %37
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  %49 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %48, i32 0, i32 5
  %50 = load i64, ptr %49, align 8, !tbaa !19
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %53, i32 0, i32 1
  %55 = load i64, ptr %54, align 8, !tbaa !20
  %56 = sub nsw i64 %55, 1
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !14
  %60 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %59, i32 0, i32 3
  %61 = load i64, ptr %60, align 8, !tbaa !21
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !14
  %65 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %64, i32 0, i32 4
  %66 = load i64, ptr %65, align 8, !tbaa !22
  %67 = add nsw i64 %61, %66
  %68 = icmp slt i64 %56, %67
  br i1 %68, label %69, label %76

69:                                               ; preds = %45
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !14
  %73 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %72, i32 0, i32 1
  %74 = load i64, ptr %73, align 8, !tbaa !20
  %75 = sub nsw i64 %74, 1
  br label %88

76:                                               ; preds = %45
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !14
  %80 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %79, i32 0, i32 3
  %81 = load i64, ptr %80, align 8, !tbaa !21
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !14
  %85 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %84, i32 0, i32 4
  %86 = load i64, ptr %85, align 8, !tbaa !22
  %87 = add nsw i64 %81, %86
  br label %88

88:                                               ; preds = %76, %69
  %89 = phi i64 [ %75, %69 ], [ %87, %76 ]
  %90 = icmp slt i64 %50, %89
  br i1 %90, label %91, label %96

91:                                               ; preds = %88
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct._generic_SUNLinearSolver, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !9
  %95 = getelementptr inbounds %struct._SUNLinearSolverContent_Band, ptr %94, i32 0, i32 2
  store i64 -803, ptr %95, align 8, !tbaa !11
  store i32 -803, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %132

96:                                               ; preds = %88
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %98, i32 0, i32 0
  %100 = load ptr, ptr %99, align 8, !tbaa !14
  %101 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %100, i32 0, i32 1
  %102 = load i64, ptr %101, align 8, !tbaa !20
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %103, i32 0, i32 0
  %105 = load ptr, ptr %104, align 8, !tbaa !14
  %106 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %105, i32 0, i32 3
  %107 = load i64, ptr %106, align 8, !tbaa !21
  %108 = load ptr, ptr %5, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %108, i32 0, i32 0
  %110 = load ptr, ptr %109, align 8, !tbaa !14
  %111 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %110, i32 0, i32 4
  %112 = load i64, ptr %111, align 8, !tbaa !22
  %113 = load ptr, ptr %5, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct._generic_SUNMatrix, ptr %113, i32 0, i32 0
  %115 = load ptr, ptr %114, align 8, !tbaa !14
  %116 = getelementptr inbounds %struct._SUNMatrixContent_Band, ptr %115, i32 0, i32 5
  %117 = load i64, ptr %116, align 8, !tbaa !19
  %118 = load ptr, ptr %7, align 8, !tbaa !5
  %119 = call i64 @SUNDlsMat_bandGBTRF(ptr noundef %97, i64 noundef %102, i64 noundef %107, i64 noundef %112, i64 noundef %117, ptr noundef %118)
  %120 = load ptr, ptr %4, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct._generic_SUNLinearSolver, ptr %120, i32 0, i32 0
  %122 = load ptr, ptr %121, align 8, !tbaa !9
  %123 = getelementptr inbounds %struct._SUNLinearSolverContent_Band, ptr %122, i32 0, i32 2
  store i64 %119, ptr %123, align 8, !tbaa !11
  %124 = load ptr, ptr %4, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct._generic_SUNLinearSolver, ptr %124, i32 0, i32 0
  %126 = load ptr, ptr %125, align 8, !tbaa !9
  %127 = getelementptr inbounds %struct._SUNLinearSolverContent_Band, ptr %126, i32 0, i32 2
  %128 = load i64, ptr %127, align 8, !tbaa !11
  %129 = icmp sgt i64 %128, 0
  br i1 %129, label %130, label %131

130:                                              ; preds = %96
  store i32 808, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %132

131:                                              ; preds = %96
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %132

132:                                              ; preds = %131, %130, %91, %40, %19, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %133 = load i32, ptr %3, align 4
  ret i32 %133
}

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

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

declare i32 @SUNMatGetID(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -803, 809) i32 @SUNLinSolSetup_Band(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %1, null
  %4 = icmp eq ptr %0, null
  %or.cond = or i1 %4, %3
  br i1 %or.cond, label %41, label %5

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

7:                                                ; preds = %5
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  store i64 -802, ptr %9, align 8, !tbaa !10
  br label %41

10:                                               ; preds = %5
  %11 = load ptr, ptr %1, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %11, i64 64
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = load ptr, ptr %0, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  %17 = icmp eq ptr %13, null
  %18 = icmp eq ptr %16, null
  %or.cond3 = select i1 %17, i1 true, i1 %18
  br i1 %or.cond3, label %19, label %21

19:                                               ; preds = %10
  %20 = getelementptr inbounds i8, ptr %14, i64 16
  store i64 -803, ptr %20, align 8, !tbaa !10
  br label %41

21:                                               ; preds = %10
  %22 = getelementptr inbounds i8, ptr %11, i64 40
  %23 = load i64, ptr %22, align 8, !tbaa !18
  %24 = getelementptr inbounds i8, ptr %11, i64 8
  %25 = load i64, ptr %24, align 8, !tbaa !19
  %26 = getelementptr inbounds i8, ptr %11, i64 24
  %27 = load i64, ptr %26, align 8, !tbaa !20
  %28 = getelementptr inbounds i8, ptr %11, i64 32
  %29 = load i64, ptr %28, align 8, !tbaa !21
  %30 = add nsw i64 %29, %27
  %.not34 = icmp sgt i64 %25, %30
  %31 = add nsw i64 %25, -1
  %32 = select i1 %.not34, i64 %30, i64 %31
  %33 = icmp slt i64 %23, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %21
  %35 = getelementptr inbounds i8, ptr %14, i64 16
  store i64 -803, ptr %35, align 8, !tbaa !10
  br label %41

36:                                               ; preds = %21
  %37 = tail call i64 @SUNDlsMat_bandGBTRF(ptr noundef nonnull %13, i64 noundef %25, i64 noundef %27, i64 noundef %29, i64 noundef %23, ptr noundef nonnull %16) #2
  %38 = load ptr, ptr %0, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 16
  store i64 %37, ptr %39, align 8, !tbaa !10
  %40 = icmp sgt i64 %37, 0
  %. = select i1 %40, i32 808, i32 0
  br label %41

41:                                               ; preds = %36, %2, %34, %19, %7
  %.0 = phi i32 [ -802, %7 ], [ -803, %19 ], [ -803, %34 ], [ -801, %2 ], [ %., %36 ]
  ret i32 %.0
}

declare i64 @SUNDlsMat_bandGBTRF(ptr noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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_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, !7, i64 64}
!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 = !{!11, !7, i64 8}
!18 = !{!16, !12, i64 40}
!19 = !{!16, !12, i64 8}
!20 = !{!16, !12, i64 24}
!21 = !{!16, !12, i64 32}


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