; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseDescrInt.ll (ZNK4Simd4Base8DescrInt21CosineDistancesDirectEmmPKPKhS5_Pf)

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

%"class.Simd::Base::DescrInt" = type { %"struct.Simd::Deletable", ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, float, ptr, i64, i64, ptr, ptr, ptr, ptr, ptr, i64, i64, i64 }
%"struct.Simd::Deletable" = type { ptr }

; 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 @_ZNK4Simd4Base8DescrInt21CosineDistancesDirectEmmPKPKhS5_Pf(ptr noundef nonnull align 8 dereferenceable(184) %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #1 align 2 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %22 = call noundef i64 @_ZN4Simd4Base10AlgCacheL2Ev()
  store i64 %22, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %23 = load i64, ptr %13, align 8, !tbaa !9
  %24 = getelementptr inbounds %"class.Simd::Base::DescrInt", ptr %21, i32 0, i32 10
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = udiv i64 %23, %25
  %27 = getelementptr inbounds %"class.Simd::Base::DescrInt", ptr %21, i32 0, i32 14
  %28 = load i64, ptr %27, align 8, !tbaa !15
  %29 = call noundef i64 @_ZN4Simd10AlignLoAnyEmm(i64 noundef %26, i64 noundef %28)
  store i64 %29, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %30 = load i64, ptr %13, align 8, !tbaa !9
  %31 = getelementptr inbounds %"class.Simd::Base::DescrInt", ptr %21, i32 0, i32 10
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = udiv i64 %30, %32
  %34 = getelementptr inbounds %"class.Simd::Base::DescrInt", ptr %21, i32 0, i32 13
  %35 = load i64, ptr %34, align 8, !tbaa !16
  %36 = call noundef i64 @_ZN4Simd10AlignLoAnyEmm(i64 noundef %33, i64 noundef %35)
  store i64 %36, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %88, %6
  %38 = load i64, ptr %16, align 8, !tbaa !9
  %39 = load i64, ptr %8, align 8, !tbaa !9
  %40 = icmp ult i64 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  store i32 2, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %92

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %43 = load i64, ptr %8, align 8, !tbaa !9
  %44 = load i64, ptr %16, align 8, !tbaa !9
  %45 = load i64, ptr %15, align 8, !tbaa !9
  %46 = add i64 %44, %45
  %47 = call noundef i64 @_ZN4Simd3MinImEET_S1_S1_(i64 noundef %43, i64 noundef %46)
  %48 = load i64, ptr %16, align 8, !tbaa !9
  %49 = sub i64 %47, %48
  store i64 %49, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  store i64 0, ptr %19, align 8, !tbaa !9
  br label %50

50:                                               ; preds = %83, %42
  %51 = load i64, ptr %19, align 8, !tbaa !9
  %52 = load i64, ptr %9, align 8, !tbaa !9
  %53 = icmp ult i64 %51, %52
  br i1 %53, label %55, label %54

54:                                               ; preds = %50
  store i32 5, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  br label %87

55:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  %56 = load i64, ptr %9, align 8, !tbaa !9
  %57 = load i64, ptr %19, align 8, !tbaa !9
  %58 = load i64, ptr %14, align 8, !tbaa !9
  %59 = add i64 %57, %58
  %60 = call noundef i64 @_ZN4Simd3MinImEET_S1_S1_(i64 noundef %56, i64 noundef %59)
  %61 = load i64, ptr %19, align 8, !tbaa !9
  %62 = sub i64 %60, %61
  store i64 %62, ptr %20, align 8, !tbaa !9
  %63 = getelementptr inbounds %"class.Simd::Base::DescrInt", ptr %21, i32 0, i32 12
  %64 = load ptr, ptr %63, align 8, !tbaa !17
  %65 = load i64, ptr %18, align 8, !tbaa !9
  %66 = load i64, ptr %20, align 8, !tbaa !9
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = load i64, ptr %16, align 8, !tbaa !9
  %69 = getelementptr inbounds ptr, ptr %67, i64 %68
  %70 = load ptr, ptr %11, align 8, !tbaa !5
  %71 = load i64, ptr %19, align 8, !tbaa !9
  %72 = getelementptr inbounds ptr, ptr %70, i64 %71
  %73 = getelementptr inbounds %"class.Simd::Base::DescrInt", ptr %21, i32 0, i32 8
  %74 = load i64, ptr %73, align 8, !tbaa !18
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = load i64, ptr %16, align 8, !tbaa !9
  %77 = load i64, ptr %9, align 8, !tbaa !9
  %78 = mul i64 %76, %77
  %79 = getelementptr inbounds float, ptr %75, i64 %78
  %80 = load i64, ptr %19, align 8, !tbaa !9
  %81 = getelementptr inbounds float, ptr %79, i64 %80
  %82 = load i64, ptr %9, align 8, !tbaa !9
  call void %64(i64 noundef %65, i64 noundef %66, ptr noundef %69, ptr noundef %72, i64 noundef %74, ptr noundef %81, i64 noundef %82)
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  br label %83

83:                                               ; preds = %55
  %84 = load i64, ptr %14, align 8, !tbaa !9
  %85 = load i64, ptr %19, align 8, !tbaa !9
  %86 = add i64 %85, %84
  store i64 %86, ptr %19, align 8, !tbaa !9
  br label %50, !llvm.loop !19

87:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  br label %88

88:                                               ; preds = %87
  %89 = load i64, ptr %15, align 8, !tbaa !9
  %90 = load i64, ptr %16, align 8, !tbaa !9
  %91 = add i64 %90, %89
  store i64 %91, ptr %16, align 8, !tbaa !9
  br label %37, !llvm.loop !21

92:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  ret void
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd4Base10AlgCacheL2Ev() #2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd10AlignLoAnyEmm(i64 noundef, i64 noundef) #2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd3MinImEET_S1_S1_(i64 noundef, i64 noundef) #2

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 = { alwaysinline 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 = { 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 = !{!"any pointer", !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, !10, i64 80}
!12 = !{!"_ZTSN4Simd4Base8DescrIntE", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !14, i64 88, !6, i64 96, !10, i64 104, !10, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !10, i64 160, !10, i64 168, !10, i64 176}
!13 = !{!"_ZTSN4Simd9DeletableE"}
!14 = !{!"float", !7, i64 0}
!15 = !{!12, !10, i64 112}
!16 = !{!12, !10, i64 104}
!17 = !{!12, !6, i64 96}
!18 = !{!12, !10, i64 64}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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 uwtable
define dso_local void @_ZNK4Simd4Base8DescrInt21CosineDistancesDirectEmmPKPKhS5_Pf(ptr nocapture noundef nonnull readonly align 8 dereferenceable(184) %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #0 align 2 {
  %7 = tail call noundef i64 @_ZN4Simd4Base10AlgCacheL2Ev()
  %8 = getelementptr inbounds i8, ptr %0, i64 80
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = udiv i64 %7, %9
  %11 = getelementptr inbounds i8, ptr %0, i64 112
  %12 = load i64, ptr %11, align 8, !tbaa !13
  %13 = tail call noundef i64 @_ZN4Simd10AlignLoAnyEmm(i64 noundef %10, i64 noundef %12)
  %14 = load i64, ptr %8, align 8, !tbaa !5
  %15 = udiv i64 %7, %14
  %16 = getelementptr inbounds i8, ptr %0, i64 104
  %17 = load i64, ptr %16, align 8, !tbaa !14
  %18 = tail call noundef i64 @_ZN4Simd10AlignLoAnyEmm(i64 noundef %15, i64 noundef %17)
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph34

.lr.ph34:                                         ; preds = %6
  %.not35 = icmp eq i64 %2, 0
  %19 = getelementptr inbounds i8, ptr %0, i64 96
  %20 = getelementptr inbounds i8, ptr %0, i64 64
  br i1 %.not35, label %.loopexit, label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph34, %..loopexit_crit_edge.us
  %.033.us = phi i64 [ %21, %..loopexit_crit_edge.us ], [ 0, %.lr.ph34 ]
  %21 = add i64 %.033.us, %18
  %22 = tail call noundef i64 @_ZN4Simd3MinImEET_S1_S1_(i64 noundef %1, i64 noundef %21)
  %23 = sub i64 %22, %.033.us
  %24 = getelementptr inbounds ptr, ptr %3, i64 %.033.us
  %25 = mul i64 %.033.us, %2
  %26 = getelementptr inbounds float, ptr %5, i64 %25
  br label %27

27:                                               ; preds = %.lr.ph.us, %27
  %.02932.us = phi i64 [ 0, %.lr.ph.us ], [ %28, %27 ]
  %28 = add i64 %.02932.us, %13
  %29 = tail call noundef i64 @_ZN4Simd3MinImEET_S1_S1_(i64 noundef %2, i64 noundef %28)
  %30 = sub i64 %29, %.02932.us
  %31 = load ptr, ptr %19, align 8, !tbaa !15
  %32 = getelementptr inbounds ptr, ptr %4, i64 %.02932.us
  %33 = load i64, ptr %20, align 8, !tbaa !16
  %34 = getelementptr inbounds float, ptr %26, i64 %.02932.us
  tail call void %31(i64 noundef %23, i64 noundef %30, ptr noundef %24, ptr noundef %32, i64 noundef %33, ptr noundef %34, i64 noundef %2)
  %35 = icmp ult i64 %28, %2
  br i1 %35, label %27, label %..loopexit_crit_edge.us, !llvm.loop !17

..loopexit_crit_edge.us:                          ; preds = %27
  %36 = icmp ult i64 %21, %1
  br i1 %36, label %.lr.ph.us, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %..loopexit_crit_edge.us, %.loopexit, %6
  ret void

.loopexit:                                        ; preds = %.lr.ph34, %.loopexit
  %.033 = phi i64 [ %37, %.loopexit ], [ 0, %.lr.ph34 ]
  %37 = add i64 %.033, %18
  %38 = tail call noundef i64 @_ZN4Simd3MinImEET_S1_S1_(i64 noundef %1, i64 noundef %37)
  %39 = icmp ult i64 %37, %1
  br i1 %39, label %.loopexit, label %._crit_edge, !llvm.loop !19
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd4Base10AlgCacheL2Ev() local_unnamed_addr #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd10AlignLoAnyEmm(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd3MinImEET_S1_S1_(i64 noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { alwaysinline 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" }

!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, !11, i64 80}
!6 = !{!"_ZTSN4Simd4Base8DescrIntE", !7, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !12, i64 88, !8, i64 96, !11, i64 104, !11, i64 112, !8, i64 120, !8, i64 128, !8, i64 136, !8, i64 144, !8, i64 152, !11, i64 160, !11, i64 168, !11, i64 176}
!7 = !{!"_ZTSN4Simd9DeletableE"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"float", !9, i64 0}
!13 = !{!6, !11, i64 112}
!14 = !{!6, !11, i64 104}
!15 = !{!6, !8, i64 96}
!16 = !{!6, !11, i64 64}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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