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

; 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.bpacketsync_s = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, [6 x i8], [12 x i8], ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i8, i8, i32, i32, ptr, ptr, %struct.framesyncstats_s }
%struct.framesyncstats_s = type { float, float, float, ptr, i32, i32, i32, i32, i32, i32 }

@.str.1 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @bpacketsync_execute_bit(ptr noundef %0, i8 noundef zeroext %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  %6 = load i8, ptr %5, align 1, !tbaa !9
  %7 = zext i8 %6 to i32
  %8 = and i32 %7, 1
  %9 = trunc i32 %8 to i8
  store i8 %9, ptr %5, align 1, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.bpacketsync_s, ptr %10, i32 0, i32 19
  %12 = load i32, ptr %11, align 8, !tbaa !10
  switch i32 %12, label %25 [
    i32 0, label %13
    i32 1, label %17
    i32 2, label %21
  ]

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i8, ptr %5, align 1, !tbaa !9
  %16 = call i32 @bpacketsync_execute_seekpn(ptr noundef %14, i8 noundef zeroext %15)
  br label %27

17:                                               ; preds = %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load i8, ptr %5, align 1, !tbaa !9
  %20 = call i32 @bpacketsync_execute_rxheader(ptr noundef %18, i8 noundef zeroext %19)
  br label %27

21:                                               ; preds = %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load i8, ptr %5, align 1, !tbaa !9
  %24 = call i32 @bpacketsync_execute_rxpayload(ptr noundef %22, i8 noundef zeroext %23)
  br label %27

25:                                               ; preds = %2
  %26 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef @.str.1, i32 noundef 286, ptr noundef @.str.14)
  store i32 %26, ptr %3, align 4
  br label %28

27:                                               ; preds = %21, %17, %13
  store i32 0, ptr %3, align 4
  br label %28

28:                                               ; preds = %27, %25
  %29 = load i32, ptr %3, align 4
  ret i32 %29
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @bpacketsync_execute_seekpn(ptr noundef, i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @bpacketsync_execute_rxheader(ptr noundef, i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @bpacketsync_execute_rxpayload(ptr noundef, i8 noundef zeroext) #0

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

!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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 128}
!11 = !{!"bpacketsync_s", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !7, i64 64, !7, i64 70, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !12, i64 128, !12, i64 132, !12, i64 136, !7, i64 140, !7, i64 141, !12, i64 144, !12, i64 148, !6, i64 152, !6, i64 160, !13, i64 168}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !6, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44}
!14 = !{!"float", !7, 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"

@.str.1 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @bpacketsync_execute_bit(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = and i8 %1, 1
  %4 = getelementptr inbounds i8, ptr %0, i64 128
  %5 = load i32, ptr %4, align 8, !tbaa !5
  switch i32 %5, label %12 [
    i32 0, label %6
    i32 1, label %8
    i32 2, label %10
  ]

6:                                                ; preds = %2
  %7 = tail call i32 @bpacketsync_execute_seekpn(ptr noundef nonnull %0, i8 noundef zeroext %3)
  br label %14

8:                                                ; preds = %2
  %9 = tail call i32 @bpacketsync_execute_rxheader(ptr noundef nonnull %0, i8 noundef zeroext %3)
  br label %14

10:                                               ; preds = %2
  %11 = tail call i32 @bpacketsync_execute_rxpayload(ptr noundef nonnull %0, i8 noundef zeroext %3)
  br label %14

12:                                               ; preds = %2
  %13 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef nonnull @.str.1, i32 noundef 286, ptr noundef nonnull @.str.14) #2
  br label %14

14:                                               ; preds = %6, %8, %10, %12
  %.0 = phi i32 [ %13, %12 ], [ 0, %10 ], [ 0, %8 ], [ 0, %6 ]
  ret i32 %.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 @bpacketsync_execute_seekpn(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @bpacketsync_execute_rxheader(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @bpacketsync_execute_rxpayload(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

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, !7, i64 128}
!6 = !{!"bpacketsync_s", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !8, i64 64, !8, i64 70, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !7, i64 128, !7, i64 132, !7, i64 136, !8, i64 140, !8, i64 141, !7, i64 144, !7, i64 148, !10, i64 152, !10, i64 160, !11, i64 168}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !10, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44}
!12 = !{!"float", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass