; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Shapes/R3Grid.ll (ZN6R3Grid13MaskNonMaximaEd)

; 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.R3Grid = type { %class.R3Affine, %class.R3Affine, double, double, ptr, [3 x i32], i32, i32, i32 }
%class.R3Affine = type { %class.R3Transformation, %class.R4Matrix, %class.R4Matrix, %class.RNFlags }
%class.R3Transformation = type { ptr }
%class.R4Matrix = type { [4 x [4 x double]] }
%class.RNFlags = type { i64 }

declare i32 @__gxx_personality_v0(...)

; 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 uwtable
define dso_local void @_ZN6R3Grid13MaskNonMaximaEd(ptr noundef nonnull align 8 dereferenceable(592) %0, double noundef %1) #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca %class.R3Grid, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 592, ptr %5) #3
  call void @_ZN6R3GridC1ERKS_(ptr noundef nonnull align 8 dereferenceable(592) %5, ptr noundef nonnull align 8 dereferenceable(592) %9)
  %10 = load double, ptr %4, align 8, !tbaa !9
  invoke void @_ZN6R3Grid9MaxFilterEd(ptr noundef nonnull align 8 dereferenceable(592) %5, double noundef %10)
          to label %11 unwind label %18

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

12:                                               ; preds = %43, %11
  %13 = load i32, ptr %8, align 4, !tbaa !11
  %14 = getelementptr inbounds %class.R3Grid, ptr %9, i32 0, i32 8
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = icmp slt i32 %13, %15
  br i1 %16, label %22, label %17

17:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %46

18:                                               ; preds = %2
  %19 = landingpad { ptr, i32 }
          cleanup
  %20 = extractvalue { ptr, i32 } %19, 0
  store ptr %20, ptr %6, align 8
  %21 = extractvalue { ptr, i32 } %19, 1
  store i32 %21, ptr %7, align 4
  call void @_ZN6R3GridD1Ev(ptr noundef nonnull align 8 dereferenceable(592) %5) #3
  call void @llvm.lifetime.end.p0(i64 592, ptr %5) #3
  br label %47

22:                                               ; preds = %12
  %23 = getelementptr inbounds %class.R3Grid, ptr %9, i32 0, i32 4
  %24 = load ptr, ptr %23, align 8, !tbaa !20
  %25 = load i32, ptr %8, align 4, !tbaa !11
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds double, ptr %24, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = getelementptr inbounds %class.R3Grid, ptr %5, i32 0, i32 4
  %30 = load ptr, ptr %29, align 8, !tbaa !20
  %31 = load i32, ptr %8, align 4, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds double, ptr %30, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = fcmp olt double %28, %34
  br i1 %35, label %36, label %42

36:                                               ; preds = %22
  %37 = getelementptr inbounds %class.R3Grid, ptr %9, i32 0, i32 4
  %38 = load ptr, ptr %37, align 8, !tbaa !20
  %39 = load i32, ptr %8, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %38, i64 %40
  store double 0.000000e+00, ptr %41, align 8, !tbaa !9
  br label %42

42:                                               ; preds = %36, %22
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %8, align 4, !tbaa !11
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %8, align 4, !tbaa !11
  br label %12, !llvm.loop !21

46:                                               ; preds = %17
  call void @_ZN6R3GridD1Ev(ptr noundef nonnull align 8 dereferenceable(592) %5) #3
  call void @llvm.lifetime.end.p0(i64 592, ptr %5) #3
  ret void

47:                                               ; preds = %18
  %48 = load ptr, ptr %6, align 8
  %49 = load i32, ptr %7, align 4
  %50 = insertvalue { ptr, i32 } poison, ptr %48, 0
  %51 = insertvalue { ptr, i32 } %50, i32 %49, 1
  resume { ptr, i32 } %51
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6R3Grid9MaxFilterEd(ptr noundef nonnull align 8 dereferenceable(592), double noundef) #2 align 2

declare void @_ZN6R3GridC1ERKS_(ptr, ptr)

declare void @_ZN6R3GridD1Ev(ptr)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 = { 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 588}
!14 = !{!"_ZTS6R3Grid", !15, i64 0, !15, i64 272, !10, i64 544, !10, i64 552, !6, i64 560, !7, i64 568, !12, i64 580, !12, i64 584, !12, i64 588}
!15 = !{!"_ZTS8R3Affine", !16, i64 0, !17, i64 8, !17, i64 136, !18, i64 264}
!16 = !{!"_ZTS16R3Transformation"}
!17 = !{!"_ZTS8R4Matrix", !7, i64 0}
!18 = !{!"_ZTS7RNFlags", !19, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!14, !6, i64 560}
!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.R3Grid = type { %class.R3Affine, %class.R3Affine, double, double, ptr, [3 x i32], i32, i32, i32 }
%class.R3Affine = type { %class.R3Transformation, %class.R4Matrix, %class.R4Matrix, %class.RNFlags }
%class.R3Transformation = type { ptr }
%class.R4Matrix = type { [4 x [4 x double]] }
%class.RNFlags = type { i64 }

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R3Grid13MaskNonMaximaEd(ptr noundef nonnull align 8 dereferenceable(592) %0, double noundef %1) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %class.R3Grid, align 8
  call void @llvm.lifetime.start.p0(i64 592, ptr nonnull %3) #3
  call void @_ZN6R3GridC1ERKS_(ptr noundef nonnull align 8 dereferenceable(592) %3, ptr noundef nonnull align 8 dereferenceable(592) %0)
  invoke void @_ZN6R3Grid9MaxFilterEd(ptr noundef nonnull align 8 dereferenceable(592) %3, double noundef %1)
          to label %.preheader unwind label %38

.preheader:                                       ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 588
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %0, i64 560
  %8 = load ptr, ptr %7, align 8, !tbaa !17
  %9 = getelementptr inbounds i8, ptr %3, i64 560
  %10 = load ptr, ptr %9, align 8, !tbaa !17
  %wide.trip.count = zext nneg i32 %5 to i64
  %min.iters.check = icmp ult i32 %5, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %11 = getelementptr inbounds double, ptr %8, i64 %indvars.iv.ph
  %12 = load double, ptr %11, align 8, !tbaa !18
  %13 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.ph
  %14 = load double, ptr %13, align 8, !tbaa !18
  %15 = fcmp olt double %12, %14
  br i1 %15, label %16, label %scalar.ph.prol.loopexit.unr-lcssa

16:                                               ; preds = %scalar.ph.prol
  store double 0.000000e+00, ptr %11, align 8, !tbaa !18
  br label %scalar.ph.prol.loopexit.unr-lcssa

scalar.ph.prol.loopexit.unr-lcssa:                ; preds = %16, %scalar.ph.prol
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol.loopexit.unr-lcssa, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol.loopexit.unr-lcssa ]
  %17 = add nsw i64 %wide.trip.count, -1
  %18 = icmp eq i64 %indvars.iv.ph, %17
  br i1 %18, label %._crit_edge, label %scalar.ph

vector.memcheck:                                  ; preds = %.lr.ph
  %19 = shl nuw nsw i64 %wide.trip.count, 3
  %scevgep = getelementptr i8, ptr %8, i64 %19
  %scevgep10 = getelementptr i8, ptr %10, i64 %19
  %bound0 = icmp ult ptr %8, %scevgep10
  %bound1 = icmp ult ptr %10, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %pred.store.continue19, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %pred.store.continue19 ]
  %20 = or disjoint i64 %index, 2
  %21 = getelementptr inbounds double, ptr %8, i64 %index
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %wide.load = load <2 x double>, ptr %21, align 8, !tbaa !18, !alias.scope !19, !noalias !22
  %wide.load11 = load <2 x double>, ptr %22, align 8, !tbaa !18, !alias.scope !19, !noalias !22
  %23 = getelementptr inbounds double, ptr %10, i64 %index
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %wide.load12 = load <2 x double>, ptr %23, align 8, !tbaa !18, !alias.scope !22
  %wide.load13 = load <2 x double>, ptr %24, align 8, !tbaa !18, !alias.scope !22
  %25 = fcmp olt <2 x double> %wide.load, %wide.load12
  %26 = fcmp olt <2 x double> %wide.load11, %wide.load13
  %27 = extractelement <2 x i1> %25, i64 0
  br i1 %27, label %pred.store.if, label %pred.store.continue

pred.store.if:                                    ; preds = %vector.body
  %28 = getelementptr inbounds double, ptr %8, i64 %index
  store double 0.000000e+00, ptr %28, align 8, !tbaa !18, !alias.scope !19, !noalias !22
  br label %pred.store.continue

pred.store.continue:                              ; preds = %pred.store.if, %vector.body
  %29 = extractelement <2 x i1> %25, i64 1
  br i1 %29, label %pred.store.if14, label %pred.store.continue15

pred.store.if14:                                  ; preds = %pred.store.continue
  %30 = or disjoint i64 %index, 1
  %31 = getelementptr inbounds double, ptr %8, i64 %30
  store double 0.000000e+00, ptr %31, align 8, !tbaa !18, !alias.scope !19, !noalias !22
  br label %pred.store.continue15

pred.store.continue15:                            ; preds = %pred.store.if14, %pred.store.continue
  %32 = extractelement <2 x i1> %26, i64 0
  br i1 %32, label %pred.store.if16, label %pred.store.continue17

pred.store.if16:                                  ; preds = %pred.store.continue15
  %33 = getelementptr inbounds double, ptr %8, i64 %20
  store double 0.000000e+00, ptr %33, align 8, !tbaa !18, !alias.scope !19, !noalias !22
  br label %pred.store.continue17

pred.store.continue17:                            ; preds = %pred.store.if16, %pred.store.continue15
  %34 = extractelement <2 x i1> %26, i64 1
  br i1 %34, label %pred.store.if18, label %pred.store.continue19

pred.store.if18:                                  ; preds = %pred.store.continue17
  %35 = or disjoint i64 %index, 3
  %36 = getelementptr inbounds double, ptr %8, i64 %35
  store double 0.000000e+00, ptr %36, align 8, !tbaa !18, !alias.scope !19, !noalias !22
  br label %pred.store.continue19

pred.store.continue19:                            ; preds = %pred.store.if18, %pred.store.continue17
  %index.next = add nuw i64 %index, 4
  %37 = icmp eq i64 %index.next, %n.vec
  br i1 %37, label %middle.block, label %vector.body, !llvm.loop !24

middle.block:                                     ; preds = %pred.store.continue19
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %52, %middle.block, %.preheader
  call void @_ZN6R3GridD1Ev(ptr noundef nonnull align 8 dereferenceable(592) %3) #3
  call void @llvm.lifetime.end.p0(i64 592, ptr nonnull %3) #3
  ret void

38:                                               ; preds = %2
  %39 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6R3GridD1Ev(ptr noundef nonnull align 8 dereferenceable(592) %3) #3
  call void @llvm.lifetime.end.p0(i64 592, ptr nonnull %3) #3
  resume { ptr, i32 } %39

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %52
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %52 ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %40 = getelementptr inbounds double, ptr %8, i64 %indvars.iv
  %41 = load double, ptr %40, align 8, !tbaa !18
  %42 = getelementptr inbounds double, ptr %10, i64 %indvars.iv
  %43 = load double, ptr %42, align 8, !tbaa !18
  %44 = fcmp olt double %41, %43
  br i1 %44, label %45, label %scalar.ph.1

45:                                               ; preds = %scalar.ph
  store double 0.000000e+00, ptr %40, align 8, !tbaa !18
  br label %scalar.ph.1

scalar.ph.1:                                      ; preds = %scalar.ph, %45
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %46 = getelementptr inbounds double, ptr %8, i64 %indvars.iv.next
  %47 = load double, ptr %46, align 8, !tbaa !18
  %48 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.next
  %49 = load double, ptr %48, align 8, !tbaa !18
  %50 = fcmp olt double %47, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %scalar.ph.1
  store double 0.000000e+00, ptr %46, align 8, !tbaa !18
  br label %52

52:                                               ; preds = %51, %scalar.ph.1
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond.not.1, label %._crit_edge, label %scalar.ph, !llvm.loop !28
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6R3Grid9MaxFilterEd(ptr noundef nonnull align 8 dereferenceable(592), double noundef) local_unnamed_addr #2 align 2

declare void @_ZN6R3GridC1ERKS_(ptr, ptr) local_unnamed_addr

declare void @_ZN6R3GridD1Ev(ptr) local_unnamed_addr

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 = { 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, !16, i64 588}
!6 = !{!"_ZTS6R3Grid", !7, i64 0, !7, i64 272, !14, i64 544, !14, i64 552, !15, i64 560, !10, i64 568, !16, i64 580, !16, i64 584, !16, i64 588}
!7 = !{!"_ZTS8R3Affine", !8, i64 0, !9, i64 8, !9, i64 136, !12, i64 264}
!8 = !{!"_ZTS16R3Transformation"}
!9 = !{!"_ZTS8R4Matrix", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTS7RNFlags", !13, i64 0}
!13 = !{!"long", !10, i64 0}
!14 = !{!"double", !10, i64 0}
!15 = !{!"any pointer", !10, i64 0}
!16 = !{!"int", !10, i64 0}
!17 = !{!6, !15, i64 560}
!18 = !{!14, !14, i64 0}
!19 = !{!20}
!20 = distinct !{!20, !21}
!21 = distinct !{!21, !"LVerDomain"}
!22 = !{!23}
!23 = distinct !{!23, !21}
!24 = distinct !{!24, !25, !26, !27}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!"llvm.loop.isvectorized", i32 1}
!27 = !{!"llvm.loop.unroll.runtime.disable"}
!28 = distinct !{!28, !25, !26}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass