; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseDescrInt.ll (ZNK4Simd4Base8DescrInt19CosineDistancesMxNpEmmPKhS3_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"

%"struct.Simd::Array" = type { ptr, i64 }
%"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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK4Simd4Base8DescrInt19CosineDistancesMxNaEmmPKPKhS5_Pf(ptr noundef nonnull align 8 dereferenceable(184), i64 noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK4Simd4Base8DescrInt19CosineDistancesMxNpEmmPKhS3_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 personality ptr @__gxx_personality_v0 {
  %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 %"struct.Simd::Array", align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca %"struct.Simd::Array", align 8
  %18 = 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
  %19 = load ptr, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #4
  %20 = load i64, ptr %8, align 8, !tbaa !9
  call void @_ZN4Simd5ArrayIPKhEC2Embm(ptr noundef nonnull align 8 dereferenceable(16) %13, i64 noundef %20, i1 noundef zeroext false, i64 noundef 8)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %36, %6
  %22 = load i64, ptr %14, align 8, !tbaa !9
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = icmp ult i64 %22, %23
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %21
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = load i64, ptr %14, align 8, !tbaa !9
  %29 = getelementptr inbounds %"class.Simd::Base::DescrInt", ptr %19, i32 0, i32 10
  %30 = load i64, ptr %29, align 8, !tbaa !11
  %31 = mul i64 %28, %30
  %32 = getelementptr inbounds i8, ptr %27, i64 %31
  %33 = load i64, ptr %14, align 8, !tbaa !9
  %34 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZN4Simd5ArrayIPKhEixEm(ptr noundef nonnull align 8 dereferenceable(16) %13, i64 noundef %33)
          to label %35 unwind label %39

35:                                               ; preds = %26
  store ptr %32, ptr %34, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %35
  %37 = load i64, ptr %14, align 8, !tbaa !9
  %38 = add i64 %37, 1
  store i64 %38, ptr %14, align 8, !tbaa !9
  br label %21, !llvm.loop !15

39:                                               ; preds = %26
  %40 = landingpad { ptr, i32 }
          cleanup
  %41 = extractvalue { ptr, i32 } %40, 0
  store ptr %41, ptr %15, align 8
  %42 = extractvalue { ptr, i32 } %40, 1
  store i32 %42, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %87

43:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 16, ptr %17) #4
  %44 = load i64, ptr %9, align 8, !tbaa !9
  invoke void @_ZN4Simd5ArrayIPKhEC2Embm(ptr noundef nonnull align 8 dereferenceable(16) %17, i64 noundef %44, i1 noundef zeroext false, i64 noundef 8)
          to label %45 unwind label %51

45:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  store i64 0, ptr %18, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %65, %45
  %47 = load i64, ptr %18, align 8, !tbaa !9
  %48 = load i64, ptr %9, align 8, !tbaa !9
  %49 = icmp ult i64 %47, %48
  br i1 %49, label %55, label %50

50:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %72

51:                                               ; preds = %43
  %52 = landingpad { ptr, i32 }
          cleanup
  %53 = extractvalue { ptr, i32 } %52, 0
  store ptr %53, ptr %15, align 8
  %54 = extractvalue { ptr, i32 } %52, 1
  store i32 %54, ptr %16, align 4
  br label %86

55:                                               ; preds = %46
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load i64, ptr %18, align 8, !tbaa !9
  %58 = getelementptr inbounds %"class.Simd::Base::DescrInt", ptr %19, i32 0, i32 10
  %59 = load i64, ptr %58, align 8, !tbaa !11
  %60 = mul i64 %57, %59
  %61 = getelementptr inbounds i8, ptr %56, i64 %60
  %62 = load i64, ptr %18, align 8, !tbaa !9
  %63 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZN4Simd5ArrayIPKhEixEm(ptr noundef nonnull align 8 dereferenceable(16) %17, i64 noundef %62)
          to label %64 unwind label %68

