; LLVM IR from sp-nitech/SPTK :: third_party/REAPER/epoch_tracker/fft_reaper.ll (ZN4sptk6reaper3FFT11makefttableEi)

; 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.sptk::reaper::FFT" = type { ptr, ptr, i32, i32, i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4sptk6reaper3FFT11makefttableEi(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %11 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = shl i32 1, %12
  %14 = getelementptr inbounds %"class.sptk::reaper::FFT", ptr %11, i32 0, i32 5
  store i32 %13, ptr %14, align 4, !tbaa !11
  %15 = getelementptr inbounds %"class.sptk::reaper::FFT", ptr %11, i32 0, i32 5
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = sdiv i32 %16, 2
  store i32 %17, ptr %5, align 4, !tbaa !9
  %18 = getelementptr inbounds %"class.sptk::reaper::FFT", ptr %11, i32 0, i32 2
  store i32 %17, ptr %18, align 8, !tbaa !13
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %20, i64 4)
  %22 = extractvalue { i64, i1 } %21, 1
  %23 = extractvalue { i64, i1 } %21, 0
  %24 = select i1 %22, i64 -1, i64 %23
  %25 = call noalias noundef nonnull ptr @_Znam(i64 noundef %24) #6
  %26 = getelementptr inbounds %"class.sptk::reaper::FFT", ptr %11, i32 0, i32 0
  store ptr %25, ptr %26, align 8, !tbaa !14
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %28, i64 4)
  %30 = extractvalue { i64, i1 } %29, 1
  %31 = extractvalue { i64, i1 } %29, 0
  %32 = select i1 %30, i64 -1, i64 %31
  %33 = call noalias noundef nonnull ptr @_Znam(i64 noundef %32) #6
  %34 = getelementptr inbounds %"class.sptk::reaper::FFT", ptr %11, i32 0, i32 1
  store ptr %33, ptr %34, align 8, !tbaa !15
  %35 = getelementptr inbounds %"class.sptk::reaper::FFT", ptr %11, i32 0, i32 5
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = sitofp i32 %36 to double
  %38 = fdiv double 0x401921FB54442D18, %37
  store double %38, ptr %9, align 8, !tbaa !16
  %39 = getelementptr inbounds %"class.sptk::reaper::FFT", ptr %11, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  store ptr %40, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %"class.sptk::reaper::FFT", ptr %11, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  store ptr %42, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %62, %2
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %47, label %65

47:                                               ; preds = %43
  %48 = load double, ptr %9, align 8, !tbaa !16
  %49 = load i32, ptr %6, align 4, !tbaa !9
  %50 = sitofp i32 %49 to double
  %51 = fmul double %48, %50
  store double %51, ptr %10, align 8, !tbaa !16
  %52 = load double, ptr %10, align 8, !tbaa !16
  %53 = call double @sin(double noundef %52) #5
  %54 = fptrunc double %53 to float
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds float, ptr %55, i32 1
  store ptr %56, ptr %8, align 8, !tbaa !5
  store float %54, ptr %55, align 4, !tbaa !18
  %57 = load double, ptr %10, align 8, !tbaa !16
  %58 = call double @cos(double noundef %57) #5
  %59 = fptrunc double %58 to float
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds float, ptr %60, i32 1
  store ptr %61, ptr %7, align 8, !tbaa !5
  store float %59, ptr %60, align 4, !tbaa !18
  br label %62

62:                                               ; preds = %47
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %6, align 4, !tbaa !9
  br label %43, !llvm.loop !20

65:                                               ; preds = %43
  %66 = getelementptr inbounds %"class.sptk::reaper::FFT", ptr %11, i32 0, i32 2
  %67 = load i32, ptr %66, align 8, !tbaa !13
  %68 = mul nsw i32 %67, 2
  %69 = getelementptr inbounds %"class.sptk::reaper::FFT", ptr %11, i32 0, i32 5
  %70 = load i32, ptr %69, align 4, !tbaa !11
  %71 = sdiv i32 %68, %70
  %72 = getelementptr inbounds %"class.sptk::reaper::FFT", ptr %11, i32 0, i32 4
  store i32 %71, ptr %72, align 8, !tbaa !22
  %73 = load i32, ptr %4, align 4, !tbaa !9
  %74 = getelementptr inbounds %"class.sptk::reaper::FFT", ptr %11, i32 0, i32 3
  store i32 %73, ptr %74, align 4, !tbaa !23
  %75 = getelementptr inbounds %"class.sptk::reaper::FFT", ptr %11, i32 0, i32 2
  %76 = load i32, ptr %75, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %76
}

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

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

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

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

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

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

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


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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4sptk6reaper3FFT11makefttableEi(ptr nocapture noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = shl nuw i32 1, %1
  %4 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %3, ptr %4, align 4, !tbaa !5
  %5 = sdiv i32 %3, 2
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %5, ptr %6, align 8, !tbaa !11
  %7 = sext i32 %5 to i64
  %8 = icmp eq i32 %1, 31
  %9 = shl nsw i64 %7, 2
  %10 = select i1 %8, i64 -1, i64 %9
  %11 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %10) #3
  store ptr %11, ptr %0, align 8, !tbaa !12
  %12 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %10) #3
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %12, ptr %13, align 8, !tbaa !13
  %14 = sitofp i32 %3 to double
  %15 = fdiv double 0x401921FB54442D18, %14
  %16 = icmp sgt i32 %3, 1
  br i1 %16, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %xtraiter = and i32 %5, 1
  %17 = and i32 %3, 2147483646
  %18 = icmp eq i32 %17, 2
  br i1 %18, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %5, 1073741822
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.017 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %36, %.lr.ph ]
  %.01316 = phi ptr [ %12, %.lr.ph.preheader.new ], [ %35, %.lr.ph ]
  %.01415 = phi ptr [ %11, %.lr.ph.preheader.new ], [ %32, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %19 = uitofp nneg i32 %.017 to double
  %20 = fmul double %15, %19
  %21 = tail call double @sin(double noundef %20) #4
  %22 = fptrunc double %21 to float
  %23 = getelementptr inbounds i8, ptr %.01415, i64 4
  store float %22, ptr %.01415, align 4, !tbaa !14
  %24 = tail call double @cos(double noundef %20) #4
  %25 = fptrunc double %24 to float
  %26 = getelementptr inbounds i8, ptr %.01316, i64 4
  store float %25, ptr %.01316, align 4, !tbaa !14
  %27 = or disjoint i32 %.017, 1
  %28 = uitofp nneg i32 %27 to double
  %29 = fmul double %15, %28
  %30 = tail call double @sin(double noundef %29) #4
  %31 = fptrunc double %30 to float
  %32 = getelementptr inbounds i8, ptr %.01415, i64 8
  store float %31, ptr %23, align 4, !tbaa !14
  %33 = tail call double @cos(double noundef %29) #4
  %34 = fptrunc double %33 to float
  %35 = getelementptr inbounds i8, ptr %.01316, i64 8
  store float %34, ptr %26, align 4, !tbaa !14
  %36 = add nuw nsw i32 %.017, 2
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa.loopexit, label %.lr.ph, !llvm.loop !16

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %.lr.ph
  %37 = uitofp nneg i32 %36 to double
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph.preheader
  %.017.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %37, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.01316.unr = phi ptr [ %12, %.lr.ph.preheader ], [ %35, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.01415.unr = phi ptr [ %11, %.lr.ph.preheader ], [ %32, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %38 = fmul double %15, %.017.unr
  %39 = tail call double @sin(double noundef %38) #4
  %40 = fptrunc double %39 to float
  store float %40, ptr %.01415.unr, align 4, !tbaa !14
  %41 = tail call double @cos(double noundef %38) #4
  %42 = fptrunc double %41 to float
  store float %42, ptr %.01316.unr, align 4, !tbaa !14
  br label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.pre = load i32, ptr %6, align 8, !tbaa !11
  %.pre18 = load i32, ptr %4, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %43 = phi i32 [ %.pre18, %._crit_edge.loopexit ], [ %3, %2 ]
  %44 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %5, %2 ]
  %45 = shl nsw i32 %44, 1
  %46 = sdiv i32 %45, %43
  %47 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %46, ptr %47, align 8, !tbaa !18
  %48 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %1, ptr %48, align 4, !tbaa !19
  ret i32 %44
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #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 = { 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 #2 = { 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 #3 = { builtin allocsize(0) }
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, !10, i64 28}
!6 = !{!"_ZTSN4sptk6reaper3FFTE", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !10, i64 24}
!19 = !{!6, !10, i64 20}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass