; LLVM IR from zsiciarz/aquila :: aquila/transform/OouraFft.ll (ZN6Aquila8OouraFftC2Em)

; 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.Aquila::OouraFft" = type { %"class.Aquila::Fft", ptr, ptr }
%"class.Aquila::Fft" = type { ptr, i64 }

@_ZTVN6Aquila8OouraFftE = external dso_local unnamed_addr constant { [6 x ptr] }, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Aquila8OouraFftC2Em(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = load i64, ptr %4, align 8, !tbaa !9
  call void @_ZN6Aquila3FftC2Em(ptr noundef nonnull align 8 dereferenceable(16) %7, i64 noundef %8)
  store ptr getelementptr inbounds inrange(-16, 32) ({ [6 x ptr] }, ptr @_ZTVN6Aquila8OouraFftE, i32 0, i32 0, i32 2), ptr %7, align 8, !tbaa !11
  %9 = getelementptr inbounds %"class.Aquila::OouraFft", ptr %7, i32 0, i32 1
  %10 = getelementptr inbounds %"class.Aquila::Fft", ptr %7, i32 0, i32 1
  %11 = load i64, ptr %10, align 8, !tbaa !13
  %12 = uitofp i64 %11 to double
  %13 = call double @sqrt(double noundef %12) #5
  %14 = fadd double 2.000000e+00, %13
  %15 = fptoui double %14 to i64
  %16 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %15, i64 4)
  %17 = extractvalue { i64, i1 } %16, 1
  %18 = extractvalue { i64, i1 } %16, 0
  %19 = select i1 %17, i64 -1, i64 %18
  %20 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %19) #6
          to label %21 unwind label %35

21:                                               ; preds = %2
  store ptr %20, ptr %9, align 8, !tbaa !15
  %22 = getelementptr inbounds %"class.Aquila::OouraFft", ptr %7, i32 0, i32 2
  %23 = getelementptr inbounds %"class.Aquila::Fft", ptr %7, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !13
  %25 = udiv i64 %24, 2
  %26 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %25, i64 8)
  %27 = extractvalue { i64, i1 } %26, 1
  %28 = extractvalue { i64, i1 } %26, 0
  %29 = select i1 %27, i64 -1, i64 %28
  %30 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %29) #6
          to label %31 unwind label %35

31:                                               ; preds = %21
  store ptr %30, ptr %22, align 8, !tbaa !17
  %32 = getelementptr inbounds %"class.Aquila::OouraFft", ptr %7, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = getelementptr inbounds i32, ptr %33, i64 0
  store i32 0, ptr %34, align 4, !tbaa !18
  ret void

35:                                               ; preds = %21, %2
  %36 = landingpad { ptr, i32 }
          cleanup
  %37 = extractvalue { ptr, i32 } %36, 0
  store ptr %37, ptr %5, align 8
  %38 = extractvalue { ptr, i32 } %36, 1
  store i32 %38, ptr %6, align 4
  call void @_ZN6Aquila3FftD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #5
  br label %39

39:                                               ; preds = %35
  %40 = load ptr, ptr %5, align 8
  %41 = load i32, ptr %6, align 4
  %42 = insertvalue { ptr, i32 } poison, ptr %40, 0
  %43 = insertvalue { ptr, i32 } %42, i32 %41, 1
  resume { ptr, i32 } %43
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Aquila3FftC2Em(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) unnamed_addr #1 align 2

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #3

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Aquila3FftD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1 align 2

attributes #0 = { 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 #1 = { 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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTSN6Aquila3FftE", !10, i64 8}
!15 = !{!16, !6, i64 16}
!16 = !{!"_ZTSN6Aquila8OouraFftE", !14, i64 0, !6, i64 16, !6, i64 24}
!17 = !{!16, !6, i64 24}
!18 = !{!19, !19, i64 0}
!19 = !{!"int", !7, i64 0}


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

@_ZTVN6Aquila8OouraFftE = external dso_local unnamed_addr constant { [6 x ptr] }, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Aquila8OouraFftC2Em(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN6Aquila3FftC2Em(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %1)
  store ptr getelementptr inbounds inrange(-16, 32) (i8, ptr @_ZTVN6Aquila8OouraFftE, i64 16), ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !8
  %5 = uitofp i64 %4 to double
  %sqrt = tail call double @llvm.sqrt.f64(double %5)
  %6 = fadd double %sqrt, 2.000000e+00
  %7 = fptoui double %6 to i64
  %8 = icmp ugt i64 %7, 4611686018427387903
  %9 = shl i64 %7, 2
  %10 = select i1 %8, i64 -1, i64 %9
  %11 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %10) #4
          to label %12 unwind label %21

12:                                               ; preds = %2
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %11, ptr %13, align 8, !tbaa !12
  %14 = icmp ugt i64 %4, 4611686018427387903
  %15 = shl i64 %4, 2
  %16 = and i64 %15, -8
  %17 = select i1 %14, i64 -1, i64 %16
  %18 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %17) #4
          to label %19 unwind label %21

19:                                               ; preds = %12
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %18, ptr %20, align 8, !tbaa !15
  store i32 0, ptr %11, align 4, !tbaa !16
  ret void

21:                                               ; preds = %12, %2
  %22 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN6Aquila3FftD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #5
  resume { ptr, i32 } %22
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Aquila3FftC2Em(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) unnamed_addr #1 align 2

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Aquila3FftD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.sqrt.f64(double) #3

attributes #0 = { 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 #1 = { 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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { builtin allocsize(0) }
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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !10, i64 8}
!9 = !{!"_ZTSN6Aquila3FftE", !10, i64 8}
!10 = !{!"long", !11, i64 0}
!11 = !{!"omnipotent char", !7, i64 0}
!12 = !{!13, !14, i64 16}
!13 = !{!"_ZTSN6Aquila8OouraFftE", !9, i64 0, !14, i64 16, !14, i64 24}
!14 = !{!"any pointer", !11, i64 0}
!15 = !{!13, !14, i64 24}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !11, i64 0}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass