; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数学算法/多项式拟合（辛普森积分）.ll (Z4calce)

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

@a = external dso_local global [110 x [110 x x86_fp80]], align 16
@pos = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local noundef x86_fp80 @_Z1fe(x86_fp80 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef x86_fp80 @_Z4calce(x86_fp80 noundef %0) #0 {
  %2 = alloca x86_fp80, align 16
  %3 = alloca x86_fp80, align 16
  %4 = alloca x86_fp80, align 16
  %5 = alloca i32, align 4
  store x86_fp80 %0, ptr %2, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #3
  store x86_fp80 0xK00000000000000000000, ptr %3, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #3
  store x86_fp80 0xK3FFF8000000000000000, ptr %4, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %25, %1
  %7 = load i32, ptr %5, align 4, !tbaa !9
  %8 = load i32, ptr @pos, align 4, !tbaa !9
  %9 = icmp sle i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %28

11:                                               ; preds = %6
  %12 = load i32, ptr @pos, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [110 x [110 x x86_fp80]], ptr @a, i64 0, i64 %13
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [110 x x86_fp80], ptr %14, i64 0, i64 %16
  %18 = load x86_fp80, ptr %17, align 16, !tbaa !5
  %19 = load x86_fp80, ptr %4, align 16, !tbaa !5
  %20 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %21 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %18, x86_fp80 %19, x86_fp80 %20)
  store x86_fp80 %21, ptr %3, align 16, !tbaa !5
  %22 = load x86_fp80, ptr %2, align 16, !tbaa !5
  %23 = load x86_fp80, ptr %4, align 16, !tbaa !5
  %24 = fmul x86_fp80 %23, %22
  store x86_fp80 %24, ptr %4, align 16, !tbaa !5
  br label %25

25:                                               ; preds = %11
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %5, align 4, !tbaa !9
  br label %6, !llvm.loop !11

28:                                               ; preds = %10
  %29 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %30 = load x86_fp80, ptr %2, align 16, !tbaa !5
  %31 = call noundef x86_fp80 @_Z1fe(x86_fp80 noundef %30)
  %32 = fmul x86_fp80 %29, %31
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #3
  ret x86_fp80 %32
}

; 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 = { 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 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

@a = external dso_local local_unnamed_addr global [110 x [110 x x86_fp80]], align 16
@pos = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local noundef x86_fp80 @_Z1fe(x86_fp80 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef x86_fp80 @_Z4calce(x86_fp80 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @pos, align 4, !tbaa !5
  %.not12 = icmp slt i32 %2, 0
  br i1 %.not12, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %3 = zext nneg i32 %2 to i64
  %4 = add nuw i32 %2, 1
  %wide.trip.count = zext i32 %4 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %5 = icmp ult i32 %2, 3
  br i1 %5, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  br label %12

._crit_edge.loopexit.unr-lcssa:                   ; preds = %12, %.lr.ph
  %.lcssa.ph = phi x86_fp80 [ poison, %.lr.ph ], [ %27, %12 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %12 ]
  %.0914.unr = phi x86_fp80 [ 0xK3FFF8000000000000000, %.lr.ph ], [ %28, %12 ]
  %.01013.unr = phi x86_fp80 [ 0xK00000000000000000000, %.lr.ph ], [ %27, %12 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.0914.epil = phi x86_fp80 [ %9, %.epil.preheader ], [ %.0914.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.01013.epil = phi x86_fp80 [ %8, %.epil.preheader ], [ %.01013.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %6 = getelementptr inbounds [110 x [110 x x86_fp80]], ptr @a, i64 0, i64 %3, i64 %indvars.iv.epil
  %7 = load x86_fp80, ptr %6, align 16, !tbaa !9
  %8 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %7, x86_fp80 %.0914.epil, x86_fp80 %.01013.epil)
  %9 = fmul x86_fp80 %.0914.epil, %0
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !11

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %1
  %.010.lcssa = phi x86_fp80 [ 0xK00000000000000000000, %1 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %8, %.epil.preheader ]
  %10 = tail call noundef x86_fp80 @_Z1fe(x86_fp80 noundef %0)
  %11 = fmul x86_fp80 %.010.lcssa, %10
  ret x86_fp80 %11

12:                                               ; preds = %12, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %12 ]
  %.0914 = phi x86_fp80 [ 0xK3FFF8000000000000000, %.lr.ph.new ], [ %28, %12 ]
  %.01013 = phi x86_fp80 [ 0xK00000000000000000000, %.lr.ph.new ], [ %27, %12 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %12 ]
  %13 = getelementptr inbounds [110 x [110 x x86_fp80]], ptr @a, i64 0, i64 %3, i64 %indvars.iv
  %14 = load x86_fp80, ptr %13, align 16, !tbaa !9
  %15 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %14, x86_fp80 %.0914, x86_fp80 %.01013)
  %16 = fmul x86_fp80 %.0914, %0
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %17 = getelementptr inbounds [110 x [110 x x86_fp80]], ptr @a, i64 0, i64 %3, i64 %indvars.iv.next
  %18 = load x86_fp80, ptr %17, align 16, !tbaa !9
  %19 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %18, x86_fp80 %16, x86_fp80 %15)
  %20 = fmul x86_fp80 %16, %0
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %21 = getelementptr inbounds [110 x [110 x x86_fp80]], ptr @a, i64 0, i64 %3, i64 %indvars.iv.next.1
  %22 = load x86_fp80, ptr %21, align 16, !tbaa !9
  %23 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %22, x86_fp80 %20, x86_fp80 %19)
  %24 = fmul x86_fp80 %20, %0
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %25 = getelementptr inbounds [110 x [110 x x86_fp80]], ptr @a, i64 0, i64 %3, i64 %indvars.iv.next.2
  %26 = load x86_fp80, ptr %25, align 16, !tbaa !9
  %27 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %26, x86_fp80 %24, x86_fp80 %23)
  %28 = fmul x86_fp80 %24, %0
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %12, !llvm.loop !13
}

; 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 = { 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass