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

; 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.RNInterval = type { double, double }
%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 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 @_ZNK6R2Grid5RangeEv(ptr dead_on_unwind noalias writable sret(%class.RNInterval) align 8 %0, ptr noundef nonnull align 8 dereferenceable(208) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store double 0x47EFFFFFE0000000, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 0xC7EFFFFFE0000000, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %10 = getelementptr inbounds %class.R2Grid, ptr %9, i32 0, i32 3
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %11, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !17
  br label %12

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

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

18:                                               ; preds = %12
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load double, ptr %19, align 8, !tbaa !9
  %21 = fcmp une double %20, -3.210000e+02
  br i1 %21, label %22, label %39

22:                                               ; preds = %18
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = load double, ptr %5, align 8, !tbaa !9
  %26 = fcmp olt double %24, %25
  br i1 %26, label %27, label %30

27:                                               ; preds = %22
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load double, ptr %28, align 8, !tbaa !9
  store double %29, ptr %5, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %27, %22
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = load double, ptr %6, align 8, !tbaa !9
  %34 = fcmp ogt double %32, %33
  br i1 %34, label %35, label %38

35:                                               ; preds = %30
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load double, ptr %36, align 8, !tbaa !9
  store double %37, ptr %6, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %35, %30
  br label %39

39:                                               ; preds = %38, %18
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds double, ptr %40, i32 1
  store ptr %41, ptr %7, align 8, !tbaa !5
  br label %42

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

45:                                               ; preds = %17
  %46 = load double, ptr %5, align 8, !tbaa !9
  %47 = load double, ptr %6, align 8, !tbaa !9
  call void @_ZN10RNIntervalC1Edd(ptr noundef nonnull align 8 dereferenceable(16) %0, double noundef %46, double noundef %47)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

declare void @_ZN10RNIntervalC1Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double noundef) unnamed_addr #2

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 = { "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, !6, i64 184}
!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, !16, i64 204}
!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.RNInterval = type { double, double }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6R2Grid5RangeEv(ptr dead_on_unwind noalias writable sret(%class.RNInterval) align 8 %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(208) %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 204
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 184
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %xtraiter = and i32 %4, 1
  %8 = icmp eq i32 %4, 1
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %4, 2147483646
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %28, %.lr.ph.preheader
  %.2.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %.2.1, %28 ]
  %.1.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %.1.1, %28 ]
  %.01220.unr = phi ptr [ %7, %.lr.ph.preheader ], [ %29, %28 ]
  %.01319.unr = phi double [ 0xC7EFFFFFE0000000, %.lr.ph.preheader ], [ %.1.1, %28 ]
  %.01418.unr = phi double [ 0x47EFFFFFE0000000, %.lr.ph.preheader ], [ %.2.1, %28 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %9 = load double, ptr %.01220.unr, align 8, !tbaa !16
  %10 = fcmp une double %9, -3.210000e+02
  br i1 %10, label %11, label %._crit_edge

11:                                               ; preds = %.lr.ph.epil
  %12 = fcmp olt double %9, %.01418.unr
  %.115.epil = select i1 %12, double %9, double %.01418.unr
  %13 = fcmp ogt double %9, %.01319.unr
  br i1 %13, label %14, label %._crit_edge

14:                                               ; preds = %11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %14, %11, %.lr.ph.epil, %2
  %.014.lcssa = phi double [ 0x47EFFFFFE0000000, %2 ], [ %.2.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.115.epil, %14 ], [ %.115.epil, %11 ], [ %.01418.unr, %.lr.ph.epil ]
  %.013.lcssa = phi double [ 0xC7EFFFFFE0000000, %2 ], [ %.1.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %9, %14 ], [ %.01319.unr, %11 ], [ %.01319.unr, %.lr.ph.epil ]
  tail call void @_ZN10RNIntervalC1Edd(ptr noundef nonnull align 8 dereferenceable(16) %0, double noundef %.014.lcssa, double noundef %.013.lcssa)
  ret void

.lr.ph:                                           ; preds = %28, %.lr.ph.preheader.new
  %.01220 = phi ptr [ %7, %.lr.ph.preheader.new ], [ %29, %28 ]
  %.01319 = phi double [ 0xC7EFFFFFE0000000, %.lr.ph.preheader.new ], [ %.1.1, %28 ]
  %.01418 = phi double [ 0x47EFFFFFE0000000, %.lr.ph.preheader.new ], [ %.2.1, %28 ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %28 ]
  %15 = load double, ptr %.01220, align 8, !tbaa !16
  %16 = fcmp une double %15, -3.210000e+02
  br i1 %16, label %17, label %.lr.ph.1

17:                                               ; preds = %.lr.ph
  %18 = fcmp olt double %15, %.01418
  %.115 = select i1 %18, double %15, double %.01418
  %19 = fcmp ogt double %15, %.01319
  br i1 %19, label %20, label %.lr.ph.1

20:                                               ; preds = %17
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %17, %20, %.lr.ph
  %.2 = phi double [ %.115, %20 ], [ %.115, %17 ], [ %.01418, %.lr.ph ]
  %.1 = phi double [ %15, %20 ], [ %.01319, %17 ], [ %.01319, %.lr.ph ]
  %21 = getelementptr inbounds i8, ptr %.01220, i64 8
  %22 = load double, ptr %21, align 8, !tbaa !16
  %23 = fcmp une double %22, -3.210000e+02
  br i1 %23, label %24, label %28

24:                                               ; preds = %.lr.ph.1
  %25 = fcmp olt double %22, %.2
  %.115.1 = select i1 %25, double %22, double %.2
  %26 = fcmp ogt double %22, %.1
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  br label %28

28:                                               ; preds = %27, %24, %.lr.ph.1
  %.2.1 = phi double [ %.115.1, %27 ], [ %.115.1, %24 ], [ %.2, %.lr.ph.1 ]
  %.1.1 = phi double [ %22, %27 ], [ %.1, %24 ], [ %.1, %.lr.ph.1 ]
  %29 = getelementptr inbounds i8, ptr %.01220, i64 16
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !17
}

declare void @_ZN10RNIntervalC1Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double noundef) unnamed_addr #1

attributes #0 = { 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 #1 = { "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, !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}
!18 = !{!"llvm.loop.mustprogress"}


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