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

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

; 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
declare dso_local i32 @qdsync_cccf_reset(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @qdsync_cccf_buf_append(ptr noundef %0, <2 x float> noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca { float, float }, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store <2 x float> %1, ptr %4, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %8, i32 0, i32 9
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = add i32 %10, 1
  store i32 %11, ptr %9, align 4, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %12, i32 0, i32 9
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %15, i32 0, i32 3
  %17 = load i32, ptr %16, align 4, !tbaa !13
  %18 = mul i32 2, %17
  %19 = icmp ule i32 %14, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  br label %79

21:                                               ; preds = %2
  %22 = getelementptr inbounds { float, float }, ptr %4, i32 0, i32 0
  %23 = load float, ptr %22, align 4
  %24 = getelementptr inbounds { float, float }, ptr %4, i32 0, i32 1
  %25 = load float, ptr %24, align 4
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %26, i32 0, i32 16
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %29, i32 0, i32 17
  %31 = load i32, ptr %30, align 8, !tbaa !15
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds { float, float }, ptr %28, i64 %32
  %34 = getelementptr inbounds { float, float }, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds { float, float }, ptr %33, i32 0, i32 1
  store float %23, ptr %34, align 4
  store float %25, ptr %35, align 4
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %36, i32 0, i32 17
  %38 = load i32, ptr %37, align 8, !tbaa !15
  %39 = add i32 %38, 1
  store i32 %39, ptr %37, align 8, !tbaa !15
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %40, i32 0, i32 17
  %42 = load i32, ptr %41, align 8, !tbaa !15
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %43, i32 0, i32 15
  %45 = load i32, ptr %44, align 4, !tbaa !16
  %46 = icmp eq i32 %42, %45
  br i1 %46, label %47, label %78

47:                                               ; preds = %21
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %48, i32 0, i32 17
  store i32 0, ptr %49, align 8, !tbaa !15
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %50, i32 0, i32 5
  %52 = load ptr, ptr %51, align 8, !tbaa !17
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %77

54:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %55, i32 0, i32 5
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %58, i32 0, i32 16
  %60 = load ptr, ptr %59, align 8, !tbaa !14
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %61, i32 0, i32 15
  %63 = load i32, ptr %62, align 4, !tbaa !16
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.qdsync_cccf_s, ptr %64, i32 0, i32 6
  %66 = load ptr, ptr %65, align 8, !tbaa !18
  %67 = call i32 %57(ptr noundef %60, i32 noundef %63, ptr noundef %66)
  store i32 %67, ptr %6, align 4, !tbaa !19
  %68 = load i32, ptr %6, align 4, !tbaa !19
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %73

70:                                               ; preds = %54
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = call i32 @qdsync_cccf_reset(ptr noundef %71)
  store i32 %72, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %74

73:                                               ; preds = %54
  store i32 0, ptr %7, align 4
  br label %74

74:                                               ; preds = %73, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %75 = load i32, ptr %7, align 4
  switch i32 %75, label %81 [
    i32 0, label %76
    i32 1, label %79
  ]

76:                                               ; preds = %74
  br label %77

77:                                               ; preds = %76, %47
  br label %78

78:                                               ; preds = %77, %21
  store i32 0, ptr %3, align 4
  br label %79

79:                                               ; preds = %78, %74, %20
  %80 = load i32, ptr %3, align 4
  ret i32 %80

81:                                               ; preds = %74
  unreachable
}

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 = { nounwind uwtable "min-legal-vector-width"="64" "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 52}
!10 = !{!"qdsync_cccf_s", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !12, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !6, i64 56, !6, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !6, i64 88, !11, i64 96}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!10, !11, i64 12}
!14 = !{!10, !6, i64 88}
!15 = !{!10, !11, i64 96}
!16 = !{!10, !11, i64 84}
!17 = !{!10, !6, i64 24}
!18 = !{!10, !6, i64 32}
!19 = !{!11, !11, i64 0}


; 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 i32 @qdsync_cccf_reset(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @qdsync_cccf_buf_append(ptr noundef %0, <2 x float> noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 52
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = add i32 %4, 1
  store i32 %5, ptr %3, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !12
  %8 = shl i32 %7, 1
  %.not = icmp ugt i32 %5, %8
  br i1 %.not, label %9, label %.thread

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 88
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %0, i64 96
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds { float, float }, ptr %11, i64 %14
  store <2 x float> %1, ptr %15, align 4
  %16 = load i32, ptr %12, align 8, !tbaa !14
  %17 = add i32 %16, 1
  store i32 %17, ptr %12, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %0, i64 84
  %19 = load i32, ptr %18, align 4, !tbaa !15
  %20 = icmp eq i32 %17, %19
  br i1 %20, label %21, label %.thread

21:                                               ; preds = %9
  store i32 0, ptr %12, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %0, i64 24
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %.not19 = icmp eq ptr %23, null
  br i1 %.not19, label %.thread, label %24

24:                                               ; preds = %21
  %25 = load ptr, ptr %10, align 8, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %0, i64 32
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %28 = tail call i32 %23(ptr noundef %25, i32 noundef %17, ptr noundef %27) #2
  %.not20.not = icmp eq i32 %28, 0
  br i1 %.not20.not, label %.thread, label %29

29:                                               ; preds = %24
  %30 = tail call i32 @qdsync_cccf_reset(ptr noundef nonnull %0)
  br label %.thread

.thread:                                          ; preds = %24, %9, %21, %29, %2
  %.1 = phi i32 [ %30, %29 ], [ 0, %2 ], [ 0, %21 ], [ 0, %9 ], [ 0, %24 ]
  ret i32 %.1
}

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 = { nounwind uwtable "min-legal-vector-width"="64" "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 }

!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, !7, i64 52}
!6 = !{!"qdsync_cccf_s", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !7, i64 48, !7, i64 52, !11, i64 56, !11, i64 64, !7, i64 72, !7, i64 76, !7, i64 80, !7, i64 84, !11, i64 88, !7, i64 96}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 12}
!13 = !{!6, !11, i64 88}
!14 = !{!6, !7, i64 96}
!15 = !{!6, !7, i64 84}
!16 = !{!6, !11, i64 24}
!17 = !{!6, !11, i64 32}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass