; LLVM IR from Lodour/ACM-CheatSheet :: src/6_计算几何/3_多边形/5_小结.ll (Z9is_convexiP5point)

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

@__const._Z9is_convexiP5point.s = external hidden unnamed_addr constant [3 x i32], align 4

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z9is_convexiP5point(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [3 x i32], align 4
  %7 = alloca %struct.point, align 8
  %8 = alloca %struct.point, align 8
  %9 = alloca %struct.point, align 8
  %10 = alloca %struct.point, align 8
  %11 = alloca %struct.point, align 8
  %12 = alloca %struct.point, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 12, ptr %6) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 @__const._Z9is_convexiP5point.s, i64 12, i1 false)
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %99, %2
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %24

17:                                               ; preds = %13
  %18 = getelementptr inbounds [3 x i32], ptr %6, i64 0, i64 1
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds [3 x i32], ptr %6, i64 0, i64 2
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = or i32 %19, %21
  %23 = icmp ne i32 %22, 0
  br label %24

24:                                               ; preds = %17, %13
  %25 = phi i1 [ false, %13 ], [ %23, %17 ]
  br i1 %25, label %26, label %102

26:                                               ; preds = %24
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = srem i32 %29, %30
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds %struct.point, ptr %27, i64 %32
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %33, i64 16, i1 false), !tbaa.struct !11
  %34 = load ptr, ptr %4, align 8, !tbaa !9
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = add nsw i32 %35, 2
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = srem i32 %36, %37
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds %struct.point, ptr %34, i64 %39
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %40, i64 16, i1 false), !tbaa.struct !11
  %41 = load ptr, ptr %4, align 8, !tbaa !9
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %struct.point, ptr %41, i64 %43
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %44, i64 16, i1 false), !tbaa.struct !11
  %45 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 0
  %46 = load double, ptr %45, align 8
  %47 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 1
  %48 = load double, ptr %47, align 8
  %49 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 0
  %50 = load double, ptr %49, align 8
  %51 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 1
  %52 = load double, ptr %51, align 8
  %53 = getelementptr inbounds { double, double }, ptr %9, i32 0, i32 0
  %54 = load double, ptr %53, align 8
  %55 = getelementptr inbounds { double, double }, ptr %9, i32 0, i32 1
  %56 = load double, ptr %55, align 8
  %57 = call noundef double @_Z5xmult5pointS_S_(double %46, double %48, double %50, double %52, double %54, double %56)
  %58 = fcmp ogt double %57, 1.000000e-08
  br i1 %58, label %59, label %60

59:                                               ; preds = %26
  br label %95

60:                                               ; preds = %26
  %61 = load ptr, ptr %4, align 8, !tbaa !9
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = srem i32 %63, %64
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds %struct.point, ptr %61, i64 %66
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %67, i64 16, i1 false), !tbaa.struct !11
  %68 = load ptr, ptr %4, align 8, !tbaa !9
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = add nsw i32 %69, 2
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = srem i32 %70, %71
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds %struct.point, ptr %68, i64 %73
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %74, i64 16, i1 false), !tbaa.struct !11
  %75 = load ptr, ptr %4, align 8, !tbaa !9
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds %struct.point, ptr %75, i64 %77
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %78, i64 16, i1 false), !tbaa.struct !11
  %79 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 0
  %80 = load double, ptr %79, align 8
  %81 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 1
  %82 = load double, ptr %81, align 8
  %83 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %84 = load double, ptr %83, align 8
  %85 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %86 = load double, ptr %85, align 8
  %87 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  %88 = load double, ptr %87, align 8
  %89 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  %90 = load double, ptr %89, align 8
  %91 = call noundef double @_Z5xmult5pointS_S_(double %80, double %82, double %84, double %86, double %88, double %90)
  %92 = fcmp olt double %91, -1.000000e-08
  %93 = zext i1 %92 to i64
  %94 = select i1 %92, i32 2, i32 0
  br label %95

95:                                               ; preds = %60, %59
  %96 = phi i32 [ 1, %59 ], [ %94, %60 ]
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [3 x i32], ptr %6, i64 0, i64 %97
  store i32 0, ptr %98, align 4, !tbaa !5
  br label %99

99:                                               ; preds = %95
  %100 = load i32, ptr %5, align 4, !tbaa !5
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %5, align 4, !tbaa !5
  br label %13, !llvm.loop !14

102:                                              ; preds = %24
  %103 = getelementptr inbounds [3 x i32], ptr %6, i64 0, i64 1
  %104 = load i32, ptr %103, align 4, !tbaa !5
  %105 = getelementptr inbounds [3 x i32], ptr %6, i64 0, i64 2
  %106 = load i32, ptr %105, align 4, !tbaa !5
  %107 = or i32 %104, %106
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %107
}

; 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

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 = { nocallback nofree 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 = !{!"any pointer", !7, i64 0}
!11 = !{i64 0, i64 8, !12, i64 8, i64 8, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}
!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.point = type { double, double }

@__const._Z9is_convexiP5point.s = external hidden unnamed_addr constant [3 x i32], align 4

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z9is_convexiP5point(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [3 x i32], align 4
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %3, ptr noundef nonnull align 4 dereferenceable(12) @__const._Z9is_convexiP5point.s, i64 12, i1 false)
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  %6 = icmp sgt i32 %0, 0
  %7 = load i32, ptr %4, align 4
  %8 = load i32, ptr %5, align 4
  %9 = or i32 %8, %7
  %10 = icmp ne i32 %9, 0
  %11 = select i1 %6, i1 %10, i1 false
  br i1 %11, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %12 = zext nneg i32 %0 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %29
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %29 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = trunc nuw nsw i64 %indvars.iv.next to i32
  %14 = urem i32 %13, %0
  %15 = zext nneg i32 %14 to i64
  %16 = getelementptr inbounds %struct.point, ptr %1, i64 %15
  %.sroa.09.0.copyload = load double, ptr %16, align 8, !tbaa !5
  %.sroa.210.0..sroa_idx = getelementptr inbounds i8, ptr %16, i64 8
  %.sroa.210.0.copyload = load double, ptr %.sroa.210.0..sroa_idx, align 8, !tbaa !5
  %17 = trunc i64 %indvars.iv to i32
  %18 = add i32 %17, 2
  %19 = urem i32 %18, %0
  %20 = zext nneg i32 %19 to i64
  %21 = getelementptr inbounds %struct.point, ptr %1, i64 %20
  %.sroa.07.0.copyload = load double, ptr %21, align 8, !tbaa !5
  %.sroa.28.0..sroa_idx = getelementptr inbounds i8, ptr %21, i64 8
  %.sroa.28.0.copyload = load double, ptr %.sroa.28.0..sroa_idx, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.point, ptr %1, i64 %indvars.iv
  %.sroa.05.0.copyload = load double, ptr %22, align 8, !tbaa !5
  %.sroa.26.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 8
  %.sroa.26.0.copyload = load double, ptr %.sroa.26.0..sroa_idx, align 8, !tbaa !5
  %23 = tail call noundef double @_Z5xmult5pointS_S_(double %.sroa.09.0.copyload, double %.sroa.210.0.copyload, double %.sroa.07.0.copyload, double %.sroa.28.0.copyload, double %.sroa.05.0.copyload, double %.sroa.26.0.copyload)
  %24 = fcmp ogt double %23, 1.000000e-08
  br i1 %24, label %29, label %25

25:                                               ; preds = %.lr.ph
  %.sroa.03.0.copyload = load double, ptr %16, align 8, !tbaa !5
  %.sroa.24.0.copyload = load double, ptr %.sroa.210.0..sroa_idx, align 8, !tbaa !5
  %.sroa.01.0.copyload = load double, ptr %21, align 8, !tbaa !5
  %.sroa.22.0.copyload = load double, ptr %.sroa.28.0..sroa_idx, align 8, !tbaa !5
  %.sroa.0.0.copyload = load double, ptr %22, align 8, !tbaa !5
  %.sroa.2.0.copyload = load double, ptr %.sroa.26.0..sroa_idx, align 8, !tbaa !5
  %26 = tail call noundef double @_Z5xmult5pointS_S_(double %.sroa.03.0.copyload, double %.sroa.24.0.copyload, double %.sroa.01.0.copyload, double %.sroa.22.0.copyload, double %.sroa.0.0.copyload, double %.sroa.2.0.copyload)
  %27 = fcmp olt double %26, -1.000000e-08
  %28 = select i1 %27, i64 2, i64 0
  br label %29

29:                                               ; preds = %.lr.ph, %25
  %30 = phi i64 [ %28, %25 ], [ 1, %.lr.ph ]
  %31 = getelementptr inbounds [3 x i32], ptr %3, i64 0, i64 %30
  store i32 0, ptr %31, align 4, !tbaa !9
  %32 = icmp ult i64 %indvars.iv.next, %12
  %33 = load i32, ptr %4, align 4
  %34 = load i32, ptr %5, align 4
  %35 = or i32 %34, %33
  %36 = icmp ne i32 %35, 0
  %37 = select i1 %32, i1 %36, i1 false
  br i1 %37, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %29, %2
  %.lcssa = phi i32 [ %9, %2 ], [ %35, %29 ]
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #3
  ret i32 %.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 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 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 = { mustprogress nocallback nofree 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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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