; LLVM IR from sp-nitech/SPTK :: src/compression (vector_quantization)

; 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.sptk::VectorQuantization" = type <{ ptr, i32, [4 x i8], %"class.sptk::DistanceCalculation", i8, [7 x i8] }>
%"class.sptk::DistanceCalculation" = type <{ ptr, i32, i32, i8, [7 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK4sptk18VectorQuantization3RunERKSt6vectorIdSaIdEERKS1_IS3_SaIS3_EEPi(ptr noundef nonnull align 8 dereferenceable(41) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef %3) #0 align 2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca double, align 8
  %14 = alloca i32, align 4
  %15 = alloca double, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = call noundef i64 @_ZNKSt6vectorIS_IdSaIdEESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %17) #4
  %19 = trunc i64 %18 to i32
  store i32 %19, ptr %10, align 4, !tbaa !9
  %20 = getelementptr inbounds %"class.sptk::VectorQuantization", ptr %16, i32 0, i32 4
  %21 = load i8, ptr %20, align 8, !tbaa !11, !range !16, !noundef !17
  %22 = trunc i8 %21 to i1
  br i1 %22, label %23, label %37

23:                                               ; preds = %4
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %24) #4
  %26 = getelementptr inbounds %"class.sptk::VectorQuantization", ptr %16, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !18
  %28 = add nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = icmp ne i64 %25, %29
  br i1 %30, label %37, label %31

31:                                               ; preds = %23
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = icmp eq i32 0, %32
  br i1 %33, label %37, label %34

34:                                               ; preds = %31
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = icmp eq ptr null, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %34, %31, %23, %4
  store i1 false, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %73

38:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store double 0x7FEFFFFFFFFFFFFF, ptr %13, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %64, %38
  %40 = load i32, ptr %14, align 4, !tbaa !9
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  store i32 2, ptr %11, align 4
  br label %67

44:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %45 = getelementptr inbounds %"class.sptk::VectorQuantization", ptr %16, i32 0, i32 3
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %14, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNKSt6vectorIS_IdSaIdEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %47, i64 noundef %49) #4
  %51 = call noundef zeroext i1 @_ZNK4sptk19DistanceCalculation3RunERKSt6vectorIdSaIdEES5_Pd(ptr noundef nonnull align 8 dereferenceable(17) %45, ptr noundef nonnull align 8 dereferenceable(24) %46, ptr noundef nonnull align 8 dereferenceable(24) %50, ptr noundef %15)
  br i1 %51, label %53, label %52

52:                                               ; preds = %44
  store i1 false, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %61

53:                                               ; preds = %44
  %54 = load double, ptr %15, align 8, !tbaa !19
  %55 = load double, ptr %13, align 8, !tbaa !19
  %56 = fcmp olt double %54, %55
  br i1 %56, label %57, label %60

57:                                               ; preds = %53
  %58 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %58, ptr %12, align 4, !tbaa !9
  %59 = load double, ptr %15, align 8, !tbaa !19
  store double %59, ptr %13, align 8, !tbaa !19
  br label %60

60:                                               ; preds = %57, %53
  store i32 0, ptr %11, align 4
  br label %61

61:                                               ; preds = %60, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  %62 = load i32, ptr %11, align 4
  switch i32 %62, label %67 [
    i32 0, label %63
  ]

63:                                               ; preds = %61
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %14, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %14, align 4, !tbaa !9
  br label %39, !llvm.loop !21

67:                                               ; preds = %61, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  %68 = load i32, ptr %11, align 4
  switch i32 %68, label %72 [
    i32 2, label %69
  ]

69:                                               ; preds = %67
  %70 = load i32, ptr %12, align 4, !tbaa !9
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %70, ptr %71, align 4, !tbaa !9
  store i1 true, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %72

72:                                               ; preds = %69, %67
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %73

73:                                               ; preds = %72, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %74 = load i1, ptr %5, align 1
  ret i1 %74
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIS_IdSaIdEESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

declare noundef zeroext i1 @_ZNK4sptk19DistanceCalculation3RunERKSt6vectorIdSaIdEES5_Pd(ptr noundef nonnull align 8 dereferenceable(17), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNKSt6vectorIS_IdSaIdEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"int", !7, i64 0}
!11 = !{!12, !15, i64 40}
!12 = !{!"_ZTSN4sptk18VectorQuantizationE", !10, i64 8, !13, i64 16, !15, i64 40}
!13 = !{!"_ZTSN4sptk19DistanceCalculationE", !10, i64 8, !14, i64 12, !15, i64 16}
!14 = !{!"_ZTSN4sptk19DistanceCalculation15DistanceMetricsE", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!12, !10, i64 8}
!19 = !{!20, !20, i64 0}
!20 = !{!"double", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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 noundef zeroext i1 @_ZNK4sptk18VectorQuantization3RunERKSt6vectorIdSaIdEERKS1_IS3_SaIS3_EEPi(ptr noundef nonnull align 8 dereferenceable(41) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef writeonly %3) local_unnamed_addr #0 align 2 {
  %5 = alloca double, align 8
  %6 = tail call noundef i64 @_ZNKSt6vectorIS_IdSaIdEESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %2) #4
  %7 = trunc i64 %6 to i32
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %9 = load i8, ptr %8, align 8, !tbaa !5, !range !13, !noundef !14
  %10 = trunc nuw i8 %9 to i1
  br i1 %10, label %11, label %29

11:                                               ; preds = %4
  %12 = tail call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #4
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i32, ptr %13, align 8, !tbaa !15
  %15 = add nsw i32 %14, 1
  %16 = sext i32 %15 to i64
  %17 = icmp ne i64 %12, %16
  %18 = icmp eq i32 %7, 0
  %or.cond = or i1 %18, %17
  %19 = icmp eq ptr %3, null
  %or.cond4 = or i1 %19, %or.cond
  br i1 %or.cond4, label %29, label %.preheader

.preheader:                                       ; preds = %11
  %.not.not42 = icmp sgt i32 %7, 0
  br i1 %.not.not42, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  %wide.trip.count = and i64 %6, 2147483647
  br label %21

21:                                               ; preds = %.lr.ph, %24
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %24 ]
  %.02144 = phi double [ 0x7FEFFFFFFFFFFFFF, %.lr.ph ], [ %.1, %24 ]
  %.02243 = phi i32 [ 0, %.lr.ph ], [ %.123, %24 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %22 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNKSt6vectorIS_IdSaIdEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %2, i64 noundef %indvars.iv) #4
  %23 = call noundef zeroext i1 @_ZNK4sptk19DistanceCalculation3RunERKSt6vectorIdSaIdEES5_Pd(ptr noundef nonnull align 8 dereferenceable(17) %20, ptr noundef nonnull align 8 dereferenceable(24) %1, ptr noundef nonnull align 8 dereferenceable(24) %22, ptr noundef nonnull %5)
  br i1 %23, label %24, label %28

24:                                               ; preds = %21
  %25 = load double, ptr %5, align 8, !tbaa !16
  %26 = fcmp olt double %25, %.02144
  %27 = trunc nuw nsw i64 %indvars.iv to i32
  %.123 = select i1 %26, i32 %27, i32 %.02243
  %.1 = select i1 %26, double %25, double %.02144
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %21, !llvm.loop !18

28:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br label %29

._crit_edge:                                      ; preds = %24, %.preheader
  %.022.lcssa = phi i32 [ 0, %.preheader ], [ %.123, %24 ]
  store i32 %.022.lcssa, ptr %3, align 4, !tbaa !20
  br label %29

29:                                               ; preds = %28, %._crit_edge, %4, %11
  %.4 = phi i1 [ false, %11 ], [ false, %4 ], [ false, %28 ], [ true, %._crit_edge ]
  ret i1 %.4
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIS_IdSaIdEESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

declare noundef zeroext i1 @_ZNK4sptk19DistanceCalculation3RunERKSt6vectorIdSaIdEES5_Pd(ptr noundef nonnull align 8 dereferenceable(17), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNKSt6vectorIS_IdSaIdEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !12, i64 40}
!6 = !{!"_ZTSN4sptk18VectorQuantizationE", !7, i64 8, !10, i64 16, !12, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN4sptk19DistanceCalculationE", !7, i64 8, !11, i64 12, !12, i64 16}
!11 = !{!"_ZTSN4sptk19DistanceCalculation15DistanceMetricsE", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!6, !7, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!7, !7, i64 0}


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