; LLVM IR from sgtlaugh/algovault :: code_library/linear_recurrence.ll (ZN3fft10initializeEv)

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

%"struct.fft::ComplexNum" = type { double, double }

@_ZN3fft11initializedE = external dso_local global i8, align 1
@_ZN3fft2dpE = external dso_local global [131072 x %"struct.fft::ComplexNum"], align 16

; 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 nounwind uwtable
declare dso_local void @_ZN3fft10ComplexNumC2Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3fft10initializeEv() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca %"struct.fft::ComplexNum", align 8
  %5 = alloca double, align 8
  %6 = alloca %"struct.fft::ComplexNum", align 8
  %7 = alloca %"struct.fft::ComplexNum", align 8
  %8 = alloca %"struct.fft::ComplexNum", align 8
  %9 = load i8, ptr @_ZN3fft11initializedE, align 1, !tbaa !5, !range !9, !noundef !10
  %10 = trunc i8 %9 to i1
  br i1 %10, label %11, label %12

11:                                               ; preds = %0
  br label %69

12:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i8 1, ptr @_ZN3fft11initializedE, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #6
  call void @_ZN3fft10ComplexNumC2Edd(ptr noundef nonnull align 8 dereferenceable(16) %4, double noundef 1.000000e+00, double noundef 0.000000e+00)
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 getelementptr inbounds ([131072 x %"struct.fft::ComplexNum"], ptr @_ZN3fft2dpE, i64 0, i64 1), ptr align 8 %4, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #6
  store i32 1, ptr %1, align 4, !tbaa !14
  br label %13

13:                                               ; preds = %65, %12
  %14 = load i32, ptr %1, align 4, !tbaa !14
  %15 = shl i32 1, %14
  %16 = icmp slt i32 %15, 131072
  br i1 %16, label %17, label %68

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %18 = call double @acos(double noundef 0.000000e+00) #6
  %19 = fmul double 2.000000e+00, %18
  %20 = load i32, ptr %1, align 4, !tbaa !14
  %21 = shl i32 1, %20
  %22 = sitofp i32 %21 to double
  %23 = fdiv double %19, %22
  store double %23, ptr %5, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #6
  %24 = load double, ptr %5, align 8, !tbaa !12
  %25 = call double @cos(double noundef %24) #6
  %26 = load double, ptr %5, align 8, !tbaa !12
  %27 = call double @sin(double noundef %26) #6
  call void @_ZN3fft10ComplexNumC2Edd(ptr noundef nonnull align 8 dereferenceable(16) %6, double noundef %25, double noundef %27)
  %28 = load i32, ptr %1, align 4, !tbaa !14
  %29 = shl i32 1, %28
  store i32 %29, ptr %3, align 4, !tbaa !14
  %30 = load i32, ptr %3, align 4, !tbaa !14
  %31 = ashr i32 %30, 1
  store i32 %31, ptr %2, align 4, !tbaa !14
  br label %32

32:                                               ; preds = %61, %17
  %33 = load i32, ptr %2, align 4, !tbaa !14
  %34 = load i32, ptr %3, align 4, !tbaa !14
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %64

36:                                               ; preds = %32
  %37 = load i32, ptr %2, align 4, !tbaa !14
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [131072 x %"struct.fft::ComplexNum"], ptr @_ZN3fft2dpE, i64 0, i64 %38
  %40 = load i32, ptr %2, align 4, !tbaa !14
  %41 = mul nsw i32 2, %40
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [131072 x %"struct.fft::ComplexNum"], ptr @_ZN3fft2dpE, i64 0, i64 %42
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %43, ptr align 16 %39, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #6
  %44 = load i32, ptr %2, align 4, !tbaa !14
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [131072 x %"struct.fft::ComplexNum"], ptr @_ZN3fft2dpE, i64 0, i64 %45
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !11
  %47 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 0
  %48 = load double, ptr %47, align 8
  %49 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 1
  %50 = load double, ptr %49, align 8
  %51 = call { double, double } @_ZN3fft10ComplexNummlES0_(ptr noundef nonnull align 8 dereferenceable(16) %46, double %48, double %50)
  %52 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 0
  %53 = extractvalue { double, double } %51, 0
  store double %53, ptr %52, align 8
  %54 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 1
  %55 = extractvalue { double, double } %51, 1
  store double %55, ptr %54, align 8
  %56 = load i32, ptr %2, align 4, !tbaa !14
  %57 = mul nsw i32 2, %56
  %58 = add nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [131072 x %"struct.fft::ComplexNum"], ptr @_ZN3fft2dpE, i64 0, i64 %59
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %60, ptr align 8 %7, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #6
  br label %61

61:                                               ; preds = %36
  %62 = load i32, ptr %2, align 4, !tbaa !14
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %2, align 4, !tbaa !14
  br label %32, !llvm.loop !16

64:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %1, align 4, !tbaa !14
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %1, align 4, !tbaa !14
  br label %13, !llvm.loop !18

68:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #6
  br label %69

69:                                               ; preds = %68, %11
  ret void
}

; 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: nounwind
declare double @acos(double noundef) #4

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local { double, double } @_ZN3fft10ComplexNummlES0_(ptr noundef nonnull align 8 dereferenceable(16), double, double) #5 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{i64 0, i64 8, !12, i64 8, i64 8, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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

%"struct.fft::ComplexNum" = type { double, double }

@_ZN3fft11initializedE = external dso_local local_unnamed_addr global i8, align 1
@_ZN3fft2dpE = external dso_local global [131072 x %"struct.fft::ComplexNum"], align 16

; 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 nounwind uwtable
declare dso_local void @_ZN3fft10ComplexNumC2Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3fft10initializeEv() local_unnamed_addr #2 {
  %1 = alloca %"struct.fft::ComplexNum", align 8
  %2 = alloca %"struct.fft::ComplexNum", align 8
  %3 = load i8, ptr @_ZN3fft11initializedE, align 1, !tbaa !5, !range !9, !noundef !10
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %0
  store i8 1, ptr @_ZN3fft11initializedE, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #6
  call void @_ZN3fft10ComplexNumC2Edd(ptr noundef nonnull align 8 dereferenceable(16) %1, double noundef 1.000000e+00, double noundef 0.000000e+00)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) getelementptr inbounds (i8, ptr @_ZN3fft2dpE, i64 16), ptr noundef nonnull align 8 dereferenceable(16) %1, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #6
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %2, i64 8
  br label %6

6:                                                ; preds = %5, %._crit_edge
  %7 = phi i32 [ 2, %5 ], [ %26, %._crit_edge ]
  %.017 = phi i32 [ 1, %5 ], [ %25, %._crit_edge ]
  %8 = sitofp i32 %7 to double
  %9 = fdiv double 0x400921FB54442D18, %8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #6
  %10 = call double @cos(double noundef %9) #6
  %11 = call double @sin(double noundef %9) #6
  call void @_ZN3fft10ComplexNumC2Edd(ptr noundef nonnull align 8 dereferenceable(16) %2, double noundef %10, double noundef %11)
  %12 = icmp sgt i32 %7, 0
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %6
  %13 = lshr exact i32 %7, 1
  %14 = zext nneg i32 %13 to i64
  %15 = zext nneg i32 %7 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %14, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %16 = getelementptr inbounds [131072 x %"struct.fft::ComplexNum"], ptr @_ZN3fft2dpE, i64 0, i64 %indvars.iv
  %17 = shl nuw nsw i64 %indvars.iv, 1
  %18 = getelementptr inbounds [131072 x %"struct.fft::ComplexNum"], ptr @_ZN3fft2dpE, i64 0, i64 %17
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %18, ptr noundef nonnull align 16 dereferenceable(16) %16, i64 16, i1 false), !tbaa.struct !11
  %.sroa.0.0.copyload = load double, ptr %2, align 8, !tbaa !12
  %.sroa.2.0.copyload = load double, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !12
  %19 = call { double, double } @_ZN3fft10ComplexNummlES0_(ptr noundef nonnull align 8 dereferenceable(16) %16, double %.sroa.0.0.copyload, double %.sroa.2.0.copyload)
  %20 = extractvalue { double, double } %19, 0
  %21 = extractvalue { double, double } %19, 1
  %22 = or disjoint i64 %17, 1
  %23 = getelementptr inbounds [131072 x %"struct.fft::ComplexNum"], ptr @_ZN3fft2dpE, i64 0, i64 %22
  store double %20, ptr %23, align 16, !tbaa !12
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %23, i64 8
  store double %21, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = icmp ult i64 %indvars.iv.next, %15
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #6
  %25 = add nuw nsw i32 %.017, 1
  %26 = shl nuw i32 2, %.017
  %exitcond.not = icmp eq i32 %25, 17
  br i1 %exitcond.not, label %.loopexit, label %6, !llvm.loop !16

.loopexit:                                        ; preds = %._crit_edge, %0
  ret void
}

; Function Attrs: mustprogress 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: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #4

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local { double, double } @_ZN3fft10ComplexNummlES0_(ptr noundef nonnull align 8 dereferenceable(16), double, double) local_unnamed_addr #5 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{i64 0, i64 8, !12, i64 8, i64 8, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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