; LLVM IR from Lodour/ACM-CheatSheet :: src/6_计算几何/3_多边形/5_小结.ll (Z10barycenteriP5point)

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

%struct.point = type { double, double }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z5xmult5pointS_S_(double, double, double, double, double, double) #0

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { double, double } @_Z10barycenter5pointS_S_(double, double, double, double, double, double) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local { double, double } @_Z10barycenteriP5point(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca %struct.point, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca %struct.point, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.point, align 8
  %11 = alloca %struct.point, align 8
  %12 = alloca %struct.point, align 8
  %13 = alloca %struct.point, align 8
  %14 = alloca %struct.point, align 8
  %15 = alloca %struct.point, align 8
  %16 = alloca %struct.point, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %17 = getelementptr inbounds %struct.point, ptr %3, i32 0, i32 1
  store double 0.000000e+00, ptr %17, align 8, !tbaa !13
  %18 = getelementptr inbounds %struct.point, ptr %3, i32 0, i32 0
  store double 0.000000e+00, ptr %18, align 8, !tbaa !15
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %96, %2
  %20 = load i32, ptr %9, align 4, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  %23 = icmp slt i32 %20, %22
  br i1 %23, label %24, label %99

24:                                               ; preds = %19
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.point, ptr %25, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %26, i64 16, i1 false), !tbaa.struct !16
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %struct.point, ptr %27, i64 %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %30, i64 16, i1 false), !tbaa.struct !16
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds %struct.point, ptr %31, i64 %34
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %35, i64 16, i1 false), !tbaa.struct !16
  %36 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 0
  %37 = load double, ptr %36, align 8
  %38 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 1
  %39 = load double, ptr %38, align 8
  %40 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %41 = load double, ptr %40, align 8
  %42 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %43 = load double, ptr %42, align 8
  %44 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  %45 = load double, ptr %44, align 8
  %46 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  %47 = load double, ptr %46, align 8
  %48 = call noundef double @_Z5xmult5pointS_S_(double %37, double %39, double %41, double %43, double %45, double %47)
  store double %48, ptr %8, align 8, !tbaa !11
  %49 = call double @llvm.fabs.f64(double %48)
  %50 = fcmp ogt double %49, 1.000000e-08
  br i1 %50, label %51, label %95

51:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #4
  %52 = load ptr, ptr %5, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.point, ptr %52, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %14, ptr align 8 %53, i64 16, i1 false), !tbaa.struct !16
  %54 = load ptr, ptr %5, align 8, !tbaa !9
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds %struct.point, ptr %54, i64 %56
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %15, ptr align 8 %57, i64 16, i1 false), !tbaa.struct !16
  %58 = load ptr, ptr %5, align 8, !tbaa !9
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct.point, ptr %58, i64 %61
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %16, ptr align 8 %62, i64 16, i1 false), !tbaa.struct !16
  %63 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %64 = load double, ptr %63, align 8
  %65 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  %66 = load double, ptr %65, align 8
  %67 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 0
  %68 = load double, ptr %67, align 8
  %69 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 1
  %70 = load double, ptr %69, align 8
  %71 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 0
  %72 = load double, ptr %71, align 8
  %73 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 1
  %74 = load double, ptr %73, align 8
  %75 = call { double, double } @_Z10barycenter5pointS_S_(double %64, double %66, double %68, double %70, double %72, double %74)
  %76 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 0
  %77 = extractvalue { double, double } %75, 0
  store double %77, ptr %76, align 8
  %78 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 1
  %79 = extractvalue { double, double } %75, 1
  store double %79, ptr %78, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %13, i64 16, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #4
  %80 = getelementptr inbounds %struct.point, ptr %6, i32 0, i32 0
  %81 = load double, ptr %80, align 8, !tbaa !15
  %82 = load double, ptr %8, align 8, !tbaa !11
  %83 = getelementptr inbounds %struct.point, ptr %3, i32 0, i32 0
  %84 = load double, ptr %83, align 8, !tbaa !15
  %85 = call double @llvm.fmuladd.f64(double %81, double %82, double %84)
  store double %85, ptr %83, align 8, !tbaa !15
  %86 = getelementptr inbounds %struct.point, ptr %6, i32 0, i32 1
  %87 = load double, ptr %86, align 8, !tbaa !13
  %88 = load double, ptr %8, align 8, !tbaa !11
  %89 = getelementptr inbounds %struct.point, ptr %3, i32 0, i32 1
  %90 = load double, ptr %89, align 8, !tbaa !13
  %91 = call double @llvm.fmuladd.f64(double %87, double %88, double %90)
  store double %91, ptr %89, align 8, !tbaa !13
  %92 = load double, ptr %8, align 8, !tbaa !11
  %93 = load double, ptr %7, align 8, !tbaa !11
  %94 = fadd double %93, %92
  store double %94, ptr %7, align 8, !tbaa !11
  br label %95

95:                                               ; preds = %51, %24
  br label %96

96:                                               ; preds = %95
  %97 = load i32, ptr %9, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %9, align 4, !tbaa !5
  br label %19, !llvm.loop !17

99:                                               ; preds = %19
  %100 = load double, ptr %7, align 8, !tbaa !11
  %101 = call double @llvm.fabs.f64(double %100)
  %102 = fcmp ogt double %101, 1.000000e-08
  br i1 %102, label %103, label %112

103:                                              ; preds = %99
  %104 = load double, ptr %7, align 8, !tbaa !11
  %105 = getelementptr inbounds %struct.point, ptr %3, i32 0, i32 0
  %106 = load double, ptr %105, align 8, !tbaa !15
  %107 = fdiv double %106, %104
  store double %107, ptr %105, align 8, !tbaa !15
  %108 = load double, ptr %7, align 8, !tbaa !11
  %109 = getelementptr inbounds %struct.point, ptr %3, i32 0, i32 1
  %110 = load double, ptr %109, align 8, !tbaa !13
  %111 = fdiv double %110, %108
  store double %111, ptr %109, align 8, !tbaa !13
  br label %112

112:                                              ; preds = %103, %99
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  %113 = load { double, double }, ptr %3, align 8
  ret { double, double } %113
}

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

attributes #0 = { mustprogress 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 speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"_ZTS5point", !12, i64 0, !12, i64 8}
!15 = !{!14, !12, i64 0}
!16 = !{i64 0, i64 8, !11, i64 8, i64 8, !11}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.point = type { double, double }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z5xmult5pointS_S_(double, double, double, double, double, double) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { double, double } @_Z10barycenter5pointS_S_(double, double, double, double, double, double) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local { double, double } @_Z10barycenteriP5point(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %0, 2
  br i1 %3, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %4 = add nsw i32 %0, -1
  %.sroa.211.0..sroa_idx = getelementptr inbounds i8, ptr %1, i64 8
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %5

5:                                                ; preds = %.lr.ph, %22
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %.037 = phi double [ 0.000000e+00, %.lr.ph ], [ %.1, %22 ]
  %6 = phi <2 x double> [ zeroinitializer, %.lr.ph ], [ %23, %22 ]
  %.sroa.010.0.copyload = load double, ptr %1, align 8, !tbaa !5
  %.sroa.211.0.copyload = load double, ptr %.sroa.211.0..sroa_idx, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.point, ptr %1, i64 %indvars.iv
  %.sroa.08.0.copyload = load double, ptr %7, align 8, !tbaa !5
  %.sroa.29.0..sroa_idx = getelementptr inbounds i8, ptr %7, i64 8
  %.sroa.29.0.copyload = load double, ptr %.sroa.29.0..sroa_idx, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = getelementptr inbounds %struct.point, ptr %1, i64 %indvars.iv.next
  %.sroa.06.0.copyload = load double, ptr %8, align 8, !tbaa !5
  %.sroa.27.0..sroa_idx = getelementptr inbounds i8, ptr %8, i64 8
  %.sroa.27.0.copyload = load double, ptr %.sroa.27.0..sroa_idx, align 8, !tbaa !5
  %9 = tail call noundef double @_Z5xmult5pointS_S_(double %.sroa.010.0.copyload, double %.sroa.211.0.copyload, double %.sroa.08.0.copyload, double %.sroa.29.0.copyload, double %.sroa.06.0.copyload, double %.sroa.27.0.copyload)
  %10 = tail call double @llvm.fabs.f64(double %9)
  %11 = fcmp ogt double %10, 1.000000e-08
  br i1 %11, label %12, label %22

12:                                               ; preds = %5
  %.sroa.03.0.copyload = load double, ptr %1, align 8, !tbaa !5
  %.sroa.24.0.copyload = load double, ptr %.sroa.211.0..sroa_idx, align 8, !tbaa !5
  %.sroa.01.0.copyload = load double, ptr %7, align 8, !tbaa !5
  %.sroa.22.0.copyload = load double, ptr %.sroa.29.0..sroa_idx, align 8, !tbaa !5
  %.sroa.0.0.copyload = load double, ptr %8, align 8, !tbaa !5
  %.sroa.2.0.copyload = load double, ptr %.sroa.27.0..sroa_idx, align 8, !tbaa !5
  %13 = tail call { double, double } @_Z10barycenter5pointS_S_(double %.sroa.03.0.copyload, double %.sroa.24.0.copyload, double %.sroa.01.0.copyload, double %.sroa.22.0.copyload, double %.sroa.0.0.copyload, double %.sroa.2.0.copyload)
  %14 = extractvalue { double, double } %13, 0
  %15 = extractvalue { double, double } %13, 1
  %16 = insertelement <2 x double> poison, double %14, i64 0
  %17 = insertelement <2 x double> %16, double %15, i64 1
  %18 = insertelement <2 x double> poison, double %9, i64 0
  %19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
  %20 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %17, <2 x double> %19, <2 x double> %6)
  %21 = fadd double %.037, %9
  br label %22

22:                                               ; preds = %5, %12
  %.1 = phi double [ %21, %12 ], [ %.037, %5 ]
  %23 = phi <2 x double> [ %20, %12 ], [ %6, %5 ]
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %5, !llvm.loop !9

._crit_edge:                                      ; preds = %22, %2
  %.0.lcssa = phi double [ 0.000000e+00, %2 ], [ %.1, %22 ]
  %24 = phi <2 x double> [ zeroinitializer, %2 ], [ %23, %22 ]
  %25 = tail call double @llvm.fabs.f64(double %.0.lcssa)
  %26 = fcmp ogt double %25, 1.000000e-08
  %27 = insertelement <2 x double> poison, double %.0.lcssa, i64 0
  %28 = shufflevector <2 x double> %27, <2 x double> poison, <2 x i32> zeroinitializer
  %29 = fdiv <2 x double> %24, %28
  %30 = insertelement <2 x i1> poison, i1 %26, i64 0
  %31 = shufflevector <2 x i1> %30, <2 x i1> poison, <2 x i32> zeroinitializer
  %32 = select <2 x i1> %31, <2 x double> %29, <2 x double> %24
  %33 = extractelement <2 x double> %32, i64 0
  %.fca.0.insert = insertvalue { double, double } poison, double %33, 0
  %34 = extractelement <2 x double> %32, i64 1
  %.fca.1.insert = insertvalue { double, double } %.fca.0.insert, double %34, 1
  ret { double, double } %.fca.1.insert
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #2

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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