; LLVM IR from shamadee/web-dsp-demo :: cpp (dft)

; 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.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%struct.DFT = type { ptr }
%struct.FFT = type { ptr, ptr, i32, i32 }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.3 = external hidden unnamed_addr constant [28 x i8], align 1

; 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

declare i32 @printf(ptr noundef, ...) #1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3DFT7forwardEPdi(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i32 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3FFT7forwardEPdi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, i32 noundef) #3 align 2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [128 x double], align 16
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.DFT, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct.FFT, align 8
  store i32 0, ptr %1, align 4
  %13 = load ptr, ptr @_ZSt4cout, align 8, !tbaa !5
  %14 = getelementptr i8, ptr %13, i64 -24
  %15 = load i64, ptr %14, align 8
  %16 = getelementptr inbounds i8, ptr @_ZSt4cout, i64 %15
  %17 = call noundef i64 @_ZNSt8ios_base9precisionEl(ptr noundef nonnull align 8 dereferenceable(216) %16, i64 noundef 20)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 5000, ptr %2, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 1024, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 0, ptr %4, align 4, !tbaa !8
  br label %18

18:                                               ; preds = %35, %0
  %19 = load i32, ptr %4, align 4, !tbaa !8
  %20 = icmp slt i32 %19, 128
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %38

22:                                               ; preds = %18
  %23 = load i32, ptr %4, align 4, !tbaa !8
  %24 = sitofp i32 %23 to double
  %25 = fdiv double %24, 1.280000e+02
  %26 = fmul double %25, 2.000000e+00
  %27 = fmul double %26, 0x400921FB54442D18
  %28 = load i32, ptr %2, align 4, !tbaa !8
  %29 = sitofp i32 %28 to double
  %30 = fmul double %27, %29
  %31 = call double @sin(double noundef %30) #6
  %32 = load i32, ptr %4, align 4, !tbaa !8
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [128 x double], ptr %3, i64 0, i64 %33
  store double %31, ptr %34, align 8, !tbaa !11
  br label %35

35:                                               ; preds = %22
  %36 = load i32, ptr %4, align 4, !tbaa !8
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %4, align 4, !tbaa !8
  br label %18, !llvm.loop !13

38:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 1, ptr %8, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !8
  br label %39

39:                                               ; preds = %55, %38
  %40 = load i32, ptr %9, align 4, !tbaa !8
  %41 = load i32, ptr %8, align 4, !tbaa !8
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %58

44:                                               ; preds = %39
  %45 = call i64 @clock() #6
  store i64 %45, ptr %5, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  call void @_ZN3DFTC2Eii(ptr noundef nonnull align 8 dereferenceable(8) %10, i32 noundef 128, i32 noundef 44100)
  %46 = getelementptr inbounds [128 x double], ptr %3, i64 0, i64 0
  call void @_ZN3DFT7forwardEPdi(ptr noundef nonnull align 8 dereferenceable(8) %10, ptr noundef %46, i32 noundef 128)
  %47 = call i64 @clock() #6
  store i64 %47, ptr %6, align 8, !tbaa !15
  %48 = load i64, ptr %6, align 8, !tbaa !15
  %49 = load i64, ptr %5, align 8, !tbaa !15
  %50 = sub nsw i64 %48, %49
  %51 = sitofp i64 %50 to double
  %52 = fdiv double %51, 1.000000e+06
  %53 = load double, ptr %7, align 8, !tbaa !11
  %54 = fadd double %53, %52
  store double %54, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %55

55:                                               ; preds = %44
  %56 = load i32, ptr %9, align 4, !tbaa !8
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %9, align 4, !tbaa !8
  br label %39, !llvm.loop !17

58:                                               ; preds = %43
  %59 = load double, ptr %7, align 8, !tbaa !11
  %60 = load i32, ptr %8, align 4, !tbaa !8
  %61 = sitofp i32 %60 to double
  %62 = fdiv double %59, %61
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, double noundef %62)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 0, ptr %11, align 4, !tbaa !8
  br label %64

64:                                               ; preds = %80, %58
  %65 = load i32, ptr %11, align 4, !tbaa !8
  %66 = load i32, ptr %8, align 4, !tbaa !8
  %67 = icmp slt i32 %65, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %83

69:                                               ; preds = %64
  %70 = call i64 @clock() #6
  store i64 %70, ptr %5, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 24, ptr %12) #6
  call void @_ZN3FFTC2Eii(ptr noundef nonnull align 8 dereferenceable(24) %12, i32 noundef 128, i32 noundef 44100)
  %71 = getelementptr inbounds [128 x double], ptr %3, i64 0, i64 0
  call void @_ZN3FFT7forwardEPdi(ptr noundef nonnull align 8 dereferenceable(24) %12, ptr noundef %71, i32 noundef 128)
  %72 = call i64 @clock() #6
  store i64 %72, ptr %6, align 8, !tbaa !15
  %73 = load i64, ptr %6, align 8, !tbaa !15
  %74 = load i64, ptr %5, align 8, !tbaa !15
  %75 = sub nsw i64 %73, %74
  %76 = sitofp i64 %75 to double
  %77 = fdiv double %76, 1.000000e+06
  %78 = load double, ptr %7, align 8, !tbaa !11
  %79 = fadd double %78, %77
  store double %79, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 24, ptr %12) #6
  br label %80

80:                                               ; preds = %69
  %81 = load i32, ptr %11, align 4, !tbaa !8
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %11, align 4, !tbaa !8
  br label %64, !llvm.loop !18

83:                                               ; preds = %68
  %84 = load double, ptr %7, align 8, !tbaa !11
  %85 = load i32, ptr %8, align 4, !tbaa !8
  %86 = sitofp i32 %85 to double
  %87 = fdiv double %84, %86
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, double noundef %87)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 1024, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  ret i32 0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNSt8ios_base9precisionEl(ptr noundef nonnull align 8 dereferenceable(216), i64 noundef) #5 align 2

; Function Attrs: nounwind
declare i64 @clock() #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3DFTC2Eii(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef, i32 noundef) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3FFTC2Eii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) unnamed_addr #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #4 = { mustprogress norecurse 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 #5 = { mustprogress 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 #6 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !10, i64 0}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !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"

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%struct.DFT = type { ptr }
%struct.FFT = type { ptr, ptr, i32, i32 }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.3 = external hidden unnamed_addr constant [28 x i8], align 1

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3DFT7forwardEPdi(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i32 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3FFT7forwardEPdi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, i32 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #4 {
  %1 = alloca [128 x double], align 16
  %2 = alloca %struct.DFT, align 8
  %3 = alloca %struct.FFT, align 8
  %4 = load ptr, ptr @_ZSt4cout, align 8, !tbaa !5
  %5 = getelementptr i8, ptr %4, i64 -24
  %6 = load i64, ptr %5, align 8
  %7 = getelementptr inbounds i8, ptr @_ZSt4cout, i64 %6
  %8 = tail call noundef i64 @_ZNSt8ios_base9precisionEl(ptr noundef nonnull align 8 dereferenceable(216) %7, i64 noundef 20)
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %1) #7
  br label %9

9:                                                ; preds = %9, %0
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next.1, %9 ]
  %10 = trunc nuw nsw i64 %indvars.iv to i32
  %11 = uitofp nneg i32 %10 to double
  %12 = fmul double %11, 7.812500e-03
  %13 = fmul double %12, 2.000000e+00
  %14 = fmul double %13, 0x400921FB54442D18
  %15 = fmul double %14, 5.000000e+03
  %16 = tail call double @sin(double noundef %15) #7
  %17 = getelementptr inbounds [128 x double], ptr %1, i64 0, i64 %indvars.iv
  store double %16, ptr %17, align 16, !tbaa !8
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %18 = trunc nuw nsw i64 %indvars.iv.next to i32
  %19 = uitofp nneg i32 %18 to double
  %20 = fmul double %19, 7.812500e-03
  %21 = fmul double %20, 2.000000e+00
  %22 = fmul double %21, 0x400921FB54442D18
  %23 = fmul double %22, 5.000000e+03
  %24 = tail call double @sin(double noundef %23) #7
  %25 = getelementptr inbounds [128 x double], ptr %1, i64 0, i64 %indvars.iv.next
  store double %24, ptr %25, align 8, !tbaa !8
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 128
  br i1 %exitcond.not.1, label %.preheader, label %9, !llvm.loop !11

.preheader:                                       ; preds = %9
  %26 = tail call i64 @clock() #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #7
  call void @_ZN3DFTC2Eii(ptr noundef nonnull align 8 dereferenceable(8) %2, i32 noundef 128, i32 noundef 44100)
  call void @_ZN3DFT7forwardEPdi(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull %1, i32 noundef 128)
  %27 = call i64 @clock() #7
  %28 = sub nsw i64 %27, %26
  %29 = sitofp i64 %28 to double
  %30 = fdiv double %29, 1.000000e+06
  %31 = fadd double %30, 0.000000e+00
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #7
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, double noundef %31)
  %33 = call i64 @clock() #7
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #7
  call void @_ZN3FFTC2Eii(ptr noundef nonnull align 8 dereferenceable(24) %3, i32 noundef 128, i32 noundef 44100)
  call void @_ZN3FFT7forwardEPdi(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull %1, i32 noundef 128)
  %34 = call i64 @clock() #7
  %35 = sub nsw i64 %34, %33
  %36 = sitofp i64 %35 to double
  %37 = fdiv double %36, 1.000000e+06
  %38 = fadd double %31, %37
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #7
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, double noundef %38)
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %1) #7
  ret i32 0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNSt8ios_base9precisionEl(ptr noundef nonnull align 8 dereferenceable(216), i64 noundef) local_unnamed_addr #5 align 2

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #6

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3DFTC2Eii(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef, i32 noundef) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3FFTC2Eii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) unnamed_addr #3 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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 #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 = { 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 #4 = { mustprogress norecurse 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 #5 = { mustprogress 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 #6 = { 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 #7 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"double", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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