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

@.str = external hidden unnamed_addr constant [86 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [45 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
declare dso_local i32 @qsourcecf_destroy(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @msourcecf_remove(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %28, %2
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.msourcecf_s, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp ult i32 %10, %13
  br i1 %14, label %15, label %31

15:                                               ; preds = %9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.msourcecf_s, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds ptr, ptr %18, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = call i32 @qsourcecf_get_id(ptr noundef %22)
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %15
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %31

27:                                               ; preds = %15
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = add i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !9
  br label %9, !llvm.loop !16

31:                                               ; preds = %26, %9
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %37, label %34

34:                                               ; preds = %31
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 5, ptr noundef @.str, i32 noundef 296, ptr noundef @.str.7, ptr noundef @.str.2, i32 noundef %35)
  store i32 %36, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %75

37:                                               ; preds = %31
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.msourcecf_s, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds ptr, ptr %40, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = call i32 @qsourcecf_destroy(ptr noundef %44)
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.msourcecf_s, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 8, !tbaa !11
  %49 = add i32 %48, -1
  store i32 %49, ptr %47, align 8, !tbaa !11
  br label %50

50:                                               ; preds = %71, %37
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.msourcecf_s, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !11
  %55 = icmp ult i32 %51, %54
  br i1 %55, label %56, label %74

56:                                               ; preds = %50
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.msourcecf_s, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !15
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = add i32 %60, 1
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds ptr, ptr %59, i64 %62
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.msourcecf_s, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !15
  %68 = load i32, ptr %6, align 4, !tbaa !9
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds ptr, ptr %67, i64 %69
  store ptr %64, ptr %70, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %56
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = add i32 %72, 1
  store i32 %73, ptr %6, align 4, !tbaa !9
  br label %50, !llvm.loop !18

74:                                               ; preds = %50
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %75

75:                                               ; preds = %74, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %76 = load i32, ptr %3, align 4
  ret i32 %76
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @qsourcecf_get_id(ptr noundef) #1

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #2

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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"msourcecf_s", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !13, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !10, i64 60, !14, i64 64}
!13 = !{!"float", !7, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!12, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @qsourcecf_destroy(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @msourcecf_remove(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not23.not = icmp eq i32 %4, 0
  br i1 %.not23.not, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %10
  %indvars.iv = phi i64 [ %indvars.iv.next, %10 ], [ 0, %2 ]
  %5 = load ptr, ptr %0, align 8, !tbaa !13
  %6 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  %8 = tail call i32 @qsourcecf_get_id(ptr noundef %7)
  %9 = icmp eq i32 %8, %1
  br i1 %9, label %14, label %10

10:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr %3, align 8, !tbaa !5
  %12 = zext i32 %11 to i64
  %.not = icmp ult i64 %indvars.iv.next, %12
  br i1 %.not, label %.lr.ph, label %.critedge, !llvm.loop !15

.critedge:                                        ; preds = %10, %2
  %13 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 5, ptr noundef nonnull @.str, i32 noundef 296, ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.2, i32 noundef %1) #2
  br label %.loopexit

14:                                               ; preds = %.lr.ph
  %15 = trunc nuw i64 %indvars.iv to i32
  %16 = load ptr, ptr %0, align 8, !tbaa !13
  %17 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = tail call i32 @qsourcecf_destroy(ptr noundef %18)
  %20 = load i32, ptr %3, align 8, !tbaa !5
  %21 = add i32 %20, -1
  store i32 %21, ptr %3, align 8, !tbaa !5
  %22 = icmp ugt i32 %21, %15
  br i1 %22, label %.lr.ph26.preheader, label %.loopexit

.lr.ph26.preheader:                               ; preds = %14
  %wide.trip.count = zext i32 %21 to i64
  %23 = sub nsw i64 %wide.trip.count, %indvars.iv
  %xtraiter = and i64 %23, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph26.prol.loopexit, label %.lr.ph26.prol

.lr.ph26.prol:                                    ; preds = %.lr.ph26.preheader, %.lr.ph26.prol
  %indvars.iv31.prol = phi i64 [ %indvars.iv.next32.prol, %.lr.ph26.prol ], [ %indvars.iv, %.lr.ph26.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph26.prol ], [ 0, %.lr.ph26.preheader ]
  %24 = load ptr, ptr %0, align 8, !tbaa !13
  %indvars.iv.next32.prol = add nuw nsw i64 %indvars.iv31.prol, 1
  %25 = getelementptr inbounds ptr, ptr %24, i64 %indvars.iv.next32.prol
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = getelementptr inbounds ptr, ptr %24, i64 %indvars.iv31.prol
  store ptr %26, ptr %27, align 8, !tbaa !14
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph26.prol.loopexit, label %.lr.ph26.prol, !llvm.loop !17

.lr.ph26.prol.loopexit:                           ; preds = %.lr.ph26.prol, %.lr.ph26.preheader
  %indvars.iv31.unr = phi i64 [ %indvars.iv, %.lr.ph26.preheader ], [ %indvars.iv.next32.prol, %.lr.ph26.prol ]
  %28 = sub nsw i64 %indvars.iv, %wide.trip.count
  %29 = icmp ugt i64 %28, -4
  br i1 %29, label %.loopexit, label %.lr.ph26

.lr.ph26:                                         ; preds = %.lr.ph26.prol.loopexit, %.lr.ph26
  %indvars.iv31 = phi i64 [ %indvars.iv.next32.3, %.lr.ph26 ], [ %indvars.iv31.unr, %.lr.ph26.prol.loopexit ]
  %30 = load ptr, ptr %0, align 8, !tbaa !13
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %31 = getelementptr inbounds ptr, ptr %30, i64 %indvars.iv.next32
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = getelementptr inbounds ptr, ptr %30, i64 %indvars.iv31
  store ptr %32, ptr %33, align 8, !tbaa !14
  %34 = load ptr, ptr %0, align 8, !tbaa !13
  %indvars.iv.next32.1 = add nuw nsw i64 %indvars.iv31, 2
  %35 = getelementptr inbounds ptr, ptr %34, i64 %indvars.iv.next32.1
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = getelementptr inbounds ptr, ptr %34, i64 %indvars.iv.next32
  store ptr %36, ptr %37, align 8, !tbaa !14
  %38 = load ptr, ptr %0, align 8, !tbaa !13
  %indvars.iv.next32.2 = add nuw nsw i64 %indvars.iv31, 3
  %39 = getelementptr inbounds ptr, ptr %38, i64 %indvars.iv.next32.2
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = getelementptr inbounds ptr, ptr %38, i64 %indvars.iv.next32.1
  store ptr %40, ptr %41, align 8, !tbaa !14
  %42 = load ptr, ptr %0, align 8, !tbaa !13
  %indvars.iv.next32.3 = add nuw nsw i64 %indvars.iv31, 4
  %43 = getelementptr inbounds ptr, ptr %42, i64 %indvars.iv.next32.3
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  %45 = getelementptr inbounds ptr, ptr %42, i64 %indvars.iv.next32.2
  store ptr %44, ptr %45, align 8, !tbaa !14
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next32.3, %wide.trip.count
  br i1 %exitcond.not.3, label %.loopexit, label %.lr.ph26, !llvm.loop !19

.loopexit:                                        ; preds = %.lr.ph26.prol.loopexit, %.lr.ph26, %14, %.critedge
  %.019 = phi i32 [ %13, %.critedge ], [ 0, %14 ], [ 0, %.lr.ph26 ], [ 0, %.lr.ph26.prol.loopexit ]
  ret i32 %.019
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @qsourcecf_get_id(ptr noundef) local_unnamed_addr #0

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #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 = { "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, !10, i64 8}
!6 = !{!"msourcecf_s", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !11, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !10, i64 60, !12, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass