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

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

; Function Attrs: nounwind uwtable
define dso_local void @cplx_bitwiddle_fft_ref(i32 noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %13, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [2 x double], ptr %14, i64 %16
  store ptr %17, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = mul nsw i32 2, %19
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [2 x double], ptr %18, i64 %21
  store ptr %22, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = mul nsw i32 3, %24
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [2 x double], ptr %23, i64 %26
  store ptr %27, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store i64 0, ptr %11, align 8, !tbaa !11
  br label %28

28:                                               ; preds = %57, %3
  %29 = load i64, ptr %11, align 8, !tbaa !11
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = icmp ult i64 %29, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %60

34:                                               ; preds = %28
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = load i64, ptr %11, align 8, !tbaa !11
  %37 = getelementptr inbounds [2 x double], ptr %35, i64 %36
  %38 = getelementptr inbounds [2 x double], ptr %37, i64 0, i64 0
  %39 = load ptr, ptr %9, align 8, !tbaa !9
  %40 = load i64, ptr %11, align 8, !tbaa !11
  %41 = getelementptr inbounds [2 x double], ptr %39, i64 %40
  %42 = getelementptr inbounds [2 x double], ptr %41, i64 0, i64 0
  %43 = load ptr, ptr %6, align 8, !tbaa !9
  %44 = getelementptr inbounds [2 x double], ptr %43, i64 0
  %45 = getelementptr inbounds [2 x double], ptr %44, i64 0, i64 0
  call void @ctwiddle(ptr noundef %38, ptr noundef %42, ptr noundef %45)
  %46 = load ptr, ptr %8, align 8, !tbaa !9
  %47 = load i64, ptr %11, align 8, !tbaa !11
  %48 = getelementptr inbounds [2 x double], ptr %46, i64 %47
  %49 = getelementptr inbounds [2 x double], ptr %48, i64 0, i64 0
  %50 = load ptr, ptr %10, align 8, !tbaa !9
  %51 = load i64, ptr %11, align 8, !tbaa !11
  %52 = getelementptr inbounds [2 x double], ptr %50, i64 %51
  %53 = getelementptr inbounds [2 x double], ptr %52, i64 0, i64 0
  %54 = load ptr, ptr %6, align 8, !tbaa !9
  %55 = getelementptr inbounds [2 x double], ptr %54, i64 0
  %56 = getelementptr inbounds [2 x double], ptr %55, i64 0, i64 0
  call void @ctwiddle(ptr noundef %49, ptr noundef %53, ptr noundef %56)
  br label %57

57:                                               ; preds = %34
  %58 = load i64, ptr %11, align 8, !tbaa !11
  %59 = add i64 %58, 1
  store i64 %59, ptr %11, align 8, !tbaa !11
  br label %28, !llvm.loop !13

60:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  store i64 0, ptr %12, align 8, !tbaa !11
  br label %61

61:                                               ; preds = %90, %60
  %62 = load i64, ptr %12, align 8, !tbaa !11
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = icmp ult i64 %62, %64
  br i1 %65, label %67, label %66

66:                                               ; preds = %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %93

67:                                               ; preds = %61
  %68 = load ptr, ptr %7, align 8, !tbaa !9
  %69 = load i64, ptr %12, align 8, !tbaa !11
  %70 = getelementptr inbounds [2 x double], ptr %68, i64 %69
  %71 = getelementptr inbounds [2 x double], ptr %70, i64 0, i64 0
  %72 = load ptr, ptr %8, align 8, !tbaa !9
  %73 = load i64, ptr %12, align 8, !tbaa !11
  %74 = getelementptr inbounds [2 x double], ptr %72, i64 %73
  %75 = getelementptr inbounds [2 x double], ptr %74, i64 0, i64 0
  %76 = load ptr, ptr %6, align 8, !tbaa !9
  %77 = getelementptr inbounds [2 x double], ptr %76, i64 1
  %78 = getelementptr inbounds [2 x double], ptr %77, i64 0, i64 0
  call void @ctwiddle(ptr noundef %71, ptr noundef %75, ptr noundef %78)
  %79 = load ptr, ptr %9, align 8, !tbaa !9
  %80 = load i64, ptr %12, align 8, !tbaa !11
  %81 = getelementptr inbounds [2 x double], ptr %79, i64 %80
  %82 = getelementptr inbounds [2 x double], ptr %81, i64 0, i64 0
  %83 = load ptr, ptr %10, align 8, !tbaa !9
  %84 = load i64, ptr %12, align 8, !tbaa !11
  %85 = getelementptr inbounds [2 x double], ptr %83, i64 %84
  %86 = getelementptr inbounds [2 x double], ptr %85, i64 0, i64 0
  %87 = load ptr, ptr %6, align 8, !tbaa !9
  %88 = getelementptr inbounds [2 x double], ptr %87, i64 1
  %89 = getelementptr inbounds [2 x double], ptr %88, i64 0, i64 0
  call void @citwiddle(ptr noundef %82, ptr noundef %86, ptr noundef %89)
  br label %90

90:                                               ; preds = %67
  %91 = load i64, ptr %12, align 8, !tbaa !11
  %92 = add i64 %91, 1
  store i64 %92, ptr %12, align 8, !tbaa !11
  br label %61, !llvm.loop !15

93:                                               ; preds = %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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 @ctwiddle(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @cplx_bitwiddle_fft_ref(i32 noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [2 x double], ptr %1, i64 %4
  %6 = shl nsw i32 %0, 1
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [2 x double], ptr %1, i64 %7
  %9 = mul nsw i32 %0, 3
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [2 x double], ptr %1, i64 %10
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  br i1 %.not, label %._crit_edge, label %.lr.ph36

.lr.ph36:                                         ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %2, i64 16
  br label %18

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.03234 = phi i64 [ %17, %.lr.ph ], [ 0, %3 ]
  %13 = getelementptr inbounds [2 x double], ptr %1, i64 %.03234
  %14 = getelementptr inbounds [2 x double], ptr %8, i64 %.03234
  tail call void @ctwiddle(ptr noundef %13, ptr noundef nonnull %14, ptr noundef %2)
  %15 = getelementptr inbounds [2 x double], ptr %5, i64 %.03234
  %16 = getelementptr inbounds [2 x double], ptr %11, i64 %.03234
  tail call void @ctwiddle(ptr noundef nonnull %15, ptr noundef nonnull %16, ptr noundef %2)
  %17 = add nuw i64 %.03234, 1
  %exitcond.not = icmp eq i64 %17, %4
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %18, %3, %.preheader
  ret void

18:                                               ; preds = %.lr.ph36, %18
  %.035 = phi i64 [ 0, %.lr.ph36 ], [ %23, %18 ]
  %19 = getelementptr inbounds [2 x double], ptr %1, i64 %.035
  %20 = getelementptr inbounds [2 x double], ptr %5, i64 %.035
  tail call void @ctwiddle(ptr noundef %19, ptr noundef nonnull %20, ptr noundef nonnull %12)
  %21 = getelementptr inbounds [2 x double], ptr %8, i64 %.035
  %22 = getelementptr inbounds [2 x double], ptr %11, i64 %.035
  tail call void @citwiddle(ptr noundef nonnull %21, ptr noundef nonnull %22, ptr noundef nonnull %12)
  %23 = add nuw i64 %.035, 1
  %exitcond38.not = icmp eq i64 %23, %4
  br i1 %exitcond38.not, label %._crit_edge, label %18, !llvm.loop !7
}

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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