; LLVM IR from NavInfoNC/nc-geo :: src (polygon_merger)

; 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.PolygonMerger = type { %"class.std::unordered_map", %"class.std::vector" }
%"class.std::unordered_map" = type { %"class.std::_Hashtable" }
%"class.std::_Hashtable" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"struct.std::__detail::_Hash_node_base" = type { ptr }
%"struct.std::__detail::_Prime_rehash_policy" = type { float, i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<StaticPolygon *, std::allocator<StaticPolygon *>>::_Vector_impl" }
%"struct.std::_Vector_base<StaticPolygon *, std::allocator<StaticPolygon *>>::_Vector_impl" = type { %"struct.std::_Vector_base<StaticPolygon *, std::allocator<StaticPolygon *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<StaticPolygon *, std::allocator<StaticPolygon *>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN13PolygonMerger13mergePolygonsERKSt6vectorIP13StaticPolygonSaIS2_EERi(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, ptr noundef nonnull align 4 dereferenceable(4) %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  call void @_ZN13PolygonMerger6_resetEv(ptr noundef nonnull align 8 dereferenceable(80) %8)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %20, %3
  %10 = load i64, ptr %7, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call noundef i64 @_ZNKSt6vectorIP13StaticPolygonSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %11) #3
  %13 = icmp ult i64 %10, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %23

15:                                               ; preds = %9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIP13StaticPolygonSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %16, i64 noundef %17) #3
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  call void @_ZN13PolygonMerger16_buildSegmentSetEP13StaticPolygon(ptr noundef nonnull align 8 dereferenceable(80) %8, ptr noundef %19)
  br label %20

20:                                               ; preds = %15
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = add i64 %21, 1
  store i64 %22, ptr %7, align 8, !tbaa !9
  br label %9, !llvm.loop !11

23:                                               ; preds = %14
  call void @_ZN13PolygonMerger17_generateContoursEv(ptr noundef nonnull align 8 dereferenceable(80) %8)
  %24 = getelementptr inbounds %class.PolygonMerger, ptr %8, i32 0, i32 1
  %25 = call noundef i64 @_ZNKSt6vectorIP13StaticPolygonSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %24) #3
  %26 = trunc i64 %25 to i32
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %26, ptr %27, align 4, !tbaa !13
  %28 = getelementptr inbounds %class.PolygonMerger, ptr %8, i32 0, i32 1
  %29 = call noundef ptr @_ZNSt6vectorIP13StaticPolygonSaIS1_EE4dataEv(ptr noundef nonnull align 8 dereferenceable(24) %28) #3
  ret ptr %29
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN13PolygonMerger6_resetEv(ptr noundef nonnull align 8 dereferenceable(80)) #1 align 2

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13PolygonMerger16_buildSegmentSetEP13StaticPolygon(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef) #0 align 2

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13PolygonMerger17_generateContoursEv(ptr noundef nonnull align 8 dereferenceable(80)) #0 align 2

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

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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}


; 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 ptr @_ZN13PolygonMerger13mergePolygonsERKSt6vectorIP13StaticPolygonSaIS2_EERi(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(4) %2) local_unnamed_addr #0 align 2 {
  tail call void @_ZN13PolygonMerger6_resetEv(ptr noundef nonnull align 8 dereferenceable(80) %0)
  %4 = tail call noundef i64 @_ZNKSt6vectorIP13StaticPolygonSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #2
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %3
  tail call void @_ZN13PolygonMerger17_generateContoursEv(ptr noundef nonnull align 8 dereferenceable(80) %0)
  %5 = getelementptr inbounds i8, ptr %0, i64 56
  %6 = tail call noundef i64 @_ZNKSt6vectorIP13StaticPolygonSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #2
  %7 = trunc i64 %6 to i32
  store i32 %7, ptr %2, align 4, !tbaa !5
  %8 = tail call noundef ptr @_ZNSt6vectorIP13StaticPolygonSaIS1_EE4dataEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #2
  ret ptr %8

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.06 = phi i64 [ %11, %.lr.ph ], [ 0, %3 ]
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIP13StaticPolygonSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.06) #2
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  tail call void @_ZN13PolygonMerger16_buildSegmentSetEP13StaticPolygon(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %10)
  %11 = add nuw i64 %.06, 1
  %12 = tail call noundef i64 @_ZNKSt6vectorIP13StaticPolygonSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #2
  %13 = icmp ult i64 %11, %12
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !11
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN13PolygonMerger6_resetEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13PolygonMerger16_buildSegmentSetEP13StaticPolygon(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13PolygonMerger17_generateContoursEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #0 align 2

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

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 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 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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