64:                                               ; preds = %55
  store ptr %61, ptr %63, align 8, !tbaa !5
  br label %65

65:                                               ; preds = %64
  %66 = load i64, ptr %18, align 8, !tbaa !9
  %67 = add i64 %66, 1
  store i64 %67, ptr %18, align 8, !tbaa !9
  br label %46, !llvm.loop !17

68:                                               ; preds = %55
  %69 = landingpad { ptr, i32 }
          cleanup
  %70 = extractvalue { ptr, i32 } %69, 0
  store ptr %70, ptr %15, align 8
  %71 = extractvalue { ptr, i32 } %69, 1
  store i32 %71, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %85

72:                                               ; preds = %50
  %73 = load i64, ptr %8, align 8, !tbaa !9
  %74 = load i64, ptr %9, align 8, !tbaa !9
  %75 = getelementptr inbounds %"struct.Simd::Array", ptr %13, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !18
  %77 = getelementptr inbounds %"struct.Simd::Array", ptr %17, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !18
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  invoke void @_ZNK4Simd4Base8DescrInt19CosineDistancesMxNaEmmPKPKhS5_Pf(ptr noundef nonnull align 8 dereferenceable(184) %19, i64 noundef %73, i64 noundef %74, ptr noundef %76, ptr noundef %78, ptr noundef %79)
          to label %80 unwind label %81

80:                                               ; preds = %72
  call void @_ZN4Simd5ArrayIPKhED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %17) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %17) #4
  call void @_ZN4Simd5ArrayIPKhED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %13) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #4
  ret void

81:                                               ; preds = %72
  %82 = landingpad { ptr, i32 }
          cleanup
  %83 = extractvalue { ptr, i32 } %82, 0
  store ptr %83, ptr %15, align 8
  %84 = extractvalue { ptr, i32 } %82, 1
  store i32 %84, ptr %16, align 4
  br label %85

85:                                               ; preds = %81, %68
  call void @_ZN4Simd5ArrayIPKhED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %17) #4
  br label %86

86:                                               ; preds = %85, %51
  call void @llvm.lifetime.end.p0(i64 16, ptr %17) #4
  br label %87

87:                                               ; preds = %86, %39
  call void @_ZN4Simd5ArrayIPKhED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %13) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #4
  br label %88

88:                                               ; preds = %87
  %89 = load ptr, ptr %15, align 8
  %90 = load i32, ptr %16, align 4
  %91 = insertvalue { ptr, i32 } poison, ptr %89, 0
  %92 = insertvalue { ptr, i32 } %91, i32 %90, 1
  resume { ptr, i32 } %92
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN4Simd5ArrayIPKhEC2Embm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i1 noundef zeroext, i64 noundef) unnamed_addr #2 align 2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN4Simd5ArrayIPKhEixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) #3 align 2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local void @_ZN4Simd5ArrayIPKhED2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3 align 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 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 = { 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 #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 = !{!"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 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{!19, !6, i64 0}
!19 = !{!"_ZTSN4Simd5ArrayIPKhEE", !6, i64 0, !10, i64 8}


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

%"struct.Simd::Array" = type { ptr, i64 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK4Simd4Base8DescrInt19CosineDistancesMxNaEmmPKPKhS5_Pf(ptr noundef nonnull align 8 dereferenceable(184), i64 noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK4Simd4Base8DescrInt19CosineDistancesMxNpEmmPKhS3_Pf(ptr noundef nonnull align 8 dereferenceable(184) %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %7 = alloca %"struct.Simd::Array", align 8
  %8 = alloca %"struct.Simd::Array", align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #4
  call void @_ZN4Simd5ArrayIPKhEC2Embm(ptr noundef nonnull align 8 dereferenceable(16) %7, i64 noundef %1, i1 noundef zeroext false, i64 noundef 8)
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %9 = getelementptr inbounds i8, ptr %0, i64 80
  br label %11

._crit_edge:                                      ; preds = %11, %6
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #4
  invoke void @_ZN4Simd5ArrayIPKhEC2Embm(ptr noundef nonnull align 8 dereferenceable(16) %8, i64 noundef %2, i1 noundef zeroext false, i64 noundef 8)
          to label %.preheader unwind label %19

.preheader:                                       ; preds = %._crit_edge
  %.not29 = icmp eq i64 %2, 0
  br i1 %.not29, label %._crit_edge28, label %.lr.ph27

.lr.ph27:                                         ; preds = %.preheader
  %10 = getelementptr inbounds i8, ptr %0, i64 80
  br label %21

11:                                               ; preds = %.lr.ph, %11
  %.02125 = phi i64 [ 0, %.lr.ph ], [ %16, %11 ]
  %12 = load i64, ptr %9, align 8, !tbaa !5
  %13 = mul i64 %12, %.02125
  %14 = getelementptr inbounds i8, ptr %3, i64 %13
  %15 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN4Simd5ArrayIPKhEixEm(ptr noundef nonnull align 8 dereferenceable(16) %7, i64 noundef %.02125)
  store ptr %14, ptr %15, align 8, !tbaa !13
  %16 = add nuw i64 %.02125, 1
  %exitcond.not = icmp eq i64 %16, %1
  br i1 %exitcond.not, label %._crit_edge, label %11, !llvm.loop !14

._crit_edge28:                                    ; preds = %21, %.preheader
  %17 = load ptr, ptr %7, align 8, !tbaa !16
  %18 = load ptr, ptr %8, align 8, !tbaa !16
  invoke void @_ZNK4Simd4Base8DescrInt19CosineDistancesMxNaEmmPKPKhS5_Pf(ptr noundef nonnull align 8 dereferenceable(184) %0, i64 noundef %1, i64 noundef %2, ptr noundef %17, ptr noundef %18, ptr noundef %5)
          to label %27 unwind label %28

19:                                               ; preds = %._crit_edge
  %20 = landingpad { ptr, i32 }
          cleanup
  br label %30

21:                                               ; preds = %.lr.ph27, %21
  %.026 = phi i64 [ 0, %.lr.ph27 ], [ %26, %21 ]
  %22 = load i64, ptr %10, align 8, !tbaa !5
  %23 = mul i64 %22, %.026
  %24 = getelementptr inbounds i8, ptr %4, i64 %23
  %25 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN4Simd5ArrayIPKhEixEm(ptr noundef nonnull align 8 dereferenceable(16) %8, i64 noundef %.026)
  store ptr %24, ptr %25, align 8, !tbaa !13
  %26 = add nuw i64 %.026, 1
  %exitcond30.not = icmp eq i64 %26, %2
  br i1 %exitcond30.not, label %._crit_edge28, label %21, !llvm.loop !18

27:                                               ; preds = %._crit_edge28
  call void @_ZN4Simd5ArrayIPKhED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %8) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #4
  call void @_ZN4Simd5ArrayIPKhED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  ret void

28:                                               ; preds = %._crit_edge28
  %29 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN4Simd5ArrayIPKhED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %8) #4
  br label %30

30:                                               ; preds = %28, %19
  %.pn = phi { ptr, i32 } [ %29, %28 ], [ %20, %19 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #4
  call void @_ZN4Simd5ArrayIPKhED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  resume { ptr, i32 } %.pn
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN4Simd5ArrayIPKhEC2Embm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i1 noundef zeroext, i64 noundef) unnamed_addr #2 align 2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN4Simd5ArrayIPKhEixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #3 align 2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local void @_ZN4Simd5ArrayIPKhED2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3 align 2

attributes #0 = { mustprogress 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 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 = { 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 #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, !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 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !8, i64 0}
!17 = !{!"_ZTSN4Simd5ArrayIPKhEE", !8, i64 0, !11, i64 8}
!18 = distinct !{!18, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass