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

; 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 }
%"struct.PolygonMarker::Cell" = type { %struct.Point, i32, i32, i32 }

@_ZL9sqrtOfTwo = external hidden global double, align 8
@_ZN13PolygonMarker4Cell14s_polygonCountE = external dso_local global i32, align 4
@_ZN13PolygonMarker4Cell9s_polygonE = external dso_local global ptr, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z17_isPointInPolygonPP13StaticPolygoni5Point(ptr noundef, i32 noundef, i64) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN13PolygonMarker4Cell20pointPolygonDistanceE5Point(i64) #0 align 2

; 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) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13PolygonMarker4Cell4initE5Pointi(ptr noundef nonnull align 4 dereferenceable(20) %0, i64 %1, i32 noundef %2) #0 align 2 {
  %4 = alloca %struct.Point, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.Point, align 4
  %8 = alloca %struct.Point, align 4
  store i64 %1, ptr %4, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %5, align 8
  %10 = getelementptr inbounds %"struct.PolygonMarker::Cell", ptr %9, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !11
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = getelementptr inbounds %"struct.PolygonMarker::Cell", ptr %9, i32 0, i32 1
  store i32 %11, ptr %12, align 4, !tbaa !12
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !11
  %13 = load i64, ptr %7, align 4
  %14 = call noundef i32 @_ZN13PolygonMarker4Cell20pointPolygonDistanceE5Point(i64 %13)
  %15 = getelementptr inbounds %"struct.PolygonMarker::Cell", ptr %9, i32 0, i32 2
  store i32 %14, ptr %15, align 4, !tbaa !15
  %16 = load ptr, ptr @_ZN13PolygonMarker4Cell9s_polygonE, align 8, !tbaa !5
  %17 = load i32, ptr @_ZN13PolygonMarker4Cell14s_polygonCountE, align 4, !tbaa !9
  %18 = getelementptr inbounds %"struct.PolygonMarker::Cell", ptr %9, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %18, i64 8, i1 false), !tbaa.struct !11
  %19 = load i64, ptr %8, align 4
  %20 = call noundef zeroext i1 @_Z17_isPointInPolygonPP13StaticPolygoni5Point(ptr noundef %16, i32 noundef %17, i64 %19)
  br i1 %20, label %21, label %24

21:                                               ; preds = %3
  %22 = getelementptr inbounds %"struct.PolygonMarker::Cell", ptr %9, i32 0, i32 2
  %23 = load i32, ptr %22, align 4, !tbaa !15
  br label %28

24:                                               ; preds = %3
  %25 = getelementptr inbounds %"struct.PolygonMarker::Cell", ptr %9, i32 0, i32 2
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = sub nsw i32 0, %26
  br label %28

28:                                               ; preds = %24, %21
  %29 = phi i32 [ %23, %21 ], [ %27, %24 ]
  %30 = getelementptr inbounds %"struct.PolygonMarker::Cell", ptr %9, i32 0, i32 2
  store i32 %29, ptr %30, align 4, !tbaa !15
  %31 = getelementptr inbounds %"struct.PolygonMarker::Cell", ptr %9, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !15
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = sitofp i32 %33 to double
  %35 = load double, ptr @_ZL9sqrtOfTwo, align 8, !tbaa !16
  %36 = fmul double %34, %35
  %37 = fptosi double %36 to i32
  %38 = add nsw i32 %32, %37
  %39 = getelementptr inbounds %"struct.PolygonMarker::Cell", ptr %9, i32 0, i32 3
  store i32 %38, ptr %39, align 4, !tbaa !18
  ret void
}

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 nounwind willreturn memory(argmem: readwrite) }

!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 = !{i64 0, i64 4, !9, i64 4, i64 4, !9}
!12 = !{!13, !10, i64 8}
!13 = !{!"_ZTSN13PolygonMarker4CellE", !14, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!14 = !{!"_ZTS5Point", !10, i64 0, !10, i64 4}
!15 = !{!13, !10, i64 12}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = !{!13, !10, i64 16}


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

@_ZL9sqrtOfTwo = external hidden local_unnamed_addr global double, align 8
@_ZN13PolygonMarker4Cell14s_polygonCountE = external dso_local local_unnamed_addr global i32, align 4
@_ZN13PolygonMarker4Cell9s_polygonE = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z17_isPointInPolygonPP13StaticPolygoni5Point(ptr noundef, i32 noundef, i64) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN13PolygonMarker4Cell20pointPolygonDistanceE5Point(i64) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13PolygonMarker4Cell4initE5Pointi(ptr nocapture noundef nonnull align 4 dereferenceable(20) %0, i64 %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  store i64 %1, ptr %0, align 4
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %2, ptr %4, align 4, !tbaa !5
  %5 = tail call noundef i32 @_ZN13PolygonMarker4Cell20pointPolygonDistanceE5Point(i64 %1)
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %5, ptr %6, align 4, !tbaa !11
  %7 = load ptr, ptr @_ZN13PolygonMarker4Cell9s_polygonE, align 8, !tbaa !12
  %8 = load i32, ptr @_ZN13PolygonMarker4Cell14s_polygonCountE, align 4, !tbaa !14
  %.sroa.0.0.copyload = load i64, ptr %0, align 4
  %9 = tail call noundef zeroext i1 @_Z17_isPointInPolygonPP13StaticPolygoni5Point(ptr noundef %7, i32 noundef %8, i64 %.sroa.0.0.copyload)
  %10 = load i32, ptr %6, align 4
  %11 = sub nsw i32 0, %10
  %12 = select i1 %9, i32 %10, i32 %11
  store i32 %12, ptr %6, align 4, !tbaa !11
  %13 = sitofp i32 %2 to double
  %14 = load double, ptr @_ZL9sqrtOfTwo, align 8, !tbaa !15
  %15 = fmul double %14, %13
  %16 = fptosi double %15 to i32
  %17 = add nsw i32 %12, %16
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %17, ptr %18, align 4, !tbaa !17
  ret void
}

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


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