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

; 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 void @_ZN3vot20MultiDesAccumulationEmiiPPhPiPdPm(i64 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #1 {
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store i64 %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !11
  store ptr %4, ptr %12, align 8, !tbaa !11
  store ptr %5, ptr %13, align 8, !tbaa !11
  store ptr %6, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  store i64 0, ptr %15, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %64, %7
  %20 = load i64, ptr %15, align 8, !tbaa !5
  %21 = load i64, ptr %8, align 8, !tbaa !5
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  br label %67

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #2
  %25 = load ptr, ptr %12, align 8, !tbaa !11
  %26 = load i64, ptr %15, align 8, !tbaa !5
  %27 = getelementptr inbounds i32, ptr %25, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  store i32 %28, ptr %17, align 4, !tbaa !9
  %29 = load ptr, ptr %14, align 8, !tbaa !11
  %30 = load i32, ptr %17, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i64, ptr %29, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = add i64 %33, 1
  store i64 %34, ptr %32, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #2
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %60, %24
  %36 = load i32, ptr %18, align 4, !tbaa !9
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  store i32 5, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #2
  br label %63

40:                                               ; preds = %35
  %41 = load ptr, ptr %11, align 8, !tbaa !11
  %42 = load i64, ptr %15, align 8, !tbaa !5
  %43 = getelementptr inbounds ptr, ptr %41, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  %45 = load i32, ptr %18, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %44, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !13
  %49 = uitofp i8 %48 to double
  %50 = load ptr, ptr %13, align 8, !tbaa !11
  %51 = load i32, ptr %17, align 4, !tbaa !9
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = mul nsw i32 %51, %52
  %54 = load i32, ptr %18, align 4, !tbaa !9
  %55 = add nsw i32 %53, %54
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %50, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !14
  %59 = fadd double %58, %49
  store double %59, ptr %57, align 8, !tbaa !14
  br label %60

60:                                               ; preds = %40
  %61 = load i32, ptr %18, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %18, align 4, !tbaa !9
  br label %35, !llvm.loop !16

63:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  br label %64

64:                                               ; preds = %63
  %65 = load i64, ptr %15, align 8, !tbaa !5
  %66 = add i64 %65, 1
  store i64 %66, ptr %15, align 8, !tbaa !5
  br label %19, !llvm.loop !18

67:                                               ; preds = %23
  ret void
}

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 = { 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 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !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 memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN3vot20MultiDesAccumulationEmiiPPhPiPdPm(i64 noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, ptr nocapture noundef %5, ptr nocapture noundef %6) local_unnamed_addr #0 {
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %._crit_edge22, label %.lr.ph21

.lr.ph21:                                         ; preds = %7
  %8 = icmp sgt i32 %1, 0
  br i1 %8, label %.lr.ph.us.preheader, label %.lr.ph21.split.preheader

.lr.ph21.split.preheader:                         ; preds = %.lr.ph21
  %xtraiter = and i64 %0, 3
  %9 = icmp ult i64 %0, 4
  br i1 %9, label %._crit_edge22.loopexit34.unr-lcssa, label %.lr.ph21.split.preheader.new

.lr.ph21.split.preheader.new:                     ; preds = %.lr.ph21.split.preheader
  %unroll_iter = and i64 %0, -4
  br label %.lr.ph21.split

.lr.ph.us.preheader:                              ; preds = %.lr.ph21
  %wide.trip.count = zext nneg i32 %1 to i64
  %10 = shl nuw nsw i64 %wide.trip.count, 3
  %scevgep = getelementptr i8, ptr %5, i64 %10
  %min.iters.check = icmp ult i32 %1, 4
  %n.vec = and i64 %wide.trip.count, 2147483644
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  %xtraiter35 = and i64 %wide.trip.count, 1
  %lcmp.mod36.not = icmp eq i64 %xtraiter35, 0
  %11 = add nsw i64 %wide.trip.count, -1
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.01619.us = phi i64 [ %48, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %12 = getelementptr inbounds i32, ptr %4, i64 %.01619.us
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i64, ptr %6, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = add i64 %16, 1
  store i64 %17, ptr %15, align 8, !tbaa !9
  %18 = getelementptr inbounds ptr, ptr %3, i64 %.01619.us
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = mul nsw i32 %13, %1
  %21 = sext i32 %20 to i64
  %invariant.gep = getelementptr double, ptr %5, i64 %21
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph.us
  %22 = shl nsw i64 %21, 3
  %scevgep29 = getelementptr i8, ptr %scevgep, i64 %22
  %scevgep30 = getelementptr i8, ptr %19, i64 %wide.trip.count
  %bound0 = icmp ult ptr %invariant.gep, %scevgep30
  %bound1 = icmp ult ptr %19, %scevgep29
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %vector.memcheck, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %vector.memcheck ]
  %23 = getelementptr inbounds i8, ptr %19, i64 %index
  %24 = getelementptr inbounds i8, ptr %23, i64 2
  %wide.load = load <2 x i8>, ptr %23, align 1, !tbaa !13, !alias.scope !14
  %wide.load31 = load <2 x i8>, ptr %24, align 1, !tbaa !13, !alias.scope !14
  %25 = uitofp <2 x i8> %wide.load to <2 x double>
  %26 = uitofp <2 x i8> %wide.load31 to <2 x double>
  %27 = getelementptr double, ptr %invariant.gep, i64 %index
  %28 = getelementptr i8, ptr %27, i64 16
  %wide.load32 = load <2 x double>, ptr %27, align 8, !tbaa !17, !alias.scope !19, !noalias !14
  %wide.load33 = load <2 x double>, ptr %28, align 8, !tbaa !17, !alias.scope !19, !noalias !14
  %29 = fadd <2 x double> %wide.load32, %25
  %30 = fadd <2 x double> %wide.load33, %26
  store <2 x double> %29, ptr %27, align 8, !tbaa !17, !alias.scope !19, !noalias !14
  store <2 x double> %30, ptr %28, align 8, !tbaa !17, !alias.scope !19, !noalias !14
  %index.next = add nuw i64 %index, 4
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !21

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph.us
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod36.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %32 = getelementptr inbounds i8, ptr %19, i64 %indvars.iv.ph
  %33 = load i8, ptr %32, align 1, !tbaa !13
  %34 = uitofp i8 %33 to double
  %gep.prol = getelementptr double, ptr %invariant.gep, i64 %indvars.iv.ph
  %35 = load double, ptr %gep.prol, align 8, !tbaa !17
  %36 = fadd double %35, %34
  store double %36, ptr %gep.prol, align 8, !tbaa !17
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %37 = icmp eq i64 %indvars.iv.ph, %11
  br i1 %37, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %38 = getelementptr inbounds i8, ptr %19, i64 %indvars.iv
  %39 = load i8, ptr %38, align 1, !tbaa !13
  %40 = uitofp i8 %39 to double
  %gep = getelementptr double, ptr %invariant.gep, i64 %indvars.iv
  %41 = load double, ptr %gep, align 8, !tbaa !17
  %42 = fadd double %41, %40
  store double %42, ptr %gep, align 8, !tbaa !17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = getelementptr inbounds i8, ptr %19, i64 %indvars.iv.next
  %44 = load i8, ptr %43, align 1, !tbaa !13
  %45 = uitofp i8 %44 to double
  %gep.1 = getelementptr double, ptr %invariant.gep, i64 %indvars.iv.next
  %46 = load double, ptr %gep.1, align 8, !tbaa !17
  %47 = fadd double %46, %45
  store double %47, ptr %gep.1, align 8, !tbaa !17
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond25.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond25.not.1, label %._crit_edge.us, label %scalar.ph, !llvm.loop !25

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %48 = add nuw i64 %.01619.us, 1
  %exitcond26.not = icmp eq i64 %48, %0
  br i1 %exitcond26.not, label %._crit_edge22, label %.lr.ph.us, !llvm.loop !26

._crit_edge22.loopexit34.unr-lcssa:               ; preds = %.lr.ph21.split, %.lr.ph21.split.preheader
  %.01619.unr = phi i64 [ 0, %.lr.ph21.split.preheader ], [ %83, %.lr.ph21.split ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge22, label %.lr.ph21.split.epil

.lr.ph21.split.epil:                              ; preds = %._crit_edge22.loopexit34.unr-lcssa, %.lr.ph21.split.epil
  %.01619.epil = phi i64 [ %55, %.lr.ph21.split.epil ], [ %.01619.unr, %._crit_edge22.loopexit34.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph21.split.epil ], [ 0, %._crit_edge22.loopexit34.unr-lcssa ]
  %49 = getelementptr inbounds i32, ptr %4, i64 %.01619.epil
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i64, ptr %6, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !9
  %54 = add i64 %53, 1
  store i64 %54, ptr %52, align 8, !tbaa !9
  %55 = add nuw i64 %.01619.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_edge22, label %.lr.ph21.split.epil, !llvm.loop !27

._crit_edge22:                                    ; preds = %._crit_edge22.loopexit34.unr-lcssa, %.lr.ph21.split.epil, %._crit_edge.us, %7
  ret void

.lr.ph21.split:                                   ; preds = %.lr.ph21.split, %.lr.ph21.split.preheader.new
  %.01619 = phi i64 [ 0, %.lr.ph21.split.preheader.new ], [ %83, %.lr.ph21.split ]
  %niter = phi i64 [ 0, %.lr.ph21.split.preheader.new ], [ %niter.next.3, %.lr.ph21.split ]
  %56 = getelementptr inbounds i32, ptr %4, i64 %.01619
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i64, ptr %6, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !9
  %61 = add i64 %60, 1
  store i64 %61, ptr %59, align 8, !tbaa !9
  %62 = or disjoint i64 %.01619, 1
  %63 = getelementptr inbounds i32, ptr %4, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i64, ptr %6, i64 %65
  %67 = load i64, ptr %66, align 8, !tbaa !9
  %68 = add i64 %67, 1
  store i64 %68, ptr %66, align 8, !tbaa !9
  %69 = or disjoint i64 %.01619, 2
  %70 = getelementptr inbounds i32, ptr %4, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i64, ptr %6, i64 %72
  %74 = load i64, ptr %73, align 8, !tbaa !9
  %75 = add i64 %74, 1
  store i64 %75, ptr %73, align 8, !tbaa !9
  %76 = or disjoint i64 %.01619, 3
  %77 = getelementptr inbounds i32, ptr %4, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i64, ptr %6, i64 %79
  %81 = load i64, ptr %80, align 8, !tbaa !9
  %82 = add i64 %81, 1
  store i64 %82, ptr %80, align 8, !tbaa !9
  %83 = add nuw i64 %.01619, 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_edge22.loopexit34.unr-lcssa, label %.lr.ph21.split, !llvm.loop !26
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15}
!15 = distinct !{!15, !16}
!16 = distinct !{!16, !"LVerDomain"}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !7, i64 0}
!19 = !{!20}
!20 = distinct !{!20, !16}
!21 = distinct !{!21, !22, !23, !24}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!"llvm.loop.isvectorized", i32 1}
!24 = !{!"llvm.loop.unroll.runtime.disable"}
!25 = distinct !{!25, !22, !23}
!26 = distinct !{!26, !22}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass