; LLVM IR from chdb-io/chdb :: base/glibc-compatibility/musl//polevll.ll_ (polevll)

; 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: nounwind uwtable
define dso_local x86_fp80 @__polevll(x86_fp80 noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca x86_fp80, align 16
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca x86_fp80, align 16
  store x86_fp80 %0, ptr %4, align 16, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %8 = load ptr, ptr %5, align 8, !tbaa !9
  %9 = getelementptr inbounds x86_fp80, ptr %8, i32 1
  store ptr %9, ptr %5, align 8, !tbaa !9
  %10 = load x86_fp80, ptr %8, align 16, !tbaa !5
  store x86_fp80 %10, ptr %7, align 16, !tbaa !5
  br label %11

11:                                               ; preds = %18, %3
  %12 = load x86_fp80, ptr %7, align 16, !tbaa !5
  %13 = load x86_fp80, ptr %4, align 16, !tbaa !5
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  %15 = getelementptr inbounds x86_fp80, ptr %14, i32 1
  store ptr %15, ptr %5, align 8, !tbaa !9
  %16 = load x86_fp80, ptr %14, align 16, !tbaa !5
  %17 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %12, x86_fp80 %13, x86_fp80 %16)
  store x86_fp80 %17, ptr %7, align 16, !tbaa !5
  br label %18

18:                                               ; preds = %11
  %19 = load i32, ptr %6, align 4, !tbaa !11
  %20 = add nsw i32 %19, -1
  store i32 %20, ptr %6, align 4, !tbaa !11
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %11, label %22, !llvm.loop !13

22:                                               ; preds = %18
  %23 = load x86_fp80, ptr %7, align 16, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  ret x86_fp80 %23
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 double", !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 = !{!"int", !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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local x86_fp80 @__polevll(x86_fp80 noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load x86_fp80, ptr %1, align 16, !tbaa !5
  %5 = add nsw i32 %2, -1
  %xtraiter = and i32 %2, 3
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.preheader

.prol.preheader:                                  ; preds = %3, %.prol.preheader
  %.06.prol = phi i32 [ %8, %.prol.preheader ], [ %2, %3 ]
  %.pn.prol = phi ptr [ %.05.prol, %.prol.preheader ], [ %1, %3 ]
  %.0.prol = phi x86_fp80 [ %7, %.prol.preheader ], [ %4, %3 ]
  %prol.iter = phi i32 [ %prol.iter.next, %.prol.preheader ], [ 0, %3 ]
  %.05.prol = getelementptr inbounds i8, ptr %.pn.prol, i64 16
  %6 = load x86_fp80, ptr %.05.prol, align 16, !tbaa !5
  %7 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %.0.prol, x86_fp80 %0, x86_fp80 %6)
  %8 = add nsw i32 %.06.prol, -1
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.prol.loopexit, label %.prol.preheader, !llvm.loop !9

.prol.loopexit:                                   ; preds = %.prol.preheader, %3
  %.lcssa.unr = phi x86_fp80 [ poison, %3 ], [ %7, %.prol.preheader ]
  %.06.unr = phi i32 [ %2, %3 ], [ %8, %.prol.preheader ]
  %.pn.unr = phi ptr [ %1, %3 ], [ %.05.prol, %.prol.preheader ]
  %.0.unr = phi x86_fp80 [ %4, %3 ], [ %7, %.prol.preheader ]
  %9 = icmp ult i32 %5, 3
  br i1 %9, label %.unr-lcssa, label %.new

.new:                                             ; preds = %.prol.loopexit, %.new
  %.06 = phi i32 [ %18, %.new ], [ %.06.unr, %.prol.loopexit ]
  %.pn = phi ptr [ %.05.3, %.new ], [ %.pn.unr, %.prol.loopexit ]
  %.0 = phi x86_fp80 [ %17, %.new ], [ %.0.unr, %.prol.loopexit ]
  %.05 = getelementptr inbounds i8, ptr %.pn, i64 16
  %10 = load x86_fp80, ptr %.05, align 16, !tbaa !5
  %11 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %.0, x86_fp80 %0, x86_fp80 %10)
  %.05.1 = getelementptr inbounds i8, ptr %.pn, i64 32
  %12 = load x86_fp80, ptr %.05.1, align 16, !tbaa !5
  %13 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %11, x86_fp80 %0, x86_fp80 %12)
  %.05.2 = getelementptr inbounds i8, ptr %.pn, i64 48
  %14 = load x86_fp80, ptr %.05.2, align 16, !tbaa !5
  %15 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %13, x86_fp80 %0, x86_fp80 %14)
  %.05.3 = getelementptr inbounds i8, ptr %.pn, i64 64
  %16 = load x86_fp80, ptr %.05.3, align 16, !tbaa !5
  %17 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %15, x86_fp80 %0, x86_fp80 %16)
  %18 = add nsw i32 %.06, -4
  %.not.3 = icmp eq i32 %18, 0
  br i1 %.not.3, label %.unr-lcssa, label %.new, !llvm.loop !11

.unr-lcssa:                                       ; preds = %.new, %.prol.loopexit
  %.lcssa = phi x86_fp80 [ %.lcssa.unr, %.prol.loopexit ], [ %17, %.new ]
  ret x86_fp80 %.lcssa
}

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

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass