; LLVM IR from pmla/polyhedral-template-matching :: ptm_normalize_vertices.ll (ZN3ptm18normalize_verticesEiPA3_dS1_)

; 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: mustprogress nounwind uwtable
declare dso_local void @_ZN3ptm19subtract_barycentreEiPA3_dS1_(i32 noundef, ptr noundef, ptr noundef) #0

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN3ptm18normalize_verticesEiPA3_dS1_(i32 noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = load ptr, ptr %6, align 8, !tbaa !9
  call void @_ZN3ptm19subtract_barycentreEiPA3_dS1_(i32 noundef %14, ptr noundef %15, ptr noundef %16)
  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 4, ptr %8) #4
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %54, %3
  %18 = load i32, ptr %8, align 4, !tbaa !5
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %57

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %23 = load ptr, ptr %6, align 8, !tbaa !9
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [3 x double], ptr %23, i64 %25
  %27 = getelementptr inbounds [3 x double], ptr %26, i64 0, i64 0
  %28 = load double, ptr %27, align 8, !tbaa !11
  store double %28, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %29 = load ptr, ptr %6, align 8, !tbaa !9
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [3 x double], ptr %29, i64 %31
  %33 = getelementptr inbounds [3 x double], ptr %32, i64 0, i64 1
  %34 = load double, ptr %33, align 8, !tbaa !11
  store double %34, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %35 = load ptr, ptr %6, align 8, !tbaa !9
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [3 x double], ptr %35, i64 %37
  %39 = getelementptr inbounds [3 x double], ptr %38, i64 0, i64 2
  %40 = load double, ptr %39, align 8, !tbaa !11
  store double %40, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %41 = load double, ptr %9, align 8, !tbaa !11
  %42 = load double, ptr %9, align 8, !tbaa !11
  %43 = load double, ptr %10, align 8, !tbaa !11
  %44 = load double, ptr %10, align 8, !tbaa !11
  %45 = fmul double %43, %44
  %46 = call double @llvm.fmuladd.f64(double %41, double %42, double %45)
  %47 = load double, ptr %11, align 8, !tbaa !11
  %48 = load double, ptr %11, align 8, !tbaa !11
  %49 = call double @llvm.fmuladd.f64(double %47, double %48, double %46)
  %50 = call double @sqrt(double noundef %49) #4
  store double %50, ptr %12, align 8, !tbaa !11
  %51 = load double, ptr %12, align 8, !tbaa !11
  %52 = load double, ptr %7, align 8, !tbaa !11
  %53 = fadd double %52, %51
  store double %53, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %54

54:                                               ; preds = %22
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %8, align 4, !tbaa !5
  br label %17, !llvm.loop !13

57:                                               ; preds = %21
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sitofp i32 %58 to double
  %60 = load double, ptr %7, align 8, !tbaa !11
  %61 = fdiv double %60, %59
  store double %61, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %92, %57
  %63 = load i32, ptr %13, align 4, !tbaa !5
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = icmp slt i32 %63, %64
  br i1 %65, label %67, label %66

66:                                               ; preds = %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %95

67:                                               ; preds = %62
  %68 = load double, ptr %7, align 8, !tbaa !11
  %69 = load ptr, ptr %6, align 8, !tbaa !9
  %70 = load i32, ptr %13, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [3 x double], ptr %69, i64 %71
  %73 = getelementptr inbounds [3 x double], ptr %72, i64 0, i64 0
  %74 = load double, ptr %73, align 8, !tbaa !11
  %75 = fdiv double %74, %68
  store double %75, ptr %73, align 8, !tbaa !11
  %76 = load double, ptr %7, align 8, !tbaa !11
  %77 = load ptr, ptr %6, align 8, !tbaa !9
  %78 = load i32, ptr %13, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [3 x double], ptr %77, i64 %79
  %81 = getelementptr inbounds [3 x double], ptr %80, i64 0, i64 1
  %82 = load double, ptr %81, align 8, !tbaa !11
  %83 = fdiv double %82, %76
  store double %83, ptr %81, align 8, !tbaa !11
  %84 = load double, ptr %7, align 8, !tbaa !11
  %85 = load ptr, ptr %6, align 8, !tbaa !9
  %86 = load i32, ptr %13, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [3 x double], ptr %85, i64 %87
  %89 = getelementptr inbounds [3 x double], ptr %88, i64 0, i64 2
  %90 = load double, ptr %89, align 8, !tbaa !11
  %91 = fdiv double %90, %84
  store double %91, ptr %89, align 8, !tbaa !11
  br label %92

92:                                               ; preds = %67
  %93 = load i32, ptr %13, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %13, align 4, !tbaa !5
  br label %62, !llvm.loop !15

95:                                               ; preds = %66
  %96 = load double, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret double %96
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

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

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 willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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: mustprogress nounwind uwtable
declare dso_local void @_ZN3ptm19subtract_barycentreEiPA3_dS1_(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN3ptm18normalize_verticesEiPA3_dS1_(i32 noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  tail call void @_ZN3ptm19subtract_barycentreEiPA3_dS1_(i32 noundef %0, ptr noundef %1, ptr noundef %2)
  %4 = icmp sgt i32 %0, 1
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

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

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %5, -2
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %67, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %.03438.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %67, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %7 = getelementptr inbounds [3 x double], ptr %2, i64 %indvars.iv.unr
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %7, i64 8
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %7, i64 16
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = fmul double %10, %10
  %14 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %13)
  %15 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %14)
  %sqrt.epil = tail call double @llvm.sqrt.f64(double %15)
  %16 = fadd double %.03438.unr, %sqrt.epil
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %3
  %.034.lcssa = phi double [ 0.000000e+00, %3 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %16, %.lr.ph.epil ]
  %17 = sitofp i32 %0 to double
  %18 = fdiv double %.034.lcssa, %17
  %19 = icmp sgt i32 %0, 0
  br i1 %19, label %.lr.ph41.preheader, label %._crit_edge42

