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

; 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 uwtable
define dso_local void @_ZN3vot22MultiComputeAssignmentEmiiPPhPdPiS2_Pm(i64 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7) #1 {
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca double, align 8
  %18 = alloca i64, align 8
  %19 = alloca i32, align 4
  %20 = alloca double, align 8
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca double, align 8
  store i64 %0, ptr %9, align 8, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !9
  store i32 %2, ptr %11, align 4, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !11
  store ptr %4, ptr %13, align 8, !tbaa !11
  store ptr %5, ptr %14, align 8, !tbaa !11
  store ptr %6, ptr %15, align 8, !tbaa !11
  store ptr %7, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  store double 0.000000e+00, ptr %17, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  store i64 0, ptr %18, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %78, %8
  %25 = load i64, ptr %18, align 8, !tbaa !5
  %26 = load i64, ptr %9, align 8, !tbaa !5
  %27 = icmp ult i64 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 2, ptr %19, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %81

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %30 = call noundef double @_ZNSt14numeric_limitsIdE3maxEv() #4
  store double %30, ptr %20, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  store i32 -1, ptr %21, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #4
  store i32 0, ptr %22, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %56, %29
  %32 = load i32, ptr %22, align 4, !tbaa !9
  %33 = load i32, ptr %11, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

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

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #4
  %37 = load ptr, ptr %13, align 8, !tbaa !11
  %38 = load i32, ptr %22, align 4, !tbaa !9
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = mul nsw i32 %38, %39
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds double, ptr %37, i64 %41
  %43 = load ptr, ptr %12, align 8, !tbaa !11
  %44 = load i64, ptr %18, align 8, !tbaa !5
  %45 = getelementptr inbounds ptr, ptr %43, i64 %44
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = call noundef double @_ZN3vot13DisDes2DoubleEPdPhi(ptr noundef %42, ptr noundef %46, i32 noundef %47)
  store double %48, ptr %23, align 8, !tbaa !13
  %49 = load double, ptr %20, align 8, !tbaa !13
  %50 = load double, ptr %23, align 8, !tbaa !13
  %51 = fcmp ogt double %49, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %36
  %53 = load double, ptr %23, align 8, !tbaa !13
  store double %53, ptr %20, align 8, !tbaa !13
  %54 = load i32, ptr %22, align 4, !tbaa !9
  store i32 %54, ptr %21, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %52, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #4
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %22, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %22, align 4, !tbaa !9
  br label %31, !llvm.loop !15

59:                                               ; preds = %35
  %60 = load double, ptr %20, align 8, !tbaa !13
  %61 = load double, ptr %17, align 8, !tbaa !13
  %62 = fadd double %61, %60
  store double %62, ptr %17, align 8, !tbaa !13
  %63 = load ptr, ptr %14, align 8, !tbaa !11
  %64 = load i64, ptr %18, align 8, !tbaa !5
  %65 = getelementptr inbounds i32, ptr %63, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = load i32, ptr %21, align 4, !tbaa !9
  %68 = icmp ne i32 %66, %67
  br i1 %68, label %69, label %77

69:                                               ; preds = %59
  %70 = load i32, ptr %21, align 4, !tbaa !9
  %71 = load ptr, ptr %14, align 8, !tbaa !11
  %72 = load i64, ptr %18, align 8, !tbaa !5
  %73 = getelementptr inbounds i32, ptr %71, i64 %72
  store i32 %70, ptr %73, align 4, !tbaa !9
  %74 = load ptr, ptr %16, align 8, !tbaa !11
  %75 = load i64, ptr %74, align 8, !tbaa !5
  %76 = add i64 %75, 1
  store i64 %76, ptr %74, align 8, !tbaa !5
  br label %77

77:                                               ; preds = %69, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  br label %78

78:                                               ; preds = %77
  %79 = load i64, ptr %18, align 8, !tbaa !5
  %80 = add i64 %79, 1
  store i64 %80, ptr %18, align 8, !tbaa !5
  br label %24, !llvm.loop !17

81:                                               ; preds = %28
  %82 = load double, ptr %17, align 8, !tbaa !13
  %83 = load ptr, ptr %15, align 8, !tbaa !11
  store double %82, ptr %83, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNSt14numeric_limitsIdE3maxEv() #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3vot13DisDes2DoubleEPdPhi(ptr noundef, ptr noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { inlinehint 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 #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 = !{!"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 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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
define dso_local void @_ZN3vot22MultiComputeAssignmentEmiiPPhPdPiS2_Pm(i64 noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, ptr noundef %4, ptr nocapture noundef %5, ptr nocapture noundef writeonly %6, ptr nocapture noundef %7) local_unnamed_addr #0 {
  %.not42 = icmp eq i64 %0, 0
  br i1 %.not42, label %._crit_edge40, label %.lr.ph39

.lr.ph39:                                         ; preds = %8
  %9 = icmp sgt i32 %2, 0
  br i1 %9, label %.lr.ph.us.preheader, label %.lr.ph39.split

.lr.ph.us.preheader:                              ; preds = %.lr.ph39
  %10 = sext i32 %1 to i64
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %16
  %.037.us = phi double [ %25, %16 ], [ 0.000000e+00, %.lr.ph.us.preheader ]
  %.03036.us = phi i64 [ %17, %16 ], [ 0, %.lr.ph.us.preheader ]
  %11 = tail call noundef double @_ZNSt14numeric_limitsIdE3maxEv() #2
  %12 = getelementptr inbounds ptr, ptr %3, i64 %.03036.us
  br label %18

13:                                               ; preds = %._crit_edge.us
  store i32 %.1.us, ptr %26, align 4, !tbaa !5
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = add i64 %14, 1
  store i64 %15, ptr %7, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %13, %._crit_edge.us
  %17 = add nuw i64 %.03036.us, 1
  %exitcond47.not = icmp eq i64 %17, %0
  br i1 %exitcond47.not, label %._crit_edge40, label %.lr.ph.us, !llvm.loop !11

18:                                               ; preds = %.lr.ph.us, %18
  %indvars.iv = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next, %18 ]
  %.02733.us = phi i32 [ -1, %.lr.ph.us ], [ %.1.us, %18 ]
  %.02832.us = phi double [ %11, %.lr.ph.us ], [ %.129.us, %18 ]
  %19 = mul nsw i64 %indvars.iv, %10
  %20 = getelementptr inbounds double, ptr %4, i64 %19
  %21 = load ptr, ptr %12, align 8, !tbaa !13
  %22 = tail call noundef double @_ZN3vot13DisDes2DoubleEPdPhi(ptr noundef %20, ptr noundef %21, i32 noundef %1)
  %23 = fcmp ogt double %.02832.us, %22
  %.129.us = select i1 %23, double %22, double %.02832.us
  %24 = trunc nuw nsw i64 %indvars.iv to i32
  %.1.us = select i1 %23, i32 %24, i32 %.02733.us
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond46.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond46.not, label %._crit_edge.us, label %18, !llvm.loop !15

._crit_edge.us:                                   ; preds = %18
  %25 = fadd double %.037.us, %.129.us
  %26 = getelementptr inbounds i32, ptr %5, i64 %.03036.us
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not.us = icmp eq i32 %27, %.1.us
  br i1 %.not.us, label %16, label %13

._crit_edge40:                                    ; preds = %35, %16, %8
  %.0.lcssa = phi double [ 0.000000e+00, %8 ], [ %25, %16 ], [ %29, %35 ]
  store double %.0.lcssa, ptr %6, align 8, !tbaa !16
  ret void

.lr.ph39.split:                                   ; preds = %.lr.ph39, %35
  %.037 = phi double [ %29, %35 ], [ 0.000000e+00, %.lr.ph39 ]
  %.03036 = phi i64 [ %36, %35 ], [ 0, %.lr.ph39 ]
  %28 = tail call noundef double @_ZNSt14numeric_limitsIdE3maxEv() #2
  %29 = fadd double %.037, %28
  %30 = getelementptr inbounds i32, ptr %5, i64 %.03036
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %.not = icmp eq i32 %31, -1
  br i1 %.not, label %35, label %32

32:                                               ; preds = %.lr.ph39.split
  store i32 -1, ptr %30, align 4, !tbaa !5
  %33 = load i64, ptr %7, align 8, !tbaa !9
  %34 = add i64 %33, 1
  store i64 %34, ptr %7, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %32, %.lr.ph39.split
  %36 = add nuw i64 %.03036, 1
  %exitcond.not = icmp eq i64 %36, %0
  br i1 %exitcond.not, label %._crit_edge40, label %.lr.ph39.split, !llvm.loop !11
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNSt14numeric_limitsIdE3maxEv() local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3vot13DisDes2DoubleEPdPhi(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #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 = { inlinehint 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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = distinct !{!15, !12}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}


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