; LLVM IR from NavInfoNC/nc-geo :: src/polygon_marker.ll (Z17_isPointInPolygonPP13StaticPolygoni5Point)

; 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 { i32, i32 }

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

16:                                               ; preds = %135, %3
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds ptr, ptr %22, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = call noundef i32 @_ZN13StaticPolygon11pointNumberEv(ptr noundef nonnull align 8 dereferenceable(40) %26)
  store i32 %27, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds ptr, ptr %28, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = call noundef ptr @_ZN13StaticPolygon6pointsEv(ptr noundef nonnull align 8 dereferenceable(40) %32)
  store ptr %33, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = sub nsw i32 %34, 1
  store i32 %35, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %131, %21
  %37 = load i32, ptr %13, align 4, !tbaa !9
  %38 = load i32, ptr %10, align 4, !tbaa !9
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %134

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = load i32, ptr %12, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.Point, ptr %42, i64 %44
  %46 = getelementptr inbounds %struct.Point, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 4, !tbaa !13
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = load i32, ptr %13, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %struct.Point, ptr %48, i64 %50
  %52 = getelementptr inbounds %struct.Point, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 4, !tbaa !13
  %54 = icmp slt i32 %47, %53
  br i1 %54, label %55, label %64

55:                                               ; preds = %41
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load i32, ptr %12, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds %struct.Point, ptr %56, i64 %58
  store ptr %59, ptr %14, align 8, !tbaa !5
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = load i32, ptr %13, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds %struct.Point, ptr %60, i64 %62
  store ptr %63, ptr %15, align 8, !tbaa !5
  br label %73

64:                                               ; preds = %41
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = load i32, ptr %12, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds %struct.Point, ptr %65, i64 %67
  store ptr %68, ptr %15, align 8, !tbaa !5
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = load i32, ptr %13, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds %struct.Point, ptr %69, i64 %71
  store ptr %72, ptr %14, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %64, %55
  %74 = getelementptr inbounds %struct.Point, ptr %4, i32 0, i32 0
  %75 = load i32, ptr %74, align 4, !tbaa !13
  %76 = load ptr, ptr %14, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.Point, ptr %76, i32 0, i32 0
  %78 = load i32, ptr %77, align 4, !tbaa !13
  %79 = icmp sgt i32 %75, %78
  %80 = zext i1 %79 to i32
  %81 = getelementptr inbounds %struct.Point, ptr %4, i32 0, i32 0
  %82 = load i32, ptr %81, align 4, !tbaa !13
  %83 = load ptr, ptr %15, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.Point, ptr %83, i32 0, i32 0
  %85 = load i32, ptr %84, align 4, !tbaa !13
  %86 = icmp sle i32 %82, %85
  %87 = zext i1 %86 to i32
  %88 = icmp eq i32 %80, %87
  br i1 %88, label %89, label %130

89:                                               ; preds = %73
  %90 = load ptr, ptr %14, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.Point, ptr %90, i32 0, i32 0
  %92 = load i32, ptr %91, align 4, !tbaa !13
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds %struct.Point, ptr %4, i32 0, i32 0
  %95 = load i32, ptr %94, align 4, !tbaa !13
  %96 = sext i32 %95 to i64
  %97 = sub nsw i64 %93, %96
  %98 = load ptr, ptr %15, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.Point, ptr %98, i32 0, i32 1
  %100 = load i32, ptr %99, align 4, !tbaa !15
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds %struct.Point, ptr %4, i32 0, i32 1
  %103 = load i32, ptr %102, align 4, !tbaa !15
  %104 = sext i32 %103 to i64
  %105 = sub nsw i64 %101, %104
  %106 = mul nsw i64 %97, %105
  %107 = load ptr, ptr %15, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.Point, ptr %107, i32 0, i32 0
  %109 = load i32, ptr %108, align 4, !tbaa !13
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds %struct.Point, ptr %4, i32 0, i32 0
  %112 = load i32, ptr %111, align 4, !tbaa !13
  %113 = sext i32 %112 to i64
  %114 = sub nsw i64 %110, %113
  %115 = load ptr, ptr %14, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.Point, ptr %115, i32 0, i32 1
  %117 = load i32, ptr %116, align 4, !tbaa !15
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds %struct.Point, ptr %4, i32 0, i32 1
  %120 = load i32, ptr %119, align 4, !tbaa !15
  %121 = sext i32 %120 to i64
  %122 = sub nsw i64 %118, %121
  %123 = mul nsw i64 %114, %122
  %124 = icmp sle i64 %106, %123
  br i1 %124, label %125, label %130

125:                                              ; preds = %89
  %126 = load i8, ptr %7, align 1, !tbaa !11, !range !16, !noundef !17
  %127 = trunc i8 %126 to i1
  %128 = xor i1 %127, true
  %129 = zext i1 %128 to i8
  store i8 %129, ptr %7, align 1, !tbaa !11
  br label %130

130:                                              ; preds = %125, %89, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %131

131:                                              ; preds = %130
  %132 = load i32, ptr %13, align 4, !tbaa !9
  %133 = add nsw i32 %132, 1
  store i32 %133, ptr %13, align 4, !tbaa !9
  store i32 %132, ptr %12, align 4, !tbaa !9
  br label %36, !llvm.loop !18

134:                                              ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %135

135:                                              ; preds = %134
  %136 = load i32, ptr %8, align 4, !tbaa !9
  %137 = add nsw i32 %136, 1
  store i32 %137, ptr %8, align 4, !tbaa !9
  br label %16, !llvm.loop !20

138:                                              ; preds = %20
  %139 = load i8, ptr %7, align 1, !tbaa !11, !range !16, !noundef !17
  %140 = trunc i8 %139 to i1
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  ret i1 %140
}

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN13StaticPolygon11pointNumberEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN13StaticPolygon6pointsEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 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 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 = { alwaysinline 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS5Point", !10, i64 0, !10, i64 4}
!15 = !{!14, !10, i64 4}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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 { i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z17_isPointInPolygonPP13StaticPolygoni5Point(ptr nocapture noundef readonly %0, i32 noundef %1, i64 %2) local_unnamed_addr #0 {
  %.sroa.0.0.extract.trunc = trunc i64 %2 to i32
  %4 = icmp sgt i32 %1, 0
  br i1 %4, label %.lr.ph47, label %._crit_edge48

.lr.ph47:                                         ; preds = %3
  %sext = shl i64 %2, 32
  %5 = ashr exact i64 %sext, 32
  %6 = ashr i64 %2, 32
  %wide.trip.count52 = zext nneg i32 %1 to i64
  br label %7

._crit_edge48:                                    ; preds = %._crit_edge, %3
  %.037.lcssa = phi i1 [ false, %3 ], [ %.1.lcssa, %._crit_edge ]
  ret i1 %.037.lcssa

7:                                                ; preds = %.lr.ph47, %._crit_edge
  %indvars.iv50 = phi i64 [ 0, %.lr.ph47 ], [ %indvars.iv.next51, %._crit_edge ]
  %.03745 = phi i1 [ false, %.lr.ph47 ], [ %.1.lcssa, %._crit_edge ]
  %8 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv50
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = tail call noundef i32 @_ZN13StaticPolygon11pointNumberEv(ptr noundef nonnull align 8 dereferenceable(40) %9)
  %11 = load ptr, ptr %8, align 8, !tbaa !5
  %12 = tail call noundef ptr @_ZN13StaticPolygon6pointsEv(ptr noundef nonnull align 8 dereferenceable(40) %11)
  %13 = icmp sgt i32 %10, 0
  br i1 %13, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %7
  %14 = add nsw i32 %10, -1
  %wide.trip.count = zext nneg i32 %10 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %41, %7
  %.1.lcssa = phi i1 [ %.03745, %7 ], [ %.2, %41 ]
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %exitcond53.not = icmp eq i64 %indvars.iv.next51, %wide.trip.count52
  br i1 %exitcond53.not, label %._crit_edge48, label %7, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph.preheader, %41
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %41 ]
  %.03642 = phi i32 [ %14, %.lr.ph.preheader ], [ %42, %41 ]
  %.141 = phi i1 [ %.03745, %.lr.ph.preheader ], [ %.2, %41 ]
  %15 = sext i32 %.03642 to i64
  %16 = getelementptr inbounds %struct.Point, ptr %12, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = getelementptr inbounds %struct.Point, ptr %12, i64 %indvars.iv
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = tail call i32 @llvm.smin.i32(i32 %17, i32 %19)
  %21 = tail call i32 @llvm.smax.i32(i32 %17, i32 %19)
  %22 = icmp slt i32 %20, %.sroa.0.0.extract.trunc
  %23 = icmp slt i32 %21, %.sroa.0.0.extract.trunc
  %24 = xor i1 %22, %23
  br i1 %24, label %25, label %41

25:                                               ; preds = %.lr.ph
  %26 = icmp slt i32 %17, %19
  %.40 = select i1 %26, ptr %18, ptr %16
  %. = select i1 %26, ptr %16, ptr %18
  %27 = sext i32 %20 to i64
  %28 = sub nsw i64 %27, %5
  %29 = getelementptr inbounds i8, ptr %.40, i64 4
  %30 = load i32, ptr %29, align 4, !tbaa !14
  %31 = sext i32 %30 to i64
  %32 = sub nsw i64 %31, %6
  %33 = mul nsw i64 %32, %28
  %34 = sext i32 %21 to i64
  %35 = sub nsw i64 %34, %5
  %36 = getelementptr inbounds i8, ptr %., i64 4
  %37 = load i32, ptr %36, align 4, !tbaa !14
  %38 = sext i32 %37 to i64
  %39 = sub nsw i64 %38, %6
  %40 = mul nsw i64 %39, %35
  %.not = icmp sle i64 %33, %40
  %spec.select = xor i1 %.141, %.not
  br label %41

41:                                               ; preds = %25, %.lr.ph
  %.2 = phi i1 [ %.141, %.lr.ph ], [ %spec.select, %25 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %42 = trunc nuw nsw i64 %indvars.iv to i32
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN13StaticPolygon11pointNumberEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN13StaticPolygon6pointsEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #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 = { alwaysinline 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


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