.lr.ph41.preheader:                               ; preds = %._crit_edge
  %wide.trip.count47 = zext nneg i32 %0 to i64
  %min.iters.check = icmp eq i32 %0, 1
  br i1 %min.iters.check, label %.lr.ph41.preheader49, label %vector.ph

.lr.ph41.preheader49:                             ; preds = %middle.block, %.lr.ph41.preheader
  %indvars.iv44.ph = phi i64 [ 0, %.lr.ph41.preheader ], [ %n.vec, %middle.block ]
  %20 = insertelement <2 x double> poison, double %18, i64 0
  %21 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> zeroinitializer
  br label %.lr.ph41

vector.ph:                                        ; preds = %.lr.ph41.preheader
  %n.vec = and i64 %wide.trip.count47, 2147483646
  %broadcast.splatinsert = insertelement <2 x double> poison, double %18, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %22 = or disjoint i64 %index, 1
  %23 = getelementptr inbounds [3 x double], ptr %2, i64 %index
  %24 = getelementptr inbounds [3 x double], ptr %2, i64 %22
  %25 = load double, ptr %23, align 8, !tbaa !5
  %26 = load double, ptr %24, align 8, !tbaa !5
  %27 = insertelement <2 x double> poison, double %25, i64 0
  %28 = insertelement <2 x double> %27, double %26, i64 1
  %29 = fdiv <2 x double> %28, %broadcast.splat
  %30 = getelementptr inbounds i8, ptr %23, i64 8
  %31 = getelementptr inbounds i8, ptr %24, i64 8
  %32 = load double, ptr %30, align 8, !tbaa !5
  %33 = load double, ptr %31, align 8, !tbaa !5
  %34 = insertelement <2 x double> poison, double %32, i64 0
  %35 = insertelement <2 x double> %34, double %33, i64 1
  %36 = fdiv <2 x double> %35, %broadcast.splat
  %37 = getelementptr inbounds i8, ptr %23, i64 16
  %38 = getelementptr inbounds i8, ptr %24, i64 16
  %39 = load double, ptr %37, align 8, !tbaa !5
  %40 = load double, ptr %38, align 8, !tbaa !5
  %41 = insertelement <2 x double> poison, double %39, i64 0
  %42 = insertelement <2 x double> %41, double %40, i64 1
  %43 = fdiv <2 x double> %42, %broadcast.splat
  %44 = shufflevector <2 x double> %29, <2 x double> %36, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  %45 = shufflevector <2 x double> %43, <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
  %interleaved.vec = shufflevector <4 x double> %44, <4 x double> %45, <6 x i32> <i32 0, i32 2, i32 4, i32 1, i32 3, i32 5>
  store <6 x double> %interleaved.vec, ptr %23, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 2
  %46 = icmp eq i64 %index.next, %n.vec
  br i1 %46, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count47
  br i1 %cmp.n, label %._crit_edge42, label %.lr.ph41.preheader49

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.03438 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %67, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %47 = getelementptr inbounds [3 x double], ptr %2, i64 %indvars.iv
  %48 = load double, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %47, i64 8
  %50 = load double, ptr %49, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %47, i64 16
  %52 = load double, ptr %51, align 8, !tbaa !5
  %53 = fmul double %50, %50
  %54 = tail call double @llvm.fmuladd.f64(double %48, double %48, double %53)
  %55 = tail call double @llvm.fmuladd.f64(double %52, double %52, double %54)
  %sqrt = tail call double @llvm.sqrt.f64(double %55)
  %56 = fadd double %.03438, %sqrt
  %57 = getelementptr inbounds [3 x double], ptr %2, i64 %indvars.iv
  %58 = getelementptr inbounds i8, ptr %57, i64 24
  %59 = load double, ptr %58, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %57, i64 32
  %61 = load double, ptr %60, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %57, i64 40
  %63 = load double, ptr %62, align 8, !tbaa !5
  %64 = fmul double %61, %61
  %65 = tail call double @llvm.fmuladd.f64(double %59, double %59, double %64)
  %66 = tail call double @llvm.fmuladd.f64(double %63, double %63, double %65)
  %sqrt.1 = tail call double @llvm.sqrt.f64(double %66)
  %67 = fadd double %56, %sqrt.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.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !13

._crit_edge42:                                    ; preds = %.lr.ph41, %middle.block, %._crit_edge
  ret double %18

.lr.ph41:                                         ; preds = %.lr.ph41.preheader49, %.lr.ph41
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %.lr.ph41 ], [ %indvars.iv44.ph, %.lr.ph41.preheader49 ]
  %68 = getelementptr inbounds [3 x double], ptr %2, i64 %indvars.iv44
  %69 = load <2 x double>, ptr %68, align 8, !tbaa !5
  %70 = fdiv <2 x double> %69, %21
  store <2 x double> %70, ptr %68, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %68, i64 16
  %72 = load double, ptr %71, align 8, !tbaa !5
  %73 = fdiv double %72, %18
  store double %73, ptr %71, align 8, !tbaa !5
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %exitcond48.not = icmp eq i64 %indvars.iv.next45, %wide.trip.count47
  br i1 %exitcond48.not, label %._crit_edge42, label %.lr.ph41, !llvm.loop !14
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.sqrt.f64(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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10, !12, !11}


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