; LLVM IR from tangjz/acm-icpc :: codeforces/gym/100506H.ll (Z5valid5Point)

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

@p = external dso_local global [101 x %struct.Point], align 16
@n = external dso_local global i32, align 4
@r = external dso_local global double, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4dcmpd(double noundef) #0

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

10:                                               ; preds = %31, %2
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %6, align 4
  br label %34

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [101 x %struct.Point], ptr @p, i64 0, i64 %17
  %19 = call { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(16) %18)
  %20 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 0
  %21 = extractvalue { double, double } %19, 0
  store double %21, ptr %20, align 8
  %22 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 1
  %23 = extractvalue { double, double } %19, 1
  store double %23, ptr %22, align 8
  %24 = call noundef double @_ZNK5Point4modeEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  %25 = load double, ptr @r, align 8, !tbaa !9
  %26 = fsub double %24, %25
  %27 = call noundef i32 @_Z4dcmpd(double noundef %26)
  %28 = icmp slt i32 %27, 0
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  br i1 %28, label %29, label %30

29:                                               ; preds = %15
  store i1 false, ptr %3, align 1
  store i32 1, ptr %6, align 4
  br label %34

30:                                               ; preds = %15
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %5, align 4, !tbaa !5
  br label %10, !llvm.loop !11

34:                                               ; preds = %29, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %35 = load i32, ptr %6, align 4
  switch i32 %35, label %39 [
    i32 2, label %36
    i32 1, label %37
  ]

36:                                               ; preds = %34
  store i1 true, ptr %3, align 1
  br label %37

37:                                               ; preds = %36, %34
  %38 = load i1, ptr %3, align 1
  ret i1 %38

39:                                               ; preds = %34
  unreachable
}

; 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 { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #0 align 2

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

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

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

@p = external dso_local global [101 x %struct.Point], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@r = external dso_local local_unnamed_addr global double, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4dcmpd(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z5valid5Point(double %0, double %1) local_unnamed_addr #0 {
  %3 = alloca %struct.Point, align 8
  %4 = alloca %struct.Point, align 8
  store double %0, ptr %3, align 8
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  store double %1, ptr %5, align 8
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 1
  br i1 %7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %8 = getelementptr inbounds i8, ptr %4, i64 8
  br label %12

9:                                                ; preds = %12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %.not = icmp slt i64 %indvars.iv.next, %11
  br i1 %.not, label %12, label %._crit_edge, !llvm.loop !9

12:                                               ; preds = %.lr.ph, %9
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %9 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #2
  %13 = getelementptr inbounds [101 x %struct.Point], ptr @p, i64 0, i64 %indvars.iv
  %14 = call { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 8 dereferenceable(16) %13)
  %15 = extractvalue { double, double } %14, 0
  store double %15, ptr %4, align 8
  %16 = extractvalue { double, double } %14, 1
  store double %16, ptr %8, align 8
  %17 = call noundef double @_ZNK5Point4modeEv(ptr noundef nonnull align 8 dereferenceable(16) %4)
  %18 = load double, ptr @r, align 8, !tbaa !11
  %19 = fsub double %17, %18
  %20 = call noundef i32 @_Z4dcmpd(double noundef %19)
  %21 = icmp sgt i32 %20, -1
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #2
  br i1 %21, label %9, label %._crit_edge

._crit_edge:                                      ; preds = %9, %12, %2
  %.lcssa = phi i1 [ true, %2 ], [ %21, %12 ], [ %21, %9 ]
  ret i1 %.lcssa
}

; 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 { double, double } @_ZNK5PointmiERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5Point4modeEv(ptr noundef nonnull align 8 dereferenceable(16)) 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

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 = { mustprogress 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 = !{!"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}


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