; LLVM IR from ahr9n/psolving-paradigms :: 3.binary-search/Gym 103081C - Safe Distance.ll (Z5mergee)

; 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.DSU = type { [1005 x i32], [1005 x i32], i32 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<point, std::allocator<point>>::_Vector_impl" }
%"struct.std::_Vector_base<point, std::allocator<point>>::_Vector_impl" = type { %"struct.std::_Vector_base<point, std::allocator<point>>::_Vector_impl_data" }
%"struct.std::_Vector_base<point, std::allocator<point>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.point = type { x86_fp80, x86_fp80 }

@dsu = external dso_local global %struct.DSU, align 4
@p = external dso_local global %"class.std::vector", align 8
@x = external dso_local global x86_fp80, align 16
@y = external dso_local global x86_fp80, align 16
@n = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5mergee(x86_fp80 noundef %0) #0 {
  %2 = alloca x86_fp80, align 16
  %3 = alloca i32, align 4
  store x86_fp80 %0, ptr %2, align 16, !tbaa !5
  %4 = load i32, ptr @n, align 4, !tbaa !9
  %5 = add nsw i32 %4, 2
  call void @_ZN3DSU4initEi(ptr noundef nonnull align 4 dereferenceable(8044) @dsu, i32 noundef %5)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %57, %1
  %7 = load i32, ptr %3, align 4, !tbaa !9
  %8 = load i32, ptr @n, align 4, !tbaa !9
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %60

11:                                               ; preds = %6
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = call noundef nonnull align 16 dereferenceable(32) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @p, i64 noundef %13) #3
  %15 = getelementptr inbounds %struct.point, ptr %14, i32 0, i32 0
  %16 = load x86_fp80, ptr %15, align 16, !tbaa !11
  %17 = load x86_fp80, ptr %2, align 16, !tbaa !5
  %18 = fcmp ole x86_fp80 %16, %17
  br i1 %18, label %29, label %19

19:                                               ; preds = %11
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = call noundef nonnull align 16 dereferenceable(32) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @p, i64 noundef %21) #3
  %23 = getelementptr inbounds %struct.point, ptr %22, i32 0, i32 1
  %24 = load x86_fp80, ptr %23, align 16, !tbaa !13
  %25 = load x86_fp80, ptr %2, align 16, !tbaa !5
  %26 = fadd x86_fp80 %24, %25
  %27 = load x86_fp80, ptr @y, align 16, !tbaa !5
  %28 = fcmp oge x86_fp80 %26, %27
  br i1 %28, label %29, label %33

29:                                               ; preds = %19, %11
  %30 = load i32, ptr %3, align 4, !tbaa !9
  %31 = load i32, ptr @n, align 4, !tbaa !9
  %32 = call noundef zeroext i1 @_ZN3DSU5mergeEii(ptr noundef nonnull align 4 dereferenceable(8044) @dsu, i32 noundef %30, i32 noundef %31)
  br label %33

33:                                               ; preds = %29, %19
  %34 = load i32, ptr %3, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = call noundef nonnull align 16 dereferenceable(32) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @p, i64 noundef %35) #3
  %37 = getelementptr inbounds %struct.point, ptr %36, i32 0, i32 0
  %38 = load x86_fp80, ptr %37, align 16, !tbaa !11
  %39 = load x86_fp80, ptr %2, align 16, !tbaa !5
  %40 = fadd x86_fp80 %38, %39
  %41 = load x86_fp80, ptr @x, align 16, !tbaa !5
  %42 = fcmp oge x86_fp80 %40, %41
  br i1 %42, label %51, label %43

43:                                               ; preds = %33
  %44 = load i32, ptr %3, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = call noundef nonnull align 16 dereferenceable(32) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @p, i64 noundef %45) #3
  %47 = getelementptr inbounds %struct.point, ptr %46, i32 0, i32 1
  %48 = load x86_fp80, ptr %47, align 16, !tbaa !13
  %49 = load x86_fp80, ptr %2, align 16, !tbaa !5
  %50 = fcmp ole x86_fp80 %48, %49
  br i1 %50, label %51, label %56

51:                                               ; preds = %43, %33
  %52 = load i32, ptr %3, align 4, !tbaa !9
  %53 = load i32, ptr @n, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  %55 = call noundef zeroext i1 @_ZN3DSU5mergeEii(ptr noundef nonnull align 4 dereferenceable(8044) @dsu, i32 noundef %52, i32 noundef %54)
  br label %56

56:                                               ; preds = %51, %43
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %3, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %3, align 4, !tbaa !9
  br label %6, !llvm.loop !14

60:                                               ; preds = %10
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3DSU4initEi(ptr noundef nonnull align 4 dereferenceable(8044), i32 noundef) #0 align 2

; 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 nonnull align 16 dereferenceable(32) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3DSU5mergeEii(ptr noundef nonnull align 4 dereferenceable(8044), i32 noundef, i32 noundef) #0 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 = { 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 = !{!"long double", !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, !6, i64 0}
!12 = !{!"_ZTS5point", !6, i64 0, !6, i64 16}
!13 = !{!12, !6, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"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"

%struct.DSU = type { [1005 x i32], [1005 x i32], i32 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<point, std::allocator<point>>::_Vector_impl" }
%"struct.std::_Vector_base<point, std::allocator<point>>::_Vector_impl" = type { %"struct.std::_Vector_base<point, std::allocator<point>>::_Vector_impl_data" }
%"struct.std::_Vector_base<point, std::allocator<point>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@dsu = external dso_local global %struct.DSU, align 4
@p = external dso_local global %"class.std::vector", align 8
@x = external dso_local local_unnamed_addr global x86_fp80, align 16
@y = external dso_local local_unnamed_addr global x86_fp80, align 16
@n = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5mergee(x86_fp80 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = add nsw i32 %2, 2
  tail call void @_ZN3DSU4initEi(ptr noundef nonnull align 4 dereferenceable(8044) @dsu, i32 noundef %3)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %36, %1
  ret void

.lr.ph:                                           ; preds = %1, %36
  %indvars.iv = phi i64 [ %indvars.iv.next, %36 ], [ 0, %1 ]
  %6 = tail call noundef nonnull align 16 dereferenceable(32) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @p, i64 noundef %indvars.iv) #2
  %7 = load x86_fp80, ptr %6, align 16, !tbaa !9
  %8 = fcmp ugt x86_fp80 %7, %0
  br i1 %8, label %9, label %16

9:                                                ; preds = %.lr.ph
  %10 = tail call noundef nonnull align 16 dereferenceable(32) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @p, i64 noundef %indvars.iv) #2
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = load x86_fp80, ptr %11, align 16, !tbaa !12
  %13 = fadd x86_fp80 %12, %0
  %14 = load x86_fp80, ptr @y, align 16, !tbaa !13
  %15 = fcmp ult x86_fp80 %13, %14
  br i1 %15, label %20, label %16

16:                                               ; preds = %9, %.lr.ph
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = trunc nuw nsw i64 %indvars.iv to i32
  %19 = tail call noundef zeroext i1 @_ZN3DSU5mergeEii(ptr noundef nonnull align 4 dereferenceable(8044) @dsu, i32 noundef %18, i32 noundef %17)
  br label %20

20:                                               ; preds = %16, %9
  %21 = tail call noundef nonnull align 16 dereferenceable(32) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @p, i64 noundef %indvars.iv) #2
  %22 = load x86_fp80, ptr %21, align 16, !tbaa !9
  %23 = fadd x86_fp80 %22, %0
  %24 = load x86_fp80, ptr @x, align 16, !tbaa !13
  %25 = fcmp ult x86_fp80 %23, %24
  br i1 %25, label %26, label %31

26:                                               ; preds = %20
  %27 = tail call noundef nonnull align 16 dereferenceable(32) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @p, i64 noundef %indvars.iv) #2
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  %29 = load x86_fp80, ptr %28, align 16, !tbaa !12
  %30 = fcmp ugt x86_fp80 %29, %0
  br i1 %30, label %36, label %31

31:                                               ; preds = %26, %20
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  %34 = trunc nuw nsw i64 %indvars.iv to i32
  %35 = tail call noundef zeroext i1 @_ZN3DSU5mergeEii(ptr noundef nonnull align 4 dereferenceable(8044) @dsu, i32 noundef %34, i32 noundef %33)
  br label %36

36:                                               ; preds = %26, %31
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = icmp slt i64 %indvars.iv.next, %38
  br i1 %39, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3DSU4initEi(ptr noundef nonnull align 4 dereferenceable(8044), i32 noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3DSU5mergeEii(ptr noundef nonnull align 4 dereferenceable(8044), i32 noundef, i32 noundef) local_unnamed_addr #0 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, !11, i64 0}
!10 = !{!"_ZTS5point", !11, i64 0, !11, i64 16}
!11 = !{!"long double", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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