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

; 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]] }

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 @_ZN6R2Grid6DilateEd(ptr noundef nonnull align 8 dereferenceable(208) %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.R2Grid, 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 208, ptr %5) #3
  call void @_ZN6R2GridC1ERKS_(ptr noundef nonnull align 8 dereferenceable(208) %5, ptr noundef nonnull align 8 dereferenceable(208) %9)
  invoke void @_ZN6R2Grid24SquaredDistanceTransformEv(ptr noundef nonnull align 8 dereferenceable(208) %9)
          to label %10 unwind label %21

10:                                               ; preds = %2
  %11 = load double, ptr %4, align 8, !tbaa !9
  %12 = load double, ptr %4, align 8, !tbaa !9
  %13 = fmul double %11, %12
  invoke void @_ZN6R2Grid9ThresholdEddd(ptr noundef nonnull align 8 dereferenceable(208) %9, double noundef %13, double noundef 1.000000e+00, double noundef 0.000000e+00)
          to label %14 unwind label %21

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

15:                                               ; preds = %40, %14
  %16 = load i32, ptr %8, align 4, !tbaa !11
  %17 = getelementptr inbounds %class.R2Grid, ptr %9, i32 0, i32 6
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %19 = icmp slt i32 %16, %18
  br i1 %19, label %25, label %20

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

21:                                               ; preds = %10, %2
  %22 = landingpad { ptr, i32 }
          cleanup
  %23 = extractvalue { ptr, i32 } %22, 0
  store ptr %23, ptr %6, align 8
  %24 = extractvalue { ptr, i32 } %22, 1
  store i32 %24, ptr %7, align 4
  call void @_ZN6R2GridD1Ev(ptr noundef nonnull align 8 dereferenceable(208) %5) #3
  call void @llvm.lifetime.end.p0(i64 208, ptr %5) #3
  br label %44

25:                                               ; preds = %15
  %26 = getelementptr inbounds %class.R2Grid, ptr %5, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !18
  %28 = load i32, ptr %8, align 4, !tbaa !11
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds double, ptr %27, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = fcmp oeq double %31, -3.210000e+02
  br i1 %32, label %33, label %39

33:                                               ; preds = %25
  %34 = getelementptr inbounds %class.R2Grid, ptr %9, i32 0, i32 3
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = load i32, ptr %8, align 4, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %35, i64 %37
  store double -3.210000e+02, ptr %38, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %33, %25
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %8, align 4, !tbaa !11
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %8, align 4, !tbaa !11
  br label %15, !llvm.loop !19

43:                                               ; preds = %20
  call void @_ZN6R2GridD1Ev(ptr noundef nonnull align 8 dereferenceable(208) %5) #3
  call void @llvm.lifetime.end.p0(i64 208, ptr %5) #3
  ret void

44:                                               ; preds = %21
  %45 = load ptr, ptr %6, align 8
  %46 = load i32, ptr %7, align 4
  %47 = insertvalue { ptr, i32 } poison, ptr %45, 0
  %48 = insertvalue { ptr, i32 } %47, i32 %46, 1
  resume { ptr, i32 } %48
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6R2Grid9ThresholdEddd(ptr noundef nonnull align 8 dereferenceable(208), double noundef, double noundef, double noundef) #2 align 2

declare void @_ZN6R2GridC1ERKS_(ptr, ptr)

declare void @_ZN6R2GridD1Ev(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 = { 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 #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 204}
!14 = !{!"_ZTS6R2Grid", !15, i64 0, !15, i64 88, !10, i64 176, !6, i64 184, !7, i64 192, !12, i64 200, !12, i64 204}
!15 = !{!"_ZTS8R2Affine", !16, i64 0, !17, i64 8, !12, i64 80}
!16 = !{!"_ZTS16R2Transformation"}
!17 = !{!"_ZTS8R3Matrix", !7, i64 0}
!18 = !{!14, !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"

%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]] }

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 @_ZN6R2Grid6DilateEd(ptr noundef nonnull align 8 dereferenceable(208) %0, double noundef %1) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %class.R2Grid, align 8
  call void @llvm.lifetime.start.p0(i64 208, ptr nonnull %3) #3
  call void @_ZN6R2GridC1ERKS_(ptr noundef nonnull align 8 dereferenceable(208) %3, ptr noundef nonnull align 8 dereferenceable(208) %0)
  invoke void @_ZN6R2Grid24SquaredDistanceTransformEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
          to label %4 unwind label %39

4:                                                ; preds = %2
  %5 = fmul double %1, %1
  call void @_ZN6R2Grid9ThresholdEddd(ptr noundef nonnull align 8 dereferenceable(208) %0, double noundef %5, double noundef 1.000000e+00, double noundef 0.000000e+00)
  %6 = getelementptr inbounds i8, ptr %0, i64 204
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %9 = getelementptr inbounds i8, ptr %3, i64 184
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %0, i64 184
  %12 = load ptr, ptr %11, align 8
  %wide.trip.count = zext nneg i32 %7 to i64
  %min.iters.check = icmp ult i32 %7, 4
  %13 = ptrtoint ptr %12 to i64
  %14 = ptrtoint ptr %10 to i64
  %15 = sub i64 %13, %14
  %diff.check = icmp ult i64 %15, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 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
  %16 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.ph
  %17 = load double, ptr %16, align 8, !tbaa !16
  %18 = fcmp oeq double %17, -3.210000e+02
  br i1 %18, label %19, label %scalar.ph.prol.loopexit.unr-lcssa

19:                                               ; preds = %scalar.ph.prol
  %20 = getelementptr inbounds double, ptr %12, i64 %indvars.iv.ph
  store double -3.210000e+02, ptr %20, align 8, !tbaa !16
  br label %scalar.ph.prol.loopexit.unr-lcssa

scalar.ph.prol.loopexit.unr-lcssa:                ; preds = %19, %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 ]
  %21 = add nsw i64 %wide.trip.count, -1
  %22 = icmp eq i64 %indvars.iv.ph, %21
  br i1 %22, label %._crit_edge, label %scalar.ph

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

vector.body:                                      ; preds = %pred.store.continue16, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %pred.store.continue16 ]
  %23 = or disjoint i64 %index, 2
  %24 = getelementptr inbounds double, ptr %10, i64 %index
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %wide.load = load <2 x double>, ptr %24, align 8, !tbaa !16
  %wide.load10 = load <2 x double>, ptr %25, align 8, !tbaa !16
  %26 = fcmp oeq <2 x double> %wide.load, <double -3.210000e+02, double -3.210000e+02>
  %27 = fcmp oeq <2 x double> %wide.load10, <double -3.210000e+02, double -3.210000e+02>
  %28 = extractelement <2 x i1> %26, i64 0
  br i1 %28, label %pred.store.if, label %pred.store.continue

pred.store.if:                                    ; preds = %vector.body
  %29 = getelementptr inbounds double, ptr %12, i64 %index
  store double -3.210000e+02, ptr %29, align 8, !tbaa !16
  br label %pred.store.continue

pred.store.continue:                              ; preds = %pred.store.if, %vector.body
  %30 = extractelement <2 x i1> %26, i64 1
  br i1 %30, label %pred.store.if11, label %pred.store.continue12

pred.store.if11:                                  ; preds = %pred.store.continue
  %31 = or disjoint i64 %index, 1
  %32 = getelementptr inbounds double, ptr %12, i64 %31
  store double -3.210000e+02, ptr %32, align 8, !tbaa !16
  br label %pred.store.continue12

pred.store.continue12:                            ; preds = %pred.store.if11, %pred.store.continue
  %33 = extractelement <2 x i1> %27, i64 0
  br i1 %33, label %pred.store.if13, label %pred.store.continue14

pred.store.if13:                                  ; preds = %pred.store.continue12
  %34 = getelementptr inbounds double, ptr %12, i64 %23
  store double -3.210000e+02, ptr %34, align 8, !tbaa !16
  br label %pred.store.continue14

pred.store.continue14:                            ; preds = %pred.store.if13, %pred.store.continue12
  %35 = extractelement <2 x i1> %27, i64 1
  br i1 %35, label %pred.store.if15, label %pred.store.continue16

pred.store.if15:                                  ; preds = %pred.store.continue14
  %36 = or disjoint i64 %index, 3
  %37 = getelementptr inbounds double, ptr %12, i64 %36
  store double -3.210000e+02, ptr %37, align 8, !tbaa !16
  br label %pred.store.continue16

pred.store.continue16:                            ; preds = %pred.store.if15, %pred.store.continue14
  %index.next = add nuw i64 %index, 4
  %38 = icmp eq i64 %index.next, %n.vec
  br i1 %38, label %middle.block, label %vector.body, !llvm.loop !17

middle.block:                                     ; preds = %pred.store.continue16
  %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, %51, %middle.block, %4
  call void @_ZN6R2GridD1Ev(ptr noundef nonnull align 8 dereferenceable(208) %3) #3
  call void @llvm.lifetime.end.p0(i64 208, ptr nonnull %3) #3
  ret void

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

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %51
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %51 ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %41 = getelementptr inbounds double, ptr %10, i64 %indvars.iv
  %42 = load double, ptr %41, align 8, !tbaa !16
  %43 = fcmp oeq double %42, -3.210000e+02
  br i1 %43, label %44, label %scalar.ph.1

44:                                               ; preds = %scalar.ph
  %45 = getelementptr inbounds double, ptr %12, i64 %indvars.iv
  store double -3.210000e+02, ptr %45, align 8, !tbaa !16
  br label %scalar.ph.1

scalar.ph.1:                                      ; preds = %scalar.ph, %44
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %46 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.next
  %47 = load double, ptr %46, align 8, !tbaa !16
  %48 = fcmp oeq double %47, -3.210000e+02
  br i1 %48, label %49, label %51

49:                                               ; preds = %scalar.ph.1
  %50 = getelementptr inbounds double, ptr %12, i64 %indvars.iv.next
  store double -3.210000e+02, ptr %50, align 8, !tbaa !16
  br label %51

51:                                               ; preds = %49, %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 !21
}

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

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

declare void @_ZN6R2GridC1ERKS_(ptr, ptr) local_unnamed_addr

declare void @_ZN6R2GridD1Ev(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 = { 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 #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, !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 = distinct !{!17, !18, !19, !20}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!"llvm.loop.isvectorized", i32 1}
!20 = !{!"llvm.loop.unroll.runtime.disable"}
!21 = distinct !{!21, !18, !19}


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