; LLVM IR from Izaron/ACM-ICPC :: Timus Online Judge/Volume 3/1207. Median on the Plane.ll (Z10insertSortPP6Point2l)

; 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.Point2 = type { i32, x86_fp80 }

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

8:                                                ; preds = %53, %2
  %9 = load i64, ptr %6, align 8, !tbaa !9
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = icmp slt i64 %9, %10
  br i1 %11, label %12, label %56

12:                                               ; preds = %8
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = getelementptr inbounds ptr, ptr %13, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %16, ptr %5, align 8, !tbaa !5
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = sub nsw i64 %17, 1
  store i64 %18, ptr %7, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %44, %12
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = icmp sge i64 %20, 0
  br i1 %21, label %22, label %33

22:                                               ; preds = %19
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = getelementptr inbounds ptr, ptr %23, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Point2, ptr %26, i32 0, i32 1
  %28 = load x86_fp80, ptr %27, align 16, !tbaa !11
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Point2, ptr %29, i32 0, i32 1
  %31 = load x86_fp80, ptr %30, align 16, !tbaa !11
  %32 = fcmp olt x86_fp80 %28, %31
  br label %33

33:                                               ; preds = %22, %19
  %34 = phi i1 [ false, %19 ], [ %32, %22 ]
  br i1 %34, label %35, label %47

35:                                               ; preds = %33
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = getelementptr inbounds ptr, ptr %36, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = add nsw i64 %41, 1
  %43 = getelementptr inbounds ptr, ptr %40, i64 %42
  store ptr %39, ptr %43, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %35
  %45 = load i64, ptr %7, align 8, !tbaa !9
  %46 = add nsw i64 %45, -1
  store i64 %46, ptr %7, align 8, !tbaa !9
  br label %19, !llvm.loop !15

47:                                               ; preds = %33
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load i64, ptr %7, align 8, !tbaa !9
  %51 = add nsw i64 %50, 1
  %52 = getelementptr inbounds ptr, ptr %49, i64 %51
  store ptr %48, ptr %52, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %47
  %54 = load i64, ptr %6, align 8, !tbaa !9
  %55 = add nsw i64 %54, 1
  store i64 %55, ptr %6, align 8, !tbaa !9
  br label %8, !llvm.loop !17

56:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

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

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

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


; 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 nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z10insertSortPP6Point2l(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i64 %1, 0
  br i1 %3, label %.lr.ph24, label %._crit_edge

.lr.ph24:                                         ; preds = %2, %.critedge
  %.01723 = phi i64 [ %18, %.critedge ], [ 0, %2 ]
  %4 = getelementptr inbounds ptr, ptr %0, i64 %.01723
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %.01723, 0
  br i1 %.not, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph24
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %7 = load x86_fp80, ptr %6, align 16, !tbaa !9
  br label %8

8:                                                ; preds = %.lr.ph, %14
  %.0.in19 = phi i64 [ %.01723, %.lr.ph ], [ %.020, %14 ]
  %.020 = add nsw i64 %.0.in19, -1
  %9 = getelementptr inbounds ptr, ptr %0, i64 %.020
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = load x86_fp80, ptr %11, align 16, !tbaa !9
  %13 = fcmp olt x86_fp80 %12, %7
  br i1 %13, label %14, label %.critedge

14:                                               ; preds = %8
  %15 = getelementptr inbounds ptr, ptr %0, i64 %.0.in19
  store ptr %10, ptr %15, align 8, !tbaa !5
  %16 = icmp sgt i64 %.0.in19, 1
  br i1 %16, label %8, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %8, %14, %.lr.ph24
  %.0.in.lcssa = phi i64 [ 0, %.lr.ph24 ], [ 0, %14 ], [ %.0.in19, %8 ]
  %17 = getelementptr inbounds ptr, ptr %0, i64 %.0.in.lcssa
  store ptr %5, ptr %17, align 8, !tbaa !5
  %18 = add nuw nsw i64 %.01723, 1
  %exitcond.not = icmp eq i64 %18, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph24, !llvm.loop !15

._crit_edge:                                      ; preds = %.critedge, %2
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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" }

!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 16}
!10 = !{!"_ZTS6Point2", !11, i64 0, !12, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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