; LLVM IR from kmilo17pet/qlibs :: qffmath (qFFMath_Legendre)

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

%union.anon = type { [2 x i32] }

@s_values = external hidden constant %union.anon, align 4

; 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
declare dso_local zeroext i1 @qFFMath_IsNaN(float noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @qFFMath_IsEqual(float noundef, float noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: nounwind uwtable
define dso_local float @qFFMath_Legendre(i64 noundef %0, float noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca i64, align 8
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store float 0.000000e+00, ptr %5, align 4, !tbaa !9
  %11 = load float, ptr %4, align 4, !tbaa !9
  %12 = call zeroext i1 @qFFMath_IsNaN(float noundef %11)
  br i1 %12, label %13, label %15

13:                                               ; preds = %2
  %14 = load float, ptr getelementptr (i8, ptr @s_values, i64 4), align 4, !tbaa !9
  store float %14, ptr %5, align 4, !tbaa !9
  br label %71

15:                                               ; preds = %2
  %16 = load float, ptr %4, align 4, !tbaa !9
  %17 = call zeroext i1 @qFFMath_IsEqual(float noundef 1.000000e+00, float noundef %16)
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  store float 1.000000e+00, ptr %5, align 4, !tbaa !9
  br label %70

19:                                               ; preds = %15
  %20 = load float, ptr %4, align 4, !tbaa !9
  %21 = call zeroext i1 @qFFMath_IsEqual(float noundef -1.000000e+00, float noundef %20)
  br i1 %21, label %22, label %28

22:                                               ; preds = %19
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = urem i64 %23, 2
  %25 = icmp eq i64 1, %24
  %26 = zext i1 %25 to i64
  %27 = select i1 %25, float -1.000000e+00, float 1.000000e+00
  store float %27, ptr %5, align 4, !tbaa !9
  br label %69

28:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store float 1.000000e+00, ptr %6, align 4, !tbaa !9
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = icmp eq i64 0, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %28
  %32 = load float, ptr %6, align 4, !tbaa !9
  store float %32, ptr %5, align 4, !tbaa !9
  br label %68

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %34 = load float, ptr %4, align 4, !tbaa !9
  store float %34, ptr %7, align 4, !tbaa !9
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = icmp eq i64 1, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %33
  %38 = load float, ptr %7, align 4, !tbaa !9
  store float %38, ptr %5, align 4, !tbaa !9
  br label %67

39:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 2, ptr %8, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %63, %39
  %41 = load i64, ptr %8, align 8, !tbaa !5
  %42 = load i64, ptr %3, align 8, !tbaa !5
  %43 = icmp ule i64 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %66

45:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %46 = load i64, ptr %8, align 8, !tbaa !5
  %47 = uitofp i64 %46 to float
  store float %47, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %48 = load float, ptr %4, align 4, !tbaa !9
  %49 = load float, ptr %7, align 4, !tbaa !9
  %50 = fmul float %48, %49
  store float %50, ptr %10, align 4, !tbaa !9
  %51 = load float, ptr %10, align 4, !tbaa !9
  %52 = load float, ptr %6, align 4, !tbaa !9
  %53 = fneg float %52
  %54 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %51, float %53)
  %55 = load float, ptr %10, align 4, !tbaa !9
  %56 = load float, ptr %6, align 4, !tbaa !9
  %57 = fsub float %55, %56
  %58 = load float, ptr %9, align 4, !tbaa !9
  %59 = fdiv float %57, %58
  %60 = fsub float %54, %59
  store float %60, ptr %5, align 4, !tbaa !9
  %61 = load float, ptr %7, align 4, !tbaa !9
  store float %61, ptr %6, align 4, !tbaa !9
  %62 = load float, ptr %5, align 4, !tbaa !9
  store float %62, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %63

63:                                               ; preds = %45
  %64 = load i64, ptr %8, align 8, !tbaa !5
  %65 = add i64 %64, 1
  store i64 %65, ptr %8, align 8, !tbaa !5
  br label %40, !llvm.loop !11

66:                                               ; preds = %44
  br label %67

67:                                               ; preds = %66, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %68

68:                                               ; preds = %67, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %69

69:                                               ; preds = %68, %22
  br label %70

70:                                               ; preds = %69, %18
  br label %71

71:                                               ; preds = %70, %13
  %72 = load float, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret float %72
}

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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

%union.anon = type { [2 x i32] }

@s_values = external hidden local_unnamed_addr constant %union.anon, align 4

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @qFFMath_IsNaN(float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @qFFMath_IsEqual(float noundef, float noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: nounwind uwtable
define dso_local float @qFFMath_Legendre(i64 noundef %0, float noundef %1) local_unnamed_addr #0 {
  %3 = tail call zeroext i1 @qFFMath_IsNaN(float noundef %1)
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  %5 = load float, ptr getelementptr inbounds (i8, ptr @s_values, i64 4), align 4, !tbaa !5
  br label %.loopexit

6:                                                ; preds = %2
  %7 = tail call zeroext i1 @qFFMath_IsEqual(float noundef 1.000000e+00, float noundef %1)
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %6
  %9 = tail call zeroext i1 @qFFMath_IsEqual(float noundef -1.000000e+00, float noundef %1)
  br i1 %9, label %10, label %13

10:                                               ; preds = %8
  %11 = and i64 %0, 1
  %.not26 = icmp eq i64 %11, 0
  %12 = select i1 %.not26, float 1.000000e+00, float -1.000000e+00
  br label %.loopexit

13:                                               ; preds = %8
  switch i64 %0, label %.lr.ph.preheader [
    i64 0, label %.loopexit
    i64 1, label %34
  ]

.lr.ph.preheader:                                 ; preds = %13
  %14 = add i64 %0, 1
  %umax = tail call i64 @llvm.umax.i64(i64 %14, i64 3)
  %xtraiter = and i64 %umax, 1
  %15 = icmp ult i64 %14, 4
  br i1 %15, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %16 = and i64 %umax, -2
  %17 = add i64 %16, -4
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.02230 = phi float [ 1.000000e+00, %.lr.ph.preheader.new ], [ %24, %.lr.ph ]
  %.02329 = phi i64 [ 2, %.lr.ph.preheader.new ], [ %33, %.lr.ph ]
  %.02428 = phi float [ %1, %.lr.ph.preheader.new ], [ %32, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %18 = uitofp i64 %.02329 to float
  %19 = fmul float %.02428, %1
  %20 = fneg float %.02230
  %21 = tail call float @llvm.fmuladd.f32(float %19, float 2.000000e+00, float %20)
  %22 = fsub float %19, %.02230
  %23 = fdiv float %22, %18
  %24 = fsub float %21, %23
  %25 = or disjoint i64 %.02329, 1
  %26 = uitofp i64 %25 to float
  %27 = fmul float %24, %1
  %28 = fneg float %.02428
  %29 = tail call float @llvm.fmuladd.f32(float %27, float 2.000000e+00, float %28)
  %30 = fsub float %27, %.02428
  %31 = fdiv float %30, %26
  %32 = fsub float %29, %31
  %33 = add nuw i64 %.02329, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter, %17
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa.loopexit, label %.lr.ph, !llvm.loop !9

34:                                               ; preds = %13
  br label %.loopexit

.loopexit.loopexit.unr-lcssa.loopexit:            ; preds = %.lr.ph
  %35 = uitofp i64 %33 to float
  br label %.loopexit.loopexit.unr-lcssa

.loopexit.loopexit.unr-lcssa:                     ; preds = %.loopexit.loopexit.unr-lcssa.loopexit, %.lr.ph.preheader
  %.lcssa.ph = phi float [ poison, %.lr.ph.preheader ], [ %32, %.loopexit.loopexit.unr-lcssa.loopexit ]
  %.02230.unr = phi float [ 1.000000e+00, %.lr.ph.preheader ], [ %24, %.loopexit.loopexit.unr-lcssa.loopexit ]
  %.02329.unr = phi float [ 2.000000e+00, %.lr.ph.preheader ], [ %35, %.loopexit.loopexit.unr-lcssa.loopexit ]
  %.02428.unr = phi float [ %1, %.lr.ph.preheader ], [ %32, %.loopexit.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit.unr-lcssa
  %36 = fmul float %.02428.unr, %1
  %37 = fneg float %.02230.unr
  %38 = tail call float @llvm.fmuladd.f32(float %36, float 2.000000e+00, float %37)
  %39 = fsub float %36, %.02230.unr
  %40 = fdiv float %39, %.02329.unr
  %41 = fsub float %38, %40
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.epil, %.loopexit.loopexit.unr-lcssa, %34, %13, %6, %10, %4
  %.3 = phi float [ %5, %4 ], [ %12, %10 ], [ 1.000000e+00, %6 ], [ 1.000000e+00, %13 ], [ %1, %34 ], [ %.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %41, %.lr.ph.epil ]
  ret float %.3
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #2

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) }
attributes #2 = { 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"float", !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: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass