; LLVM IR from tangjz/acm-icpc :: hdu (1154)

; 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 }

@n = external dso_local global i32, align 4
@p = external dso_local global [1001 x %struct.Point], align 16
@line = external dso_local global [1001 x %struct.Line], align 16
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z5solve4Line(ptr noundef byval(%struct.Line) align 8) #0

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

6:                                                ; preds = %56, %0
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @n, ptr noundef %2)
  %8 = icmp eq i32 %7, 2
  br i1 %8, label %9, label %14

9:                                                ; preds = %6
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = add nsw i32 %10, %11
  %13 = icmp ne i32 %12, 0
  br label %14

14:                                               ; preds = %9, %6
  %15 = phi i1 [ false, %6 ], [ %13, %9 ]
  br i1 %15, label %16, label %57

16:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %40, %16
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #7
  br label %43

22:                                               ; preds = %17
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [1001 x %struct.Point], ptr @p, i64 0, i64 %24
  call void @_ZN5Point4readEv(ptr noundef nonnull align 8 dereferenceable(16) %25)
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %39

28:                                               ; preds = %22
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1001 x %struct.Line], ptr @line, i64 0, i64 %30
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sub nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1001 x %struct.Point], ptr @p, i64 0, i64 %34
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1001 x %struct.Point], ptr @p, i64 0, i64 %37
  call void @_ZN4Line4initERK5PointS2_(ptr noundef nonnull align 8 dereferenceable(32) %31, ptr noundef nonnull align 8 dereferenceable(16) %35, ptr noundef nonnull align 8 dereferenceable(16) %38)
  br label %39

39:                                               ; preds = %28, %22
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %3, align 4, !tbaa !5
  br label %17, !llvm.loop !9

43:                                               ; preds = %21
  %44 = load i32, ptr @n, align 4, !tbaa !5
  %45 = sub nsw i32 %44, 1
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1001 x %struct.Point], ptr @p, i64 0, i64 %46
  call void @_ZN4Line4initERK5PointS2_(ptr noundef nonnull align 8 dereferenceable(32) @line, ptr noundef nonnull align 8 dereferenceable(16) %47, ptr noundef nonnull align 8 dereferenceable(16) @p)
  br label %48

48:                                               ; preds = %52, %43
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = add nsw i32 %49, -1
  store i32 %50, ptr %2, align 4, !tbaa !5
  %51 = icmp ne i32 %49, 0
  br i1 %51, label %52, label %56

52:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #7
  %53 = getelementptr inbounds %struct.Line, ptr %4, i32 0, i32 0
  call void @_ZN5Point4readEv(ptr noundef nonnull align 8 dereferenceable(16) %53)
  %54 = getelementptr inbounds %struct.Line, ptr %4, i32 0, i32 1
  call void @_ZN5Point4readEv(ptr noundef nonnull align 8 dereferenceable(16) %54)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %4, i64 32, i1 false), !tbaa.struct !11
  %55 = call noundef double @_Z5solve4Line(ptr noundef byval(%struct.Line) align 8 %5)
  call void @_Z7writeDBdc(double noundef %55, i8 noundef signext 10)
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #7
  br label %48, !llvm.loop !14

56:                                               ; preds = %48
  br label %6, !llvm.loop !15

57:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #7
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #5

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z7writeDBdc(double noundef, i8 noundef signext) #6

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 = { mustprogress norecurse 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 = { "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 #6 = { inlinehint 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 #7 = { 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 = !{i64 0, i64 8, !12, i64 8, i64 8, !12, i64 16, i64 8, !12, i64 24, i64 8, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


; 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 }

@n = external dso_local global i32, align 4
@p = external dso_local global [1001 x %struct.Point], align 16
@line = external dso_local global [1001 x %struct.Line], align 16
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z5solve4Line(ptr noundef byval(%struct.Line) align 8) local_unnamed_addr #0

; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.Line, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @n, ptr noundef nonnull %1)
  %4 = icmp eq i32 %3, 2
  %5 = load i32, ptr @n, align 4
  %6 = load i32, ptr %1, align 4
  %7 = sub i32 0, %6
  %8 = icmp ne i32 %5, %7
  %9 = select i1 %4, i1 %8, i1 false
  br i1 %9, label %.preheader.lr.ph, label %._crit_edge13

