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

; 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.flexframesync_s = type { ptr, ptr, %struct.framesyncstats_s, %struct.framedatastats_s, i32, float, ptr, float, float, float, float, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i32, ptr, i32, ptr, ptr, i32, ptr, i32, i32, ptr, i32, %struct.flexframegenprops_s, i32, ptr, ptr, i32, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, ptr }
%struct.framesyncstats_s = type { float, float, float, ptr, i32, i32, i32, i32, i32, i32 }
%struct.framedatastats_s = type { i32, i32, i32, i64 }
%struct.flexframegenprops_s = type { i32, i32, i32, i32 }

declare ptr @qpacketmodem_create(...) #0

declare i32 @qpacketmodem_configure(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

declare i32 @qpacketmodem_get_frame_len(ptr noundef) #0

declare i32 @qpilotsync_destroy(ptr noundef) #0

declare i32 @qpacketmodem_destroy(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @flexframesync_set_header_len(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.flexframesync_s, ptr %6, i32 0, i32 26
  store i32 %5, ptr %7, align 8, !tbaa !11
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.flexframesync_s, ptr %8, i32 0, i32 26
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = add i32 6, %10
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.flexframesync_s, ptr %12, i32 0, i32 27
  store i32 %11, ptr %13, align 4, !tbaa !18
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.flexframesync_s, ptr %14, i32 0, i32 28
  %16 = load ptr, ptr %15, align 8, !tbaa !19
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.flexframesync_s, ptr %17, i32 0, i32 27
  %19 = load i32, ptr %18, align 4, !tbaa !18
  %20 = zext i32 %19 to i64
  %21 = mul i64 %20, 1
  %22 = call ptr @realloc(ptr noundef %16, i64 noundef %21) #3
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.flexframesync_s, ptr %23, i32 0, i32 28
  store ptr %22, ptr %24, align 8, !tbaa !19
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.flexframesync_s, ptr %25, i32 0, i32 25
  %27 = load ptr, ptr %26, align 8, !tbaa !20
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %34

29:                                               ; preds = %2
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.flexframesync_s, ptr %30, i32 0, i32 25
  %32 = load ptr, ptr %31, align 8, !tbaa !20
  %33 = call i32 @qpacketmodem_destroy(ptr noundef %32)
  br label %34

34:                                               ; preds = %29, %2
  %35 = call ptr (...) @qpacketmodem_create()
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.flexframesync_s, ptr %36, i32 0, i32 25
  store ptr %35, ptr %37, align 8, !tbaa !20
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.flexframesync_s, ptr %38, i32 0, i32 25
  %40 = load ptr, ptr %39, align 8, !tbaa !20
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.flexframesync_s, ptr %41, i32 0, i32 27
  %43 = load i32, ptr %42, align 4, !tbaa !18
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.flexframesync_s, ptr %44, i32 0, i32 30
  %46 = getelementptr inbounds %struct.flexframegenprops_s, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 4, !tbaa !21
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.flexframesync_s, ptr %48, i32 0, i32 30
  %50 = getelementptr inbounds %struct.flexframegenprops_s, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !22
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.flexframesync_s, ptr %52, i32 0, i32 30
  %54 = getelementptr inbounds %struct.flexframegenprops_s, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 4, !tbaa !23
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.flexframesync_s, ptr %56, i32 0, i32 30
  %58 = getelementptr inbounds %struct.flexframegenprops_s, ptr %57, i32 0, i32 3
  %59 = load i32, ptr %58, align 4, !tbaa !24
  %60 = call i32 @qpacketmodem_configure(ptr noundef %40, i32 noundef %43, i32 noundef %47, i32 noundef %51, i32 noundef %55, i32 noundef %59)
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.flexframesync_s, ptr %61, i32 0, i32 25
  %63 = load ptr, ptr %62, align 8, !tbaa !20
  %64 = call i32 @qpacketmodem_get_frame_len(ptr noundef %63)
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.flexframesync_s, ptr %65, i32 0, i32 24
  store i32 %64, ptr %66, align 8, !tbaa !25
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.flexframesync_s, ptr %67, i32 0, i32 23
  %69 = load ptr, ptr %68, align 8, !tbaa !26
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.flexframesync_s, ptr %70, i32 0, i32 24
  %72 = load i32, ptr %71, align 8, !tbaa !25
  %73 = zext i32 %72 to i64
  %74 = mul i64 %73, 8
  %75 = call ptr @realloc(ptr noundef %69, i64 noundef %74) #3
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.flexframesync_s, ptr %76, i32 0, i32 23
  store ptr %75, ptr %77, align 8, !tbaa !26
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.flexframesync_s, ptr %78, i32 0, i32 22
  %80 = load ptr, ptr %79, align 8, !tbaa !27
  %81 = icmp ne ptr %80, null
  br i1 %81, label %82, label %87

82:                                               ; preds = %34
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.flexframesync_s, ptr %83, i32 0, i32 22
  %85 = load ptr, ptr %84, align 8, !tbaa !27
  %86 = call i32 @qpilotsync_destroy(ptr noundef %85)
  br label %87

87:                                               ; preds = %82, %34
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.flexframesync_s, ptr %88, i32 0, i32 24
  %90 = load i32, ptr %89, align 8, !tbaa !25
  %91 = call ptr @qpilotsync_create(i32 noundef %90, i32 noundef 16)
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.flexframesync_s, ptr %92, i32 0, i32 22
  store ptr %91, ptr %93, align 8, !tbaa !27
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.flexframesync_s, ptr %94, i32 0, i32 22
  %96 = load ptr, ptr %95, align 8, !tbaa !27
  %97 = call i32 @qpilotsync_get_frame_len(ptr noundef %96)
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.flexframesync_s, ptr %98, i32 0, i32 21
  store i32 %97, ptr %99, align 8, !tbaa !28
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.flexframesync_s, ptr %100, i32 0, i32 20
  %102 = load ptr, ptr %101, align 8, !tbaa !29
  %103 = load ptr, ptr %3, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.flexframesync_s, ptr %103, i32 0, i32 21
  %105 = load i32, ptr %104, align 8, !tbaa !28
  %106 = zext i32 %105 to i64
  %107 = mul i64 %106, 8
  %108 = call ptr @realloc(ptr noundef %102, i64 noundef %107) #3
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.flexframesync_s, ptr %109, i32 0, i32 20
  store ptr %108, ptr %110, align 8, !tbaa !29
  ret i32 0
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #2

declare ptr @qpilotsync_create(i32 noundef, i32 noundef) #0

declare i32 @qpilotsync_get_frame_len(ptr noundef) #0

attributes #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"="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 allocsize(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 #3 = { nounwind allocsize(1) }

!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 232}
!12 = !{!"flexframesync_s", !6, i64 0, !6, i64 8, !13, i64 16, !15, i64 64, !10, i64 88, !14, i64 92, !6, i64 96, !14, i64 104, !14, i64 108, !14, i64 112, !14, i64 116, !6, i64 120, !6, i64 128, !6, i64 136, !10, i64 144, !10, i64 148, !10, i64 152, !6, i64 160, !6, i64 168, !10, i64 176, !6, i64 184, !10, i64 192, !6, i64 200, !6, i64 208, !10, i64 216, !6, i64 224, !10, i64 232, !10, i64 236, !6, i64 240, !10, i64 248, !17, i64 252, !10, i64 268, !6, i64 272, !6, i64 280, !10, i64 288, !6, i64 296, !6, i64 304, !10, i64 312, !10, i64 316, !10, i64 320, !10, i64 324, !10, i64 328, !10, i64 332, !10, i64 336, !10, i64 340, !6, i64 344}
!13 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44}
!14 = !{!"float", !7, i64 0}
!15 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !16, i64 16}
!16 = !{!"long", !7, i64 0}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!18 = !{!12, !10, i64 236}
!19 = !{!12, !6, i64 240}
!20 = !{!12, !6, i64 224}
!21 = !{!12, !10, i64 252}
!22 = !{!12, !10, i64 256}
!23 = !{!12, !10, i64 260}
!24 = !{!12, !10, i64 264}
!25 = !{!12, !10, i64 216}
!26 = !{!12, !6, i64 208}
!27 = !{!12, !6, i64 200}
!28 = !{!12, !10, i64 192}
!29 = !{!12, !6, i64 184}


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

declare ptr @qpacketmodem_create(...) local_unnamed_addr #0

declare i32 @qpacketmodem_configure(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare i32 @qpacketmodem_get_frame_len(ptr noundef) local_unnamed_addr #0

declare i32 @qpilotsync_destroy(ptr noundef) local_unnamed_addr #0

declare i32 @qpacketmodem_destroy(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @flexframesync_set_header_len(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 232
  store i32 %1, ptr %3, align 8, !tbaa !5
  %4 = add i32 %1, 6
  %5 = getelementptr inbounds i8, ptr %0, i64 236
  store i32 %4, ptr %5, align 4, !tbaa !16
  %6 = getelementptr inbounds i8, ptr %0, i64 240
  %7 = load ptr, ptr %6, align 8, !tbaa !17
  %8 = zext i32 %4 to i64
  %9 = tail call ptr @realloc(ptr noundef %7, i64 noundef %8) #3
  store ptr %9, ptr %6, align 8, !tbaa !17
  %10 = getelementptr inbounds i8, ptr %0, i64 224
  %11 = load ptr, ptr %10, align 8, !tbaa !18
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %14, label %12

12:                                               ; preds = %2
  %13 = tail call i32 @qpacketmodem_destroy(ptr noundef nonnull %11) #4
  br label %14

14:                                               ; preds = %12, %2
  %15 = tail call ptr (...) @qpacketmodem_create() #4
  store ptr %15, ptr %10, align 8, !tbaa !18
  %16 = load i32, ptr %5, align 4, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %0, i64 252
  %18 = load i32, ptr %17, align 4, !tbaa !19
  %19 = getelementptr inbounds i8, ptr %0, i64 256
  %20 = load i32, ptr %19, align 4, !tbaa !20
  %21 = getelementptr inbounds i8, ptr %0, i64 260
  %22 = load i32, ptr %21, align 4, !tbaa !21
  %23 = getelementptr inbounds i8, ptr %0, i64 264
  %24 = load i32, ptr %23, align 4, !tbaa !22
  %25 = tail call i32 @qpacketmodem_configure(ptr noundef %15, i32 noundef %16, i32 noundef %18, i32 noundef %20, i32 noundef %22, i32 noundef %24) #4
  %26 = load ptr, ptr %10, align 8, !tbaa !18
  %27 = tail call i32 @qpacketmodem_get_frame_len(ptr noundef %26) #4
  %28 = getelementptr inbounds i8, ptr %0, i64 216
  store i32 %27, ptr %28, align 8, !tbaa !23
  %29 = getelementptr inbounds i8, ptr %0, i64 208
  %30 = load ptr, ptr %29, align 8, !tbaa !24
  %31 = zext i32 %27 to i64
  %32 = shl nuw nsw i64 %31, 3
  %33 = tail call ptr @realloc(ptr noundef %30, i64 noundef %32) #3
  store ptr %33, ptr %29, align 8, !tbaa !24
  %34 = getelementptr inbounds i8, ptr %0, i64 200
  %35 = load ptr, ptr %34, align 8, !tbaa !25
  %.not30 = icmp eq ptr %35, null
  br i1 %.not30, label %38, label %36

36:                                               ; preds = %14
  %37 = tail call i32 @qpilotsync_destroy(ptr noundef nonnull %35) #4
  br label %38

38:                                               ; preds = %36, %14
  %39 = load i32, ptr %28, align 8, !tbaa !23
  %40 = tail call ptr @qpilotsync_create(i32 noundef %39, i32 noundef 16) #4
  store ptr %40, ptr %34, align 8, !tbaa !25
  %41 = tail call i32 @qpilotsync_get_frame_len(ptr noundef %40) #4
  %42 = getelementptr inbounds i8, ptr %0, i64 192
  store i32 %41, ptr %42, align 8, !tbaa !26
  %43 = getelementptr inbounds i8, ptr %0, i64 184
  %44 = load ptr, ptr %43, align 8, !tbaa !27
  %45 = zext i32 %41 to i64
  %46 = shl nuw nsw i64 %45, 3
  %47 = tail call ptr @realloc(ptr noundef %44, i64 noundef %46) #3
  store ptr %47, ptr %43, align 8, !tbaa !27
  ret i32 0
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

declare ptr @qpilotsync_create(i32 noundef, i32 noundef) local_unnamed_addr #0

declare i32 @qpilotsync_get_frame_len(ptr noundef) local_unnamed_addr #0

attributes #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"="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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(1) }
attributes #4 = { 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, !12, i64 232}
!6 = !{!"flexframesync_s", !7, i64 0, !7, i64 8, !10, i64 16, !13, i64 64, !12, i64 88, !11, i64 92, !7, i64 96, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !7, i64 120, !7, i64 128, !7, i64 136, !12, i64 144, !12, i64 148, !12, i64 152, !7, i64 160, !7, i64 168, !12, i64 176, !7, i64 184, !12, i64 192, !7, i64 200, !7, i64 208, !12, i64 216, !7, i64 224, !12, i64 232, !12, i64 236, !7, i64 240, !12, i64 248, !15, i64 252, !12, i64 268, !7, i64 272, !7, i64 280, !12, i64 288, !7, i64 296, !7, i64 304, !12, i64 312, !12, i64 316, !12, i64 320, !12, i64 324, !12, i64 328, !12, i64 332, !12, i64 336, !12, i64 340, !7, i64 344}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !7, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44}
!11 = !{!"float", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !14, i64 16}
!14 = !{!"long", !8, i64 0}
!15 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12}
!16 = !{!6, !12, i64 236}
!17 = !{!6, !7, i64 240}
!18 = !{!6, !7, i64 224}
!19 = !{!6, !12, i64 252}
!20 = !{!6, !12, i64 256}
!21 = !{!6, !12, i64 260}
!22 = !{!6, !12, i64 264}
!23 = !{!6, !12, i64 216}
!24 = !{!6, !7, i64 208}
!25 = !{!6, !7, i64 200}
!26 = !{!6, !12, i64 192}
!27 = !{!6, !7, i64 184}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass