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

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

@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.62 = external hidden unnamed_addr constant [89 x i8], align 1
@.str.67 = external hidden unnamed_addr constant [48 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 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @symstreamcf_write_samples(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @symstreamrcf_fill_buffer(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca { float, float }, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.symstreamrcf_s, ptr %5, i32 0, i32 5
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.symstreamrcf_s, ptr %8, i32 0, i32 4
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = icmp ne i32 %7, %10
  br i1 %11, label %12, label %14

12:                                               ; preds = %1
  %13 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 1, ptr noundef @.str.62, i32 noundef 216, ptr noundef @.str.67, ptr noundef @.str.2)
  store i32 %13, ptr %2, align 4
  br label %40

14:                                               ; preds = %1
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.symstreamrcf_s, ptr %15, i32 0, i32 4
  store i32 0, ptr %16, align 4, !tbaa !12
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.symstreamrcf_s, ptr %17, i32 0, i32 5
  store i32 0, ptr %18, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %25, %14
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.symstreamrcf_s, ptr %20, i32 0, i32 4
  %22 = load i32, ptr %21, align 4, !tbaa !12
  %23 = icmp ne i32 %22, 0
  %24 = xor i1 %23, true
  br i1 %24, label %25, label %39

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.symstreamrcf_s, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = call i32 @symstreamcf_write_samples(ptr noundef %28, ptr noundef %4, i32 noundef 1)
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.symstreamrcf_s, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.symstreamrcf_s, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.symstreamrcf_s, ptr %36, i32 0, i32 4
  %38 = call i32 @msresamp_crcf_execute(ptr noundef %32, ptr noundef %4, i32 noundef 1, ptr noundef %35, ptr noundef %37)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %19, !llvm.loop !16

39:                                               ; preds = %19
  store i32 0, ptr %2, align 4
  br label %40

40:                                               ; preds = %39, %12
  %41 = load i32, ptr %2, align 4
  ret i32 %41
}

declare i32 @msresamp_crcf_execute(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr 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 = { 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 #3 = { 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, !11, i64 32}
!10 = !{!"symstreamrcf_s", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 28, !11, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 28}
!13 = !{!10, !6, i64 0}
!14 = !{!10, !6, i64 8}
!15 = !{!10, !6, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.62 = external hidden unnamed_addr constant [89 x i8], align 1
@.str.67 = external hidden unnamed_addr constant [48 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 i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @symstreamcf_write_samples(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @symstreamrcf_fill_buffer(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca { float, float }, align 4
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 28
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %.not = icmp eq i32 %4, %6
  br i1 %.not, label %9, label %7

7:                                                ; preds = %1
  %8 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 1, ptr noundef nonnull @.str.62, i32 noundef 216, ptr noundef nonnull @.str.67, ptr noundef nonnull @.str.2) #3
  br label %.loopexit

9:                                                ; preds = %1
  store i32 0, ptr %5, align 4, !tbaa !11
  store i32 0, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  br label %12

12:                                               ; preds = %9, %12
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %13 = load ptr, ptr %0, align 8, !tbaa !12
  %14 = call i32 @symstreamcf_write_samples(ptr noundef %13, ptr noundef nonnull %2, i32 noundef 1)
  %15 = load ptr, ptr %10, align 8, !tbaa !13
  %16 = load ptr, ptr %11, align 8, !tbaa !14
  %17 = call i32 @msresamp_crcf_execute(ptr noundef %15, ptr noundef nonnull %2, i32 noundef 1, ptr noundef %16, ptr noundef nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  %.pr = load i32, ptr %5, align 4, !tbaa !11
  %.not9 = icmp eq i32 %.pr, 0
  br i1 %.not9, label %12, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %12, %7
  %.0 = phi i32 [ %8, %7 ], [ 0, %12 ]
  ret i32 %.0
}

declare i32 @msresamp_crcf_execute(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr 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 = { 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 #3 = { 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, !10, i64 32}
!6 = !{!"symstreamrcf_s", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !10, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 28}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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