.preheader.lr.ph:                                 ; preds = %0
  %10 = getelementptr inbounds i8, ptr %2, i64 16
  br label %.preheader

.loopexit:                                        ; preds = %.lr.ph12, %._crit_edge
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @n, ptr noundef nonnull %1)
  %12 = icmp eq i32 %11, 2
  %13 = load i32, ptr @n, align 4
  %14 = load i32, ptr %1, align 4
  %15 = sub i32 0, %14
  %16 = icmp ne i32 %13, %15
  %17 = select i1 %12, i1 %16, i1 false
  br i1 %17, label %.preheader, label %._crit_edge13, !llvm.loop !5

.preheader:                                       ; preds = %.preheader.lr.ph, %.loopexit
  %18 = phi i32 [ %5, %.preheader.lr.ph ], [ %13, %.loopexit ]
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %20, label %._crit_edge

20:                                               ; preds = %.preheader
  call void @_ZN5Point4readEv(ptr noundef nonnull align 8 dereferenceable(16) @p)
  %.pre = load i32, ptr @n, align 4, !tbaa !7
  %21 = icmp sgt i32 %.pre, 1
  br i1 %21, label %.lr.ph.peel.next, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.peel.next, %20, %.preheader
  %.lcssa = phi i32 [ %18, %.preheader ], [ %.pre, %20 ], [ %31, %.lr.ph.peel.next ]
  %22 = add nsw i32 %.lcssa, -1
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1001 x %struct.Point], ptr @p, i64 0, i64 %23
  call void @_ZN4Line4initERK5PointS2_(ptr noundef nonnull align 8 dereferenceable(32) @line, ptr noundef nonnull align 8 dereferenceable(16) %24, ptr noundef nonnull align 8 dereferenceable(16) @p)
  %25 = load i32, ptr %1, align 4, !tbaa !7
  %26 = add nsw i32 %25, -1
  store i32 %26, ptr %1, align 4, !tbaa !7
  %.not10 = icmp eq i32 %25, 0
  br i1 %.not10, label %.loopexit, label %.lr.ph12

.lr.ph.peel.next:                                 ; preds = %20, %.lr.ph.peel.next
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph.peel.next ], [ 1, %20 ]
  %27 = getelementptr inbounds [1001 x %struct.Point], ptr @p, i64 0, i64 %indvars.iv
  call void @_ZN5Point4readEv(ptr noundef nonnull align 8 dereferenceable(16) %27)
  %28 = getelementptr inbounds [1001 x %struct.Line], ptr @line, i64 0, i64 %indvars.iv
  %29 = add nsw i64 %indvars.iv, -1
  %30 = getelementptr inbounds [1001 x %struct.Point], ptr @p, i64 0, i64 %29
  call void @_ZN4Line4initERK5PointS2_(ptr noundef nonnull align 8 dereferenceable(32) %28, ptr noundef nonnull align 8 dereferenceable(16) %30, ptr noundef nonnull align 8 dereferenceable(16) %27)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load i32, ptr @n, align 4, !tbaa !7
  %32 = sext i32 %31 to i64
  %33 = icmp slt i64 %indvars.iv.next, %32
  br i1 %33, label %.lr.ph.peel.next, label %._crit_edge, !llvm.loop !11

.lr.ph12:                                         ; preds = %._crit_edge, %.lr.ph12
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #6
  call void @_ZN5Point4readEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  call void @_ZN5Point4readEv(ptr noundef nonnull align 8 dereferenceable(16) %10)
  %34 = call noundef double @_Z5solve4Line(ptr noundef nonnull byval(%struct.Line) align 8 %2)
  call void @_Z7writeDBdc(double noundef %34, i8 noundef signext 10)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #6
  %35 = load i32, ptr %1, align 4, !tbaa !7
  %36 = add nsw i32 %35, -1
  store i32 %36, ptr %1, align 4, !tbaa !7
  %.not = icmp eq i32 %35, 0
  br i1 %.not, label %.loopexit, label %.lr.ph12, !llvm.loop !13

._crit_edge13:                                    ; preds = %.loopexit, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z7writeDBdc(double noundef, i8 noundef signext) local_unnamed_addr #5

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 = { mustprogress norecurse 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 = { nofree nounwind "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 = { inlinehint 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 #6 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6, !12}
!12 = !{!"llvm.loop.peeled.count", i32 1}
!13 = distinct !{!13, !6}


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