; LLVM IR from jgaeddert/liquid-dsp :: src/fec/src (packetizer)

; 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.packetizer_s = type { i32, i32, i32, i32, ptr, i32, i32, ptr, ptr }
%struct.fecintlv_plan = type { i32, i32, i32, ptr, ptr }

@.str.3 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [35 x i8], align 1
@crc_scheme_str = external global [7 x [2 x ptr]], align 16
@.str.5 = external hidden unnamed_addr constant [34 x i8], align 1
@fec_scheme_str = external global [28 x [2 x ptr]], align 16

; 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
define dso_local i32 @packetizer_print(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.packetizer_s, ptr %4, i32 0, i32 0
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.packetizer_s, ptr %7, i32 0, i32 1
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %6, i32 noundef %9)
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.packetizer_s, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.packetizer_s, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.packetizer_s, ptr %17, i32 0, i32 3
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = add i32 %16, %19
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.packetizer_s, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !14
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds [7 x [2 x ptr]], ptr @crc_scheme_str, i64 0, i64 %24
  %26 = getelementptr inbounds [2 x ptr], ptr %25, i64 0, i64 0
  %27 = load ptr, ptr %26, align 16, !tbaa !5
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %13, i32 noundef %20, ptr noundef %27)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !15
  br label %29

29:                                               ; preds = %66, %1
  %30 = load i32, ptr %3, align 4, !tbaa !15
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.packetizer_s, ptr %31, i32 0, i32 5
  %33 = load i32, ptr %32, align 8, !tbaa !16
  %34 = icmp ult i32 %30, %33
  br i1 %34, label %35, label %69

35:                                               ; preds = %29
  %36 = load i32, ptr %3, align 4, !tbaa !15
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.packetizer_s, ptr %37, i32 0, i32 4
  %39 = load ptr, ptr %38, align 8, !tbaa !17
  %40 = load i32, ptr %3, align 4, !tbaa !15
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds %struct.fecintlv_plan, ptr %39, i64 %41
  %43 = getelementptr inbounds %struct.fecintlv_plan, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !18
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.packetizer_s, ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !17
  %48 = load i32, ptr %3, align 4, !tbaa !15
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds %struct.fecintlv_plan, ptr %47, i64 %49
  %51 = getelementptr inbounds %struct.fecintlv_plan, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !20
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.packetizer_s, ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !17
  %56 = load i32, ptr %3, align 4, !tbaa !15
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds %struct.fecintlv_plan, ptr %55, i64 %57
  %59 = getelementptr inbounds %struct.fecintlv_plan, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 8, !tbaa !21
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds [28 x [2 x ptr]], ptr @fec_scheme_str, i64 0, i64 %61
  %63 = getelementptr inbounds [2 x ptr], ptr %62, i64 0, i64 1
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %36, i32 noundef %44, i32 noundef %52, ptr noundef %64)
  br label %66

66:                                               ; preds = %35
  %67 = load i32, ptr %3, align 4, !tbaa !15
  %68 = add i32 %67, 1
  store i32 %68, ptr %3, align 4, !tbaa !15
  br label %29, !llvm.loop !22

69:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 0
}

declare i32 @printf(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, !11, i64 0}
!10 = !{!"packetizer_s", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16, !11, i64 24, !11, i64 28, !6, i64 32, !6, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !11, i64 12}
!14 = !{!10, !11, i64 8}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !11, i64 24}
!17 = !{!10, !6, i64 16}
!18 = !{!19, !11, i64 0}
!19 = !{!"fecintlv_plan", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24}
!20 = !{!19, !11, i64 4}
!21 = !{!19, !11, i64 8}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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

%struct.fecintlv_plan = type { i32, i32, i32, ptr, ptr }

@.str.3 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [35 x i8], align 1
@crc_scheme_str = external local_unnamed_addr global [7 x [2 x ptr]], align 16
@.str.5 = external hidden unnamed_addr constant [34 x i8], align 1
@fec_scheme_str = external local_unnamed_addr global [28 x [2 x ptr]], align 16

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @packetizer_print(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !11
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %2, i32 noundef %4)
  %6 = load i32, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !12
  %9 = add i32 %8, %6
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds [7 x [2 x ptr]], ptr @crc_scheme_str, i64 0, i64 %12
  %14 = load ptr, ptr %13, align 16, !tbaa !14
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %6, i32 noundef %9, ptr noundef %14)
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  %17 = load i32, ptr %16, align 8, !tbaa !15
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  br label %19

19:                                               ; preds = %.lr.ph, %19
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %19 ]
  %20 = load ptr, ptr %18, align 8, !tbaa !16
  %21 = getelementptr inbounds %struct.fecintlv_plan, ptr %20, i64 %indvars.iv
  %22 = load i32, ptr %21, align 8, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %21, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !19
  %25 = getelementptr inbounds i8, ptr %21, i64 8
  %26 = load i32, ptr %25, align 8, !tbaa !20
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [28 x [2 x ptr]], ptr @fec_scheme_str, i64 0, i64 %27, i64 1
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = trunc nuw i64 %indvars.iv to i32
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %30, i32 noundef %22, i32 noundef %24, ptr noundef %29)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = load i32, ptr %16, align 8, !tbaa !15
  %33 = zext i32 %32 to i64
  %34 = icmp ult i64 %indvars.iv.next, %33
  br i1 %34, label %19, label %._crit_edge, !llvm.loop !21

._crit_edge:                                      ; preds = %19, %1
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { nofree 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 = { nofree nounwind "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, !7, i64 0}
!6 = !{!"packetizer_s", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !7, i64 24, !7, i64 28, !10, i64 32, !10, i64 40}
!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, !7, i64 12}
!13 = !{!6, !7, i64 8}
!14 = !{!10, !10, i64 0}
!15 = !{!6, !7, i64 24}
!16 = !{!6, !10, i64 16}
!17 = !{!18, !7, i64 0}
!18 = !{!"fecintlv_plan", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24}
!19 = !{!18, !7, i64 4}
!20 = !{!18, !7, i64 8}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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