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

; 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.RNFlags = type { i64 }
%class.R2Point = type { [2 x double] }
%class.R2Circle = type { %class.R2Solid, %class.R2Point, double }
%class.R2Solid = type { %class.R2Shape }
%class.R2Shape = type { ptr }

@R2_EDGES_DRAW_FLAG = external global %class.RNFlags, align 8
@R2circle_npoints = external constant i32, align 4
@R2circle_points = external global [0 x %class.R2Point], align 8
@R2_SURFACES_DRAW_FLAG = external global %class.RNFlags, align 8

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK7RNFlagsixES_(ptr noundef nonnull align 8 dereferenceable(8), i64) #1 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare void @_ZplRK7R2PointS1_(ptr dead_on_unwind writable sret(%class.R2Point) align 8, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #3

declare void @_ZmlRK7R2Pointd(ptr dead_on_unwind writable sret(%class.R2Point) align 8, ptr noundef nonnull align 8 dereferenceable(16), double noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z14R2BeginPolygonv() #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z12R2EndPolygonv() #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z11R2BeginLoopv() #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z9R2EndLoopv() #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK8R2Circle4DrawE7RNFlags(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 %1) unnamed_addr #4 align 2 {
  %3 = alloca %class.RNFlags, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %class.RNFlags, align 8
  %6 = alloca i32, align 4
  %7 = alloca %class.R2Point, align 8
  %8 = alloca %class.R2Point, align 8
  %9 = alloca %class.RNFlags, align 8
  %10 = alloca i32, align 4
  %11 = alloca %class.R2Point, align 8
  %12 = alloca %class.R2Point, align 8
  %13 = getelementptr inbounds %class.RNFlags, ptr %3, i32 0, i32 0
  store i64 %1, ptr %13, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 @R2_SURFACES_DRAW_FLAG, i64 8, i1 false), !tbaa.struct !9
  %15 = getelementptr inbounds %class.RNFlags, ptr %5, i32 0, i32 0
  %16 = load i64, ptr %15, align 8
  %17 = call noundef i32 @_ZNK7RNFlagsixES_(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 %16)
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %36

19:                                               ; preds = %2
  call void @_Z14R2BeginPolygonv()
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !12
  br label %20

20:                                               ; preds = %32, %19
  %21 = load i32, ptr %6, align 4, !tbaa !12
  %22 = load i32, ptr @R2circle_npoints, align 4, !tbaa !12
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %35

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  %26 = getelementptr inbounds %class.R2Circle, ptr %14, i32 0, i32 1
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #5
  %27 = load i32, ptr %6, align 4, !tbaa !12
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [0 x %class.R2Point], ptr @R2circle_points, i64 0, i64 %28
  %30 = getelementptr inbounds %class.R2Circle, ptr %14, i32 0, i32 2
  %31 = load double, ptr %30, align 8, !tbaa !14
  call void @_ZmlRK7R2Pointd(ptr dead_on_unwind writable sret(%class.R2Point) align 8 %8, ptr noundef nonnull align 8 dereferenceable(16) %29, double noundef %31)
  call void @_ZplRK7R2PointS1_(ptr dead_on_unwind writable sret(%class.R2Point) align 8 %7, ptr noundef nonnull align 8 dereferenceable(16) %26, ptr noundef nonnull align 8 dereferenceable(16) %8)
  call void @_Z11R2LoadPointRK7R2Point(ptr noundef nonnull align 8 dereferenceable(16) %7)
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  br label %32

32:                                               ; preds = %25
  %33 = load i32, ptr %6, align 4, !tbaa !12
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %6, align 4, !tbaa !12
  br label %20, !llvm.loop !20

35:                                               ; preds = %24
  call void @_Z12R2EndPolygonv()
  br label %36

36:                                               ; preds = %35, %2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 @R2_EDGES_DRAW_FLAG, i64 8, i1 false), !tbaa.struct !9
  %37 = getelementptr inbounds %class.RNFlags, ptr %9, i32 0, i32 0
  %38 = load i64, ptr %37, align 8
  %39 = call noundef i32 @_ZNK7RNFlagsixES_(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 %38)
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %58

41:                                               ; preds = %36
  call void @_Z11R2BeginLoopv()
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !12
  br label %42

42:                                               ; preds = %54, %41
  %43 = load i32, ptr %10, align 4, !tbaa !12
  %44 = load i32, ptr @R2circle_npoints, align 4, !tbaa !12
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %57

47:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #5
  %48 = getelementptr inbounds %class.R2Circle, ptr %14, i32 0, i32 1
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #5
  %49 = load i32, ptr %10, align 4, !tbaa !12
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [0 x %class.R2Point], ptr @R2circle_points, i64 0, i64 %50
  %52 = getelementptr inbounds %class.R2Circle, ptr %14, i32 0, i32 2
  %53 = load double, ptr %52, align 8, !tbaa !14
  call void @_ZmlRK7R2Pointd(ptr dead_on_unwind writable sret(%class.R2Point) align 8 %12, ptr noundef nonnull align 8 dereferenceable(16) %51, double noundef %53)
  call void @_ZplRK7R2PointS1_(ptr dead_on_unwind writable sret(%class.R2Point) align 8 %11, ptr noundef nonnull align 8 dereferenceable(16) %48, ptr noundef nonnull align 8 dereferenceable(16) %12)
  call void @_Z11R2LoadPointRK7R2Point(ptr noundef nonnull align 8 dereferenceable(16) %11)
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #5
  br label %54

54:                                               ; preds = %47
  %55 = load i32, ptr %10, align 4, !tbaa !12
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %10, align 4, !tbaa !12
  br label %42, !llvm.loop !22

57:                                               ; preds = %46
  call void @_Z9R2EndLoopv()
  br label %58

58:                                               ; preds = %57, %36
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { 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 = { 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 = !{i64 0, i64 8, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !19, i64 24}
!15 = !{!"_ZTS8R2Circle", !16, i64 0, !18, i64 8, !19, i64 24}
!16 = !{!"_ZTS7R2Solid", !17, i64 0}
!17 = !{!"_ZTS7R2Shape"}
!18 = !{!"_ZTS7R2Point", !7, i64 0}
!19 = !{!"double", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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.RNFlags = type { i64 }
%class.R2Point = type { [2 x double] }

@R2_EDGES_DRAW_FLAG = external local_unnamed_addr global %class.RNFlags, align 8
@R2circle_npoints = external local_unnamed_addr constant i32, align 4
@R2circle_points = external global [0 x %class.R2Point], align 8
@R2_SURFACES_DRAW_FLAG = external local_unnamed_addr global %class.RNFlags, align 8

; 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: inlinehint mustprogress uwtable
declare dso_local void @_Z11R2LoadPointRK7R2Point(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK7RNFlagsixES_(ptr noundef nonnull align 8 dereferenceable(8), i64) local_unnamed_addr #1 align 2

declare void @_ZplRK7R2PointS1_(ptr dead_on_unwind writable sret(%class.R2Point) align 8, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

declare void @_ZmlRK7R2Pointd(ptr dead_on_unwind writable sret(%class.R2Point) align 8, ptr noundef nonnull align 8 dereferenceable(16), double noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z14R2BeginPolygonv() local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z12R2EndPolygonv() local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z11R2BeginLoopv() local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z9R2EndLoopv() local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK8R2Circle4DrawE7RNFlags(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 %1) unnamed_addr #3 align 2 {
  %3 = alloca %class.RNFlags, align 8
  %4 = alloca %class.R2Point, align 8
  %5 = alloca %class.R2Point, align 8
  %6 = alloca %class.R2Point, align 8
  %7 = alloca %class.R2Point, align 8
  store i64 %1, ptr %3, align 8
  %.sroa.06.0.copyload = load i64, ptr @R2_SURFACES_DRAW_FLAG, align 8, !tbaa !5
  %8 = call noundef i32 @_ZNK7RNFlagsixES_(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 %.sroa.06.0.copyload)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %17, label %9

9:                                                ; preds = %2
  call void @_Z14R2BeginPolygonv()
  %10 = load i32, ptr @R2circle_npoints, align 4, !tbaa !9
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %wide.trip.count = zext nneg i32 %10 to i64
  br label %14

._crit_edge:                                      ; preds = %14, %9
  call void @_Z12R2EndPolygonv()
  br label %17

14:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  %15 = getelementptr inbounds [0 x %class.R2Point], ptr @R2circle_points, i64 0, i64 %indvars.iv
  %16 = load double, ptr %13, align 8, !tbaa !11
  call void @_ZmlRK7R2Pointd(ptr dead_on_unwind nonnull writable sret(%class.R2Point) align 8 %5, ptr noundef nonnull align 8 dereferenceable(16) %15, double noundef %16)
  call void @_ZplRK7R2PointS1_(ptr dead_on_unwind nonnull writable sret(%class.R2Point) align 8 %4, ptr noundef nonnull align 8 dereferenceable(16) %12, ptr noundef nonnull align 8 dereferenceable(16) %5)
  call void @_Z11R2LoadPointRK7R2Point(ptr noundef nonnull align 8 dereferenceable(16) %4)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %14, !llvm.loop !17

17:                                               ; preds = %._crit_edge, %2
  %.sroa.0.0.copyload = load i64, ptr @R2_EDGES_DRAW_FLAG, align 8, !tbaa !5
  %18 = call noundef i32 @_ZNK7RNFlagsixES_(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 %.sroa.0.0.copyload)
  %.not8 = icmp eq i32 %18, 0
  br i1 %.not8, label %27, label %19

19:                                               ; preds = %17
  call void @_Z11R2BeginLoopv()
  %20 = load i32, ptr @R2circle_npoints, align 4, !tbaa !9
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph12, label %._crit_edge13

.lr.ph12:                                         ; preds = %19
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  %wide.trip.count18 = zext nneg i32 %20 to i64
  br label %24

._crit_edge13:                                    ; preds = %24, %19
  call void @_Z9R2EndLoopv()
  br label %27

24:                                               ; preds = %.lr.ph12, %24
  %indvars.iv15 = phi i64 [ 0, %.lr.ph12 ], [ %indvars.iv.next16, %24 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #4
  %25 = getelementptr inbounds [0 x %class.R2Point], ptr @R2circle_points, i64 0, i64 %indvars.iv15
  %26 = load double, ptr %23, align 8, !tbaa !11
  call void @_ZmlRK7R2Pointd(ptr dead_on_unwind nonnull writable sret(%class.R2Point) align 8 %7, ptr noundef nonnull align 8 dereferenceable(16) %25, double noundef %26)
  call void @_ZplRK7R2PointS1_(ptr dead_on_unwind nonnull writable sret(%class.R2Point) align 8 %6, ptr noundef nonnull align 8 dereferenceable(16) %22, ptr noundef nonnull align 8 dereferenceable(16) %7)
  call void @_Z11R2LoadPointRK7R2Point(ptr noundef nonnull align 8 dereferenceable(16) %6)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  %indvars.iv.next16 = add nuw nsw i64 %indvars.iv15, 1
  %exitcond19.not = icmp eq i64 %indvars.iv.next16, %wide.trip.count18
  br i1 %exitcond19.not, label %._crit_edge13, label %24, !llvm.loop !19

27:                                               ; preds = %._crit_edge13, %17
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = { 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 = !{!"long", !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, !16, i64 24}
!12 = !{!"_ZTS8R2Circle", !13, i64 0, !15, i64 8, !16, i64 24}
!13 = !{!"_ZTS7R2Solid", !14, i64 0}
!14 = !{!"_ZTS7R2Shape"}
!15 = !{!"_ZTS7R2Point", !7, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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