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

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

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

; 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 i32 @SUNRCompareTol(double noundef %0, double noundef %1, double noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  store double %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !5
  store double %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load double, ptr %5, align 8, !tbaa !5
  %12 = load double, ptr %6, align 8, !tbaa !5
  %13 = fcmp oeq double %11, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %65

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

19:                                               ; preds = %15
  %20 = load double, ptr %6, align 8, !tbaa !5
  %21 = call i32 @sunIsNaN(double noundef %20)
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %19, %15
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %65

24:                                               ; preds = %19
  %25 = load double, ptr %5, align 8, !tbaa !5
  %26 = call i32 @sunIsInf(double noundef %25)
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %32, label %28

28:                                               ; preds = %24
  %29 = load double, ptr %6, align 8, !tbaa !5
  %30 = call i32 @sunIsInf(double noundef %29)
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %28, %24
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %65

33:                                               ; preds = %28
  %34 = load double, ptr %5, align 8, !tbaa !5
  %35 = load double, ptr %6, align 8, !tbaa !5
  %36 = fsub double %34, %35
  %37 = call double @llvm.fabs.f64(double %36)
  store double %37, ptr %8, align 8, !tbaa !5
  %38 = load double, ptr %5, align 8, !tbaa !5
  %39 = load double, ptr %6, align 8, !tbaa !5
  %40 = fadd double %38, %39
  %41 = call double @llvm.fabs.f64(double %40)
  %42 = fcmp olt double %41, 0x7FEFFFFFFFFFFFFF
  br i1 %42, label %43, label %48

43:                                               ; preds = %33
  %44 = load double, ptr %5, align 8, !tbaa !5
  %45 = load double, ptr %6, align 8, !tbaa !5
  %46 = fadd double %44, %45
  %47 = call double @llvm.fabs.f64(double %46)
  br label %49

48:                                               ; preds = %33
  br label %49

49:                                               ; preds = %48, %43
  %50 = phi double [ %47, %43 ], [ 0x7FEFFFFFFFFFFFFF, %48 ]
  store double %50, ptr %9, align 8, !tbaa !5
  %51 = load double, ptr %8, align 8, !tbaa !5
  %52 = load double, ptr %7, align 8, !tbaa !5
  %53 = load double, ptr %9, align 8, !tbaa !5
  %54 = fmul double %52, %53
  %55 = fcmp ogt double 0x3CE4000000000000, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %49
  br label %61

57:                                               ; preds = %49
  %58 = load double, ptr %7, align 8, !tbaa !5
  %59 = load double, ptr %9, align 8, !tbaa !5
  %60 = fmul double %58, %59
  br label %61

61:                                               ; preds = %57, %56
  %62 = phi double [ 0x3CE4000000000000, %56 ], [ %60, %57 ]
  %63 = fcmp oge double %51, %62
  %64 = zext i1 %63 to i32
  store i32 %64, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %65

65:                                               ; preds = %61, %32, %23, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %66 = load i32, ptr %4, align 4
  ret i32 %66
}

; Function Attrs: nounwind uwtable
declare hidden i32 @sunIsNaN(double noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @sunIsInf(double noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; 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 0, 2) i32 @SUNRCompareTol(double noundef %0, double noundef %1, double noundef %2) local_unnamed_addr #0 {
  %4 = fcmp oeq double %0, %1
  br i1 %4, label %25, label %5

5:                                                ; preds = %3
  %6 = tail call i32 @sunIsNaN(double noundef %0)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %25

7:                                                ; preds = %5
  %8 = tail call i32 @sunIsNaN(double noundef %1)
  %.not20 = icmp eq i32 %8, 0
  br i1 %.not20, label %9, label %25

9:                                                ; preds = %7
  %10 = tail call i32 @sunIsInf(double noundef %0)
  %.not21 = icmp eq i32 %10, 0
  br i1 %.not21, label %11, label %25

11:                                               ; preds = %9
  %12 = tail call i32 @sunIsInf(double noundef %1)
  %.not22 = icmp eq i32 %12, 0
  br i1 %.not22, label %13, label %25

13:                                               ; preds = %11
  %14 = fsub double %0, %1
  %15 = tail call double @llvm.fabs.f64(double %14)
  %16 = fadd double %0, %1
  %17 = tail call double @llvm.fabs.f64(double %16)
  %18 = fcmp olt double %17, 0x7FEFFFFFFFFFFFFF
  %19 = select i1 %18, double %17, double 0x7FEFFFFFFFFFFFFF
  %20 = fmul double %19, %2
  %21 = fcmp olt double %20, 0x3CE4000000000000
  %22 = select i1 %21, double 0x3CE4000000000000, double %20
  %23 = fcmp oge double %15, %22
  %24 = zext i1 %23 to i32
  br label %25

25:                                               ; preds = %9, %11, %5, %7, %3, %13
  %.0 = phi i32 [ %24, %13 ], [ 0, %3 ], [ 1, %7 ], [ 1, %5 ], [ 1, %11 ], [ 1, %9 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @sunIsNaN(double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @sunIsInf(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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)"}


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