; LLVM IR from romerojosh/zefr :: src/polynomials.ll (Z8Legendrejd)

; 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: mustprogress uwtable
define dso_local noundef double @_Z8Legendrejd(i32 noundef %0, double noundef %1) #0 {
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  store double 1.000000e+00, ptr %3, align 8
  br label %41

9:                                                ; preds = %2
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %14

12:                                               ; preds = %9
  %13 = load double, ptr %5, align 8, !tbaa !9
  store double %13, ptr %3, align 8
  br label %41

14:                                               ; preds = %9
  br label %15

15:                                               ; preds = %14
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = uitofp i32 %16 to double
  %18 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %17, double -1.000000e+00)
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = uitofp i32 %19 to double
  %21 = fdiv double %18, %20
  %22 = load double, ptr %5, align 8, !tbaa !9
  %23 = fmul double %21, %22
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sub i32 %24, 1
  %26 = load double, ptr %5, align 8, !tbaa !9
  %27 = call noundef double @_Z8Legendrejd(i32 noundef %25, double noundef %26)
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = uitofp i32 %28 to double
  %30 = fsub double %29, 1.000000e+00
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = uitofp i32 %31 to double
  %33 = fdiv double %30, %32
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sub i32 %34, 2
  %36 = load double, ptr %5, align 8, !tbaa !9
  %37 = call noundef double @_Z8Legendrejd(i32 noundef %35, double noundef %36)
  %38 = fmul double %33, %37
  %39 = fneg double %38
  %40 = call double @llvm.fmuladd.f64(double %23, double %27, double %39)
  store double %40, ptr %3, align 8
  br label %41

41:                                               ; preds = %15, %12, %8
  %42 = load double, ptr %3, align 8
  ret double %42
}

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

attributes #0 = { mustprogress 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}


; 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 nofree nosync nounwind willreturn memory(none) uwtable
define dso_local noundef double @_Z8Legendrejd(i32 noundef %0, double noundef %1) local_unnamed_addr #0 {
  switch i32 %0, label %4 [
    i32 0, label %common.ret13
    i32 1, label %3
  ]

3:                                                ; preds = %2
  br label %common.ret13

common.ret13:                                     ; preds = %2, %3, %4
  %common.ret13.op = phi double [ %17, %4 ], [ %1, %3 ], [ 1.000000e+00, %2 ]
  ret double %common.ret13.op

4:                                                ; preds = %2
  %5 = uitofp i32 %0 to double
  %6 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double -1.000000e+00)
  %7 = fdiv double %6, %5
  %8 = fmul double %7, %1
  %9 = add i32 %0, -1
  %10 = tail call noundef double @_Z8Legendrejd(i32 noundef %9, double noundef %1)
  %11 = fadd double %5, -1.000000e+00
  %12 = add i32 %0, -2
  %13 = tail call noundef double @_Z8Legendrejd(i32 noundef %12, double noundef %1)
  %14 = fneg double %11
  %15 = fdiv double %14, %5
  %16 = fmul double %15, %13
  %17 = tail call double @llvm.fmuladd.f64(double %8, double %10, double %16)
  br label %common.ret13
}

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

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(none) 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,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass