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

; 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"

%struct.R3MeshProperty = type { ptr, [1024 x i8], i32, ptr, double, double, double, double, double, double }

; 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 nounwind uwtable
declare dso_local void @_ZN14R3MeshProperty15ResetStatisticsEv(ptr noundef nonnull align 8 dereferenceable(1096)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14R3MeshProperty6DivideERKS_(ptr noundef nonnull align 8 dereferenceable(1096) %0, ptr noundef nonnull align 8 dereferenceable(1096) %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %57, %2
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = getelementptr inbounds %struct.R3MeshProperty, ptr %6, i32 0, i32 2
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = icmp slt i32 %8, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %7
  %14 = getelementptr inbounds %struct.R3MeshProperty, ptr %6, i32 0, i32 3
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds double, ptr %15, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !15
  %20 = fcmp oeq double %19, -1.000000e+00
  br i1 %20, label %21, label %22

21:                                               ; preds = %13
  br label %57

22:                                               ; preds = %13
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.R3MeshProperty, ptr %23, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds double, ptr %25, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !15
  %30 = fcmp oeq double %29, -1.000000e+00
  br i1 %30, label %31, label %32

31:                                               ; preds = %22
  br label %57

32:                                               ; preds = %22
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.R3MeshProperty, ptr %33, i32 0, i32 3
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %35, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !15
  %40 = fcmp oeq double %39, 0.000000e+00
  br i1 %40, label %41, label %42

41:                                               ; preds = %32
  br label %57

42:                                               ; preds = %32
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.R3MeshProperty, ptr %43, i32 0, i32 3
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %45, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !15
  %50 = getelementptr inbounds %struct.R3MeshProperty, ptr %6, i32 0, i32 3
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds double, ptr %51, i64 %53
  %55 = load double, ptr %54, align 8, !tbaa !15
  %56 = fdiv double %55, %49
  store double %56, ptr %54, align 8, !tbaa !15
  br label %57

57:                                               ; preds = %42, %41, %31, %21
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !16

60:                                               ; preds = %12
  call void @_ZN14R3MeshProperty15ResetStatisticsEv(ptr noundef nonnull align 8 dereferenceable(1096) %6)
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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, !10, i64 1032}
!12 = !{!"_ZTS14R3MeshProperty", !6, i64 0, !7, i64 8, !10, i64 1032, !6, i64 1040, !13, i64 1048, !13, i64 1056, !13, i64 1064, !13, i64 1072, !13, i64 1080, !13, i64 1088}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !6, i64 1040}
!15 = !{!13, !13, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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: mustprogress nounwind uwtable
declare dso_local void @_ZN14R3MeshProperty15ResetStatisticsEv(ptr noundef nonnull align 8 dereferenceable(1096)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN14R3MeshProperty6DivideERKS_(ptr noundef nonnull align 8 dereferenceable(1096) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(1096) %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 1032
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 1040
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %1, i64 1040
  %9 = load ptr, ptr %8, align 8
  %wide.trip.count = zext nneg i32 %4 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %10 = icmp eq i32 %4, 1
  br i1 %10, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

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

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

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa
  %11 = getelementptr inbounds double, ptr %7, i64 %indvars.iv.unr
  %12 = load double, ptr %11, align 8, !tbaa !13
  %13 = fcmp oeq double %12, -1.000000e+00
  br i1 %13, label %._crit_edge, label %14

14:                                               ; preds = %.epil.preheader
  %15 = getelementptr inbounds double, ptr %9, i64 %indvars.iv.unr
  %16 = load double, ptr %15, align 8, !tbaa !13
  %17 = fcmp oeq double %16, -1.000000e+00
  %18 = fcmp oeq double %16, 0.000000e+00
  %or.cond.epil = or i1 %17, %18
  br i1 %or.cond.epil, label %._crit_edge, label %19

19:                                               ; preds = %14
  %20 = fdiv double %12, %16
  store double %20, ptr %11, align 8, !tbaa !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %19, %14, %.epil.preheader, %2
  tail call void @_ZN14R3MeshProperty15ResetStatisticsEv(ptr noundef nonnull align 8 dereferenceable(1096) %0)
  ret void

21:                                               ; preds = %43, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %43 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %43 ]
  %22 = getelementptr inbounds double, ptr %7, i64 %indvars.iv
  %23 = load double, ptr %22, align 8, !tbaa !13
  %24 = fcmp oeq double %23, -1.000000e+00
  br i1 %24, label %32, label %25

25:                                               ; preds = %21
  %26 = getelementptr inbounds double, ptr %9, i64 %indvars.iv
  %27 = load double, ptr %26, align 8, !tbaa !13
  %28 = fcmp oeq double %27, -1.000000e+00
  %29 = fcmp oeq double %27, 0.000000e+00
  %or.cond = or i1 %28, %29
  br i1 %or.cond, label %32, label %30

30:                                               ; preds = %25
  %31 = fdiv double %23, %27
  store double %31, ptr %22, align 8, !tbaa !13
  br label %32

32:                                               ; preds = %25, %21, %30
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %33 = getelementptr inbounds double, ptr %7, i64 %indvars.iv.next
  %34 = load double, ptr %33, align 8, !tbaa !13
  %35 = fcmp oeq double %34, -1.000000e+00
  br i1 %35, label %43, label %36

36:                                               ; preds = %32
  %37 = getelementptr inbounds double, ptr %9, i64 %indvars.iv.next
  %38 = load double, ptr %37, align 8, !tbaa !13
  %39 = fcmp oeq double %38, -1.000000e+00
  %40 = fcmp oeq double %38, 0.000000e+00
  %or.cond.1 = or i1 %39, %40
  br i1 %or.cond.1, label %43, label %41

41:                                               ; preds = %36
  %42 = fdiv double %34, %38
  store double %42, ptr %33, align 8, !tbaa !13
  br label %43

43:                                               ; preds = %41, %36, %32
  %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 %._crit_edge.loopexit.unr-lcssa, label %21, !llvm.loop !14
}

attributes #0 = { 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" }

!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, !10, i64 1032}
!6 = !{!"_ZTS14R3MeshProperty", !7, i64 0, !8, i64 8, !10, i64 1032, !7, i64 1040, !11, i64 1048, !11, i64 1056, !11, i64 1064, !11, i64 1072, !11, i64 1080, !11, i64 1088}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!6, !7, i64 1040}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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