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

; 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.R3Point = type { [3 x double] }

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [88 x i8], align 1
@_ZZNK6R3Grid14DrawIsoSurfaceEdE15isosurface_grid = external hidden global ptr, align 8
@_ZZNK6R3Grid14DrawIsoSurfaceEdE16isosurface_level = external hidden global double, align 8
@_ZZNK6R3Grid14DrawIsoSurfaceEdE17isosurface_points = external hidden global ptr, align 8
@_ZZNK6R3Grid14DrawIsoSurfaceEdE18isosurface_npoints = external hidden global i32, align 4
@.str.170 = external hidden unnamed_addr constant [18 x i8], align 1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #0

declare void @_Z7RNAbortPKcz(ptr noundef, ...) #1

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

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

declare void @_ZN7R3PointC1Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK6R3Grid18GenerateIsoSurfaceEdP7R3Pointi(ptr noundef nonnull align 8 dereferenceable(592), double noundef, ptr noundef, i32 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6R3Grid14DrawIsoSurfaceEd(ptr noundef nonnull align 8 dereferenceable(592) %0, double noundef %1) #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %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
  %10 = load ptr, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE17isosurface_points, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %29, label %12

12:                                               ; preds = %2
  %13 = call noalias noundef nonnull ptr @_Znam(i64 noundef 201326592) #6
  %14 = getelementptr inbounds %class.R3Point, ptr %13, i64 8388608
  br label %15

15:                                               ; preds = %17, %12
  %16 = phi ptr [ %13, %12 ], [ %18, %17 ]
  invoke void @_ZN7R3PointC1Ev(ptr noundef nonnull align 8 dereferenceable(24) %16)
          to label %17 unwind label %24

17:                                               ; preds = %15
  %18 = getelementptr inbounds %class.R3Point, ptr %16, i64 1
  %19 = icmp eq ptr %18, %14
  br i1 %19, label %20, label %15

20:                                               ; preds = %17
  store ptr %13, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE17isosurface_points, align 8, !tbaa !5
  %21 = load ptr, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE17isosurface_points, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %28, label %23

23:                                               ; preds = %20
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.170, i32 noundef 5147, ptr noundef @.str.2)
  br label %28

24:                                               ; preds = %15
  %25 = landingpad { ptr, i32 }
          cleanup
  %26 = extractvalue { ptr, i32 } %25, 0
  store ptr %26, ptr %5, align 8
  %27 = extractvalue { ptr, i32 } %25, 1
  store i32 %27, ptr %6, align 4
  call void @_ZdaPvm(ptr noundef %13, i64 noundef 201326592) #7
  br label %59

28:                                               ; preds = %23, %20
  br label %29

29:                                               ; preds = %28, %2
  %30 = load ptr, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE15isosurface_grid, align 8, !tbaa !5
  %31 = icmp ne ptr %9, %30
  br i1 %31, label %36, label %32

32:                                               ; preds = %29
  %33 = load double, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE16isosurface_level, align 8, !tbaa !9
  %34 = load double, ptr %4, align 8, !tbaa !9
  %35 = fcmp une double %33, %34
  br i1 %35, label %36, label %41

36:                                               ; preds = %32, %29
  %37 = load double, ptr %4, align 8, !tbaa !9
  %38 = load ptr, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE17isosurface_points, align 8, !tbaa !5
  %39 = call noundef i32 @_ZNK6R3Grid18GenerateIsoSurfaceEdP7R3Pointi(ptr noundef nonnull align 8 dereferenceable(592) %9, double noundef %37, ptr noundef %38, i32 noundef 8388608)
  store i32 %39, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE18isosurface_npoints, align 4, !tbaa !11
  store ptr %9, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE15isosurface_grid, align 8, !tbaa !5
  %40 = load double, ptr %4, align 8, !tbaa !9
  store double %40, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE16isosurface_level, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %36, %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #8
  %42 = load ptr, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE17isosurface_points, align 8, !tbaa !5
  store ptr %42, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %43

43:                                               ; preds = %55, %41
  %44 = load i32, ptr %8, align 4, !tbaa !11
  %45 = load i32, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE18isosurface_npoints, align 4, !tbaa !11
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %48, label %47

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

48:                                               ; preds = %43
  call void @glBegin(i32 noundef 9)
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %class.R3Point, ptr %49, i32 1
  store ptr %50, ptr %7, align 8, !tbaa !5
  call void @_Z11R3LoadPointRK7R3Point(ptr noundef nonnull align 8 dereferenceable(24) %49)
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %class.R3Point, ptr %51, i32 1
  store ptr %52, ptr %7, align 8, !tbaa !5
  call void @_Z11R3LoadPointRK7R3Point(ptr noundef nonnull align 8 dereferenceable(24) %51)
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %class.R3Point, ptr %53, i32 1
  store ptr %54, ptr %7, align 8, !tbaa !5
  call void @_Z11R3LoadPointRK7R3Point(ptr noundef nonnull align 8 dereferenceable(24) %53)
  call void @glEnd()
  br label %55

55:                                               ; preds = %48
  %56 = load i32, ptr %8, align 4, !tbaa !11
  %57 = add nsw i32 %56, 3
  store i32 %57, ptr %8, align 4, !tbaa !11
  br label %43, !llvm.loop !13

58:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #8
  ret void

59:                                               ; preds = %24
  %60 = load ptr, ptr %5, align 8
  %61 = load i32, ptr %6, align 4
  %62 = insertvalue { ptr, i32 } poison, ptr %60, 0
  %63 = insertvalue { ptr, i32 } %62, i32 %61, 1
  resume { ptr, i32 } %63
}

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPvm(ptr noundef, i64 noundef) #4

declare void @glBegin(i32 noundef) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z11R3LoadPointRK7R3Point(ptr noundef nonnull align 8 dereferenceable(24)) #5

declare void @glEnd() #1

attributes #0 = { nobuiltin allocsize(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" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nobuiltin nounwind "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 #5 = { 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 #6 = { builtin allocsize(0) }
attributes #7 = { builtin nounwind }
attributes #8 = { 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"}


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

@_ZZNK6R3Grid14DrawIsoSurfaceEdE15isosurface_grid = external hidden local_unnamed_addr global ptr, align 8
@_ZZNK6R3Grid14DrawIsoSurfaceEdE16isosurface_level = external hidden local_unnamed_addr global double, align 8
@_ZZNK6R3Grid14DrawIsoSurfaceEdE17isosurface_points = external hidden local_unnamed_addr global ptr, align 8
@_ZZNK6R3Grid14DrawIsoSurfaceEdE18isosurface_npoints = external hidden local_unnamed_addr global i32, align 4

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

declare void @_ZN7R3PointC1Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6R3Grid14DrawIsoSurfaceEd(ptr noundef nonnull align 8 dereferenceable(592) %0, double noundef %1) local_unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = load ptr, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE17isosurface_points, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %4, label %12

4:                                                ; preds = %2
  %5 = tail call noalias noundef nonnull dereferenceable(201326592) ptr @_Znam(i64 noundef 201326592) #5
  br label %6

6:                                                ; preds = %7, %4
  %.idx = phi i64 [ 0, %4 ], [ %.add, %7 ]
  %.ptr = getelementptr inbounds i8, ptr %5, i64 %.idx
  invoke void @_ZN7R3PointC1Ev(ptr noundef nonnull align 8 dereferenceable(24) %.ptr)
          to label %7 unwind label %10

7:                                                ; preds = %6
  %.add = add nuw nsw i64 %.idx, 24
  %8 = icmp eq i64 %.add, 201326592
  br i1 %8, label %9, label %6

9:                                                ; preds = %7
  store ptr %5, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE17isosurface_points, align 8, !tbaa !5
  br label %12

10:                                               ; preds = %6
  %11 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdaPvm(ptr noundef nonnull %5, i64 noundef 201326592) #6
  resume { ptr, i32 } %11

12:                                               ; preds = %9, %2
  %13 = phi ptr [ %5, %9 ], [ %3, %2 ]
  %14 = load ptr, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE15isosurface_grid, align 8, !tbaa !5
  %.not13 = icmp ne ptr %14, %0
  %15 = load double, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE16isosurface_level, align 8
  %16 = fcmp une double %15, %1
  %or.cond = select i1 %.not13, i1 true, i1 %16
  br i1 %or.cond, label %17, label %._crit_edge17

._crit_edge17:                                    ; preds = %12
  %.pre18 = load i32, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE18isosurface_npoints, align 4, !tbaa !9
  br label %19

17:                                               ; preds = %12
  %18 = tail call noundef i32 @_ZNK6R3Grid18GenerateIsoSurfaceEdP7R3Pointi(ptr noundef nonnull align 8 dereferenceable(592) %0, double noundef %1, ptr noundef nonnull %13, i32 noundef 8388608)
  store i32 %18, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE18isosurface_npoints, align 4, !tbaa !9
  store ptr %0, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE15isosurface_grid, align 8, !tbaa !5
  store double %1, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE16isosurface_level, align 8, !tbaa !11
  %.pre = load ptr, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE17isosurface_points, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %._crit_edge17, %17
  %20 = phi i32 [ %.pre18, %._crit_edge17 ], [ %18, %17 ]
  %21 = phi ptr [ %13, %._crit_edge17 ], [ %.pre, %17 ]
  %22 = icmp sgt i32 %20, 0
  br i1 %22, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %19
  ret void

.lr.ph:                                           ; preds = %19, %.lr.ph
  %.016 = phi i32 [ %26, %.lr.ph ], [ 0, %19 ]
  %.01015 = phi ptr [ %25, %.lr.ph ], [ %21, %19 ]
  tail call void @glBegin(i32 noundef 9)
  %23 = getelementptr inbounds i8, ptr %.01015, i64 24
  tail call void @_Z11R3LoadPointRK7R3Point(ptr noundef nonnull align 8 dereferenceable(24) %.01015)
  %24 = getelementptr inbounds i8, ptr %.01015, i64 48
  tail call void @_Z11R3LoadPointRK7R3Point(ptr noundef nonnull align 8 dereferenceable(24) %23)
  %25 = getelementptr inbounds i8, ptr %.01015, i64 72
  tail call void @_Z11R3LoadPointRK7R3Point(ptr noundef nonnull align 8 dereferenceable(24) %24)
  tail call void @glEnd()
  %26 = add nuw nsw i32 %.016, 3
  %27 = load i32, ptr @_ZZNK6R3Grid14DrawIsoSurfaceEdE18isosurface_npoints, align 4, !tbaa !9
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPvm(ptr noundef, i64 noundef) local_unnamed_addr #3

declare void @glBegin(i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z11R3LoadPointRK7R3Point(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #4

declare void @glEnd() local_unnamed_addr #1

attributes #0 = { nobuiltin allocsize(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" }
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 = { nobuiltin nounwind "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 #4 = { 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 #5 = { builtin allocsize(0) }
attributes #6 = { builtin 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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass