; LLVM IR from jgaeddert/liquid-dsp :: src/framing/tests (msource_autotest)

; 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.autotest_psd_s = type { float, float, float, float, i32, i32 }

@liquid_autotest_verbose = external global i32, align 4
@__const.autotest_msourcecf_chirp.regions = external hidden unnamed_addr constant [3 x %struct.autotest_psd_s], align 16
@.str.1 = external hidden unnamed_addr constant [41 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 ptr @spgramcf_create_default(i32 noundef) #1

declare ptr @msourcecf_create_default() #1

declare i32 @msourcecf_add_noise(ptr noundef, float noundef, float noundef, float noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

declare i64 @msourcecf_get_num_samples(ptr noundef) #1

declare i32 @msourcecf_write_samples(ptr noundef, ptr noundef, i32 noundef) #1

declare i32 @spgramcf_write(ptr noundef, ptr noundef, i32 noundef) #1

declare i32 @spgramcf_get_psd(ptr noundef, ptr noundef) #1

declare i32 @msourcecf_destroy(ptr noundef) #1

declare i32 @spgramcf_destroy(ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare i32 @liquid_autotest_validate_spectrum(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

; Function Attrs: nounwind uwtable
define dso_local void @autotest_msourcecf_chirp() #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca [3 x %struct.autotest_psd_s], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  store i32 2400, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 192000, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = call ptr @spgramcf_create_default(i32 noundef %10)
  store ptr %11, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %12 = call ptr @msourcecf_create_default()
  store ptr %12, ptr %4, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !9
  %14 = call i32 @msourcecf_add_noise(ptr noundef %13, float noundef 0.000000e+00, float noundef 1.000000e+00, float noundef -4.000000e+01)
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = uitofp i32 %16 to double
  %18 = fmul double %17, 9.000000e-01
  %19 = fptrunc double %18 to float
  %20 = call i32 @msourcecf_add_chirp(ptr noundef %15, float noundef 0.000000e+00, float noundef 0x3FE3333340000000, float noundef 2.000000e+01, float noundef %19, i32 noundef 0, i32 noundef 1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1024, ptr %5, align 4, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = zext i32 %21 to i64
  %23 = call ptr @llvm.stacksave.p0()
  store ptr %23, ptr %6, align 8
  %24 = alloca { float, float }, i64 %22, align 16
  store i64 %22, ptr %7, align 8
  br label %25

25:                                               ; preds = %31, %0
  %26 = load ptr, ptr %4, align 8, !tbaa !9
  %27 = call i64 @msourcecf_get_num_samples(ptr noundef %26)
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = zext i32 %28 to i64
  %30 = icmp ult i64 %27, %29
  br i1 %30, label %31, label %38

31:                                               ; preds = %25
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = call i32 @msourcecf_write_samples(ptr noundef %32, ptr noundef %24, i32 noundef %33)
  %35 = load ptr, ptr %3, align 8, !tbaa !9
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = call i32 @spgramcf_write(ptr noundef %35, ptr noundef %24, i32 noundef %36)
  br label %25, !llvm.loop !11

38:                                               ; preds = %25
  %39 = load i32, ptr %1, align 4, !tbaa !5
  %40 = zext i32 %39 to i64
  %41 = alloca float, i64 %40, align 16
  store i64 %40, ptr %8, align 8
  %42 = load ptr, ptr %3, align 8, !tbaa !9
  %43 = call i32 @spgramcf_get_psd(ptr noundef %42, ptr noundef %41)
  %44 = load ptr, ptr %4, align 8, !tbaa !9
  %45 = call i32 @msourcecf_destroy(ptr noundef %44)
  %46 = load ptr, ptr %3, align 8, !tbaa !9
  %47 = call i32 @spgramcf_destroy(ptr noundef %46)
  call void @llvm.lifetime.start.p0(i64 72, ptr %9) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %9, ptr align 16 @__const.autotest_msourcecf_chirp.regions, i64 72, i1 false)
  %48 = load i32, ptr %1, align 4, !tbaa !5
  %49 = getelementptr inbounds [3 x %struct.autotest_psd_s], ptr %9, i64 0, i64 0
  %50 = load i32, ptr @liquid_autotest_verbose, align 4, !tbaa !5
  %51 = icmp ne i32 %50, 0
  %52 = zext i1 %51 to i64
  %53 = select i1 %51, ptr @.str.1, ptr null
  %54 = call i32 @liquid_autotest_validate_spectrum(ptr noundef %41, i32 noundef %48, ptr noundef %49, i32 noundef 3, ptr noundef %53)
  call void @llvm.lifetime.end.p0(i64 72, ptr %9) #5
  %55 = load ptr, ptr %6, align 8
  call void @llvm.stackrestore.p0(ptr %55)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret void
}

declare i32 @msourcecf_add_chirp(ptr noundef, float noundef, float noundef, float noundef, float noundef, i32 noundef, i32 noundef) #1

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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

%struct.autotest_psd_s = type { float, float, float, float, i32, i32 }

@liquid_autotest_verbose = external local_unnamed_addr global i32, align 4
@__const.autotest_msourcecf_chirp.regions = external hidden unnamed_addr constant [3 x %struct.autotest_psd_s], align 16
@.str.1 = external hidden unnamed_addr constant [41 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

declare ptr @spgramcf_create_default(i32 noundef) local_unnamed_addr #1

declare ptr @msourcecf_create_default() local_unnamed_addr #1

declare i32 @msourcecf_add_noise(ptr noundef, float noundef, float noundef, float noundef) local_unnamed_addr #1

declare i64 @msourcecf_get_num_samples(ptr noundef) local_unnamed_addr #1

declare i32 @msourcecf_write_samples(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @spgramcf_write(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @spgramcf_get_psd(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @msourcecf_destroy(ptr noundef) local_unnamed_addr #1

declare i32 @spgramcf_destroy(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare i32 @liquid_autotest_validate_spectrum(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @autotest_msourcecf_chirp() local_unnamed_addr #3 {
  %1 = alloca [3 x %struct.autotest_psd_s], align 16
  %2 = tail call ptr @spgramcf_create_default(i32 noundef 2400) #4
  %3 = tail call ptr @msourcecf_create_default() #4
  %4 = tail call i32 @msourcecf_add_noise(ptr noundef %3, float noundef 0.000000e+00, float noundef 1.000000e+00, float noundef -4.000000e+01) #4
  %5 = tail call i32 @msourcecf_add_chirp(ptr noundef %3, float noundef 0.000000e+00, float noundef 0x3FE3333340000000, float noundef 2.000000e+01, float noundef 1.728000e+05, i32 noundef 0, i32 noundef 1) #4
  %6 = alloca [1024 x { float, float }], align 16
  %7 = tail call i64 @msourcecf_get_num_samples(ptr noundef %3) #4
  %8 = icmp ult i64 %7, 192000
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %9 = call i32 @msourcecf_write_samples(ptr noundef %3, ptr noundef nonnull %6, i32 noundef 1024) #4
  %10 = call i32 @spgramcf_write(ptr noundef %2, ptr noundef nonnull %6, i32 noundef 1024) #4
  %11 = call i64 @msourcecf_get_num_samples(ptr noundef %3) #4
  %12 = icmp ult i64 %11, 192000
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %0
  %13 = alloca [2400 x float], align 16
  %14 = call i32 @spgramcf_get_psd(ptr noundef %2, ptr noundef nonnull %13) #4
  %15 = call i32 @msourcecf_destroy(ptr noundef %3) #4
  %16 = call i32 @spgramcf_destroy(ptr noundef %2) #4
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %1) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(72) %1, ptr noundef nonnull align 16 dereferenceable(72) @__const.autotest_msourcecf_chirp.regions, i64 72, i1 false)
  %17 = load i32, ptr @liquid_autotest_verbose, align 4, !tbaa !7
  %.not = icmp eq i32 %17, 0
  %18 = select i1 %.not, ptr null, ptr @.str.1
  %19 = call i32 @liquid_autotest_validate_spectrum(ptr noundef nonnull %13, i32 noundef 2400, ptr noundef nonnull %1, i32 noundef 3, ptr noundef %18) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %1) #4
  ret void
}

declare i32 @msourcecf_add_chirp(ptr noundef, float noundef, float noundef, float noundef, float noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}


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