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

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

@R3circle_angles = external dso_local global [32 x double], align 16
@R3circle_points = external dso_local global [32 x %class.R3Point], align 16
@R3circle_texcoords = external dso_local global [32 x %class.R2Point], align 16
@RN_TWO_PI = external constant double, align 8

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

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

; 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 noundef i32 @_Z12R3InitCirclev() #2 {
  %1 = alloca i32, align 4
  %2 = alloca %class.R3Point, align 8
  %3 = alloca %class.R2Point, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %47, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 32
  br i1 %6, label %8, label %7

7:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  br label %50

8:                                                ; preds = %4
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = sitofp i32 %9 to double
  %11 = load double, ptr @RN_TWO_PI, align 8, !tbaa !9
  %12 = fmul double %10, %11
  %13 = fdiv double %12, 3.200000e+01
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [32 x double], ptr @R3circle_angles, i64 0, i64 %15
  store double %13, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %2) #5
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [32 x double], ptr @R3circle_angles, i64 0, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !9
  %21 = call double @cos(double noundef %20) #5
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [32 x double], ptr @R3circle_angles, i64 0, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !9
  %26 = call double @sin(double noundef %25) #5
  call void @_ZN7R3PointC1Eddd(ptr noundef nonnull align 8 dereferenceable(24) %2, double noundef %21, double noundef %26, double noundef 0.000000e+00)
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [32 x %class.R3Point], ptr @R3circle_points, i64 0, i64 %28
  %30 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24) %29, ptr noundef nonnull align 8 dereferenceable(24) %2)
  call void @llvm.lifetime.end.p0(i64 24, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #5
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [32 x %class.R3Point], ptr @R3circle_points, i64 0, i64 %32
  %34 = call noundef double @_ZNK7R3Point1XEv(ptr noundef nonnull align 8 dereferenceable(24) %33)
  %35 = fadd double %34, 1.000000e+00
  %36 = fmul double 5.000000e-01, %35
  %37 = load i32, ptr %1, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [32 x %class.R3Point], ptr @R3circle_points, i64 0, i64 %38
  %40 = call noundef double @_ZNK7R3Point1YEv(ptr noundef nonnull align 8 dereferenceable(24) %39)
  %41 = fadd double %40, 1.000000e+00
  %42 = fmul double 5.000000e-01, %41
  call void @_ZN7R2PointC1Edd(ptr noundef nonnull align 8 dereferenceable(16) %3, double noundef %36, double noundef %42)
  %43 = load i32, ptr %1, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [32 x %class.R2Point], ptr @R3circle_texcoords, i64 0, i64 %44
  %46 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(16) %45, ptr noundef nonnull align 8 dereferenceable(16) %3)
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #5
  br label %47

47:                                               ; preds = %8
  %48 = load i32, ptr %1, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !11

50:                                               ; preds = %7
  ret i32 1
}

; Function Attrs: nounwind
declare double @cos(double noundef) #3

; Function Attrs: nounwind
declare double @sin(double noundef) #3

declare noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #1

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

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

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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.R3Point = type { [3 x double] }
%class.R2Point = type { [2 x double] }

@R3circle_angles = external dso_local local_unnamed_addr global [32 x double], align 16
@R3circle_points = external dso_local global [32 x %class.R3Point], align 16
@R3circle_texcoords = external dso_local global [32 x %class.R2Point], align 16
@RN_TWO_PI = external local_unnamed_addr constant double, align 8

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

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

; Function Attrs: mustprogress 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 noundef i32 @_Z12R3InitCirclev() local_unnamed_addr #2 {
  %1 = alloca %class.R3Point, align 8
  %2 = alloca %class.R2Point, align 8
  %3 = load double, ptr @RN_TWO_PI, align 8, !tbaa !5
  br label %5

4:                                                ; preds = %5
  ret i32 1

5:                                                ; preds = %0, %5
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %5 ]
  %6 = trunc nuw nsw i64 %indvars.iv to i32
  %7 = uitofp nneg i32 %6 to double
  %8 = fmul double %3, %7
  %9 = fmul double %8, 3.125000e-02
  %10 = getelementptr inbounds [32 x double], ptr @R3circle_angles, i64 0, i64 %indvars.iv
  store double %9, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %1) #5
  %11 = call double @cos(double noundef %9) #5
  %12 = load double, ptr %10, align 8, !tbaa !5
  %13 = call double @sin(double noundef %12) #5
  call void @_ZN7R3PointC1Eddd(ptr noundef nonnull align 8 dereferenceable(24) %1, double noundef %11, double noundef %13, double noundef 0.000000e+00)
  %14 = getelementptr inbounds [32 x %class.R3Point], ptr @R3circle_points, i64 0, i64 %indvars.iv
  %15 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24) %14, ptr noundef nonnull align 8 dereferenceable(24) %1)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #5
  %16 = call noundef double @_ZNK7R3Point1XEv(ptr noundef nonnull align 8 dereferenceable(24) %14)
  %17 = fadd double %16, 1.000000e+00
  %18 = fmul double %17, 5.000000e-01
  %19 = call noundef double @_ZNK7R3Point1YEv(ptr noundef nonnull align 8 dereferenceable(24) %14)
  %20 = fadd double %19, 1.000000e+00
  %21 = fmul double %20, 5.000000e-01
  call void @_ZN7R2PointC1Edd(ptr noundef nonnull align 8 dereferenceable(16) %2, double noundef %18, double noundef %21)
  %22 = getelementptr inbounds [32 x %class.R2Point], ptr @R3circle_texcoords, i64 0, i64 %indvars.iv
  %23 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(16) %22, ptr noundef nonnull align 8 dereferenceable(16) %2)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 32
  br i1 %exitcond.not, label %4, label %5, !llvm.loop !9
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #3

declare noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1

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

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

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nofree nounwind willreturn memory(write) "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 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 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass