; LLVM IR from NavInfoNC/nc-geo :: src/static_polygon.ll (ZN13StaticPolygon10updateBBoxEv)

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

%class.StaticPolygon = type { ptr, i32, %struct.Rect, i8, i64 }
%struct.Rect = type { i32, i32, i32, i32 }
%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 nounwind uwtable
define dso_local void @_ZN13StaticPolygon10updateBBoxEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 2
  %6 = getelementptr inbounds %struct.Rect, ptr %5, i32 0, i32 1
  store i32 2147483647, ptr %6, align 4, !tbaa !9
  %7 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 2
  %8 = getelementptr inbounds %struct.Rect, ptr %7, i32 0, i32 0
  store i32 2147483647, ptr %8, align 4, !tbaa !15
  %9 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 2
  %10 = getelementptr inbounds %struct.Rect, ptr %9, i32 0, i32 3
  store i32 -2147483648, ptr %10, align 4, !tbaa !16
  %11 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 2
  %12 = getelementptr inbounds %struct.Rect, ptr %11, i32 0, i32 2
  store i32 -2147483648, ptr %12, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !18
  br label %13

13:                                               ; preds = %108, %1
  %14 = load i32, ptr %3, align 4, !tbaa !18
  %15 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !19
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %111

19:                                               ; preds = %13
  %20 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !20
  %22 = load i32, ptr %3, align 4, !tbaa !18
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds %struct.Point, ptr %21, i64 %23
  %25 = getelementptr inbounds %struct.Point, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 4, !tbaa !21
  %27 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 2
  %28 = getelementptr inbounds %struct.Rect, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 4, !tbaa !15
  %30 = icmp slt i32 %26, %29
  br i1 %30, label %31, label %41

31:                                               ; preds = %19
  %32 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !20
  %34 = load i32, ptr %3, align 4, !tbaa !18
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct.Point, ptr %33, i64 %35
  %37 = getelementptr inbounds %struct.Point, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 4, !tbaa !21
  %39 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 2
  %40 = getelementptr inbounds %struct.Rect, ptr %39, i32 0, i32 0
  store i32 %38, ptr %40, align 4, !tbaa !15
  br label %41

41:                                               ; preds = %31, %19
  %42 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !20
  %44 = load i32, ptr %3, align 4, !tbaa !18
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds %struct.Point, ptr %43, i64 %45
  %47 = getelementptr inbounds %struct.Point, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !23
  %49 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 2
  %50 = getelementptr inbounds %struct.Rect, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = icmp slt i32 %48, %51
  br i1 %52, label %53, label %63

53:                                               ; preds = %41
  %54 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !20
  %56 = load i32, ptr %3, align 4, !tbaa !18
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds %struct.Point, ptr %55, i64 %57
  %59 = getelementptr inbounds %struct.Point, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !23
  %61 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 2
  %62 = getelementptr inbounds %struct.Rect, ptr %61, i32 0, i32 1
  store i32 %60, ptr %62, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %53, %41
  %64 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !20
  %66 = load i32, ptr %3, align 4, !tbaa !18
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds %struct.Point, ptr %65, i64 %67
  %69 = getelementptr inbounds %struct.Point, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 4, !tbaa !21
  %71 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 2
  %72 = getelementptr inbounds %struct.Rect, ptr %71, i32 0, i32 2
  %73 = load i32, ptr %72, align 4, !tbaa !17
  %74 = icmp sgt i32 %70, %73
  br i1 %74, label %75, label %85

75:                                               ; preds = %63
  %76 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !20
  %78 = load i32, ptr %3, align 4, !tbaa !18
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds %struct.Point, ptr %77, i64 %79
  %81 = getelementptr inbounds %struct.Point, ptr %80, i32 0, i32 0
  %82 = load i32, ptr %81, align 4, !tbaa !21
  %83 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 2
  %84 = getelementptr inbounds %struct.Rect, ptr %83, i32 0, i32 2
  store i32 %82, ptr %84, align 4, !tbaa !17
  br label %85

85:                                               ; preds = %75, %63
  %86 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !20
  %88 = load i32, ptr %3, align 4, !tbaa !18
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds %struct.Point, ptr %87, i64 %89
  %91 = getelementptr inbounds %struct.Point, ptr %90, i32 0, i32 1
  %92 = load i32, ptr %91, align 4, !tbaa !23
  %93 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 2
  %94 = getelementptr inbounds %struct.Rect, ptr %93, i32 0, i32 3
  %95 = load i32, ptr %94, align 4, !tbaa !16
  %96 = icmp sgt i32 %92, %95
  br i1 %96, label %97, label %107

97:                                               ; preds = %85
  %98 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 0
  %99 = load ptr, ptr %98, align 8, !tbaa !20
  %100 = load i32, ptr %3, align 4, !tbaa !18
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds %struct.Point, ptr %99, i64 %101
  %103 = getelementptr inbounds %struct.Point, ptr %102, i32 0, i32 1
  %104 = load i32, ptr %103, align 4, !tbaa !23
  %105 = getelementptr inbounds %class.StaticPolygon, ptr %4, i32 0, i32 2
  %106 = getelementptr inbounds %struct.Rect, ptr %105, i32 0, i32 3
  store i32 %104, ptr %106, align 4, !tbaa !16
  br label %107

107:                                              ; preds = %97, %85
  br label %108

108:                                              ; preds = %107
  %109 = load i32, ptr %3, align 4, !tbaa !18
  %110 = add nsw i32 %109, 1
  store i32 %110, ptr %3, align 4, !tbaa !18
  br label %13, !llvm.loop !24

111:                                              ; preds = %18
  ret void
}

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN13StaticPolygon10updateBBoxEv(ptr nocapture noundef nonnull align 8 dereferenceable(40) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 12
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  store <4 x i32> <i32 2147483647, i32 2147483647, i32 -2147483648, i32 -2147483648>, ptr %2, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %9 = load ptr, ptr %0, align 8, !tbaa !15
  %wide.trip.count = zext nneg i32 %7 to i64
  br label %10

._crit_edge:                                      ; preds = %33, %1
  ret void

10:                                               ; preds = %.lr.ph, %33
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %33 ]
  %11 = phi i32 [ 2147483647, %.lr.ph ], [ %20, %33 ]
  %12 = phi i32 [ 2147483647, %.lr.ph ], [ %26, %33 ]
  %13 = phi i32 [ -2147483648, %.lr.ph ], [ %30, %33 ]
  %14 = phi i32 [ -2147483648, %.lr.ph ], [ %34, %33 ]
  %15 = getelementptr inbounds %struct.Point, ptr %9, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !16
  %17 = icmp slt i32 %16, %11
  br i1 %17, label %18, label %19

18:                                               ; preds = %10
  store i32 %16, ptr %2, align 4, !tbaa !18
  br label %19

19:                                               ; preds = %18, %10
  %20 = phi i32 [ %16, %18 ], [ %11, %10 ]
  %21 = getelementptr inbounds %struct.Point, ptr %9, i64 %indvars.iv, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !19
  %23 = icmp slt i32 %22, %12
  br i1 %23, label %24, label %25

24:                                               ; preds = %19
  store i32 %22, ptr %3, align 8, !tbaa !20
  br label %25

25:                                               ; preds = %24, %19
  %26 = phi i32 [ %22, %24 ], [ %12, %19 ]
  %27 = icmp sgt i32 %16, %13
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  store i32 %16, ptr %5, align 4, !tbaa !21
  br label %29

29:                                               ; preds = %28, %25
  %30 = phi i32 [ %16, %28 ], [ %13, %25 ]
  %31 = icmp sgt i32 %22, %14
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  store i32 %22, ptr %4, align 8, !tbaa !22
  br label %33

33:                                               ; preds = %29, %32
  %34 = phi i32 [ %14, %29 ], [ %22, %32 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %10, !llvm.loop !23
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS13StaticPolygon", !11, i64 0, !6, i64 8, !12, i64 12, !13, i64 28, !14, i64 32}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"_ZTS4Rect", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!10, !11, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"_ZTS5Point", !6, i64 0, !6, i64 4}
!18 = !{!10, !6, i64 12}
!19 = !{!17, !6, i64 4}
!20 = !{!10, !6, i64 16}
!21 = !{!10, !6, i64 20}
!22 = !{!10, !6, i64 24}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass