; LLVM IR from stan-dev/math :: lib/sundials_6.1.1/src/cvodes (cvodes_ls)

; 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.CVLsMemRec = type { i32, i32, i32, ptr, ptr, i32, i32, double, double, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, ptr, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, i32, ptr, ptr, i32 }

@.str.18 = external hidden unnamed_addr constant [21 x i8], align 1

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

declare i64 @N_VGetLength(ptr noundef) #1

; Function Attrs: nounwind
declare double @sqrt(double 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
declare dso_local i32 @cvLs_AccessLMem(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

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

14:                                               ; preds = %2
  %15 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %15, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %73

16:                                               ; preds = %2
  %17 = load double, ptr %5, align 8, !tbaa !9
  %18 = fcmp ogt double %17, 0.000000e+00
  br i1 %18, label %19, label %23

19:                                               ; preds = %16
  %20 = load double, ptr %5, align 8, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.CVLsMemRec, ptr %21, i32 0, i32 8
  store double %20, ptr %22, align 8, !tbaa !13
  br label %72

23:                                               ; preds = %16
  %24 = load double, ptr %5, align 8, !tbaa !9
  %25 = fcmp olt double %24, 0.000000e+00
  br i1 %25, label %26, label %52

26:                                               ; preds = %23
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.CVLsMemRec, ptr %27, i32 0, i32 12
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  call void @N_VConst(double noundef 1.000000e+00, ptr noundef %29)
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.CVLsMemRec, ptr %30, i32 0, i32 12
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.CVLsMemRec, ptr %33, i32 0, i32 12
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = call double @N_VDotProd(ptr noundef %32, ptr noundef %35)
  %37 = fcmp ole double %36, 0.000000e+00
  br i1 %37, label %38, label %39

38:                                               ; preds = %26
  br label %48

39:                                               ; preds = %26
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.CVLsMemRec, ptr %40, i32 0, i32 12
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.CVLsMemRec, ptr %43, i32 0, i32 12
  %45 = load ptr, ptr %44, align 8, !tbaa !16
  %46 = call double @N_VDotProd(ptr noundef %42, ptr noundef %45)
  %47 = call double @sqrt(double noundef %46) #4
  br label %48

48:                                               ; preds = %39, %38
  %49 = phi double [ 0.000000e+00, %38 ], [ %47, %39 ]
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.CVLsMemRec, ptr %50, i32 0, i32 8
  store double %49, ptr %51, align 8, !tbaa !13
  br label %71

52:                                               ; preds = %23
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.CVLsMemRec, ptr %53, i32 0, i32 12
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  %56 = call i64 @N_VGetLength(ptr noundef %55)
  %57 = sitofp i64 %56 to double
  %58 = fcmp ole double %57, 0.000000e+00
  br i1 %58, label %59, label %60

59:                                               ; preds = %52
  br label %67

60:                                               ; preds = %52
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.CVLsMemRec, ptr %61, i32 0, i32 12
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  %64 = call i64 @N_VGetLength(ptr noundef %63)
  %65 = sitofp i64 %64 to double
  %66 = call double @sqrt(double noundef %65) #4
  br label %67

67:                                               ; preds = %60, %59
  %68 = phi double [ 0.000000e+00, %59 ], [ %66, %60 ]
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.CVLsMemRec, ptr %69, i32 0, i32 8
  store double %68, ptr %70, align 8, !tbaa !13
  br label %71

71:                                               ; preds = %67, %48
  br label %72

72:                                               ; preds = %71, %19
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %73

73:                                               ; preds = %72, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

declare void @N_VConst(double noundef, ptr noundef) #1

declare double @N_VDotProd(ptr 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 "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 }

!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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 48}
!14 = !{!"CVLsMemRec", !12, i64 0, !12, i64 4, !12, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 36, !10, i64 40, !10, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !15, i64 112, !15, i64 120, !15, i64 128, !15, i64 136, !15, i64 144, !15, i64 152, !15, i64 160, !15, i64 168, !15, i64 176, !15, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !12, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !12, i64 264, !6, i64 272, !6, i64 280, !12, i64 288}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !6, i64 80}


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

@.str.18 = external hidden unnamed_addr constant [21 x i8], align 1

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

declare i64 @N_VGetLength(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @cvLs_AccessLMem(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local i32 @CVodeSetLSNormFactor(ptr noundef %0, double noundef %1) local_unnamed_addr #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %5 = call i32 @cvLs_AccessLMem(ptr noundef %0, ptr noundef nonnull @.str.18, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %35

6:                                                ; preds = %2
  %7 = fcmp ogt double %1, 0.000000e+00
  br i1 %7, label %.sink.split, label %8

8:                                                ; preds = %6
  %9 = fcmp olt double %1, 0.000000e+00
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 80
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  br i1 %9, label %13, label %24

13:                                               ; preds = %8
  call void @N_VConst(double noundef 1.000000e+00, ptr noundef %12) #4
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 80
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = call double @N_VDotProd(ptr noundef %16, ptr noundef %16) #4
  %18 = fcmp ugt double %17, 0.000000e+00
  br i1 %18, label %19, label %.sink.split

19:                                               ; preds = %13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 80
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = call double @N_VDotProd(ptr noundef %22, ptr noundef %22) #4
  br label %.sink.split.sink.split

24:                                               ; preds = %8
  %25 = call i64 @N_VGetLength(ptr noundef %12) #4
  %26 = icmp slt i64 %25, 1
  br i1 %26, label %.sink.split, label %27

27:                                               ; preds = %24
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 80
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = call i64 @N_VGetLength(ptr noundef %30) #4
  %32 = sitofp i64 %31 to double
  br label %.sink.split.sink.split

.sink.split.sink.split:                           ; preds = %19, %27
  %.sink10 = phi double [ %32, %27 ], [ %23, %19 ]
  %33 = call double @sqrt(double noundef %.sink10) #4
  br label %.sink.split

.sink.split:                                      ; preds = %.sink.split.sink.split, %24, %13, %6
  %.sink = phi double [ %1, %6 ], [ 0.000000e+00, %13 ], [ 0.000000e+00, %24 ], [ %33, %.sink.split.sink.split ]
  %.sink9 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %.sink9, i64 48
  store double %.sink, ptr %34, align 8, !tbaa !14
  br label %35

35:                                               ; preds = %.sink.split, %2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  ret i32 %5
}

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

declare double @N_VDotProd(ptr noundef, 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 = { mustprogress nofree nounwind willreturn memory(write) "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 }

!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 80}
!10 = !{!"CVLsMemRec", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !11, i64 36, !12, i64 40, !12, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !13, i64 112, !13, i64 120, !13, i64 128, !13, i64 136, !13, i64 144, !13, i64 152, !13, i64 160, !13, i64 168, !13, i64 176, !13, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !11, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !11, i64 264, !6, i64 272, !6, i64 280, !11, i64 288}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !12, i64 48}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass