; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/cplx (cplx_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"

; 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: nounwind uwtable
declare dso_local void @cplx_set_e2pix(ptr noundef, double noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @fill_cplx_fft_omegas_bfs_16(double noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  %13 = alloca double, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca double, align 8
  %17 = alloca i32, align 4
  store double %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %18 = load i32, ptr %6, align 4, !tbaa !11
  store i32 %18, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %19 = load i32, ptr %6, align 4, !tbaa !11
  %20 = uitofp i32 %19 to double
  %21 = call double @log2(double noundef %20) #4
  %22 = fptoui double %21 to i32
  store i32 %22, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %23 = load double, ptr %4, align 8, !tbaa !5
  store double %23, ptr %9, align 8, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !11
  %25 = urem i32 %24, 2
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %69

27:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %28 = load i32, ptr %7, align 4, !tbaa !11
  %29 = udiv i32 %28, 2
  store i32 %29, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %30 = load double, ptr %9, align 8, !tbaa !5
  %31 = fdiv double %30, 2.000000e+00
  store double %31, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %32

32:                                               ; preds = %63, %27
  %33 = load i32, ptr %12, align 4, !tbaa !11
  %34 = load i32, ptr %6, align 4, !tbaa !11
  %35 = load i32, ptr %7, align 4, !tbaa !11
  %36 = udiv i32 %34, %35
  %37 = icmp ult i32 %33, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %66

39:                                               ; preds = %32
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds ptr, ptr %40, i64 0
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds [2 x double], ptr %42, i64 0
  %44 = getelementptr inbounds [2 x double], ptr %43, i64 0, i64 0
  %45 = load double, ptr %11, align 8, !tbaa !5
  %46 = load i32, ptr %12, align 4, !tbaa !11
  %47 = call double @fracrevbits(i32 noundef %46)
  %48 = fdiv double %47, 2.000000e+00
  %49 = fadd double %45, %48
  call void @cplx_set_e2pix(ptr noundef %44, double noundef %49)
  %50 = load ptr, ptr %5, align 8, !tbaa !9
  %51 = getelementptr inbounds ptr, ptr %50, i64 0
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = getelementptr inbounds [2 x double], ptr %52, i64 1
  %54 = getelementptr inbounds [2 x double], ptr %53, i64 0, i64 0
  %55 = load ptr, ptr %5, align 8, !tbaa !9
  %56 = getelementptr inbounds ptr, ptr %55, i64 0
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  %58 = getelementptr inbounds [2 x double], ptr %57, i64 0
  %59 = getelementptr inbounds [2 x double], ptr %58, i64 0, i64 0
  call void @cplx_set(ptr noundef %54, ptr noundef %59)
  %60 = load ptr, ptr %5, align 8, !tbaa !9
  %61 = load ptr, ptr %60, align 8, !tbaa !9
  %62 = getelementptr inbounds [2 x double], ptr %61, i64 2
  store ptr %62, ptr %60, align 8, !tbaa !9
  br label %63

63:                                               ; preds = %39
  %64 = load i32, ptr %12, align 4, !tbaa !11
  %65 = add i32 %64, 1
  store i32 %65, ptr %12, align 4, !tbaa !11
  br label %32, !llvm.loop !13

66:                                               ; preds = %38
  %67 = load i32, ptr %10, align 4, !tbaa !11
  store i32 %67, ptr %7, align 4, !tbaa !11
  %68 = load double, ptr %11, align 8, !tbaa !5
  store double %68, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %69

69:                                               ; preds = %66, %3
  br label %70

70:                                               ; preds = %110, %69
  %71 = load i32, ptr %7, align 4, !tbaa !11
  %72 = icmp ugt i32 %71, 16
  br i1 %72, label %73, label %113

73:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %74 = load double, ptr %9, align 8, !tbaa !5
  %75 = fdiv double %74, 4.000000e+00
  store double %75, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %76 = load i32, ptr %7, align 4, !tbaa !11
  %77 = udiv i32 %76, 4
  store i32 %77, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !11
  br label %78

78:                                               ; preds = %107, %73
  %79 = load i32, ptr %15, align 4, !tbaa !11
  %80 = load i32, ptr %6, align 4, !tbaa !11
  %81 = load i32, ptr %7, align 4, !tbaa !11
  %82 = udiv i32 %80, %81
  %83 = icmp ult i32 %79, %82
  br i1 %83, label %85, label %84

84:                                               ; preds = %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %110

85:                                               ; preds = %78
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %86 = load double, ptr %13, align 8, !tbaa !5
  %87 = load i32, ptr %15, align 4, !tbaa !11
  %88 = call double @fracrevbits(i32 noundef %87)
  %89 = fdiv double %88, 4.000000e+00
  %90 = fadd double %86, %89
  store double %90, ptr %16, align 8, !tbaa !5
  %91 = load ptr, ptr %5, align 8, !tbaa !9
  %92 = getelementptr inbounds ptr, ptr %91, i64 0
  %93 = load ptr, ptr %92, align 8, !tbaa !9
  %94 = getelementptr inbounds [2 x double], ptr %93, i64 0
  %95 = getelementptr inbounds [2 x double], ptr %94, i64 0, i64 0
  %96 = load double, ptr %16, align 8, !tbaa !5
  %97 = fmul double 2.000000e+00, %96
  call void @cplx_set_e2pix(ptr noundef %95, double noundef %97)
  %98 = load ptr, ptr %5, align 8, !tbaa !9
  %99 = getelementptr inbounds ptr, ptr %98, i64 0
  %100 = load ptr, ptr %99, align 8, !tbaa !9
  %101 = getelementptr inbounds [2 x double], ptr %100, i64 1
  %102 = getelementptr inbounds [2 x double], ptr %101, i64 0, i64 0
  %103 = load double, ptr %16, align 8, !tbaa !5
  call void @cplx_set_e2pix(ptr noundef %102, double noundef %103)
  %104 = load ptr, ptr %5, align 8, !tbaa !9
  %105 = load ptr, ptr %104, align 8, !tbaa !9
  %106 = getelementptr inbounds [2 x double], ptr %105, i64 2
  store ptr %106, ptr %104, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  br label %107

107:                                              ; preds = %85
  %108 = load i32, ptr %15, align 4, !tbaa !11
  %109 = add i32 %108, 1
  store i32 %109, ptr %15, align 4, !tbaa !11
  br label %78, !llvm.loop !15

110:                                              ; preds = %84
  %111 = load i32, ptr %14, align 4, !tbaa !11
  store i32 %111, ptr %7, align 4, !tbaa !11
  %112 = load double, ptr %13, align 8, !tbaa !5
  store double %112, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %70, !llvm.loop !16

113:                                              ; preds = %70
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  store i32 0, ptr %17, align 4, !tbaa !11
  br label %114

114:                                              ; preds = %126, %113
  %115 = load i32, ptr %17, align 4, !tbaa !11
  %116 = load i32, ptr %6, align 4, !tbaa !11
  %117 = udiv i32 %116, 16
  %118 = icmp ult i32 %115, %117
  br i1 %118, label %120, label %119

119:                                              ; preds = %114
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %129

120:                                              ; preds = %114
  %121 = load double, ptr %9, align 8, !tbaa !5
  %122 = load i32, ptr %17, align 4, !tbaa !11
  %123 = call double @fracrevbits(i32 noundef %122)
  %124 = fadd double %121, %123
  %125 = load ptr, ptr %5, align 8, !tbaa !9
  call void @cplx_fft16_precomp(double noundef %124, ptr noundef %125)
  br label %126

126:                                              ; preds = %120
  %127 = load i32, ptr %17, align 4, !tbaa !11
  %128 = add i32 %127, 1
  store i32 %128, ptr %17, align 4, !tbaa !11
  br label %114, !llvm.loop !17

129:                                              ; preds = %119
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

declare double @fracrevbits(i32 noundef) #3

declare void @cplx_set(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 = { 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 }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}


; 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: nounwind uwtable
declare dso_local void @cplx_set_e2pix(ptr noundef, double noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @fill_cplx_fft_omegas_bfs_16(double noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = uitofp i32 %2 to double
  %5 = tail call double @log2(double noundef %4) #3
  %6 = fptoui double %5 to i32
  %7 = and i32 %6, 1
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %18, label %.critedge

.critedge:                                        ; preds = %3
  %8 = lshr i32 %2, 1
  %9 = fmul double %0, 5.000000e-01
  %10 = load ptr, ptr %1, align 8, !tbaa !5
  %11 = tail call double @fracrevbits(i32 noundef 0) #3
  %12 = fmul double %11, 5.000000e-01
  %13 = fadd double %9, %12
  tail call void @cplx_set_e2pix(ptr noundef %10, double noundef %13)
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  tail call void @cplx_set(ptr noundef nonnull %15, ptr noundef %14) #3
  %16 = load ptr, ptr %1, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 32
  store ptr %17, ptr %1, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %.critedge, %3
  %.041 = phi double [ %9, %.critedge ], [ %0, %3 ]
  %.039 = phi i32 [ %8, %.critedge ], [ %2, %3 ]
  %19 = icmp ugt i32 %.039, 16
  br i1 %19, label %.lr.ph47, label %.preheader

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph47
  %20 = icmp ugt i32 %.146, 67
  br i1 %20, label %.lr.ph47, label %.preheader, !llvm.loop !9

.preheader:                                       ; preds = %.loopexit, %18
  %.142.lcssa = phi double [ %.041, %18 ], [ %22, %.loopexit ]
  %21 = lshr i32 %2, 4
  %.not51 = icmp ult i32 %2, 16
  br i1 %.not51, label %._crit_edge, label %.lr.ph49

.lr.ph47:                                         ; preds = %18, %.loopexit
  %.146 = phi i32 [ %23, %.loopexit ], [ %.039, %18 ]
  %.14245 = phi double [ %22, %.loopexit ], [ %.041, %18 ]
  %22 = fmul double %.14245, 2.500000e-01
  %23 = lshr i32 %.146, 2
  %24 = udiv i32 %2, %.146
  %.not50 = icmp ugt i32 %.146, %2
  br i1 %.not50, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph47, %.lr.ph
  %.04044 = phi i32 [ %34, %.lr.ph ], [ 0, %.lr.ph47 ]
  %25 = tail call double @fracrevbits(i32 noundef %.04044) #3
  %26 = fmul double %25, 2.500000e-01
  %27 = fadd double %22, %26
  %28 = load ptr, ptr %1, align 8, !tbaa !5
  %29 = fmul double %27, 2.000000e+00
  tail call void @cplx_set_e2pix(ptr noundef %28, double noundef %29)
  %30 = load ptr, ptr %1, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  tail call void @cplx_set_e2pix(ptr noundef nonnull %31, double noundef %27)
  %32 = load ptr, ptr %1, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 32
  store ptr %33, ptr %1, align 8, !tbaa !5
  %34 = add nuw nsw i32 %.04044, 1
  %35 = icmp ult i32 %34, %24
  br i1 %35, label %.lr.ph, label %.loopexit, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph49, %.preheader
  ret void

.lr.ph49:                                         ; preds = %.preheader, %.lr.ph49
  %.048 = phi i32 [ %38, %.lr.ph49 ], [ 0, %.preheader ]
  %36 = tail call double @fracrevbits(i32 noundef %.048) #3
  %37 = fadd double %.142.lcssa, %36
  tail call void @cplx_fft16_precomp(double noundef %37, ptr noundef %1)
  %38 = add nuw nsw i32 %.048, 1
  %exitcond.not = icmp eq i32 %38, %21
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph49, !llvm.loop !12
}

declare double @fracrevbits(i32 noundef) local_unnamed_addr #2

declare void @cplx_set(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { 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 #2 = { "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 }

!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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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