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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @bpacketsync_execute_rxheader(ptr noundef %0, i8 noundef zeroext %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.bpacketsync_s, ptr %5, i32 0, i32 22
  %7 = load i8, ptr %6, align 4, !tbaa !10
  %8 = zext i8 %7 to i32
  %9 = shl i32 %8, 1
  %10 = trunc i32 %9 to i8
  store i8 %10, ptr %6, align 4, !tbaa !10
  %11 = load i8, ptr %4, align 1, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = and i32 %12, 1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.bpacketsync_s, ptr %14, i32 0, i32 22
  %16 = load i8, ptr %15, align 4, !tbaa !10
  %17 = zext i8 %16 to i32
  %18 = or i32 %17, %13
  %19 = trunc i32 %18 to i8
  store i8 %19, ptr %15, align 4, !tbaa !10
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.bpacketsync_s, ptr %20, i32 0, i32 21
  %22 = load i32, ptr %21, align 8, !tbaa !15
  %23 = add i32 %22, 1
  store i32 %23, ptr %21, align 8, !tbaa !15
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.bpacketsync_s, ptr %24, i32 0, i32 21
  %26 = load i32, ptr %25, align 8, !tbaa !15
  %27 = icmp eq i32 %26, 8
  br i1 %27, label %28, label %80

28:                                               ; preds = %2
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.bpacketsync_s, ptr %29, i32 0, i32 22
  %31 = load i8, ptr %30, align 4, !tbaa !10
  %32 = zext i8 %31 to i32
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.bpacketsync_s, ptr %33, i32 0, i32 23
  %35 = load i8, ptr %34, align 1, !tbaa !16
  %36 = zext i8 %35 to i32
  %37 = xor i32 %32, %36
  %38 = trunc i32 %37 to i8
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.bpacketsync_s, ptr %39, i32 0, i32 13
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.bpacketsync_s, ptr %41, i32 0, i32 20
  %43 = load i32, ptr %42, align 4, !tbaa !17
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds [12 x i8], ptr %40, i64 0, i64 %44
  store i8 %38, ptr %45, align 1, !tbaa !9
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.bpacketsync_s, ptr %46, i32 0, i32 21
  store i32 0, ptr %47, align 8, !tbaa !15
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.bpacketsync_s, ptr %48, i32 0, i32 20
  %50 = load i32, ptr %49, align 4, !tbaa !17
  %51 = add i32 %50, 1
  store i32 %51, ptr %49, align 4, !tbaa !17
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.bpacketsync_s, ptr %52, i32 0, i32 20
  %54 = load i32, ptr %53, align 4, !tbaa !17
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.bpacketsync_s, ptr %55, i32 0, i32 7
  %57 = load i32, ptr %56, align 4, !tbaa !18
  %58 = icmp eq i32 %54, %57
  br i1 %58, label %59, label %79

59:                                               ; preds = %28
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.bpacketsync_s, ptr %60, i32 0, i32 21
  store i32 0, ptr %61, align 8, !tbaa !15
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.bpacketsync_s, ptr %62, i32 0, i32 20
  store i32 0, ptr %63, align 4, !tbaa !17
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = call i32 @bpacketsync_decode_header(ptr noundef %64)
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.bpacketsync_s, ptr %66, i32 0, i32 24
  %68 = load i32, ptr %67, align 8, !tbaa !19
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %75

70:                                               ; preds = %59
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = call i32 @bpacketsync_reconfig(ptr noundef %71)
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.bpacketsync_s, ptr %73, i32 0, i32 19
  store i32 2, ptr %74, align 8, !tbaa !20
  br label %78

75:                                               ; preds = %59
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = call i32 @bpacketsync_reset(ptr noundef %76)
  br label %78

78:                                               ; preds = %75, %70
  br label %79

79:                                               ; preds = %78, %28
  br label %80

80:                                               ; preds = %79, %2
  ret i32 0
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @bpacketsync_reconfig(ptr noundef) #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" }

!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, !7, i64 140}
!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}
!15 = !{!11, !12, i64 136}
!16 = !{!11, !7, i64 141}
!17 = !{!11, !12, i64 132}
!18 = !{!11, !12, i64 28}
!19 = !{!11, !12, i64 144}
!20 = !{!11, !12, i64 128}


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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @bpacketsync_execute_rxheader(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 140
  %4 = load i8, ptr %3, align 4, !tbaa !5
  %5 = shl i8 %4, 1
  %6 = and i8 %1, 1
  %7 = or disjoint i8 %5, %6
  store i8 %7, ptr %3, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 136
  %9 = load i32, ptr %8, align 8, !tbaa !13
  %10 = add i32 %9, 1
  store i32 %10, ptr %8, align 8, !tbaa !13
  %11 = icmp eq i32 %10, 8
  br i1 %11, label %12, label %35

12:                                               ; preds = %2
  %13 = getelementptr inbounds i8, ptr %0, i64 141
  %14 = load i8, ptr %13, align 1, !tbaa !14
  %15 = xor i8 %14, %7
  %16 = getelementptr inbounds i8, ptr %0, i64 70
  %17 = getelementptr inbounds i8, ptr %0, i64 132
  %18 = load i32, ptr %17, align 4, !tbaa !15
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds [12 x i8], ptr %16, i64 0, i64 %19
  store i8 %15, ptr %20, align 1, !tbaa !16
  store i32 0, ptr %8, align 8, !tbaa !13
  %21 = load i32, ptr %17, align 4, !tbaa !15
  %22 = add i32 %21, 1
  store i32 %22, ptr %17, align 4, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %0, i64 28
  %24 = load i32, ptr %23, align 4, !tbaa !17
  %25 = icmp eq i32 %22, %24
  br i1 %25, label %26, label %35

26:                                               ; preds = %12
  store i32 0, ptr %17, align 4, !tbaa !15
  %27 = tail call i32 @bpacketsync_decode_header(ptr noundef nonnull %0)
  %28 = getelementptr inbounds i8, ptr %0, i64 144
  %29 = load i32, ptr %28, align 8, !tbaa !18
  %.not = icmp eq i32 %29, 0
  br i1 %.not, label %33, label %30

30:                                               ; preds = %26
  %31 = tail call i32 @bpacketsync_reconfig(ptr noundef nonnull %0)
  %32 = getelementptr inbounds i8, ptr %0, i64 128
  store i32 2, ptr %32, align 8, !tbaa !19
  br label %35

33:                                               ; preds = %26
  %34 = tail call i32 @bpacketsync_reset(ptr noundef nonnull %0)
  br label %35

35:                                               ; preds = %12, %33, %30, %2
  ret i32 0
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @bpacketsync_reconfig(ptr noundef) 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" }

!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, !8, i64 140}
!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}
!13 = !{!6, !7, i64 136}
!14 = !{!6, !8, i64 141}
!15 = !{!6, !7, i64 132}
!16 = !{!8, !8, i64 0}
!17 = !{!6, !7, i64 28}
!18 = !{!6, !7, i64 144}
!19 = !{!6, !7, i64 128}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass