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

; 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.bpacketgen_s = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, [6 x i8], [12 x i8], ptr, ptr, ptr }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @bpacketgen_assemble_pnsequence(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.bpacketgen_s, ptr %6, i32 0, i32 12
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = call i32 @msequence_reset(ptr noundef %8)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %3, align 4, !tbaa !12
  br label %10

10:                                               ; preds = %44, %1
  %11 = load i32, ptr %3, align 4, !tbaa !12
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.bpacketgen_s, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = icmp ult i32 %11, %14
  br i1 %15, label %16, label %47

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  store i8 0, ptr %5, align 1, !tbaa !14
  store i32 0, ptr %4, align 4, !tbaa !12
  br label %17

17:                                               ; preds = %33, %16
  %18 = load i32, ptr %4, align 4, !tbaa !12
  %19 = icmp ult i32 %18, 8
  br i1 %19, label %20, label %36

20:                                               ; preds = %17
  %21 = load i8, ptr %5, align 1, !tbaa !14
  %22 = zext i8 %21 to i32
  %23 = shl i32 %22, 1
  %24 = trunc i32 %23 to i8
  store i8 %24, ptr %5, align 1, !tbaa !14
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.bpacketgen_s, ptr %25, i32 0, i32 12
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = call i32 @msequence_advance(ptr noundef %27)
  %29 = load i8, ptr %5, align 1, !tbaa !14
  %30 = zext i8 %29 to i32
  %31 = or i32 %30, %28
  %32 = trunc i32 %31 to i8
  store i8 %32, ptr %5, align 1, !tbaa !14
  br label %33

33:                                               ; preds = %20
  %34 = load i32, ptr %4, align 4, !tbaa !12
  %35 = add i32 %34, 1
  store i32 %35, ptr %4, align 4, !tbaa !12
  br label %17, !llvm.loop !15

36:                                               ; preds = %17
  %37 = load i8, ptr %5, align 1, !tbaa !14
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.bpacketgen_s, ptr %38, i32 0, i32 9
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = load i32, ptr %3, align 4, !tbaa !12
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  store i8 %37, ptr %43, align 1, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  br label %44

44:                                               ; preds = %36
  %45 = load i32, ptr %3, align 4, !tbaa !12
  %46 = add i32 %45, 1
  store i32 %46, ptr %3, align 4, !tbaa !12
  br label %10, !llvm.loop !18

47:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @msequence_reset(ptr noundef) #2

declare i32 @msequence_advance(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, !6, i64 72}
!10 = !{!"bpacketgen_s", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !6, i64 40, !7, i64 48, !7, i64 54, !6, i64 72, !6, i64 80, !6, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !6, i64 40}
!18 = distinct !{!18, !16}


; 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
define dso_local void @bpacketgen_assemble_pnsequence(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 72
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = tail call i32 @msequence_reset(ptr noundef %3) #2
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %._crit_edge, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  %indvars.iv = phi i64 [ 0, %.preheader.lr.ph ], [ %indvars.iv.next, %.preheader ]
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = tail call i32 @msequence_advance(ptr noundef %8) #2
  %10 = trunc i32 %9 to i8
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = tail call i32 @msequence_advance(ptr noundef %11) #2
  %13 = trunc i32 %12 to i8
  %14 = shl i8 %10, 2
  %15 = shl i8 %13, 1
  %16 = or i8 %14, %15
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = tail call i32 @msequence_advance(ptr noundef %17) #2
  %19 = trunc i32 %18 to i8
  %20 = or i8 %16, %19
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = tail call i32 @msequence_advance(ptr noundef %21) #2
  %23 = trunc i32 %22 to i8
  %24 = shl i8 %20, 2
  %25 = shl i8 %23, 1
  %26 = or i8 %24, %25
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = tail call i32 @msequence_advance(ptr noundef %27) #2
  %29 = trunc i32 %28 to i8
  %30 = or i8 %26, %29
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = tail call i32 @msequence_advance(ptr noundef %31) #2
  %33 = trunc i32 %32 to i8
  %34 = shl i8 %30, 2
  %35 = shl i8 %33, 1
  %36 = or i8 %34, %35
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = tail call i32 @msequence_advance(ptr noundef %37) #2
  %39 = trunc i32 %38 to i8
  %40 = or i8 %36, %39
  %41 = shl i8 %40, 1
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = tail call i32 @msequence_advance(ptr noundef %42) #2
  %44 = trunc i32 %43 to i8
  %45 = or i8 %41, %44
  %46 = load ptr, ptr %7, align 8, !tbaa !12
  %47 = getelementptr inbounds i8, ptr %46, i64 %indvars.iv
  store i8 %45, ptr %47, align 1, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %48 = load i32, ptr %5, align 4, !tbaa !11
  %49 = zext i32 %48 to i64
  %50 = icmp ult i64 %indvars.iv.next, %49
  br i1 %50, label %.preheader, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.preheader, %1
  ret void
}

declare i32 @msequence_reset(ptr noundef) local_unnamed_addr #1

declare i32 @msequence_advance(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 72}
!6 = !{!"bpacketgen_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, !8, i64 48, !8, i64 54, !10, i64 72, !10, i64 80, !10, i64 88}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 40}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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