; LLVM IR from NavInfoNC/nc-geo :: src/polyline_tile_splitter.ll (ZN12LineSplitter15testPointOnEdgeEPK5Pointj)

; 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.Rect = type { i32, i32, i32, i32 }
%class.LineSplitter = type { i32, ptr, i64, ptr, i64 }
%struct.Point = type { i32, i32 }

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

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

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_Z15getRectByGridIdji(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN12LineSplitter15testPointOnEdgeEPK5Pointj(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.Rect, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #2
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = getelementptr inbounds %class.LineSplitter, ptr %9, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = call { i64, i64 } @_Z15getRectByGridIdji(i32 noundef %10, i32 noundef %12)
  %14 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %15 = extractvalue { i64, i64 } %13, 0
  store i64 %15, ptr %14, align 4
  %16 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %17 = extractvalue { i64, i64 } %13, 1
  store i64 %17, ptr %16, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !14
  %18 = getelementptr inbounds %struct.Rect, ptr %7, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !16
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Point, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !18
  %23 = icmp sle i32 %19, %22
  br i1 %23, label %24, label %53

24:                                               ; preds = %3
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Point, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !18
  %28 = getelementptr inbounds %struct.Rect, ptr %7, i32 0, i32 3
  %29 = load i32, ptr %28, align 4, !tbaa !20
  %30 = icmp sle i32 %27, %29
  br i1 %30, label %31, label %53

31:                                               ; preds = %24
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Point, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 4, !tbaa !21
  %35 = getelementptr inbounds %struct.Rect, ptr %7, i32 0, i32 0
  %36 = load i32, ptr %35, align 4, !tbaa !22
  %37 = icmp eq i32 %34, %36
  br i1 %37, label %38, label %41

38:                                               ; preds = %31
  %39 = load i32, ptr %8, align 4, !tbaa !14
  %40 = or i32 %39, 1
  store i32 %40, ptr %8, align 4, !tbaa !14
  br label %52

41:                                               ; preds = %31
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Point, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 4, !tbaa !21
  %45 = getelementptr inbounds %struct.Rect, ptr %7, i32 0, i32 2
  %46 = load i32, ptr %45, align 4, !tbaa !23
  %47 = icmp eq i32 %44, %46
  br i1 %47, label %48, label %51

48:                                               ; preds = %41
  %49 = load i32, ptr %8, align 4, !tbaa !14
  %50 = or i32 %49, 2
  store i32 %50, ptr %8, align 4, !tbaa !14
  br label %51

51:                                               ; preds = %48, %41
  br label %52

52:                                               ; preds = %51, %38
  br label %53

53:                                               ; preds = %52, %24, %3
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Point, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 4, !tbaa !21
  %57 = getelementptr inbounds %struct.Rect, ptr %7, i32 0, i32 0
  %58 = load i32, ptr %57, align 4, !tbaa !22
  %59 = icmp sge i32 %56, %58
  br i1 %59, label %60, label %89

60:                                               ; preds = %53
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.Point, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 4, !tbaa !21
  %64 = getelementptr inbounds %struct.Rect, ptr %7, i32 0, i32 2
  %65 = load i32, ptr %64, align 4, !tbaa !23
  %66 = icmp sle i32 %63, %65
  br i1 %66, label %67, label %89

67:                                               ; preds = %60
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Point, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !18
  %71 = getelementptr inbounds %struct.Rect, ptr %7, i32 0, i32 1
  %72 = load i32, ptr %71, align 4, !tbaa !16
  %73 = icmp eq i32 %70, %72
  br i1 %73, label %74, label %77

74:                                               ; preds = %67
  %75 = load i32, ptr %8, align 4, !tbaa !14
  %76 = or i32 %75, 8
  store i32 %76, ptr %8, align 4, !tbaa !14
  br label %88

77:                                               ; preds = %67
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.Point, ptr %78, i32 0, i32 1
  %80 = load i32, ptr %79, align 4, !tbaa !18
  %81 = getelementptr inbounds %struct.Rect, ptr %7, i32 0, i32 3
  %82 = load i32, ptr %81, align 4, !tbaa !20
  %83 = icmp eq i32 %80, %82
  br i1 %83, label %84, label %87

84:                                               ; preds = %77
  %85 = load i32, ptr %8, align 4, !tbaa !14
  %86 = or i32 %85, 4
  store i32 %86, ptr %8, align 4, !tbaa !14
  br label %87

87:                                               ; preds = %84, %77
  br label %88

88:                                               ; preds = %87, %74
  br label %89

89:                                               ; preds = %88, %60, %53
  %90 = load i32, ptr %8, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #2
  ret i32 %90
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 0}
!12 = !{!"_ZTS12LineSplitter", !10, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !13, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"_ZTSN12LineSplitter8PositionE", !7, i64 0}
!16 = !{!17, !10, i64 4}
!17 = !{!"_ZTS4Rect", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!18 = !{!19, !10, i64 4}
!19 = !{!"_ZTS5Point", !10, i64 0, !10, i64 4}
!20 = !{!17, !10, i64 12}
!21 = !{!19, !10, i64 0}
!22 = !{!17, !10, i64 0}
!23 = !{!17, !10, i64 8}


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

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_Z15getRectByGridIdji(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 12) i32 @_ZN12LineSplitter15testPointOnEdgeEPK5Pointj(ptr nocapture noundef nonnull readonly align 8 dereferenceable(40) %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = tail call { i64, i64 } @_Z15getRectByGridIdji(i32 noundef %2, i32 noundef %4)
  %6 = extractvalue { i64, i64 } %5, 0
  %7 = extractvalue { i64, i64 } %5, 1
  %.sroa.0.4.extract.shift = lshr i64 %6, 32
  %.sroa.0.4.extract.trunc = trunc nuw i64 %.sroa.0.4.extract.shift to i32
  %8 = getelementptr inbounds i8, ptr %1, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %.not = icmp slt i32 %9, %.sroa.0.4.extract.trunc
  %.sroa.7.12.extract.shift = lshr i64 %7, 32
  %.sroa.7.12.extract.trunc = trunc nuw i64 %.sroa.7.12.extract.shift to i32
  %.not28 = icmp sgt i32 %9, %.sroa.7.12.extract.trunc
  %or.cond = select i1 %.not, i1 true, i1 %.not28
  %.pre = load i32, ptr %1, align 4, !tbaa !14
  %.pre33 = trunc i64 %6 to i32
  br i1 %or.cond, label %._crit_edge, label %10

10:                                               ; preds = %3
  %11 = icmp eq i32 %.pre, %.pre33
  br i1 %11, label %._crit_edge, label %12

12:                                               ; preds = %10
  %.sroa.7.8.extract.trunc = trunc i64 %7 to i32
  %13 = icmp eq i32 %.pre, %.sroa.7.8.extract.trunc
  %spec.select = select i1 %13, i32 2, i32 0
  br label %._crit_edge

._crit_edge:                                      ; preds = %3, %12, %10
  %.0 = phi i32 [ %spec.select, %12 ], [ 1, %10 ], [ 0, %3 ]
  %.not29 = icmp slt i32 %.pre, %.pre33
  %.sroa.7.8.extract.trunc11 = trunc i64 %7 to i32
  %.not30 = icmp sgt i32 %.pre, %.sroa.7.8.extract.trunc11
  %or.cond31 = select i1 %.not29, i1 true, i1 %.not30
  br i1 %or.cond31, label %21, label %14

14:                                               ; preds = %._crit_edge
  %15 = icmp eq i32 %9, %.sroa.0.4.extract.trunc
  br i1 %15, label %16, label %18

16:                                               ; preds = %14
  %17 = or disjoint i32 %.0, 8
  br label %21

18:                                               ; preds = %14
  %19 = icmp eq i32 %9, %.sroa.7.12.extract.trunc
  %20 = or disjoint i32 %.0, 4
  %spec.select32 = select i1 %19, i32 %20, i32 %.0
  br label %21

21:                                               ; preds = %18, %16, %._crit_edge
  %.1 = phi i32 [ %17, %16 ], [ %.0, %._crit_edge ], [ %spec.select32, %18 ]
  ret i32 %.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" }

!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, !7, i64 0}
!6 = !{!"_ZTS12LineSplitter", !7, i64 0, !10, i64 8, !11, i64 16, !10, i64 24, !11, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!13, !7, i64 4}
!13 = !{!"_ZTS5Point", !7, i64 0, !7, i64 4}
!14 = !{!13, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass