; LLVM IR from CLASS-SZ/class_sz :: class-sz/tools (hyperspherical)

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind uwtable
define dso_local double @cheb(double noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  store double %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !11
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store double 0.000000e+00, ptr %7, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !11
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = sub nsw i32 %15, 1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds double, ptr %14, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !5
  store double %19, ptr %8, align 8, !tbaa !5
  %20 = load double, ptr %4, align 8, !tbaa !5
  %21 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %20, double -1.000000e+00)
  store double %21, ptr %9, align 8, !tbaa !5
  %22 = load double, ptr %9, align 8, !tbaa !5
  %23 = fmul double 2.000000e+00, %22
  store double %23, ptr %10, align 8, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = sub nsw i32 %24, 1
  store i32 %25, ptr %13, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %44, %3
  %27 = load i32, ptr %13, align 4, !tbaa !9
  %28 = icmp sgt i32 %27, 1
  br i1 %28, label %29, label %47

29:                                               ; preds = %26
  %30 = load double, ptr %7, align 8, !tbaa !5
  store double %30, ptr %11, align 8, !tbaa !5
  %31 = load double, ptr %8, align 8, !tbaa !5
  store double %31, ptr %7, align 8, !tbaa !5
  %32 = load double, ptr %10, align 8, !tbaa !5
  %33 = load double, ptr %7, align 8, !tbaa !5
  %34 = load double, ptr %11, align 8, !tbaa !5
  %35 = fneg double %34
  %36 = call double @llvm.fmuladd.f64(double %32, double %33, double %35)
  %37 = load ptr, ptr %6, align 8, !tbaa !11
  %38 = load i32, ptr %13, align 4, !tbaa !9
  %39 = sub nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %37, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !5
  %43 = fadd double %36, %42
  store double %43, ptr %8, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %29
  %45 = load i32, ptr %13, align 4, !tbaa !9
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr %13, align 4, !tbaa !9
  br label %26, !llvm.loop !13

47:                                               ; preds = %26
  %48 = load double, ptr %9, align 8, !tbaa !5
  %49 = load double, ptr %8, align 8, !tbaa !5
  %50 = load double, ptr %7, align 8, !tbaa !5
  %51 = fneg double %50
  %52 = call double @llvm.fmuladd.f64(double %48, double %49, double %51)
  %53 = load ptr, ptr %6, align 8, !tbaa !11
  %54 = getelementptr inbounds double, ptr %53, i64 0
  %55 = load double, ptr %54, align 8, !tbaa !5
  %56 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %55, double %52)
  store double %56, ptr %12, align 8, !tbaa !5
  %57 = load double, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  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
  ret double %57
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local double @cheb(double noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = add nsw i32 %1, -1
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds double, ptr %2, i64 %5
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = tail call double @llvm.fmuladd.f64(double %0, double 2.000000e+00, double -1.000000e+00)
  %9 = fmul double %8, 2.000000e+00
  %invariant.gep = getelementptr i8, ptr %2, i64 -8
  %10 = icmp sgt i32 %1, 2
  br i1 %10, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %11 = zext nneg i32 %4 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %11, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.01821 = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %.01920, %.lr.ph ]
  %.01920 = phi double [ %7, %.lr.ph.preheader ], [ %15, %.lr.ph ]
  %12 = fneg double %.01821
  %13 = tail call double @llvm.fmuladd.f64(double %9, double %.01920, double %12)
  %gep = getelementptr double, ptr %invariant.gep, i64 %indvars.iv
  %14 = load double, ptr %gep, align 8, !tbaa !5
  %15 = fadd double %13, %14
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %16 = icmp ugt i64 %indvars.iv, 2
  br i1 %16, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.019.lcssa = phi double [ %7, %3 ], [ %15, %.lr.ph ]
  %.018.lcssa = phi double [ 0.000000e+00, %3 ], [ %.01920, %.lr.ph ]
  %17 = fneg double %.018.lcssa
  %18 = tail call double @llvm.fmuladd.f64(double %8, double %.019.lcssa, double %17)
  %19 = load double, ptr %2, align 8, !tbaa !5
  %20 = tail call double @llvm.fmuladd.f64(double %19, double 5.000000e-01, double %18)
  ret double %20
}

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

!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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass