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

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

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208)) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R2Grid16RasterizeGridBoxEPKiS1_di(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr noundef %1, ptr noundef %2, double noundef %3, i32 noundef %4) #2 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store double %3, ptr %9, align 8, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !11
  %18 = load ptr, ptr %6, align 8
  %19 = load double, ptr %9, align 8, !tbaa !9
  %20 = fcmp oeq double %19, -3.210000e+02
  br i1 %20, label %21, label %22

21:                                               ; preds = %5
  br label %110

22:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds i32, ptr %23, i64 0
  %25 = load i32, ptr %24, align 4, !tbaa !11
  store i32 %25, ptr %11, align 4, !tbaa !11
  %26 = load i32, ptr %11, align 4, !tbaa !11
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %22
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %28, %22
  %30 = load i32, ptr %11, align 4, !tbaa !11
  %31 = call noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %18)
  %32 = sub nsw i32 %31, 1
  %33 = icmp sgt i32 %30, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  store i32 1, ptr %12, align 4
  br label %108

35:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds i32, ptr %36, i64 0
  %38 = load i32, ptr %37, align 4, !tbaa !11
  store i32 %38, ptr %13, align 4, !tbaa !11
  %39 = load i32, ptr %13, align 4, !tbaa !11
  %40 = icmp slt i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %35
  store i32 1, ptr %12, align 4
  br label %107

42:                                               ; preds = %35
  %43 = load i32, ptr %13, align 4, !tbaa !11
  %44 = call noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %18)
  %45 = sub nsw i32 %44, 1
  %46 = icmp sgt i32 %43, %45
  br i1 %46, label %47, label %50

47:                                               ; preds = %42
  %48 = call noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %18)
  %49 = sub nsw i32 %48, 1
  store i32 %49, ptr %13, align 4, !tbaa !11
  br label %50

50:                                               ; preds = %47, %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds i32, ptr %51, i64 1
  %53 = load i32, ptr %52, align 4, !tbaa !11
  store i32 %53, ptr %14, align 4, !tbaa !11
  %54 = load i32, ptr %14, align 4, !tbaa !11
  %55 = icmp slt i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %50
  store i32 0, ptr %14, align 4, !tbaa !11
  br label %57

57:                                               ; preds = %56, %50
  %58 = load i32, ptr %14, align 4, !tbaa !11
  %59 = call noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %18)
  %60 = sub nsw i32 %59, 1
  %61 = icmp sgt i32 %58, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %57
  store i32 1, ptr %12, align 4
  br label %106

63:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds i32, ptr %64, i64 1
  %66 = load i32, ptr %65, align 4, !tbaa !11
  store i32 %66, ptr %15, align 4, !tbaa !11
  %67 = load i32, ptr %15, align 4, !tbaa !11
  %68 = icmp slt i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %63
  store i32 1, ptr %12, align 4
  br label %105

70:                                               ; preds = %63
  %71 = load i32, ptr %15, align 4, !tbaa !11
  %72 = call noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %18)
  %73 = sub nsw i32 %72, 1
  %74 = icmp sgt i32 %71, %73
  br i1 %74, label %75, label %78

75:                                               ; preds = %70
  %76 = call noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %18)
  %77 = sub nsw i32 %76, 1
  store i32 %77, ptr %15, align 4, !tbaa !11
  br label %78

78:                                               ; preds = %75, %70
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %79 = load i32, ptr %11, align 4, !tbaa !11
  store i32 %79, ptr %16, align 4, !tbaa !11
  br label %80

80:                                               ; preds = %101, %78
  %81 = load i32, ptr %16, align 4, !tbaa !11
  %82 = load i32, ptr %13, align 4, !tbaa !11
  %83 = icmp sle i32 %81, %82
  br i1 %83, label %85, label %84

84:                                               ; preds = %80
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %104

85:                                               ; preds = %80
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %86 = load i32, ptr %14, align 4, !tbaa !11
  store i32 %86, ptr %17, align 4, !tbaa !11
  br label %87

87:                                               ; preds = %97, %85
  %88 = load i32, ptr %17, align 4, !tbaa !11
  %89 = load i32, ptr %15, align 4, !tbaa !11
  %90 = icmp sle i32 %88, %89
  br i1 %90, label %92, label %91

91:                                               ; preds = %87
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  br label %100

92:                                               ; preds = %87
  %93 = load i32, ptr %16, align 4, !tbaa !11
  %94 = load i32, ptr %17, align 4, !tbaa !11
  %95 = load double, ptr %9, align 8, !tbaa !9
  %96 = load i32, ptr %10, align 4, !tbaa !11
  call void @_ZN6R2Grid18RasterizeGridValueEiidi(ptr noundef nonnull align 8 dereferenceable(208) %18, i32 noundef %93, i32 noundef %94, double noundef %95, i32 noundef %96)
  br label %97

97:                                               ; preds = %92
  %98 = load i32, ptr %17, align 4, !tbaa !11
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %17, align 4, !tbaa !11
  br label %87, !llvm.loop !13

100:                                              ; preds = %91
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %16, align 4, !tbaa !11
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %16, align 4, !tbaa !11
  br label %80, !llvm.loop !15

104:                                              ; preds = %84
  store i32 0, ptr %12, align 4
  br label %105

105:                                              ; preds = %104, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %106

106:                                              ; preds = %105, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %107

107:                                              ; preds = %106, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %108

108:                                              ; preds = %107, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %109 = load i32, ptr %12, align 4
  switch i32 %109, label %111 [
    i32 0, label %110
    i32 1, label %110
  ]

110:                                              ; preds = %108, %108, %21
  ret void

111:                                              ; preds = %108
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208)) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R2Grid16RasterizeGridBoxEPKiS1_di(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, double noundef %3, i32 noundef %4) local_unnamed_addr #1 align 2 {
  %6 = fcmp oeq double %3, -3.210000e+02
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %5
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %8, i32 0)
  %9 = tail call noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %.not = icmp slt i32 %spec.store.select, %9
  br i1 %.not, label %10, label %.loopexit

10:                                               ; preds = %7
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %.loopexit, label %13

13:                                               ; preds = %10
  %14 = tail call noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %.not32 = icmp slt i32 %11, %14
  br i1 %.not32, label %18, label %15

15:                                               ; preds = %13
  %16 = tail call noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %17 = add nsw i32 %16, -1
  br label %18

18:                                               ; preds = %15, %13
  %.028 = phi i32 [ %17, %15 ], [ %11, %13 ]
  %19 = getelementptr inbounds i8, ptr %1, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %spec.store.select1 = tail call i32 @llvm.smax.i32(i32 %20, i32 0)
  %21 = tail call noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %.not33 = icmp slt i32 %spec.store.select1, %21
  br i1 %.not33, label %22, label %.loopexit

22:                                               ; preds = %18
  %23 = getelementptr inbounds i8, ptr %2, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp slt i32 %24, 0
  br i1 %25, label %.loopexit, label %26

26:                                               ; preds = %22
  %27 = tail call noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %.not34 = icmp slt i32 %24, %27
  br i1 %.not34, label %31, label %28

28:                                               ; preds = %26
  %29 = tail call noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %30 = add nsw i32 %29, -1
  br label %31

31:                                               ; preds = %28, %26
  %.027 = phi i32 [ %30, %28 ], [ %24, %26 ]
  %.not3539 = icmp sgt i32 %spec.store.select, %.028
  %.not3637 = icmp sgt i32 %spec.store.select1, %.027
  %or.cond = select i1 %.not3539, i1 true, i1 %.not3637
  br i1 %or.cond, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %31, %._crit_edge
  %.02640 = phi i32 [ %32, %._crit_edge ], [ %spec.store.select, %31 ]
  br label %33

._crit_edge:                                      ; preds = %33
  %32 = add nuw i32 %.02640, 1
  %exitcond42.not = icmp eq i32 %.02640, %.028
  br i1 %exitcond42.not, label %.loopexit, label %.preheader, !llvm.loop !9

33:                                               ; preds = %.preheader, %33
  %.038 = phi i32 [ %spec.store.select1, %.preheader ], [ %34, %33 ]
  tail call void @_ZN6R2Grid18RasterizeGridValueEiidi(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %.02640, i32 noundef %.038, double noundef %3, i32 noundef %4)
  %34 = add nuw i32 %.038, 1
  %exitcond.not = icmp eq i32 %.038, %.027
  br i1 %exitcond.not, label %._crit_edge, label %33, !llvm.loop !11

.loopexit:                                        ; preds = %._crit_edge, %31, %7, %18, %22, %10, %5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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