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

@__const.autotest_msourcecf_tone.regions = external hidden unnamed_addr constant [13 x %struct.autotest_psd_s], align 16
@liquid_autotest_verbose = external global i32, align 4
@.str = external hidden unnamed_addr constant [40 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

; Function Attrs: nounwind uwtable
define dso_local void @autotest_msourcecf_tone() #1 {
  %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 [13 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 = call i32 @msourcecf_add_tone(ptr noundef %15, float noundef 0xBFD99999A0000000, float noundef 0.000000e+00, float noundef 2.000000e+01)
  %17 = load ptr, ptr %4, align 8, !tbaa !9
  %18 = call i32 @msourcecf_add_tone(ptr noundef %17, float noundef 0xBFD3333340000000, float noundef 0.000000e+00, float noundef 1.000000e+01)
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  %20 = call i32 @msourcecf_add_tone(ptr noundef %19, float noundef 0xBFC99999A0000000, float noundef 0.000000e+00, float noundef 0.000000e+00)
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  %22 = call i32 @msourcecf_add_tone(ptr noundef %21, float noundef 0xBFB99999A0000000, float noundef 0.000000e+00, float noundef -1.000000e+01)
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = call i32 @msourcecf_add_tone(ptr noundef %23, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef -2.000000e+01)
  %25 = load ptr, ptr %4, align 8, !tbaa !9
  %26 = call i32 @msourcecf_add_tone(ptr noundef %25, float noundef 0x3FB99999A0000000, float noundef 0.000000e+00, float noundef -3.000000e+01)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1024, ptr %5, align 4, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = zext i32 %27 to i64
  %29 = call ptr @llvm.stacksave.p0()
  store ptr %29, ptr %6, align 8
  %30 = alloca { float, float }, i64 %28, align 16
  store i64 %28, ptr %7, align 8
  br label %31

31:                                               ; preds = %37, %0
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  %33 = call i64 @msourcecf_get_num_samples(ptr noundef %32)
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = zext i32 %34 to i64
  %36 = icmp ult i64 %33, %35
  br i1 %36, label %37, label %44

37:                                               ; preds = %31
  %38 = load ptr, ptr %4, align 8, !tbaa !9
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = call i32 @msourcecf_write_samples(ptr noundef %38, ptr noundef %30, i32 noundef %39)
  %41 = load ptr, ptr %3, align 8, !tbaa !9
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = call i32 @spgramcf_write(ptr noundef %41, ptr noundef %30, i32 noundef %42)
  br label %31, !llvm.loop !11

44:                                               ; preds = %31
  %45 = load i32, ptr %1, align 4, !tbaa !5
  %46 = zext i32 %45 to i64
  %47 = alloca float, i64 %46, align 16
  store i64 %46, ptr %8, align 8
  %48 = load ptr, ptr %3, align 8, !tbaa !9
  %49 = call i32 @spgramcf_get_psd(ptr noundef %48, ptr noundef %47)
  %50 = load ptr, ptr %4, align 8, !tbaa !9
  %51 = call i32 @msourcecf_destroy(ptr noundef %50)
  %52 = load ptr, ptr %3, align 8, !tbaa !9
  %53 = call i32 @spgramcf_destroy(ptr noundef %52)
  call void @llvm.lifetime.start.p0(i64 312, ptr %9) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %9, ptr align 16 @__const.autotest_msourcecf_tone.regions, i64 312, i1 false)
  %54 = load i32, ptr %1, align 4, !tbaa !5
  %55 = getelementptr inbounds [13 x %struct.autotest_psd_s], ptr %9, i64 0, i64 0
  %56 = load i32, ptr @liquid_autotest_verbose, align 4, !tbaa !5
  %57 = icmp ne i32 %56, 0
  %58 = zext i1 %57 to i64
  %59 = select i1 %57, ptr @.str, ptr null
  %60 = call i32 @liquid_autotest_validate_spectrum(ptr noundef %47, i32 noundef %54, ptr noundef %55, i32 noundef 13, ptr noundef %59)
  call void @llvm.lifetime.end.p0(i64 312, ptr %9) #5
  %61 = load ptr, ptr %6, align 8
  call void @llvm.stackrestore.p0(ptr %61)
  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 ptr @spgramcf_create_default(i32 noundef) #2

declare ptr @msourcecf_create_default() #2

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

declare i32 @msourcecf_add_tone(ptr noundef, float noundef, float noundef, float noundef) #2

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

declare i64 @msourcecf_get_num_samples(ptr noundef) #2

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

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

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

declare i32 @msourcecf_destroy(ptr noundef) #2

declare i32 @spgramcf_destroy(ptr noundef) #2

; 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) #4

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { "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 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }

@__const.autotest_msourcecf_tone.regions = external hidden unnamed_addr constant [13 x %struct.autotest_psd_s], align 16
@liquid_autotest_verbose = external local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [40 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: nounwind uwtable
define dso_local void @autotest_msourcecf_tone() local_unnamed_addr #1 {
  %1 = alloca [13 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_tone(ptr noundef %3, float noundef 0xBFD99999A0000000, float noundef 0.000000e+00, float noundef 2.000000e+01) #4
  %6 = tail call i32 @msourcecf_add_tone(ptr noundef %3, float noundef 0xBFD3333340000000, float noundef 0.000000e+00, float noundef 1.000000e+01) #4
  %7 = tail call i32 @msourcecf_add_tone(ptr noundef %3, float noundef 0xBFC99999A0000000, float noundef 0.000000e+00, float noundef 0.000000e+00) #4
  %8 = tail call i32 @msourcecf_add_tone(ptr noundef %3, float noundef 0xBFB99999A0000000, float noundef 0.000000e+00, float noundef -1.000000e+01) #4
  %9 = tail call i32 @msourcecf_add_tone(ptr noundef %3, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef -2.000000e+01) #4
  %10 = tail call i32 @msourcecf_add_tone(ptr noundef %3, float noundef 0x3FB99999A0000000, float noundef 0.000000e+00, float noundef -3.000000e+01) #4
  %11 = alloca [1024 x { float, float }], align 16
  %12 = tail call i64 @msourcecf_get_num_samples(ptr noundef %3) #4
  %13 = icmp ult i64 %12, 192000
  br i1 %13, label %.lr.ph, label %._crit_edge

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

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

declare ptr @spgramcf_create_default(i32 noundef) local_unnamed_addr #2

declare ptr @msourcecf_create_default() local_unnamed_addr #2

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

declare i32 @msourcecf_add_tone(ptr noundef, float noundef, float noundef, float noundef) local_unnamed_addr #2

declare i64 @msourcecf_get_num_samples(ptr noundef) local_unnamed_addr #2

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

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

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

declare i32 @msourcecf_destroy(ptr noundef) local_unnamed_addr #2

declare i32 @spgramcf_destroy(ptr noundef) local_unnamed_addr #2

; 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) #3

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

attributes #0 = { mustprogress 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 = { "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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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