; LLVM IR from lzyrapx/Competitive-Programming :: ACdream/1097（计算几何+直线与线段相交）.ll (Z5solvev)

; 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.Point = type { double, double }
%struct.Line = type { %struct.Point, %struct.Point }

@dot = external dso_local global [220 x %struct.Point], align 16
@line = external dso_local global [55 x %struct.Line], align 16
@n = external dso_local global i32, align 4

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

11:                                               ; preds = %64, %0
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = mul nsw i32 2, %13
  %15 = icmp sle i32 %12, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %67

17:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %5, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %60, %17
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = mul nsw i32 2, %22
  %24 = icmp sle i32 %21, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %20
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %63

26:                                               ; preds = %20
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #5
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [220 x %struct.Point], ptr @dot, i64 0, i64 %28
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 16 %29, i64 16, i1 false), !tbaa.struct !9
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [220 x %struct.Point], ptr @dot, i64 0, i64 %31
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 16 %32, i64 16, i1 false), !tbaa.struct !9
  %33 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 0
  %34 = load double, ptr %33, align 8
  %35 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 1
  %36 = load double, ptr %35, align 8
  %37 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 0
  %38 = load double, ptr %37, align 8
  %39 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 1
  %40 = load double, ptr %39, align 8
  call void @_ZN4LineC2E5PointS0_(ptr noundef nonnull align 8 dereferenceable(32) %6, double %34, double %36, double %38, double %40)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %54, %26
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = load i32, ptr @n, align 4, !tbaa !5
  %44 = icmp sle i32 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %57

46:                                               ; preds = %41
  %47 = load i32, ptr %9, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [55 x %struct.Line], ptr @line, i64 0, i64 %48
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 16 %49, i64 32, i1 false), !tbaa.struct !12
  %50 = call noundef zeroext i1 @_ZN4Line12intersectionES_(ptr noundef nonnull align 8 dereferenceable(32) %6, ptr noundef byval(%struct.Line) align 8 %10)
  %51 = zext i1 %50 to i32
  %52 = load i32, ptr %1, align 4, !tbaa !5
  %53 = add nsw i32 %52, %51
  store i32 %53, ptr %1, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %46
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %9, align 4, !tbaa !5
  br label %41, !llvm.loop !13

57:                                               ; preds = %45
  %58 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %59 = load i32, ptr %58, align 4, !tbaa !5
  store i32 %59, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #5
  br label %60

60:                                               ; preds = %57
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %5, align 4, !tbaa !5
  br label %20, !llvm.loop !15

63:                                               ; preds = %25
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %3, align 4, !tbaa !5
  br label %11, !llvm.loop !16

67:                                               ; preds = %16
  %68 = load i32, ptr %2, align 4, !tbaa !5
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret i32 %68
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4LineC2E5PointS0_(ptr noundef nonnull align 8 dereferenceable(32), double, double, double, double) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4Line12intersectionES_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef byval(%struct.Line) align 8) #0 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #4

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


; 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.Point = type { double, double }
%struct.Line = type { %struct.Point, %struct.Point }

@dot = external dso_local local_unnamed_addr global [220 x %struct.Point], align 16
@line = external dso_local local_unnamed_addr global [55 x %struct.Line], align 16
@n = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5solvev() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %struct.Line, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %.not22 = icmp slt i32 %4, 1
  br i1 %.not22, label %._crit_edge26, label %.lr.ph25

.loopexit:                                        ; preds = %._crit_edge, %.lr.ph25
  %.pre-phi36 = phi i64 [ %11, %.lr.ph25 ], [ %20, %._crit_edge ]
  %5 = phi i32 [ %8, %.lr.ph25 ], [ %17, %._crit_edge ]
  %6 = phi i32 [ %9, %.lr.ph25 ], [ %18, %._crit_edge ]
  %.not.not = icmp slt i64 %indvars.iv33, %.pre-phi36
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  br i1 %.not.not, label %.lr.ph25, label %._crit_edge26, !llvm.loop !9

._crit_edge26:                                    ; preds = %.loopexit, %0
  %7 = phi i32 [ 0, %0 ], [ %5, %.loopexit ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 %7

.lr.ph25:                                         ; preds = %0, %.loopexit
  %8 = phi i32 [ %5, %.loopexit ], [ 0, %0 ]
  %9 = phi i32 [ %6, %.loopexit ], [ %4, %0 ]
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %.loopexit ], [ 1, %0 ]
  %indvars.iv28 = phi i64 [ %indvars.iv.next29, %.loopexit ], [ 2, %0 ]
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %10 = shl nsw i32 %9, 1
  %11 = sext i32 %10 to i64
  %.not1418.not = icmp slt i64 %indvars.iv33, %11
  br i1 %.not1418.not, label %.lr.ph21, label %.loopexit

.lr.ph21:                                         ; preds = %.lr.ph25
  %12 = getelementptr inbounds [220 x %struct.Point], ptr @dot, i64 0, i64 %indvars.iv33
  %.sroa.24.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 8
  br label %13

13:                                               ; preds = %.lr.ph21, %._crit_edge
  %indvars.iv30 = phi i64 [ %indvars.iv28, %.lr.ph21 ], [ %indvars.iv.next31, %._crit_edge ]
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  %.sroa.03.0.copyload = load double, ptr %12, align 16, !tbaa !11
  %.sroa.24.0.copyload = load double, ptr %.sroa.24.0..sroa_idx, align 8, !tbaa !11
  %14 = getelementptr inbounds [220 x %struct.Point], ptr @dot, i64 0, i64 %indvars.iv30
  %.sroa.0.0.copyload = load double, ptr %14, align 16, !tbaa !11
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %14, i64 8
  %.sroa.2.0.copyload = load double, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !11
  call void @_ZN4LineC2E5PointS0_(ptr noundef nonnull align 8 dereferenceable(32) %3, double %.sroa.03.0.copyload, double %.sroa.24.0.copyload, double %.sroa.0.0.copyload, double %.sroa.2.0.copyload)
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %.not1516 = icmp slt i32 %15, 1
  br i1 %.not1516, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %13
  %16 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %17 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %17, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = shl nsw i32 %18, 1
  %20 = sext i32 %19 to i64
  %.not14.not = icmp slt i64 %indvars.iv30, %20
  br i1 %.not14.not, label %13, label %.loopexit, !llvm.loop !13

.lr.ph:                                           ; preds = %13, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %13 ]
  %21 = getelementptr inbounds [55 x %struct.Line], ptr @line, i64 0, i64 %indvars.iv
  %22 = call noundef zeroext i1 @_ZN4Line12intersectionES_(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull byval(%struct.Line) align 8 %21)
  %23 = zext i1 %22 to i32
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = add nsw i32 %24, %23
  store i32 %25, ptr %1, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %.not15.not = icmp slt i64 %indvars.iv, %27
  br i1 %.not15.not, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

; 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 void @_ZN4LineC2E5PointS0_(ptr noundef nonnull align 8 dereferenceable(32), double, double, double, double) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4Line12intersectionES_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef byval(%struct.Line) align 8) local_unnamed_addr #0 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

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


; Effective O3 passes: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass