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

; 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 double @r8poly_lagrange_2(i32 noundef %0, ptr noundef %1, double noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %61, %3
  %13 = load i32, ptr %10, align 4, !tbaa !5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %16, label %64

16:                                               ; preds = %12
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %57, %16
  %18 = load i32, ptr %9, align 4, !tbaa !5
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %60

21:                                               ; preds = %17
  %22 = load i32, ptr %9, align 4, !tbaa !5
  %23 = load i32, ptr %10, align 4, !tbaa !5
  %24 = icmp ne i32 %22, %23
  br i1 %24, label %25, label %56

25:                                               ; preds = %21
  store double 1.000000e+00, ptr %11, align 8, !tbaa !11
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %49, %25
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %52

30:                                               ; preds = %26
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = icmp ne i32 %31, %32
  br i1 %33, label %34, label %48

34:                                               ; preds = %30
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = icmp ne i32 %35, %36
  br i1 %37, label %38, label %48

38:                                               ; preds = %34
  %39 = load double, ptr %11, align 8, !tbaa !11
  %40 = load double, ptr %6, align 8, !tbaa !11
  %41 = load ptr, ptr %5, align 8, !tbaa !9
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds double, ptr %41, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = fsub double %40, %45
  %47 = fmul double %39, %46
  store double %47, ptr %11, align 8, !tbaa !11
  br label %48

48:                                               ; preds = %38, %34, %30
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %8, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %8, align 4, !tbaa !5
  br label %26, !llvm.loop !13

52:                                               ; preds = %26
  %53 = load double, ptr %7, align 8, !tbaa !11
  %54 = load double, ptr %11, align 8, !tbaa !11
  %55 = fadd double %53, %54
  store double %55, ptr %7, align 8, !tbaa !11
  br label %56

56:                                               ; preds = %52, %21
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %9, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %9, align 4, !tbaa !5
  br label %17, !llvm.loop !15

60:                                               ; preds = %17
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %10, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %10, align 4, !tbaa !5
  br label %12, !llvm.loop !16

64:                                               ; preds = %12
  %65 = load double, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret double %65
}

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 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local double @r8poly_lagrange_2(i32 noundef %0, ptr nocapture noundef readonly %1, double noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %0, 0
  br i1 %4, label %.preheader29.us.preheader, label %._crit_edge

.preheader29.us.preheader:                        ; preds = %3
  %wide.trip.count50 = zext nneg i32 %0 to i64
  %xtraiter = and i64 %wide.trip.count50, 1
  %5 = icmp eq i32 %0, 1
  %unroll_iter = and i64 %wide.trip.count50, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader29.us

.preheader29.us:                                  ; preds = %.preheader29.us.preheader, %._crit_edge36.split.us.us
  %indvars.iv47 = phi i64 [ 0, %.preheader29.us.preheader ], [ %indvars.iv.next48, %._crit_edge36.split.us.us ]
  %.02438.us = phi double [ 0.000000e+00, %.preheader29.us.preheader ], [ %.2.us.us, %._crit_edge36.split.us.us ]
  br label %6

6:                                                ; preds = %18, %.preheader29.us
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %18 ], [ 0, %.preheader29.us ]
  %.12532.us.us = phi double [ %.2.us.us, %18 ], [ %.02438.us, %.preheader29.us ]
  %.not.us.us = icmp eq i64 %indvars.iv42, %indvars.iv47
  br i1 %.not.us.us, label %18, label %.preheader.us.us.preheader

.preheader.us.us.preheader:                       ; preds = %6
  br i1 %5, label %._crit_edge.us.us.unr-lcssa, label %.preheader.us.us

.preheader.us.us:                                 ; preds = %.preheader.us.us.preheader, %17
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %17 ], [ 0, %.preheader.us.us.preheader ]
  %.031.us.us = phi double [ %.1.us.us.1, %17 ], [ 1.000000e+00, %.preheader.us.us.preheader ]
  %niter = phi i64 [ %niter.next.1, %17 ], [ 0, %.preheader.us.us.preheader ]
  %.not27.us.us = icmp eq i64 %indvars.iv, %indvars.iv42
  %.not28.us.us = icmp eq i64 %indvars.iv, %indvars.iv47
  %or.cond.us.us = or i1 %.not27.us.us, %.not28.us.us
  br i1 %or.cond.us.us, label %.preheader.us.us.1, label %7

7:                                                ; preds = %.preheader.us.us
  %8 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = fsub double %2, %9
  %11 = fmul double %.031.us.us, %10
  br label %.preheader.us.us.1

.preheader.us.us.1:                               ; preds = %7, %.preheader.us.us
  %.1.us.us = phi double [ %11, %7 ], [ %.031.us.us, %.preheader.us.us ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %.not27.us.us.1 = icmp eq i64 %indvars.iv.next, %indvars.iv42
  %.not28.us.us.1 = icmp eq i64 %indvars.iv.next, %indvars.iv47
  %or.cond.us.us.1 = or i1 %.not27.us.us.1, %.not28.us.us.1
  br i1 %or.cond.us.us.1, label %17, label %12

12:                                               ; preds = %.preheader.us.us.1
  %13 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next
  %14 = load double, ptr %13, align 8, !tbaa !5
  %15 = fsub double %2, %14
  %16 = fmul double %.1.us.us, %15
  br label %17

17:                                               ; preds = %12, %.preheader.us.us.1
  %.1.us.us.1 = phi double [ %16, %12 ], [ %.1.us.us, %.preheader.us.us.1 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.us.unr-lcssa, label %.preheader.us.us, !llvm.loop !9

18:                                               ; preds = %._crit_edge.us.us, %6
  %.2.us.us = phi double [ %24, %._crit_edge.us.us ], [ %.12532.us.us, %6 ]
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %exitcond46.not = icmp eq i64 %indvars.iv.next43, %wide.trip.count50
  br i1 %exitcond46.not, label %._crit_edge36.split.us.us, label %6, !llvm.loop !11

._crit_edge.us.us.unr-lcssa:                      ; preds = %17, %.preheader.us.us.preheader
  %.1.us.us.lcssa.ph = phi double [ poison, %.preheader.us.us.preheader ], [ %.1.us.us.1, %17 ]
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us.us.preheader ], [ %indvars.iv.next.1, %17 ]
  %.031.us.us.unr = phi double [ 1.000000e+00, %.preheader.us.us.preheader ], [ %.1.us.us.1, %17 ]
  br i1 %lcmp.mod.not, label %._crit_edge.us.us, label %.preheader.us.us.epil

.preheader.us.us.epil:                            ; preds = %._crit_edge.us.us.unr-lcssa
  %.not27.us.us.epil = icmp eq i64 %indvars.iv.unr, %indvars.iv42
  %.not28.us.us.epil = icmp eq i64 %indvars.iv.unr, %indvars.iv47
  %or.cond.us.us.epil = or i1 %.not27.us.us.epil, %.not28.us.us.epil
  br i1 %or.cond.us.us.epil, label %._crit_edge.us.us, label %19

19:                                               ; preds = %.preheader.us.us.epil
  %20 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.unr
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = fsub double %2, %21
  %23 = fmul double %.031.us.us.unr, %22
  br label %._crit_edge.us.us

._crit_edge.us.us:                                ; preds = %.preheader.us.us.epil, %19, %._crit_edge.us.us.unr-lcssa
  %.1.us.us.lcssa = phi double [ %.1.us.us.lcssa.ph, %._crit_edge.us.us.unr-lcssa ], [ %23, %19 ], [ %.031.us.us.unr, %.preheader.us.us.epil ]
  %24 = fadd double %.12532.us.us, %.1.us.us.lcssa
  br label %18

._crit_edge36.split.us.us:                        ; preds = %18
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %exitcond51.not = icmp eq i64 %indvars.iv.next48, %wide.trip.count50
  br i1 %exitcond51.not, label %._crit_edge, label %.preheader29.us, !llvm.loop !12

._crit_edge:                                      ; preds = %._crit_edge36.split.us.us, %3
  %.024.lcssa = phi double [ 0.000000e+00, %3 ], [ %.2.us.us, %._crit_edge36.split.us.us ]
  ret double %.024.lcssa
}

attributes #0 = { 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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass