; LLVM IR from ImperialCollegeLondon/pnflow :: src/pnm/pnflow/polygon/polygon.ll (ZN7PolygonD2Ev)

; 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.Polygon = type { %class.VoidElem, i32, %"class.std::vector.16", ptr, ptr, i16, i8, double }
%class.VoidElem = type { %class.ElemModel, double, double, double, double }
%class.ElemModel = type { ptr, double, double, ptr, ptr, double, ptr, i8, i8, i8, i8, i32, double, double, double, double, double, double, double, %"struct.std::pair", %"struct.std::pair" }
%"struct.std::pair" = type { double, double }
%"class.std::vector.16" = type { %"struct.std::_Vector_base.17" }
%"struct.std::_Vector_base.17" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%class.CornerApex = type { %class.Apex, ptr, double, double, double, ptr }
%class.Apex = type { ptr, i8, double, double, ptr, i32, double, double, double, double, i8, i8, i8, i8, %"struct.std::pair.0" }
%"struct.std::pair.0" = type { i32, double }
%class.LayerApex = type { %class.Apex, i32, ptr, double, ptr, double }

@_ZTV7Polygon = external dso_local unnamed_addr constant { [32 x ptr] }, align 8

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPvm(ptr noundef, i64 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ApexD2Ev(ptr noundef nonnull align 8 dereferenceable(104)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIdSaIdEED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN9ElemModelD2Ev(ptr noundef nonnull align 8 dereferenceable(152)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7PolygonD2Ev(ptr noundef nonnull align 8 dereferenceable(248) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  store ptr getelementptr inbounds inrange(-16, 240) ({ [32 x ptr] }, ptr @_ZTV7Polygon, i32 0, i32 0, i32 2), ptr %3, align 8, !tbaa !9
  %4 = getelementptr inbounds %class.Polygon, ptr %3, i32 0, i32 3
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %6 = icmp eq ptr %5, null
  br i1 %6, label %19, label %7

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %5, i64 -8
  %9 = load i64, ptr %8, align 8
  %10 = getelementptr inbounds %class.CornerApex, ptr %5, i64 %9
  %11 = icmp eq ptr %5, %10
  br i1 %11, label %16, label %12

12:                                               ; preds = %12, %7
  %13 = phi ptr [ %10, %7 ], [ %14, %12 ]
  %14 = getelementptr inbounds %class.CornerApex, ptr %13, i64 -1
  call void @_ZN4ApexD2Ev(ptr noundef nonnull align 8 dereferenceable(144) %14) #2
  %15 = icmp eq ptr %14, %5
  br i1 %15, label %16, label %12

16:                                               ; preds = %12, %7
  %17 = mul i64 144, %9
  %18 = add i64 %17, 8
  call void @_ZdaPvm(ptr noundef %8, i64 noundef %18) #3
  br label %19

19:                                               ; preds = %16, %1
  %20 = getelementptr inbounds %class.Polygon, ptr %3, i32 0, i32 4
  %21 = load ptr, ptr %20, align 8, !tbaa !24
  %22 = icmp eq ptr %21, null
  br i1 %22, label %35, label %23

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %21, i64 -8
  %25 = load i64, ptr %24, align 8
  %26 = getelementptr inbounds %class.LayerApex, ptr %21, i64 %25
  %27 = icmp eq ptr %21, %26
  br i1 %27, label %32, label %28

28:                                               ; preds = %28, %23
  %29 = phi ptr [ %26, %23 ], [ %30, %28 ]
  %30 = getelementptr inbounds %class.LayerApex, ptr %29, i64 -1
  call void @_ZN4ApexD2Ev(ptr noundef nonnull align 8 dereferenceable(144) %30) #2
  %31 = icmp eq ptr %30, %21
  br i1 %31, label %32, label %28

32:                                               ; preds = %28, %23
  %33 = mul i64 144, %25
  %34 = add i64 %33, 8
  call void @_ZdaPvm(ptr noundef %24, i64 noundef %34) #3
  br label %35

35:                                               ; preds = %32, %19
  %36 = getelementptr inbounds %class.Polygon, ptr %3, i32 0, i32 2
  call void @_ZNSt6vectorIdSaIdEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %36) #2
  call void @_ZN9ElemModelD2Ev(ptr noundef nonnull align 8 dereferenceable(184) %3) #2
  ret void
}

attributes #0 = { nobuiltin nounwind "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 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 }
attributes #3 = { builtin 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !6, i64 216}
!12 = !{!"_ZTS7Polygon", !13, i64 0, !17, i64 184, !19, i64 192, !6, i64 216, !6, i64 224, !23, i64 232, !7, i64 234, !15, i64 240}
!13 = !{!"_ZTS8VoidElem", !14, i64 0, !15, i64 152, !15, i64 160, !15, i64 168, !15, i64 176}
!14 = !{!"_ZTS9ElemModel", !15, i64 8, !15, i64 16, !6, i64 24, !6, i64 32, !15, i64 40, !6, i64 48, !16, i64 56, !16, i64 57, !16, i64 58, !16, i64 59, !17, i64 60, !15, i64 64, !15, i64 72, !15, i64 80, !15, i64 88, !15, i64 96, !15, i64 104, !15, i64 112, !18, i64 120, !18, i64 136}
!15 = !{!"double", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!"_ZTSSt4pairIddE", !15, i64 0, !15, i64 8}
!19 = !{!"_ZTSSt6vectorIdSaIdEE", !20, i64 0}
!20 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !22, i64 0}
!22 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!23 = !{!"short", !7, i64 0}
!24 = !{!12, !6, i64 224}


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

%class.CornerApex = type { %class.Apex, ptr, double, double, double, ptr }
%class.Apex = type { ptr, i8, double, double, ptr, i32, double, double, double, double, i8, i8, i8, i8, %"struct.std::pair.0" }
%"struct.std::pair.0" = type { i32, double }
%class.LayerApex = type { %class.Apex, i32, ptr, double, ptr, double }

@_ZTV7Polygon = external dso_local unnamed_addr constant { [32 x ptr] }, align 8

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ApexD2Ev(ptr noundef nonnull align 8 dereferenceable(104)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIdSaIdEED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN9ElemModelD2Ev(ptr noundef nonnull align 8 dereferenceable(152)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7PolygonD2Ev(ptr noundef nonnull align 8 dereferenceable(248) %0) unnamed_addr #1 align 2 {
  store ptr getelementptr inbounds inrange(-16, 240) (i8, ptr @_ZTV7Polygon, i64 16), ptr %0, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %0, i64 216
  %3 = load ptr, ptr %2, align 8, !tbaa !8
  %4 = icmp eq ptr %3, null
  br i1 %4, label %15, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %3, i64 -8
  %7 = load i64, ptr %6, align 8
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %.loopexit5, label %.preheader4.preheader

.preheader4.preheader:                            ; preds = %5
  %9 = getelementptr inbounds %class.CornerApex, ptr %3, i64 %7
  br label %.preheader4

.preheader4:                                      ; preds = %.preheader4.preheader, %.preheader4
  %10 = phi ptr [ %11, %.preheader4 ], [ %9, %.preheader4.preheader ]
  %11 = getelementptr inbounds i8, ptr %10, i64 -144
  tail call void @_ZN4ApexD2Ev(ptr noundef nonnull align 8 dereferenceable(144) %11) #2
  %12 = icmp eq ptr %11, %3
  br i1 %12, label %.loopexit5, label %.preheader4

.loopexit5:                                       ; preds = %.preheader4, %5
  %13 = mul i64 %7, 144
  %14 = or disjoint i64 %13, 8
  tail call void @_ZdaPvm(ptr noundef nonnull %6, i64 noundef %14) #3
  br label %15

15:                                               ; preds = %.loopexit5, %1
  %16 = getelementptr inbounds i8, ptr %0, i64 224
  %17 = load ptr, ptr %16, align 8, !tbaa !23
  %18 = icmp eq ptr %17, null
  br i1 %18, label %29, label %19

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %17, i64 -8
  %21 = load i64, ptr %20, align 8
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %19
  %23 = getelementptr inbounds %class.LayerApex, ptr %17, i64 %21
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %24 = phi ptr [ %25, %.preheader ], [ %23, %.preheader.preheader ]
  %25 = getelementptr inbounds i8, ptr %24, i64 -144
  tail call void @_ZN4ApexD2Ev(ptr noundef nonnull align 8 dereferenceable(144) %25) #2
  %26 = icmp eq ptr %25, %17
  br i1 %26, label %.loopexit, label %.preheader

.loopexit:                                        ; preds = %.preheader, %19
  %27 = mul i64 %21, 144
  %28 = or disjoint i64 %27, 8
  tail call void @_ZdaPvm(ptr noundef nonnull %20, i64 noundef %28) #3
  br label %29

29:                                               ; preds = %.loopexit, %15
  %30 = getelementptr inbounds i8, ptr %0, i64 192
  tail call void @_ZNSt6vectorIdSaIdEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %30) #2
  tail call void @_ZN9ElemModelD2Ev(ptr noundef nonnull align 8 dereferenceable(184) %0) #2
  ret void
}

attributes #0 = { nobuiltin nounwind "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 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 }
attributes #3 = { builtin 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !14, i64 216}
!9 = !{!"_ZTS7Polygon", !10, i64 0, !16, i64 184, !18, i64 192, !14, i64 216, !14, i64 224, !22, i64 232, !13, i64 234, !12, i64 240}
!10 = !{!"_ZTS8VoidElem", !11, i64 0, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176}
!11 = !{!"_ZTS9ElemModel", !12, i64 8, !12, i64 16, !14, i64 24, !14, i64 32, !12, i64 40, !14, i64 48, !15, i64 56, !15, i64 57, !15, i64 58, !15, i64 59, !16, i64 60, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !17, i64 120, !17, i64 136}
!12 = !{!"double", !13, i64 0}
!13 = !{!"omnipotent char", !7, i64 0}
!14 = !{!"any pointer", !13, i64 0}
!15 = !{!"bool", !13, i64 0}
!16 = !{!"int", !13, i64 0}
!17 = !{!"_ZTSSt4pairIddE", !12, i64 0, !12, i64 8}
!18 = !{!"_ZTSSt6vectorIdSaIdEE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!22 = !{!"short", !13, i64 0}
!23 = !{!9, !14, i64 224}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass