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

; 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] }

@R2_EDGES_DRAW_FLAG = external global %class.RNFlags, align 8
@R2circle_npoints = external constant i32, align 4
@RN_TWO_PI = external constant double, align 8
@R2circle_points = external global [0 x %class.R2Point], 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 @_Z11R2BeginLinev() #1

; 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 void @_Z9R2EndLinev() #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK5R2Arc4DrawE7RNFlags(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 %1) unnamed_addr #2 align 2 {
  %3 = alloca %class.RNFlags, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %class.RNFlags, align 8
  %6 = alloca %class.R2Point, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %class.R2Point, align 8
  %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_EDGES_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 %53

19:                                               ; preds = %2
  call void @_Z11R2BeginLinev()
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #6
  call void @_ZNK5R2Arc10StartPointEv(ptr dead_on_unwind writable sret(%class.R2Point) align 8 %6, ptr noundef nonnull align 8 dereferenceable(56) %14)
  call void @_Z11R2LoadPointRK7R2Point(ptr noundef nonnull align 8 dereferenceable(16) %6)
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %20 = load i32, ptr @R2circle_npoints, align 4, !tbaa !12
  %21 = sitofp i32 %20 to double
  %22 = call noundef double @_ZNK5R2Arc10StartAngleEv(ptr noundef nonnull align 8 dereferenceable(56) %14)
  %23 = fmul double %21, %22
  %24 = load double, ptr @RN_TWO_PI, align 8, !tbaa !14
  %25 = fdiv double %23, %24
  %26 = fadd double 1.000000e+00, %25
  %27 = fptosi double %26 to i32
  store i32 %27, ptr %7, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %28 = load i32, ptr @R2circle_npoints, align 4, !tbaa !12
  %29 = sitofp i32 %28 to double
  %30 = call noundef double @_ZNK5R2Arc9StopAngleEv(ptr noundef nonnull align 8 dereferenceable(56) %14)
  %31 = fmul double %29, %30
  %32 = load double, ptr @RN_TWO_PI, align 8, !tbaa !14
  %33 = fdiv double %31, %32
  %34 = fptosi double %33 to i32
  store i32 %34, ptr %8, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %35 = load i32, ptr %7, align 4, !tbaa !12
  store i32 %35, ptr %9, align 4, !tbaa !12
  br label %36

36:                                               ; preds = %49, %19
  %37 = load i32, ptr %9, align 4, !tbaa !12
  %38 = load i32, ptr %8, align 4, !tbaa !12
  %39 = icmp sle i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %52

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #6
  %42 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK5R2Arc6CenterEv(ptr noundef nonnull align 8 dereferenceable(56) %14)
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #6
  %43 = load i32, ptr %9, align 4, !tbaa !12
  %44 = load i32, ptr @R2circle_npoints, align 4, !tbaa !12
  %45 = srem i32 %43, %44
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [0 x %class.R2Point], ptr @R2circle_points, i64 0, i64 %46
  %48 = call noundef double @_ZNK5R2Arc6RadiusEv(ptr noundef nonnull align 8 dereferenceable(56) %14)
  call void @_ZmlRK7R2Pointd(ptr dead_on_unwind writable sret(%class.R2Point) align 8 %11, ptr noundef nonnull align 8 dereferenceable(16) %47, double noundef %48)
  call void @_ZplRK7R2PointS1_(ptr dead_on_unwind writable sret(%class.R2Point) align 8 %10, ptr noundef nonnull align 8 dereferenceable(16) %42, ptr noundef nonnull align 8 dereferenceable(16) %11)
  call void @_Z11R2LoadPointRK7R2Point(ptr noundef nonnull align 8 dereferenceable(16) %10)
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #6
  br label %49

49:                                               ; preds = %41
  %50 = load i32, ptr %9, align 4, !tbaa !12
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %9, align 4, !tbaa !12
  br label %36, !llvm.loop !16

52:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #6
  call void @_ZNK5R2Arc9StopPointEv(ptr dead_on_unwind writable sret(%class.R2Point) align 8 %12, ptr noundef nonnull align 8 dereferenceable(56) %14)
  call void @_Z11R2LoadPointRK7R2Point(ptr noundef nonnull align 8 dereferenceable(16) %12)
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #6
  call void @_Z9R2EndLinev()
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %53

53:                                               ; preds = %52, %2
  ret void
}

; 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) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK5R2Arc10StartPointEv(ptr dead_on_unwind noalias writable sret(%class.R2Point) align 8, ptr noundef nonnull align 8 dereferenceable(56)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5R2Arc10StartAngleEv(ptr noundef nonnull align 8 dereferenceable(56)) #4 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5R2Arc9StopAngleEv(ptr noundef nonnull align 8 dereferenceable(56)) #4 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)) #5

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNK5R2Arc6CenterEv(ptr noundef nonnull align 8 dereferenceable(56)) #1 align 2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK5R2Arc6RadiusEv(ptr noundef nonnull align 8 dereferenceable(56)) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK5R2Arc9StopPointEv(ptr dead_on_unwind noalias writable sret(%class.R2Point) align 8, ptr noundef nonnull align 8 dereferenceable(56)) #1 align 2

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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { "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 = { 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, !15, i64 0}
!15 = !{!"double", !7, 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"

%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
@RN_TWO_PI = external local_unnamed_addr constant double, align 8
@R2circle_points = external global [0 x %class.R2Point], 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 @_Z11R2BeginLinev() local_unnamed_addr #1

; 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 void @_Z9R2EndLinev() local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK5R2Arc4DrawE7RNFlags(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 %1) unnamed_addr #2 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.0.0.copyload = load i64, ptr @R2_EDGES_DRAW_FLAG, align 8, !tbaa !5
  %8 = call noundef i32 @_ZNK7RNFlagsixES_(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 %.sroa.0.0.copyload)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %28, label %9

9:                                                ; preds = %2
  call void @_Z11R2BeginLinev()
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  call void @_ZNK5R2Arc10StartPointEv(ptr dead_on_unwind nonnull writable sret(%class.R2Point) align 8 %4, ptr noundef nonnull align 8 dereferenceable(56) %0)
  call void @_Z11R2LoadPointRK7R2Point(ptr noundef nonnull align 8 dereferenceable(16) %4)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  %10 = load i32, ptr @R2circle_npoints, align 4, !tbaa !9
  %11 = sitofp i32 %10 to double
  %12 = call noundef double @_ZNK5R2Arc10StartAngleEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
  %13 = fmul double %12, %11
  %14 = load double, ptr @RN_TWO_PI, align 8, !tbaa !11
  %15 = fdiv double %13, %14
  %16 = fadd double %15, 1.000000e+00
  %17 = fptosi double %16 to i32
  %18 = call noundef double @_ZNK5R2Arc9StopAngleEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
  %19 = fmul double %18, %11
  %20 = fdiv double %19, %14
  %21 = fptosi double %20 to i32
  %.not56 = icmp sgt i32 %17, %21
  br i1 %.not56, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %9
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #5
  call void @_ZNK5R2Arc9StopPointEv(ptr dead_on_unwind nonnull writable sret(%class.R2Point) align 8 %7, ptr noundef nonnull align 8 dereferenceable(56) %0)
  call void @_Z11R2LoadPointRK7R2Point(ptr noundef nonnull align 8 dereferenceable(16) %7)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #5
  call void @_Z9R2EndLinev()
  br label %28

.lr.ph:                                           ; preds = %9, %.lr.ph
  %.07 = phi i32 [ %27, %.lr.ph ], [ %17, %9 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #5
  %22 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK5R2Arc6CenterEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #5
  %23 = srem i32 %.07, %10
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [0 x %class.R2Point], ptr @R2circle_points, i64 0, i64 %24
  %26 = call noundef double @_ZNK5R2Arc6RadiusEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
  call void @_ZmlRK7R2Pointd(ptr dead_on_unwind nonnull writable sret(%class.R2Point) align 8 %6, 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 %5, ptr noundef nonnull align 8 dereferenceable(16) %22, ptr noundef nonnull align 8 dereferenceable(16) %6)
  call void @_Z11R2LoadPointRK7R2Point(ptr noundef nonnull align 8 dereferenceable(16) %5)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  %27 = add i32 %.07, 1
  %exitcond.not = icmp eq i32 %.07, %21
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

28:                                               ; preds = %._crit_edge, %2
  ret void
}

; 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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK5R2Arc10StartPointEv(ptr dead_on_unwind noalias writable sret(%class.R2Point) align 8, ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5R2Arc10StartAngleEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5R2Arc9StopAngleEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #3 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 #4

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK5R2Arc6RadiusEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK5R2Arc9StopPointEv(ptr dead_on_unwind noalias writable sret(%class.R2Point) align 8, ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #1 align 2

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 = { 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 = { 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 #4 = { "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 = !{!"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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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