; LLVM IR from ox-vgg/vise :: src/search_engine/relja_retrival/external/KMCode_relja/descriptor/EdgeDetector._9605d441 (Z14checkVariationP7Segment)

; 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.Segment = type { %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<ChainPoint *, std::allocator<ChainPoint *>>::_Vector_impl" }
%"struct.std::_Vector_base<ChainPoint *, std::allocator<ChainPoint *>>::_Vector_impl" = type { %"struct.std::_Vector_base<ChainPoint *, std::allocator<ChainPoint *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ChainPoint *, std::allocator<ChainPoint *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%class.ChainPoint = type { i32, i32, float, float }

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4fabsf(float noundef) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_Z14checkVariationP7Segment(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store float 0.000000e+00, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 2, ptr %5, align 4, !tbaa !11
  br label %6

6:                                                ; preds = %56, %1
  %7 = load i32, ptr %5, align 4, !tbaa !11
  %8 = zext i32 %7 to i64
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %class.Segment, ptr %9, i32 0, i32 0
  %11 = call noundef i64 @_ZNKSt6vectorIP10ChainPointSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %10) #4
  %12 = sub i64 %11, 2
  %13 = icmp ult i64 %8, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %59

15:                                               ; preds = %6
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %class.Segment, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %5, align 4, !tbaa !11
  %19 = sub i32 %18, 2
  %20 = zext i32 %19 to i64
  %21 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP10ChainPointSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %17, i64 noundef %20) #4
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds %class.ChainPoint, ptr %22, i32 0, i32 2
  %24 = load float, ptr %23, align 4, !tbaa !13
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.Segment, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %5, align 4, !tbaa !11
  %28 = add i32 %27, 2
  %29 = zext i32 %28 to i64
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP10ChainPointSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %26, i64 noundef %29) #4
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.ChainPoint, ptr %31, i32 0, i32 2
  %33 = load float, ptr %32, align 4, !tbaa !13
  %34 = fsub float %24, %33
  %35 = call noundef float @_ZSt4fabsf(float noundef %34)
  store float %35, ptr %4, align 4, !tbaa !9
  %36 = load float, ptr %4, align 4, !tbaa !9
  %37 = fpext float %36 to double
  %38 = fcmp ogt double %37, 0x400921FB54442D18
  br i1 %38, label %39, label %44

39:                                               ; preds = %15
  %40 = load float, ptr %4, align 4, !tbaa !9
  %41 = fpext float %40 to double
  %42 = fsub double 0x401921FB544486E0, %41
  %43 = fptrunc double %42 to float
  store float %43, ptr %4, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %39, %15
  %45 = load float, ptr %4, align 4, !tbaa !9
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %class.Segment, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %5, align 4, !tbaa !11
  %49 = zext i32 %48 to i64
  %50 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP10ChainPointSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %47, i64 noundef %49) #4
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  %52 = getelementptr inbounds %class.ChainPoint, ptr %51, i32 0, i32 3
  store float %45, ptr %52, align 4, !tbaa !15
  %53 = load float, ptr %4, align 4, !tbaa !9
  %54 = load float, ptr %3, align 4, !tbaa !9
  %55 = fadd float %54, %53
  store float %55, ptr %3, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %44
  %57 = load i32, ptr %5, align 4, !tbaa !11
  %58 = add i32 %57, 1
  store i32 %58, ptr %5, align 4, !tbaa !11
  br label %6, !llvm.loop !16

59:                                               ; preds = %14
  %60 = load float, ptr %3, align 4, !tbaa !9
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %class.Segment, ptr %61, i32 0, i32 0
  %63 = call noundef i64 @_ZNKSt6vectorIP10ChainPointSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %62) #4
  %64 = uitofp i64 %63 to float
  %65 = fdiv float %60, %64
  store float %65, ptr %3, align 4, !tbaa !9
  %66 = load float, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret float %66
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTS10ChainPoint", !12, i64 0, !12, i64 4, !10, i64 8, !10, i64 12}
!15 = !{!14, !10, i64 12}
!16 = distinct !{!16, !17}
!17 = !{!"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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4fabsf(float noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_Z14checkVariationP7Segment(ptr noundef nonnull %0) local_unnamed_addr #1 {
  %2 = tail call noundef i64 @_ZNKSt6vectorIP10ChainPointSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %3 = add i64 %2, -5
  %4 = icmp ult i64 %3, -3
  br i1 %4, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.017.lcssa = phi float [ 0.000000e+00, %1 ], [ %30, %.lr.ph ]
  %5 = tail call noundef i64 @_ZNKSt6vectorIP10ChainPointSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %6 = uitofp i64 %5 to float
  %7 = fdiv float %.017.lcssa, %6
  ret float %7

.lr.ph:                                           ; preds = %1, %.lr.ph
  %8 = phi i64 [ %32, %.lr.ph ], [ 2, %1 ]
  %.021 = phi i32 [ %31, %.lr.ph ], [ 2, %1 ]
  %.01720 = phi float [ %30, %.lr.ph ], [ 0.000000e+00, %1 ]
  %9 = add i32 %.021, -2
  %10 = zext i32 %9 to i64
  %11 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP10ChainPointSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %10) #2
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = load float, ptr %13, align 4, !tbaa !9
  %15 = add i32 %.021, 2
  %16 = zext i32 %15 to i64
  %17 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP10ChainPointSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %16) #2
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load float, ptr %19, align 4, !tbaa !9
  %21 = fsub float %14, %20
  %22 = tail call noundef float @_ZSt4fabsf(float noundef %21)
  %23 = fpext float %22 to double
  %24 = fcmp ogt double %23, 0x400921FB54442D18
  %25 = fsub double 0x401921FB544486E0, %23
  %26 = fptrunc double %25 to float
  %.016 = select i1 %24, float %26, float %22
  %27 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP10ChainPointSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %8) #2
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 12
  store float %.016, ptr %29, align 4, !tbaa !13
  %30 = fadd float %.01720, %.016
  %31 = add i32 %.021, 1
  %32 = zext i32 %31 to i64
  %33 = tail call noundef i64 @_ZNKSt6vectorIP10ChainPointSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %34 = add i64 %33, -2
  %35 = icmp ugt i64 %34, %32
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

attributes #0 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 8}
!10 = !{!"_ZTS10ChainPoint", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!10, !12, i64 12}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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