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

; 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 speculatable willreturn memory(none)
declare x86_fp80 @llvm.fmuladd.f80(x86_fp80, x86_fp80, x86_fp80) #1

; 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 x86_fp80 @__p1evll(x86_fp80 noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %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 i32, ptr %6, align 4, !tbaa !11
  %9 = sub nsw i32 %8, 1
  store i32 %9, ptr %6, align 4, !tbaa !11
  %10 = load x86_fp80, ptr %4, align 16, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  %12 = getelementptr inbounds x86_fp80, ptr %11, i32 1
  store ptr %12, ptr %5, align 8, !tbaa !9
  %13 = load x86_fp80, ptr %11, align 16, !tbaa !5
  %14 = fadd x86_fp80 %10, %13
  store x86_fp80 %14, ptr %7, align 16, !tbaa !5
  br label %15

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

22:                                               ; preds = %15
  %23 = load i32, ptr %6, align 4, !tbaa !11
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr %6, align 4, !tbaa !11
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %15, label %26, !llvm.loop !13

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare x86_fp80 @llvm.fmuladd.f80(x86_fp80, x86_fp80, x86_fp80) #0

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local x86_fp80 @__p1evll(x86_fp80 noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = add i32 %2, -1
  %5 = load x86_fp80, ptr %1, align 16, !tbaa !5
  %6 = fadd x86_fp80 %5, %0
  %7 = add i32 %2, -2
  %xtraiter = and i32 %4, 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
  %.08.prol = phi i32 [ %10, %.prol.preheader ], [ %4, %3 ]
  %.pn.prol = phi ptr [ %.07.prol, %.prol.preheader ], [ %1, %3 ]
  %.0.prol = phi x86_fp80 [ %9, %.prol.preheader ], [ %6, %3 ]
  %prol.iter = phi i32 [ %prol.iter.next, %.prol.preheader ], [ 0, %3 ]
  %.07.prol = getelementptr inbounds i8, ptr %.pn.prol, i64 16
  %8 = load x86_fp80, ptr %.07.prol, align 16, !tbaa !5
  %9 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %.0.prol, x86_fp80 %0, x86_fp80 %8)
  %10 = add nsw i32 %.08.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 ], [ %9, %.prol.preheader ]
  %.08.unr = phi i32 [ %4, %3 ], [ %10, %.prol.preheader ]
  %.pn.unr = phi ptr [ %1, %3 ], [ %.07.prol, %.prol.preheader ]
  %.0.unr = phi x86_fp80 [ %6, %3 ], [ %9, %.prol.preheader ]
  %11 = icmp ult i32 %7, 3
  br i1 %11, label %.unr-lcssa, label %.new

.new:                                             ; preds = %.prol.loopexit, %.new
  %.08 = phi i32 [ %20, %.new ], [ %.08.unr, %.prol.loopexit ]
  %.pn = phi ptr [ %.07.3, %.new ], [ %.pn.unr, %.prol.loopexit ]
  %.0 = phi x86_fp80 [ %19, %.new ], [ %.0.unr, %.prol.loopexit ]
  %.07 = getelementptr inbounds i8, ptr %.pn, i64 16
  %12 = load x86_fp80, ptr %.07, align 16, !tbaa !5
  %13 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %.0, x86_fp80 %0, x86_fp80 %12)
  %.07.1 = getelementptr inbounds i8, ptr %.pn, i64 32
  %14 = load x86_fp80, ptr %.07.1, align 16, !tbaa !5
  %15 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %13, x86_fp80 %0, x86_fp80 %14)
  %.07.2 = getelementptr inbounds i8, ptr %.pn, i64 48
  %16 = load x86_fp80, ptr %.07.2, align 16, !tbaa !5
  %17 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %15, x86_fp80 %0, x86_fp80 %16)
  %.07.3 = getelementptr inbounds i8, ptr %.pn, i64 64
  %18 = load x86_fp80, ptr %.07.3, align 16, !tbaa !5
  %19 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %17, x86_fp80 %0, x86_fp80 %18)
  %20 = add nsw i32 %.08, -4
  %.not.3 = icmp eq i32 %20, 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 ], [ %19, %.new ]
  ret x86_fp80 %.lcssa
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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" }

!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,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass