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

; 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.R2Grid = type { %class.R2Affine, %class.R2Affine, double, ptr, [2 x i32], i32, i32 }
%class.R2Affine = type <{ %class.R2Transformation, %class.R3Matrix, i32, [4 x i8] }>
%class.R2Transformation = type { ptr }
%class.R3Matrix = type { [3 x [3 x double]] }

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

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

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

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6R2Grid19ConnectedComponentsEdiPiS0_S0_(ptr noundef nonnull align 8 dereferenceable(208), double noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R2Grid28ConnectedComponentSizeFilterEd(ptr noundef nonnull align 8 dereferenceable(208) %0, double noundef %1) #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %10 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %11 = getelementptr inbounds %class.R2Grid, ptr %10, i32 0, i32 6
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = sext i32 %12 to i64
  %14 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %13, i64 4)
  %15 = extractvalue { i64, i1 } %14, 1
  %16 = extractvalue { i64, i1 } %14, 0
  %17 = select i1 %15, i64 -1, i64 %16
  %18 = call noalias noundef nonnull ptr @_Znam(i64 noundef %17) #6
  store ptr %18, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %19 = getelementptr inbounds %class.R2Grid, ptr %10, i32 0, i32 6
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = sext i32 %20 to i64
  %22 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %21, i64 4)
  %23 = extractvalue { i64, i1 } %22, 1
  %24 = extractvalue { i64, i1 } %22, 0
  %25 = select i1 %23, i64 -1, i64 %24
  %26 = call noalias noundef nonnull ptr @_Znam(i64 noundef %25) #6
  store ptr %26, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %27 = load double, ptr %4, align 8, !tbaa !9
  %28 = getelementptr inbounds %class.R2Grid, ptr %10, i32 0, i32 6
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = call noundef i32 @_ZN6R2Grid19ConnectedComponentsEdiPiS0_S0_(ptr noundef nonnull align 8 dereferenceable(208) %10, double noundef %27, i32 noundef %29, ptr noundef null, ptr noundef %30, ptr noundef %31)
  store i32 %32, ptr %7, align 4, !tbaa !17
  %33 = load i32, ptr %7, align 4, !tbaa !17
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %35, label %86

35:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !17
  br label %36

36:                                               ; preds = %82, %35
  %37 = load i32, ptr %8, align 4, !tbaa !17
  %38 = getelementptr inbounds %class.R2Grid, ptr %10, i32 0, i32 6
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = icmp slt i32 %37, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %85

42:                                               ; preds = %36
  %43 = getelementptr inbounds %class.R2Grid, ptr %10, i32 0, i32 3
  %44 = load ptr, ptr %43, align 8, !tbaa !18
  %45 = load i32, ptr %8, align 4, !tbaa !17
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds double, ptr %44, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !9
  %49 = fcmp oeq double %48, -3.210000e+02
  br i1 %49, label %50, label %51

50:                                               ; preds = %42
  br label %82

51:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !17
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !17
  store i32 %56, ptr %9, align 4, !tbaa !17
  %57 = load i32, ptr %9, align 4, !tbaa !17
  %58 = icmp slt i32 %57, 0
  br i1 %58, label %63, label %59

59:                                               ; preds = %51
  %60 = load i32, ptr %9, align 4, !tbaa !17
  %61 = load i32, ptr %7, align 4, !tbaa !17
  %62 = icmp sge i32 %60, %61
  br i1 %62, label %63, label %69

63:                                               ; preds = %59, %51
  %64 = getelementptr inbounds %class.R2Grid, ptr %10, i32 0, i32 3
  %65 = load ptr, ptr %64, align 8, !tbaa !18
  %66 = load i32, ptr %8, align 4, !tbaa !17
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds double, ptr %65, i64 %67
  store double 0.000000e+00, ptr %68, align 8, !tbaa !9
  br label %81

69:                                               ; preds = %59
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load i32, ptr %9, align 4, !tbaa !17
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i32, ptr %70, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !17
  %75 = sitofp i32 %74 to double
  %76 = getelementptr inbounds %class.R2Grid, ptr %10, i32 0, i32 3
  %77 = load ptr, ptr %76, align 8, !tbaa !18
  %78 = load i32, ptr %8, align 4, !tbaa !17
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds double, ptr %77, i64 %79
  store double %75, ptr %80, align 8, !tbaa !9
  br label %81

81:                                               ; preds = %69, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %82

82:                                               ; preds = %81, %50
  %83 = load i32, ptr %8, align 4, !tbaa !17
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %8, align 4, !tbaa !17
  br label %36, !llvm.loop !19

85:                                               ; preds = %41
  br label %86

86:                                               ; preds = %85, %2
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = icmp eq ptr %87, null
  br i1 %88, label %90, label %89

89:                                               ; preds = %86
  call void @_ZdaPv(ptr noundef %87) #7
  br label %90

90:                                               ; preds = %89, %86
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = icmp eq ptr %91, null
  br i1 %92, label %94, label %93

93:                                               ; preds = %90
  call void @_ZdaPv(ptr noundef %91) #7
  br label %94

94:                                               ; preds = %93, %90
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !16, i64 204}
!12 = !{!"_ZTS6R2Grid", !13, i64 0, !13, i64 88, !10, i64 176, !6, i64 184, !7, i64 192, !16, i64 200, !16, i64 204}
!13 = !{!"_ZTS8R2Affine", !14, i64 0, !15, i64 8, !16, i64 80}
!14 = !{!"_ZTS16R2Transformation"}
!15 = !{!"_ZTS8R3Matrix", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{!12, !6, i64 184}
!19 = distinct !{!19, !20}
!20 = !{!"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"

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R2Grid28ConnectedComponentSizeFilterEd(ptr noundef nonnull align 8 dereferenceable(208) %0, double noundef %1) local_unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 204
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = icmp slt i32 %4, 0
  %7 = shl nsw i64 %5, 2
  %8 = select i1 %6, i64 -1, i64 %7
  %9 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %8) #3
  %10 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %8) #3
  %11 = tail call noundef i32 @_ZN6R2Grid19ConnectedComponentsEdiPiS0_S0_(ptr noundef nonnull align 8 dereferenceable(208) %0, double noundef %1, i32 noundef %4, ptr noundef null, ptr noundef nonnull %9, ptr noundef nonnull %10)
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %2
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %15 = getelementptr inbounds i8, ptr %0, i64 184
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %wide.trip.count = zext nneg i32 %13 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %17 = icmp eq i32 %13, 1
  br i1 %17, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %18

18:                                               ; preds = %42, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %42 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %42 ]
  %19 = getelementptr inbounds double, ptr %16, i64 %indvars.iv
  %20 = load double, ptr %19, align 8, !tbaa !16
  %21 = fcmp oeq double %20, -3.210000e+02
  br i1 %21, label %30, label %22

22:                                               ; preds = %18
  %23 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !17
  %or.cond = icmp ult i32 %24, %11
  br i1 %or.cond, label %25, label %.sink.split

25:                                               ; preds = %22
  %26 = zext nneg i32 %24 to i64
  %27 = getelementptr inbounds i32, ptr %9, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !17
  %29 = sitofp i32 %28 to double
  br label %.sink.split

.sink.split:                                      ; preds = %22, %25
  %.sink = phi double [ %29, %25 ], [ 0.000000e+00, %22 ]
  store double %.sink, ptr %19, align 8, !tbaa !16
  br label %30

30:                                               ; preds = %.sink.split, %18
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %31 = getelementptr inbounds double, ptr %16, i64 %indvars.iv.next
  %32 = load double, ptr %31, align 8, !tbaa !16
  %33 = fcmp oeq double %32, -3.210000e+02
  br i1 %33, label %42, label %34

34:                                               ; preds = %30
  %35 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.next
  %36 = load i32, ptr %35, align 4, !tbaa !17
  %or.cond.1 = icmp ult i32 %36, %11
  br i1 %or.cond.1, label %37, label %.sink.split.1

37:                                               ; preds = %34
  %38 = zext nneg i32 %36 to i64
  %39 = getelementptr inbounds i32, ptr %9, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !17
  %41 = sitofp i32 %40 to double
  br label %.sink.split.1

.sink.split.1:                                    ; preds = %37, %34
  %.sink.1 = phi double [ %41, %37 ], [ 0.000000e+00, %34 ]
  store double %.sink.1, ptr %31, align 8, !tbaa !16
  br label %42

42:                                               ; preds = %.sink.split.1, %30
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %18, !llvm.loop !18

.loopexit.loopexit.unr-lcssa:                     ; preds = %42, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %42 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.epil.preheader

.epil.preheader:                                  ; preds = %.loopexit.loopexit.unr-lcssa
  %43 = getelementptr inbounds double, ptr %16, i64 %indvars.iv.unr
  %44 = load double, ptr %43, align 8, !tbaa !16
  %45 = fcmp oeq double %44, -3.210000e+02
  br i1 %45, label %.loopexit, label %46

46:                                               ; preds = %.epil.preheader
  %47 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.unr
  %48 = load i32, ptr %47, align 4, !tbaa !17
  %or.cond.epil = icmp ult i32 %48, %11
  br i1 %or.cond.epil, label %49, label %.sink.split.epil

49:                                               ; preds = %46
  %50 = zext nneg i32 %48 to i64
  %51 = getelementptr inbounds i32, ptr %9, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !17
  %53 = sitofp i32 %52 to double
  br label %.sink.split.epil

.sink.split.epil:                                 ; preds = %49, %46
  %.sink.epil = phi double [ %53, %49 ], [ 0.000000e+00, %46 ]
  store double %.sink.epil, ptr %43, align 8, !tbaa !16
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.sink.split.epil, %.epil.preheader, %.preheader, %2
  tail call void @_ZdaPv(ptr noundef nonnull %10) #4
  tail call void @_ZdaPv(ptr noundef nonnull %9) #4
  ret void
}

attributes #0 = { 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 #1 = { 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 #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 = { builtin allocsize(0) }
attributes #4 = { 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, !12, i64 204}
!6 = !{!"_ZTS6R2Grid", !7, i64 0, !7, i64 88, !13, i64 176, !14, i64 184, !10, i64 192, !12, i64 200, !12, i64 204}
!7 = !{!"_ZTS8R2Affine", !8, i64 0, !9, i64 8, !12, i64 80}
!8 = !{!"_ZTS16R2Transformation"}
!9 = !{!"_ZTS8R3Matrix", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!"double", !10, i64 0}
!14 = !{!"any pointer", !10, i64 0}
!15 = !{!6, !14, i64 184}
!16 = !{!13, !13, i64 0}
!17 = !{!12, !12, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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