; LLVM IR from niessner/Matterport :: code/gaps/apps/mpview/mp.ll (ZN9MPSurface12InsertVertexEP8MPVertexi)

; 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.R3Span = type { %class.R3Ray, %class.R3Point, double }
%class.R3Ray = type { %class.R3Line }
%class.R3Line = type { %class.R3Point, %class.R3Vector }
%class.R3Vector = type { [3 x double] }
%class.R3Point = type { [3 x double] }
%struct.MPSurface = type { ptr, i32, ptr, i32, %class.RNArray.5, %class.R3Point, %class.R3Vector, %class.R3Box, ptr }
%class.RNArray.5 = type { %class.RNVArray }
%class.RNVArray = type { ptr, i32, i32 }
%class.R3Box = type { %class.R3Solid, %class.R3Point, %class.R3Point }
%class.R3Solid = type { %class.R3Shape }
%class.R3Shape = type { ptr }
%struct.MPVertex = type { ptr, i32, ptr, i32, %class.R3Point, %class.R3Vector, ptr }

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16)) #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9MPSurface12InsertVertexEP8MPVertexi(ptr noundef nonnull align 8 dereferenceable(160) %0, ptr noundef %1, i32 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %class.R3Span, align 8
  %13 = alloca double, align 8
  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
  %14 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %15 = getelementptr inbounds %struct.MPSurface, ptr %14, i32 0, i32 4
  %16 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %15)
  store i32 %16, ptr %7, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %59

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 0x47EFFFFFE0000000, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %55, %19
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = getelementptr inbounds %struct.MPSurface, ptr %14, i32 0, i32 4
  %23 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %22)
  %24 = icmp slt i32 %21, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %58

26:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %27 = getelementptr inbounds %struct.MPSurface, ptr %14, i32 0, i32 4
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = call noundef ptr @_ZNK7RNArrayIP8MPVertexE3KthEi(ptr noundef nonnull align 8 dereferenceable(16) %27, i32 noundef %28)
  store ptr %29, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %30 = getelementptr inbounds %struct.MPSurface, ptr %14, i32 0, i32 4
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  %33 = getelementptr inbounds %struct.MPSurface, ptr %14, i32 0, i32 4
  %34 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %33)
  %35 = srem i32 %32, %34
  %36 = call noundef ptr @_ZNK7RNArrayIP8MPVertexE3KthEi(ptr noundef nonnull align 8 dereferenceable(16) %30, i32 noundef %35)
  store ptr %36, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 80, ptr %12) #4
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.MPVertex, ptr %37, i32 0, i32 4
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.MPVertex, ptr %39, i32 0, i32 4
  call void @_ZN6R3SpanC1ERK7R3PointS2_(ptr noundef nonnull align 8 dereferenceable(80) %12, ptr noundef nonnull align 8 dereferenceable(24) %38, ptr noundef nonnull align 8 dereferenceable(24) %40)
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.MPVertex, ptr %41, i32 0, i32 4
  %43 = call noundef double @_Z10R3DistanceRK7R3PointRK6R3Span(ptr noundef nonnull align 8 dereferenceable(24) %42, ptr noundef nonnull align 8 dereferenceable(80) %12)
  store double %43, ptr %13, align 8, !tbaa !11
  %44 = load double, ptr %13, align 8, !tbaa !11
  %45 = load double, ptr %8, align 8, !tbaa !11
  %46 = fcmp olt double %44, %45
  br i1 %46, label %47, label %54

47:                                               ; preds = %26
  %48 = load double, ptr %13, align 8, !tbaa !11
  store double %48, ptr %8, align 8, !tbaa !11
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  %51 = getelementptr inbounds %struct.MPSurface, ptr %14, i32 0, i32 4
  %52 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %51)
  %53 = srem i32 %50, %52
  store i32 %53, ptr %7, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %47, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 80, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %9, align 4, !tbaa !9
  br label %20, !llvm.loop !13

58:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %59

59:                                               ; preds = %58, %3
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.MPVertex, ptr %60, i32 0, i32 2
  store ptr %14, ptr %61, align 8, !tbaa !15
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.MPVertex, ptr %63, i32 0, i32 3
  store i32 %62, ptr %64, align 8, !tbaa !19
  %65 = getelementptr inbounds %struct.MPSurface, ptr %14, i32 0, i32 4
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = call noundef ptr @_ZN7RNArrayIP8MPVertexE9InsertKthES1_i(ptr noundef nonnull align 8 dereferenceable(16) %65, ptr noundef %66, i32 noundef %67)
  call void @_ZN9MPSurface13RecomputeBBoxEv(ptr noundef nonnull align 8 dereferenceable(160) %14)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK7RNArrayIP8MPVertexE3KthEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2 align 2

declare void @_ZN6R3SpanC1ERK7R3PointS2_(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3

declare noundef double @_Z10R3DistanceRK7R3PointRK6R3Span(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(80)) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7RNArrayIP8MPVertexE9InsertKthES1_i(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9MPSurface13RecomputeBBoxEv(ptr noundef nonnull align 8 dereferenceable(160)) #2 align 2

attributes #0 = { inlinehint 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { 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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 16}
!16 = !{!"_ZTS8MPVertex", !6, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !17, i64 32, !18, i64 56, !6, i64 80}
!17 = !{!"_ZTS7R3Point", !7, i64 0}
!18 = !{!"_ZTS8R3Vector", !7, i64 0}
!19 = !{!16, !10, i64 24}


; 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.R3Span = type { %class.R3Ray, %class.R3Point, double }
%class.R3Ray = type { %class.R3Line }
%class.R3Line = type { %class.R3Point, %class.R3Vector }
%class.R3Vector = type { [3 x double] }
%class.R3Point = type { [3 x double] }

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9MPSurface12InsertVertexEP8MPVertexi(ptr noundef nonnull align 8 dereferenceable(160) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #2 align 2 {
  %4 = alloca %class.R3Span, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %5)
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %3
  %7 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %5)
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %1, i64 32
  br label %10

10:                                               ; preds = %.lr.ph, %23
  %.023 = phi i32 [ %6, %.lr.ph ], [ %.1, %23 ]
  %.01722 = phi double [ 0x47EFFFFFE0000000, %.lr.ph ], [ %.118, %23 ]
  %.01921 = phi i32 [ 0, %.lr.ph ], [ %12, %23 ]
  %11 = call noundef ptr @_ZNK7RNArrayIP8MPVertexE3KthEi(ptr noundef nonnull align 8 dereferenceable(16) %5, i32 noundef %.01921)
  %12 = add nuw nsw i32 %.01921, 1
  %13 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %5)
  %14 = srem i32 %12, %13
  %15 = call noundef ptr @_ZNK7RNArrayIP8MPVertexE3KthEi(ptr noundef nonnull align 8 dereferenceable(16) %5, i32 noundef %14)
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %4) #4
  %16 = getelementptr inbounds i8, ptr %11, i64 32
  %17 = getelementptr inbounds i8, ptr %15, i64 32
  call void @_ZN6R3SpanC1ERK7R3PointS2_(ptr noundef nonnull align 8 dereferenceable(80) %4, ptr noundef nonnull align 8 dereferenceable(24) %16, ptr noundef nonnull align 8 dereferenceable(24) %17)
  %18 = call noundef double @_Z10R3DistanceRK7R3PointRK6R3Span(ptr noundef nonnull align 8 dereferenceable(24) %9, ptr noundef nonnull align 8 dereferenceable(80) %4)
  %19 = fcmp olt double %18, %.01722
  br i1 %19, label %20, label %23

20:                                               ; preds = %10
  %21 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %5)
  %22 = srem i32 %12, %21
  br label %23

23:                                               ; preds = %20, %10
  %.118 = phi double [ %18, %20 ], [ %.01722, %10 ]
  %.1 = phi i32 [ %22, %20 ], [ %.023, %10 ]
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %4) #4
  %24 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %5)
  %25 = icmp slt i32 %12, %24
  br i1 %25, label %10, label %.loopexit, !llvm.loop !5

.loopexit:                                        ; preds = %23, %.preheader, %3
  %.2 = phi i32 [ %6, %3 ], [ %6, %.preheader ], [ %.1, %23 ]
  %26 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr %0, ptr %26, align 8, !tbaa !7
  %27 = getelementptr inbounds i8, ptr %1, i64 24
  store i32 %.2, ptr %27, align 8, !tbaa !15
  %28 = call noundef ptr @_ZN7RNArrayIP8MPVertexE9InsertKthES1_i(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef %1, i32 noundef %.2)
  call void @_ZN9MPSurface13RecomputeBBoxEv(ptr noundef nonnull align 8 dereferenceable(160) %0)
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK7RNArrayIP8MPVertexE3KthEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #2 align 2

declare void @_ZN6R3SpanC1ERK7R3PointS2_(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3

declare noundef double @_Z10R3DistanceRK7R3PointRK6R3Span(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7RNArrayIP8MPVertexE9InsertKthES1_i(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9MPSurface13RecomputeBBoxEv(ptr noundef nonnull align 8 dereferenceable(160)) local_unnamed_addr #2 align 2

attributes #0 = { inlinehint 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 16}
!8 = !{!"_ZTS8MPVertex", !9, i64 0, !12, i64 8, !9, i64 16, !12, i64 24, !13, i64 32, !14, i64 56, !9, i64 80}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!"_ZTS7R3Point", !10, i64 0}
!14 = !{!"_ZTS8R3Vector", !10, i64 0}
!15 = !{!8, !12, i64 24}


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