; LLVM IR from hlzz/libvot :: src/vocab_tree/clustering.ll (ZN3vot12ComputeErrorEmiiPPhPdPi)

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

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

19:                                               ; preds = %66, %6
  %20 = load i32, ptr %14, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = load i64, ptr %7, align 8, !tbaa !5
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %19
  store i32 2, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %69

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %26 = load ptr, ptr %12, align 8, !tbaa !11
  %27 = load i32, ptr %14, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %26, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !9
  store i32 %30, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %62, %25
  %32 = load i32, ptr %17, align 4, !tbaa !9
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 5, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  br label %65

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %37 = load ptr, ptr %11, align 8, !tbaa !11
  %38 = load i32, ptr %16, align 4, !tbaa !9
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = mul nsw i32 %38, %39
  %41 = load i32, ptr %17, align 4, !tbaa !9
  %42 = add nsw i32 %40, %41
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds double, ptr %37, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !13
  %46 = load ptr, ptr %10, align 8, !tbaa !11
  %47 = load i32, ptr %14, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds ptr, ptr %46, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = load i32, ptr %17, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %50, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !15
  %55 = zext i8 %54 to i32
  %56 = sitofp i32 %55 to double
  %57 = fsub double %45, %56
  store double %57, ptr %18, align 8, !tbaa !13
  %58 = load double, ptr %18, align 8, !tbaa !13
  %59 = load double, ptr %18, align 8, !tbaa !13
  %60 = load double, ptr %13, align 8, !tbaa !13
  %61 = call double @llvm.fmuladd.f64(double %58, double %59, double %60)
  store double %61, ptr %13, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  br label %62

62:                                               ; preds = %36
  %63 = load i32, ptr %17, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %17, align 4, !tbaa !9
  br label %31, !llvm.loop !16

65:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %14, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %14, align 4, !tbaa !9
  br label %19, !llvm.loop !18

69:                                               ; preds = %24
  %70 = load double, ptr %13, align 8, !tbaa !13
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  ret double %70
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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 nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef double @_ZN3vot12ComputeErrorEmiiPPhPdPi(i64 noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, ptr nocapture noundef readonly %5) local_unnamed_addr #0 {
  %.not = icmp ne i64 %0, 0
  %7 = icmp sgt i32 %1, 0
  %or.cond = and i1 %.not, %7
  br i1 %or.cond, label %.lr.ph.us.preheader, label %._crit_edge28

.lr.ph.us.preheader:                              ; preds = %6
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %8 = icmp eq i32 %1, 1
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %indvars.iv33 = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next34, %._crit_edge.us ]
  %.025.us = phi double [ 0.000000e+00, %.lr.ph.us.preheader ], [ %.lcssa, %._crit_edge.us ]
  %9 = getelementptr inbounds i32, ptr %5, i64 %indvars.iv33
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = mul nsw i32 %10, %1
  %12 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv33
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = sext i32 %11 to i64
  %invariant.gep = getelementptr double, ptr %4, i64 %14
  br i1 %8, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %.lr.ph.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %.123.us = phi double [ %26, %.lr.ph.us.new ], [ %.025.us, %.lr.ph.us ]
  %niter = phi i64 [ %niter.next.1, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %gep = getelementptr double, ptr %invariant.gep, i64 %indvars.iv
  %15 = load double, ptr %gep, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv
  %17 = load i8, ptr %16, align 1, !tbaa !13
  %18 = uitofp i8 %17 to double
  %19 = fsub double %15, %18
  %20 = tail call double @llvm.fmuladd.f64(double %19, double %19, double %.123.us)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %gep.1 = getelementptr double, ptr %invariant.gep, i64 %indvars.iv.next
  %21 = load double, ptr %gep.1, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv.next
  %23 = load i8, ptr %22, align 1, !tbaa !13
  %24 = uitofp i8 %23 to double
  %25 = fsub double %21, %24
  %26 = tail call double @llvm.fmuladd.f64(double %25, double %25, double %20)
  %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.us.unr-lcssa, label %.lr.ph.us.new, !llvm.loop !14

._crit_edge.us.unr-lcssa:                         ; preds = %.lr.ph.us.new, %.lr.ph.us
  %.lcssa.ph = phi double [ poison, %.lr.ph.us ], [ %26, %.lr.ph.us.new ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next.1, %.lr.ph.us.new ]
  %.123.us.unr = phi double [ %.025.us, %.lr.ph.us ], [ %26, %.lr.ph.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %gep.epil = getelementptr double, ptr %invariant.gep, i64 %indvars.iv.unr
  %27 = load double, ptr %gep.epil, align 8, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv.unr
  %29 = load i8, ptr %28, align 1, !tbaa !13
  %30 = uitofp i8 %29 to double
  %31 = fsub double %27, %30
  %32 = tail call double @llvm.fmuladd.f64(double %31, double %31, double %.123.us.unr)
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %32, %._crit_edge.us.epilog-lcssa ]
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond36.not = icmp eq i64 %indvars.iv.next34, %0
  br i1 %exitcond36.not, label %._crit_edge28, label %.lr.ph.us, !llvm.loop !16

._crit_edge28:                                    ; preds = %._crit_edge.us, %6
  %.0.lcssa = phi double [ 0.000000e+00, %6 ], [ %.lcssa, %._crit_edge.us ]
  ret double %.0.lcssa
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn 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 = !{!"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 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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