; 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
declare double @sin(double noundef) #2

; Function Attrs: nounwind
declare double @tan(double noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @hyperspherical_forwards_recurrence(i32 noundef %0, i32 noundef %1, double noundef %2, double noundef %3, double noundef %4, double noundef %5, ptr noalias noundef %6, ptr noalias noundef %7, ptr noalias noundef %8) #3 {
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  store i32 %0, ptr %10, align 4, !tbaa !5
  store i32 %1, ptr %11, align 4, !tbaa !5
  store double %2, ptr %12, align 8, !tbaa !9
  store double %3, ptr %13, align 8, !tbaa !9
  store double %4, ptr %14, align 8, !tbaa !9
  store double %5, ptr %15, align 8, !tbaa !9
  store ptr %6, ptr %16, align 8, !tbaa !11
  store ptr %7, ptr %17, align 8, !tbaa !11
  store ptr %8, ptr %18, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  %20 = load double, ptr %12, align 8, !tbaa !9
  %21 = fdiv double 1.000000e+00, %20
  %22 = load double, ptr %12, align 8, !tbaa !9
  %23 = load double, ptr %13, align 8, !tbaa !9
  %24 = fmul double %22, %23
  %25 = call double @sin(double noundef %24) #4
  %26 = fmul double %21, %25
  %27 = load double, ptr %14, align 8, !tbaa !9
  %28 = fdiv double %26, %27
  %29 = load ptr, ptr %18, align 8, !tbaa !11
  %30 = getelementptr inbounds double, ptr %29, i64 0
  store double %28, ptr %30, align 8, !tbaa !9
  %31 = load ptr, ptr %18, align 8, !tbaa !11
  %32 = getelementptr inbounds double, ptr %31, i64 0
  %33 = load double, ptr %32, align 8, !tbaa !9
  %34 = load double, ptr %15, align 8, !tbaa !9
  %35 = load double, ptr %12, align 8, !tbaa !9
  %36 = load double, ptr %12, align 8, !tbaa !9
  %37 = load double, ptr %13, align 8, !tbaa !9
  %38 = fmul double %36, %37
  %39 = call double @tan(double noundef %38) #4
  %40 = fdiv double %35, %39
  %41 = fsub double %34, %40
  %42 = fmul double %33, %41
  %43 = load ptr, ptr %17, align 8, !tbaa !11
  %44 = getelementptr inbounds double, ptr %43, i64 1
  %45 = load double, ptr %44, align 8, !tbaa !9
  %46 = fmul double %42, %45
  %47 = load ptr, ptr %18, align 8, !tbaa !11
  %48 = getelementptr inbounds double, ptr %47, i64 1
  store double %46, ptr %48, align 8, !tbaa !9
  store i32 2, ptr %19, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %91, %9
  %50 = load i32, ptr %19, align 4, !tbaa !5
  %51 = load i32, ptr %11, align 4, !tbaa !5
  %52 = icmp sle i32 %50, %51
  br i1 %52, label %53, label %94

53:                                               ; preds = %49
  %54 = load i32, ptr %19, align 4, !tbaa !5
  %55 = mul nsw i32 2, %54
  %56 = sub nsw i32 %55, 1
  %57 = sitofp i32 %56 to double
  %58 = load double, ptr %15, align 8, !tbaa !9
  %59 = fmul double %57, %58
  %60 = load ptr, ptr %18, align 8, !tbaa !11
  %61 = load i32, ptr %19, align 4, !tbaa !5
  %62 = sub nsw i32 %61, 1
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds double, ptr %60, i64 %63
  %65 = load double, ptr %64, align 8, !tbaa !9
  %66 = load ptr, ptr %18, align 8, !tbaa !11
  %67 = load i32, ptr %19, align 4, !tbaa !5
  %68 = sub nsw i32 %67, 2
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds double, ptr %66, i64 %69
  %71 = load double, ptr %70, align 8, !tbaa !9
  %72 = load ptr, ptr %16, align 8, !tbaa !11
  %73 = load i32, ptr %19, align 4, !tbaa !5
  %74 = sub nsw i32 %73, 1
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds double, ptr %72, i64 %75
  %77 = load double, ptr %76, align 8, !tbaa !9
  %78 = fmul double %71, %77
  %79 = fneg double %78
  %80 = call double @llvm.fmuladd.f64(double %59, double %65, double %79)
  %81 = load ptr, ptr %17, align 8, !tbaa !11
  %82 = load i32, ptr %19, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds double, ptr %81, i64 %83
  %85 = load double, ptr %84, align 8, !tbaa !9
  %86 = fmul double %80, %85
  %87 = load ptr, ptr %18, align 8, !tbaa !11
  %88 = load i32, ptr %19, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds double, ptr %87, i64 %89
  store double %86, ptr %90, align 8, !tbaa !9
  br label %91

91:                                               ; preds = %53
  %92 = load i32, ptr %19, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %19, align 4, !tbaa !5
  br label %49, !llvm.loop !13

94:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  ret i32 0
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !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 = !{!"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: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local noundef i32 @hyperspherical_forwards_recurrence(i32 noundef %0, i32 noundef %1, double noundef %2, double noundef %3, double noundef %4, double noundef %5, ptr noalias nocapture noundef readonly %6, ptr noalias nocapture noundef readonly %7, ptr noalias nocapture noundef %8) local_unnamed_addr #2 {
  %10 = fdiv double 1.000000e+00, %2
  %11 = fmul double %2, %3
  %12 = tail call double @sin(double noundef %11) #3
  %13 = fmul double %10, %12
  %14 = fdiv double %13, %4
  store double %14, ptr %8, align 8, !tbaa !5
  %15 = tail call double @tan(double noundef %11) #3
  %16 = fdiv double %2, %15
  %17 = fsub double %5, %16
  %18 = fmul double %14, %17
  %19 = getelementptr inbounds i8, ptr %7, i64 8
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = fmul double %20, %18
  %22 = getelementptr inbounds i8, ptr %8, i64 8
  store double %21, ptr %22, align 8, !tbaa !5
  %.not26 = icmp slt i32 %1, 2
  br i1 %.not26, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %9
  %23 = add nuw i32 %1, 1
  %wide.trip.count = zext i32 %23 to i64
  %invariant.gep = getelementptr i8, ptr %6, i64 -8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %24 = phi double [ %21, %.lr.ph.preheader ], [ %38, %.lr.ph ]
  %indvars.iv = phi i64 [ 2, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %indvars.iv.tr = trunc i64 %indvars.iv to i32
  %25 = shl i32 %indvars.iv.tr, 1
  %26 = add i32 %25, -1
  %27 = sitofp i32 %26 to double
  %28 = fmul double %27, %5
  %29 = getelementptr double, ptr %8, i64 %indvars.iv
  %30 = getelementptr i8, ptr %29, i64 -16
  %31 = load double, ptr %30, align 8, !tbaa !5
  %gep = getelementptr double, ptr %invariant.gep, i64 %indvars.iv
  %32 = load double, ptr %gep, align 8, !tbaa !5
  %33 = fneg double %31
  %34 = fmul double %32, %33
  %35 = tail call double @llvm.fmuladd.f64(double %28, double %24, double %34)
  %36 = getelementptr inbounds double, ptr %7, i64 %indvars.iv
  %37 = load double, ptr %36, align 8, !tbaa !5
  %38 = fmul double %37, %35
  store double %38, ptr %29, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %9
  ret i32 0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { nofree nounwind memory(write, argmem: readwrite) 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass