; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/reim (reim_fft_ref)

; 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.reim_fft_precomp = type { ptr, i64, i64, ptr, ptr }

@__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] }

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

; Function Attrs: nounwind uwtable
define dso_local ptr @new_reim_fft_precomp(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = mul i32 2, %11
  %13 = zext i32 %12 to i64
  %14 = mul i64 %13, 8
  %15 = call i64 @ceilto64b(i64 noundef %14)
  store i64 %15, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = mul i32 2, %16
  %18 = zext i32 %17 to i64
  %19 = mul i64 %18, 8
  %20 = call i64 @ceilto64b(i64 noundef %19)
  store i64 %20, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = add i64 103, %21
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = mul i64 %24, %25
  %27 = add i64 %22, %26
  %28 = call noalias ptr @malloc(i64 noundef %27) #6
  store ptr %28, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %29 = load ptr, ptr %7, align 8, !tbaa !11
  %30 = ptrtoint ptr %29 to i64
  %31 = add i64 %30, 40
  %32 = call i64 @ceilto64b(i64 noundef %31)
  store i64 %32, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %33 = load ptr, ptr %7, align 8, !tbaa !11
  store ptr %33, ptr %9, align 8, !tbaa !11
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = zext i32 %34 to i64
  %36 = load ptr, ptr %9, align 8, !tbaa !11
  %37 = getelementptr inbounds %struct.reim_fft_precomp, ptr %36, i32 0, i32 1
  store i64 %35, ptr %37, align 8, !tbaa !13
  %38 = load i64, ptr %6, align 8, !tbaa !9
  %39 = load ptr, ptr %9, align 8, !tbaa !11
  %40 = getelementptr inbounds %struct.reim_fft_precomp, ptr %39, i32 0, i32 2
  store i64 %38, ptr %40, align 8, !tbaa !15
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = inttoptr i64 %41 to ptr
  %43 = load ptr, ptr %9, align 8, !tbaa !11
  %44 = getelementptr inbounds %struct.reim_fft_precomp, ptr %43, i32 0, i32 3
  store ptr %42, ptr %44, align 8, !tbaa !16
  %45 = load i64, ptr %8, align 8, !tbaa !9
  %46 = load i64, ptr %5, align 8, !tbaa !9
  %47 = add i64 %45, %46
  %48 = inttoptr i64 %47 to ptr
  %49 = load ptr, ptr %9, align 8, !tbaa !11
  %50 = getelementptr inbounds %struct.reim_fft_precomp, ptr %49, i32 0, i32 4
  store ptr %48, ptr %50, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %51 = load ptr, ptr %9, align 8, !tbaa !11
  %52 = getelementptr inbounds %struct.reim_fft_precomp, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !16
  store ptr %53, ptr %10, align 8, !tbaa !11
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = icmp ule i32 %54, 16
  br i1 %55, label %56, label %64

56:                                               ; preds = %2
  %57 = load i32, ptr %3, align 4, !tbaa !5
  switch i32 %57, label %62 [
    i32 1, label %63
    i32 2, label %58
    i32 4, label %59
    i32 8, label %60
    i32 16, label %61
  ]

58:                                               ; preds = %56
  call void @fill_reim_fft2_omegas(double noundef 2.500000e-01, ptr noundef %10)
  br label %63

59:                                               ; preds = %56
  call void @fill_reim_fft4_omegas(double noundef 2.500000e-01, ptr noundef %10)
  br label %63

60:                                               ; preds = %56
  call void @fill_reim_fft8_omegas(double noundef 2.500000e-01, ptr noundef %10)
  br label %63

61:                                               ; preds = %56
  call void @fill_reim_fft16_omegas(double noundef 2.500000e-01, ptr noundef %10)
  br label %63

62:                                               ; preds = %56
  call void @abort() #7
  unreachable

63:                                               ; preds = %61, %60, %59, %58, %56
  br label %74

64:                                               ; preds = %2
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = icmp ule i32 %65, 2048
  br i1 %66, label %67, label %70

67:                                               ; preds = %64
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = zext i32 %68 to i64
  call void @fill_reim_fft_bfs_16_omegas(i64 noundef %69, double noundef 2.500000e-01, ptr noundef %10)
  br label %73

70:                                               ; preds = %64
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = zext i32 %71 to i64
  call void @fill_reim_fft_rec_16_omegas(i64 noundef %72, double noundef 2.500000e-01, ptr noundef %10)
  br label %73

73:                                               ; preds = %70, %67
  br label %74

74:                                               ; preds = %73, %63
  %75 = load ptr, ptr %10, align 8, !tbaa !11
  %76 = ptrtoint ptr %75 to i64
  %77 = load i64, ptr %8, align 8, !tbaa !9
  %78 = sub i64 %76, %77
  %79 = load i64, ptr %5, align 8, !tbaa !9
  %80 = icmp ugt i64 %78, %79
  br i1 %80, label %81, label %82

81:                                               ; preds = %74
  call void @abort() #7
  unreachable

82:                                               ; preds = %74
  %83 = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
  %84 = and i32 %83, 16384
  %85 = icmp eq i32 %84, 16384
  %86 = and i1 true, %85
  br i1 %86, label %87, label %90

87:                                               ; preds = %82
  %88 = load ptr, ptr %9, align 8, !tbaa !11
  %89 = getelementptr inbounds %struct.reim_fft_precomp, ptr %88, i32 0, i32 0
  store ptr @reim_fft_avx2_fma, ptr %89, align 8, !tbaa !18
  br label %93

90:                                               ; preds = %82
  %91 = load ptr, ptr %9, align 8, !tbaa !11
  %92 = getelementptr inbounds %struct.reim_fft_precomp, ptr %91, i32 0, i32 0
  store ptr @reim_fft_ref, ptr %92, align 8, !tbaa !18
  br label %93

93:                                               ; preds = %90, %87
  %94 = load ptr, ptr %7, align 8, !tbaa !11
  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 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %94
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @fill_reim_fft16_omegas(double noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @fill_reim_fft8_omegas(double noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @fill_reim_fft4_omegas(double noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @fill_reim_fft2_omegas(double noundef, ptr noundef) #1

; Function Attrs: noreturn nounwind
declare void @abort() #2

; Function Attrs: nounwind uwtable
declare dso_local void @fill_reim_fft_bfs_16_omegas(i64 noundef, double noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @fill_reim_fft_rec_16_omegas(i64 noundef, double noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @reim_fft_ref(ptr noundef, ptr noundef) #1

declare i64 @ceilto64b(i64 noundef) #3

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

declare void @reim_fft_avx2_fma(ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { noreturn 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 = { "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 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 = { nounwind allocsize(0) }
attributes #7 = { noreturn 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"reim_fft_precomp", !12, i64 0, !10, i64 8, !10, i64 16, !12, i64 24, !12, i64 32}
!15 = !{!14, !10, i64 16}
!16 = !{!14, !12, i64 24}
!17 = !{!14, !12, i64 32}
!18 = !{!14, !12, 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"

@__cpu_model = external dso_local local_unnamed_addr global { i32, i32, i32, [1 x i32] }

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @new_reim_fft_precomp(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca ptr, align 8
  %4 = shl i32 %0, 1
  %5 = zext i32 %4 to i64
  %6 = shl nuw nsw i64 %5, 3
  %7 = tail call i64 @ceilto64b(i64 noundef %6) #5
  %8 = tail call i64 @ceilto64b(i64 noundef %6) #5
  %9 = add i64 %7, 103
  %10 = zext i32 %1 to i64
  %11 = mul i64 %8, %10
  %12 = add i64 %9, %11
  %13 = tail call noalias ptr @malloc(i64 noundef %12) #6
  %14 = ptrtoint ptr %13 to i64
  %15 = add i64 %14, 40
  %16 = tail call i64 @ceilto64b(i64 noundef %15) #5
  %17 = zext i32 %0 to i64
  %18 = getelementptr inbounds i8, ptr %13, i64 8
  store i64 %17, ptr %18, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %13, i64 16
  store i64 %8, ptr %19, align 8, !tbaa !11
  %20 = inttoptr i64 %16 to ptr
  %21 = getelementptr inbounds i8, ptr %13, i64 24
  store ptr %20, ptr %21, align 8, !tbaa !12
  %22 = add i64 %16, %7
  %23 = inttoptr i64 %22 to ptr
  %24 = getelementptr inbounds i8, ptr %13, i64 32
  store ptr %23, ptr %24, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  store ptr %20, ptr %3, align 8, !tbaa !14
  %25 = icmp ult i32 %0, 17
  br i1 %25, label %26, label %32

26:                                               ; preds = %2
  switch i32 %0, label %31 [
    i32 1, label %36
    i32 2, label %27
    i32 4, label %28
    i32 8, label %29
    i32 16, label %30
  ]

27:                                               ; preds = %26
  call void @fill_reim_fft2_omegas(double noundef 2.500000e-01, ptr noundef nonnull %3)
  br label %36

28:                                               ; preds = %26
  call void @fill_reim_fft4_omegas(double noundef 2.500000e-01, ptr noundef nonnull %3)
  br label %36

29:                                               ; preds = %26
  call void @fill_reim_fft8_omegas(double noundef 2.500000e-01, ptr noundef nonnull %3)
  br label %36

30:                                               ; preds = %26
  call void @fill_reim_fft16_omegas(double noundef 2.500000e-01, ptr noundef nonnull %3)
  br label %36

31:                                               ; preds = %26
  tail call void @abort() #7
  unreachable

32:                                               ; preds = %2
  %33 = icmp ult i32 %0, 2049
  br i1 %33, label %34, label %35

34:                                               ; preds = %32
  call void @fill_reim_fft_bfs_16_omegas(i64 noundef %17, double noundef 2.500000e-01, ptr noundef nonnull %3)
  br label %36

35:                                               ; preds = %32
  call void @fill_reim_fft_rec_16_omegas(i64 noundef %17, double noundef 2.500000e-01, ptr noundef nonnull %3)
  br label %36

36:                                               ; preds = %34, %35, %26, %27, %28, %29, %30
  %37 = load ptr, ptr %3, align 8, !tbaa !14
  %38 = ptrtoint ptr %37 to i64
  %39 = sub i64 %38, %16
  %40 = icmp ugt i64 %39, %7
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  call void @abort() #7
  unreachable

42:                                               ; preds = %36
  %43 = load i32, ptr getelementptr inbounds (i8, ptr @__cpu_model, i64 12), align 4
  %44 = and i32 %43, 16384
  %.not = icmp eq i32 %44, 0
  %reim_fft_ref.reim_fft_avx2_fma = select i1 %.not, ptr @reim_fft_ref, ptr @reim_fft_avx2_fma
  store ptr %reim_fft_ref.reim_fft_avx2_fma, ptr %13, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  ret ptr %13
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @fill_reim_fft16_omegas(double noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @fill_reim_fft8_omegas(double noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @fill_reim_fft4_omegas(double noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @fill_reim_fft2_omegas(double noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @fill_reim_fft_bfs_16_omegas(i64 noundef, double noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @fill_reim_fft_rec_16_omegas(i64 noundef, double noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @reim_fft_ref(ptr noundef, ptr noundef) #1

declare i64 @ceilto64b(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

declare void @reim_fft_avx2_fma(ptr noundef, ptr noundef) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { noreturn 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 = { "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind allocsize(0) }
attributes #7 = { noreturn 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 8}
!6 = !{!"reim_fft_precomp", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !7, i64 24}
!13 = !{!6, !7, i64 32}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass