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

; 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 @fill_reim_fft16_omegas(double noundef, ptr noundef) #1

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

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

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

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

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

28:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %29 = load i64, ptr %8, align 8, !tbaa !5
  %30 = lshr i64 %29, 1
  store i64 %30, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %31 = load double, ptr %9, align 8, !tbaa !9
  %32 = fdiv double %31, 2.000000e+00
  store double %32, ptr %11, align 8, !tbaa !9
  %33 = load double, ptr %11, align 8, !tbaa !9
  %34 = fmul double 0x401921FB54442D18, %33
  %35 = call double @cos(double noundef %34) #5
  %36 = load ptr, ptr %6, align 8, !tbaa !11
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds double, ptr %37, i64 0
  store double %35, ptr %38, align 8, !tbaa !9
  %39 = load double, ptr %11, align 8, !tbaa !9
  %40 = fmul double 0x401921FB54442D18, %39
  %41 = call double @sin(double noundef %40) #5
  %42 = load ptr, ptr %6, align 8, !tbaa !11
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  %44 = getelementptr inbounds double, ptr %43, i64 1
  store double %41, ptr %44, align 8, !tbaa !9
  %45 = load ptr, ptr %6, align 8, !tbaa !11
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = getelementptr inbounds double, ptr %46, i64 2
  store ptr %47, ptr %45, align 8, !tbaa !11
  %48 = load i64, ptr %10, align 8, !tbaa !5
  store i64 %48, ptr %8, align 8, !tbaa !5
  %49 = load double, ptr %11, align 8, !tbaa !9
  store double %49, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %50

50:                                               ; preds = %28, %3
  br label %51

51:                                               ; preds = %106, %50
  %52 = load i64, ptr %8, align 8, !tbaa !5
  %53 = icmp ugt i64 %52, 16
  br i1 %53, label %54, label %109

54:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %55 = load i64, ptr %8, align 8, !tbaa !5
  %56 = lshr i64 %55, 2
  store i64 %56, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %57 = load double, ptr %9, align 8, !tbaa !9
  %58 = fdiv double %57, 4.000000e+00
  store double %58, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  store i64 0, ptr %14, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %102, %54
  %60 = load i64, ptr %14, align 8, !tbaa !5
  %61 = load i64, ptr %4, align 8, !tbaa !5
  %62 = icmp ult i64 %60, %61
  br i1 %62, label %64, label %63

63:                                               ; preds = %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %106

64:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %65 = load double, ptr %13, align 8, !tbaa !9
  %66 = load i64, ptr %14, align 8, !tbaa !5
  %67 = load i64, ptr %8, align 8, !tbaa !5
  %68 = udiv i64 %66, %67
  %69 = trunc i64 %68 to i32
  %70 = call double @fracrevbits(i32 noundef %69)
  %71 = fdiv double %70, 4.000000e+00
  %72 = fadd double %65, %71
  store double %72, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %73 = load double, ptr %15, align 8, !tbaa !9
  %74 = fmul double 2.000000e+00, %73
  store double %74, ptr %16, align 8, !tbaa !9
  %75 = load double, ptr %16, align 8, !tbaa !9
  %76 = fmul double 0x401921FB54442D18, %75
  %77 = call double @cos(double noundef %76) #5
  %78 = load ptr, ptr %6, align 8, !tbaa !11
  %79 = load ptr, ptr %78, align 8, !tbaa !11
  %80 = getelementptr inbounds double, ptr %79, i64 0
  store double %77, ptr %80, align 8, !tbaa !9
  %81 = load double, ptr %16, align 8, !tbaa !9
  %82 = fmul double 0x401921FB54442D18, %81
  %83 = call double @sin(double noundef %82) #5
  %84 = load ptr, ptr %6, align 8, !tbaa !11
  %85 = load ptr, ptr %84, align 8, !tbaa !11
  %86 = getelementptr inbounds double, ptr %85, i64 1
  store double %83, ptr %86, align 8, !tbaa !9
  %87 = load double, ptr %15, align 8, !tbaa !9
  %88 = fmul double 0x401921FB54442D18, %87
  %89 = call double @cos(double noundef %88) #5
  %90 = load ptr, ptr %6, align 8, !tbaa !11
  %91 = load ptr, ptr %90, align 8, !tbaa !11
  %92 = getelementptr inbounds double, ptr %91, i64 2
  store double %89, ptr %92, align 8, !tbaa !9
  %93 = load double, ptr %15, align 8, !tbaa !9
  %94 = fmul double 0x401921FB54442D18, %93
  %95 = call double @sin(double noundef %94) #5
  %96 = load ptr, ptr %6, align 8, !tbaa !11
  %97 = load ptr, ptr %96, align 8, !tbaa !11
  %98 = getelementptr inbounds double, ptr %97, i64 3
  store double %95, ptr %98, align 8, !tbaa !9
  %99 = load ptr, ptr %6, align 8, !tbaa !11
  %100 = load ptr, ptr %99, align 8, !tbaa !11
  %101 = getelementptr inbounds double, ptr %100, i64 4
  store ptr %101, ptr %99, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  br label %102

102:                                              ; preds = %64
  %103 = load i64, ptr %8, align 8, !tbaa !5
  %104 = load i64, ptr %14, align 8, !tbaa !5
  %105 = add i64 %104, %103
  store i64 %105, ptr %14, align 8, !tbaa !5
  br label %59, !llvm.loop !13

106:                                              ; preds = %63
  %107 = load i64, ptr %12, align 8, !tbaa !5
  store i64 %107, ptr %8, align 8, !tbaa !5
  %108 = load double, ptr %13, align 8, !tbaa !9
  store double %108, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %51, !llvm.loop !15

109:                                              ; preds = %51
  %110 = load i64, ptr %8, align 8, !tbaa !5
  %111 = icmp ne i64 %110, 16
  br i1 %111, label %112, label %113

112:                                              ; preds = %109
  call void @abort() #6
  unreachable

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

114:                                              ; preds = %128, %113
  %115 = load i64, ptr %17, align 8, !tbaa !5
  %116 = load i64, ptr %4, align 8, !tbaa !5
  %117 = icmp ult i64 %115, %116
  br i1 %117, label %119, label %118

118:                                              ; preds = %114
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  br label %131

119:                                              ; preds = %114
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  %120 = load double, ptr %9, align 8, !tbaa !9
  %121 = load i64, ptr %17, align 8, !tbaa !5
  %122 = udiv i64 %121, 16
  %123 = trunc i64 %122 to i32
  %124 = call double @fracrevbits(i32 noundef %123)
  %125 = fadd double %120, %124
  store double %125, ptr %18, align 8, !tbaa !9
  %126 = load double, ptr %18, align 8, !tbaa !9
  %127 = load ptr, ptr %6, align 8, !tbaa !11
  call void @fill_reim_fft16_omegas(double noundef %126, ptr noundef %127)
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  br label %128

128:                                              ; preds = %119
  %129 = load i64, ptr %17, align 8, !tbaa !5
  %130 = add i64 %129, 16
  store i64 %130, ptr %17, align 8, !tbaa !5
  br label %114, !llvm.loop !16

131:                                              ; preds = %118
  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
  ret void
}

declare double @fracrevbits(i32 noundef) #4

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 = { 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 #4 = { "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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !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 @fill_reim_fft16_omegas(double noundef, ptr noundef) local_unnamed_addr #0

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

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

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

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

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

8:                                                ; preds = %3
  %9 = lshr i64 %0, 1
  %10 = fmul double %1, 5.000000e-01
  %11 = fmul double %10, 0x401921FB54442D18
  %12 = tail call double @cos(double noundef %11) #4
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  store double %12, ptr %13, align 8, !tbaa !9
  %14 = tail call double @sin(double noundef %11) #4
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  store double %14, ptr %16, align 8, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %15, i64 16
  store ptr %17, ptr %2, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %8, %3
  %.043 = phi double [ %10, %8 ], [ %1, %3 ]
  %.0 = phi i64 [ %9, %8 ], [ %0, %3 ]
  %19 = icmp ugt i64 %.0, 16
  br i1 %19, label %.lr.ph50, label %._crit_edge

.lr.ph50:                                         ; preds = %18
  %.not55 = icmp eq i64 %0, 0
  br i1 %.not55, label %.loopexit, label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph50, %..loopexit_crit_edge.us
  %.149.us = phi i64 [ %44, %..loopexit_crit_edge.us ], [ %.0, %.lr.ph50 ]
  %.14448.us = phi double [ %20, %..loopexit_crit_edge.us ], [ %.043, %.lr.ph50 ]
  %20 = fmul double %.14448.us, 2.500000e-01
  br label %21

21:                                               ; preds = %.lr.ph.us, %21
  %.04547.us = phi i64 [ 0, %.lr.ph.us ], [ %42, %21 ]
  %22 = udiv i64 %.04547.us, %.149.us
  %23 = trunc i64 %22 to i32
  %24 = tail call double @fracrevbits(i32 noundef %23) #4
  %25 = fmul double %24, 2.500000e-01
  %26 = fadd double %20, %25
  %27 = fmul double %26, 2.000000e+00
  %28 = fmul double %27, 0x401921FB54442D18
  %29 = tail call double @cos(double noundef %28) #4
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  store double %29, ptr %30, align 8, !tbaa !9
  %31 = tail call double @sin(double noundef %28) #4
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  store double %31, ptr %33, align 8, !tbaa !9
  %34 = fmul double %26, 0x401921FB54442D18
  %35 = tail call double @cos(double noundef %34) #4
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 16
  store double %35, ptr %37, align 8, !tbaa !9
  %38 = tail call double @sin(double noundef %34) #4
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 24
  store double %38, ptr %40, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %39, i64 32
  store ptr %41, ptr %2, align 8, !tbaa !5
  %42 = add i64 %.04547.us, %.149.us
  %43 = icmp ult i64 %42, %0
  br i1 %43, label %21, label %..loopexit_crit_edge.us, !llvm.loop !11

..loopexit_crit_edge.us:                          ; preds = %21
  %44 = lshr i64 %.149.us, 2
  %45 = icmp ugt i64 %.149.us, 67
  br i1 %45, label %.lr.ph.us, label %._crit_edge, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph50, %.loopexit
  %.149 = phi i64 [ %46, %.loopexit ], [ %.0, %.lr.ph50 ]
  %.14448 = phi double [ %47, %.loopexit ], [ %.043, %.lr.ph50 ]
  %46 = lshr i64 %.149, 2
  %47 = fmul double %.14448, 2.500000e-01
  %48 = icmp ugt i64 %.149, 67
  br i1 %48, label %.loopexit, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %..loopexit_crit_edge.us, %.loopexit, %18
  %.144.lcssa = phi double [ %.043, %18 ], [ %47, %.loopexit ], [ %20, %..loopexit_crit_edge.us ]
  %.1.lcssa = phi i64 [ %.0, %18 ], [ %46, %.loopexit ], [ %44, %..loopexit_crit_edge.us ]
  %.not46 = icmp eq i64 %.1.lcssa, 16
  br i1 %.not46, label %.preheader, label %49

.preheader:                                       ; preds = %._crit_edge
  %.not56 = icmp eq i64 %0, 0
  br i1 %.not56, label %._crit_edge54, label %.lr.ph

49:                                               ; preds = %._crit_edge
  tail call void @abort() #5
  unreachable

._crit_edge54:                                    ; preds = %.lr.ph, %.preheader
  ret void

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.04253 = phi i64 [ %54, %.lr.ph ], [ 0, %.preheader ]
  %50 = lshr exact i64 %.04253, 4
  %51 = trunc i64 %50 to i32
  %52 = tail call double @fracrevbits(i32 noundef %51) #4
  %53 = fadd double %.144.lcssa, %52
  tail call void @fill_reim_fft16_omegas(double noundef %53, ptr noundef %2)
  %54 = add i64 %.04253, 16
  %55 = icmp ult i64 %54, %0
  br i1 %55, label %.lr.ph, label %._crit_edge54, !llvm.loop !14
}

declare double @fracrevbits(i32 noundef) local_unnamed_addr #3

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 = { 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 }
attributes #5 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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