; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R2Polyline.ll (ZN10R2PolylineC2ERKS_)

; 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.R2Polyline = type { %class.R2Curve, ptr, i32, %class.R2Box }
%class.R2Curve = type { %class.R2Shape }
%class.R2Shape = type { ptr }
%class.R2Box = type { %class.R2Solid, %class.R2Point, %class.R2Point }
%class.R2Solid = type { %class.R2Shape }
%class.R2Point = type { [2 x double] }

@_ZTV10R2Polyline = external dso_local unnamed_addr constant { [15 x ptr] }, align 8

declare void @_ZN7R2CurveC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #0

declare void @_ZN5R2BoxC1ERKS_(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN7R2CurveD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10R2PolylineC2ERKS_(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull align 8 dereferenceable(64) %1) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @_ZN7R2CurveC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %8)
  store ptr getelementptr inbounds inrange(-16, 104) ({ [15 x ptr] }, ptr @_ZTV10R2Polyline, i32 0, i32 0, i32 2), ptr %8, align 8, !tbaa !9
  %9 = getelementptr inbounds %class.R2Polyline, ptr %8, i32 0, i32 1
  store ptr null, ptr %9, align 8, !tbaa !11
  %10 = getelementptr inbounds %class.R2Polyline, ptr %8, i32 0, i32 2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %class.R2Polyline, ptr %11, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !19
  store i32 %13, ptr %10, align 8, !tbaa !19
  %14 = getelementptr inbounds %class.R2Polyline, ptr %8, i32 0, i32 3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %class.R2Polyline, ptr %15, i32 0, i32 3
  invoke void @_ZN5R2BoxC1ERKS_(ptr noundef nonnull align 8 dereferenceable(40) %14, ptr noundef nonnull align 8 dereferenceable(40) %16)
          to label %17 unwind label %48

17:                                               ; preds = %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %class.R2Polyline, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !19
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %22, label %82

22:                                               ; preds = %17
  %23 = getelementptr inbounds %class.R2Polyline, ptr %8, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !19
  %25 = sext i32 %24 to i64
  %26 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %25, i64 16)
  %27 = extractvalue { i64, i1 } %26, 1
  %28 = extractvalue { i64, i1 } %26, 0
  %29 = select i1 %27, i64 -1, i64 %28
  %30 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %29) #7
          to label %31 unwind label %52

31:                                               ; preds = %22
  %32 = icmp eq i64 %25, 0
  br i1 %32, label %40, label %33

33:                                               ; preds = %31
  %34 = getelementptr inbounds %class.R2Point, ptr %30, i64 %25
  br label %35

35:                                               ; preds = %37, %33
  %36 = phi ptr [ %30, %33 ], [ %38, %37 ]
  invoke void @_ZN7R2PointC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %36)
          to label %37 unwind label %56

37:                                               ; preds = %35
  %38 = getelementptr inbounds %class.R2Point, ptr %36, i64 1
  %39 = icmp eq ptr %38, %34
  br i1 %39, label %40, label %35

40:                                               ; preds = %37, %31
  %41 = getelementptr inbounds %class.R2Polyline, ptr %8, i32 0, i32 1
  store ptr %30, ptr %41, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  store i32 0, ptr %7, align 4, !tbaa !20
  br label %42

42:                                               ; preds = %74, %40
  %43 = load i32, ptr %7, align 4, !tbaa !20
  %44 = getelementptr inbounds %class.R2Polyline, ptr %8, i32 0, i32 2
  %45 = load i32, ptr %44, align 8, !tbaa !19
  %46 = icmp slt i32 %43, %45
  br i1 %46, label %60, label %47

47:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  br label %81

48:                                               ; preds = %2
  %49 = landingpad { ptr, i32 }
          cleanup
  %50 = extractvalue { ptr, i32 } %49, 0
  store ptr %50, ptr %5, align 8
  %51 = extractvalue { ptr, i32 } %49, 1
  store i32 %51, ptr %6, align 4
  br label %84

52:                                               ; preds = %22
  %53 = landingpad { ptr, i32 }
          cleanup
  %54 = extractvalue { ptr, i32 } %53, 0
  store ptr %54, ptr %5, align 8
  %55 = extractvalue { ptr, i32 } %53, 1
  store i32 %55, ptr %6, align 4
  br label %83

56:                                               ; preds = %35
  %57 = landingpad { ptr, i32 }
          cleanup
  %58 = extractvalue { ptr, i32 } %57, 0
  store ptr %58, ptr %5, align 8
  %59 = extractvalue { ptr, i32 } %57, 1
  store i32 %59, ptr %6, align 4
  call void @_ZdaPvm(ptr noundef %30, i64 noundef %29) #9
  br label %83

60:                                               ; preds = %42
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %class.R2Polyline, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !11
  %64 = load i32, ptr %7, align 4, !tbaa !20
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %class.R2Point, ptr %63, i64 %65
  %67 = getelementptr inbounds %class.R2Polyline, ptr %8, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !11
  %69 = load i32, ptr %7, align 4, !tbaa !20
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds %class.R2Point, ptr %68, i64 %70
  %72 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(16) %71, ptr noundef nonnull align 8 dereferenceable(16) %66)
          to label %73 unwind label %77

73:                                               ; preds = %60
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %7, align 4, !tbaa !20
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %7, align 4, !tbaa !20
  br label %42, !llvm.loop !21

77:                                               ; preds = %60
  %78 = landingpad { ptr, i32 }
          cleanup
  %79 = extractvalue { ptr, i32 } %78, 0
  store ptr %79, ptr %5, align 8
  %80 = extractvalue { ptr, i32 } %78, 1
  store i32 %80, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  br label %83

81:                                               ; preds = %47
  br label %82

82:                                               ; preds = %81, %17
  ret void

83:                                               ; preds = %77, %56, %52
  call void @_ZN7R2SolidD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %14) #8
  br label %84

84:                                               ; preds = %83, %48
  call void @_ZN7R2CurveD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %8) #8
  br label %85

85:                                               ; preds = %84
  %86 = load ptr, ptr %5, align 8
  %87 = load i32, ptr %6, align 4
  %88 = insertvalue { ptr, i32 } poison, ptr %86, 0
  %89 = insertvalue { ptr, i32 } %88, i32 %87, 1
  resume { ptr, i32 } %89
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #3

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #4

declare void @_ZN7R2PointC1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0

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

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #0

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

; Function Attrs: nounwind
declare void @_ZN7R2SolidD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1

attributes #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 = { 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nobuiltin allocsize(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 #5 = { 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 #6 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { nounwind }
attributes #9 = { 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 8}
!12 = !{!"_ZTS10R2Polyline", !13, i64 0, !6, i64 8, !15, i64 16, !16, i64 24}
!13 = !{!"_ZTS7R2Curve", !14, i64 0}
!14 = !{!"_ZTS7R2Shape"}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTS5R2Box", !17, i64 0, !18, i64 8, !18, i64 24}
!17 = !{!"_ZTS7R2Solid", !14, i64 0}
!18 = !{!"_ZTS7R2Point", !7, i64 0}
!19 = !{!12, !15, i64 16}
!20 = !{!15, !15, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

%class.R2Point = type { [2 x double] }

@_ZTV10R2Polyline = external dso_local unnamed_addr constant { [15 x ptr] }, align 8

declare void @_ZN7R2CurveC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #0

declare void @_ZN5R2BoxC1ERKS_(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN7R2CurveD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10R2PolylineC2ERKS_(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull align 8 dereferenceable(64) %1) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN7R2CurveC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  store ptr getelementptr inbounds inrange(-16, 104) (i8, ptr @_ZTV10R2Polyline, i64 16), ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %3, align 8, !tbaa !8
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !18
  store i32 %6, ptr %4, align 8, !tbaa !18
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = getelementptr inbounds i8, ptr %1, i64 24
  invoke void @_ZN5R2BoxC1ERKS_(ptr noundef nonnull align 8 dereferenceable(40) %7, ptr noundef nonnull align 8 dereferenceable(40) %8)
          to label %9 unwind label %30

9:                                                ; preds = %2
  %10 = load i32, ptr %5, align 8, !tbaa !18
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %.loopexit

12:                                               ; preds = %9
  %13 = load i32, ptr %4, align 8, !tbaa !18
  %14 = sext i32 %13 to i64
  %15 = icmp slt i32 %13, 0
  %16 = shl nsw i64 %14, 4
  %17 = select i1 %15, i64 -1, i64 %16
  %18 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %17) #5
          to label %19 unwind label %32

19:                                               ; preds = %12
  %20 = icmp eq i32 %13, 0
  br i1 %20, label %.loopexit17.thread, label %21

.loopexit17.thread:                               ; preds = %19
  store ptr %18, ptr %3, align 8, !tbaa !8
  br label %.loopexit

21:                                               ; preds = %19
  %22 = getelementptr inbounds %class.R2Point, ptr %18, i64 %14
  br label %23

23:                                               ; preds = %25, %21
  %24 = phi ptr [ %18, %21 ], [ %26, %25 ]
  invoke void @_ZN7R2PointC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %24)
          to label %25 unwind label %34

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %24, i64 16
  %27 = icmp eq ptr %26, %22
  br i1 %27, label %.loopexit17, label %23

.loopexit17:                                      ; preds = %25
  %.pre = load i32, ptr %4, align 8, !tbaa !18
  %28 = icmp sgt i32 %.pre, 0
  store ptr %18, ptr %3, align 8, !tbaa !8
  br i1 %28, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.loopexit17
  %29 = getelementptr inbounds i8, ptr %1, i64 8
  br label %36

30:                                               ; preds = %2
  %31 = landingpad { ptr, i32 }
          cleanup
  br label %49

32:                                               ; preds = %12
  %33 = landingpad { ptr, i32 }
          cleanup
  br label %48

34:                                               ; preds = %23
  %35 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdaPvm(ptr noundef nonnull %18, i64 noundef %17) #6
  br label %48

36:                                               ; preds = %.lr.ph, %42
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %42 ]
  %37 = load ptr, ptr %29, align 8, !tbaa !8
  %38 = getelementptr inbounds %class.R2Point, ptr %37, i64 %indvars.iv
  %39 = load ptr, ptr %3, align 8, !tbaa !8
  %40 = getelementptr inbounds %class.R2Point, ptr %39, i64 %indvars.iv
  %41 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(16) %40, ptr noundef nonnull align 8 dereferenceable(16) %38)
          to label %42 unwind label %46

42:                                               ; preds = %36
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = load i32, ptr %4, align 8, !tbaa !18
  %44 = sext i32 %43 to i64
  %45 = icmp slt i64 %indvars.iv.next, %44
  br i1 %45, label %36, label %.loopexit, !llvm.loop !19

46:                                               ; preds = %36
  %47 = landingpad { ptr, i32 }
          cleanup
  br label %48

.loopexit:                                        ; preds = %42, %.loopexit17.thread, %.loopexit17, %9
  ret void

48:                                               ; preds = %46, %34, %32
  %.pn = phi { ptr, i32 } [ %47, %46 ], [ %35, %34 ], [ %33, %32 ]
  tail call void @_ZN7R2SolidD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %7) #7
  br label %49

49:                                               ; preds = %48, %30
  %.pn.pn = phi { ptr, i32 } [ %.pn, %48 ], [ %31, %30 ]
  tail call void @_ZN7R2CurveD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0) #7
  resume { ptr, i32 } %.pn.pn
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #3

declare void @_ZN7R2PointC1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0

; Function Attrs: nounwind
declare void @_ZN7R2SolidD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1

attributes #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 = { 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 #2 = { 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 #3 = { nobuiltin allocsize(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 #4 = { 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 #5 = { builtin allocsize(0) }
attributes #6 = { builtin nounwind }
attributes #7 = { 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, !12, i64 8}
!9 = !{!"_ZTS10R2Polyline", !10, i64 0, !12, i64 8, !14, i64 16, !15, i64 24}
!10 = !{!"_ZTS7R2Curve", !11, i64 0}
!11 = !{!"_ZTS7R2Shape"}
!12 = !{!"any pointer", !13, i64 0}
!13 = !{!"omnipotent char", !7, i64 0}
!14 = !{!"int", !13, i64 0}
!15 = !{!"_ZTS5R2Box", !16, i64 0, !17, i64 8, !17, i64 24}
!16 = !{!"_ZTS7R2Solid", !11, i64 0}
!17 = !{!"_ZTS7R2Point", !13, i64 0}
!18 = !{!9, !14, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass