; LLVM IR from CerebusOSS/CereLink :: cbhwlib/CCFUtilsBinary.ll (ZN14CCFUtilsBinary22ReadCCFData_cb2005_310EP8_IO_FILE)

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

%class.CCFUtilsBinary = type { %class.CCFUtils.base, [2 x i8], %"struct.ccf::ccfBinaryData" }
%class.CCFUtils.base = type <{ ptr, ptr, i8, [7 x i8], ptr, i8, [7 x i8], ptr, i32, i32, i32, [4 x i8], ptr, i8, i8 }>
%"struct.ccf::ccfBinaryData" = type <{ [160 x %struct.cbPKT_CHANINFO], %"struct.ccf::cbPKT_ADAPTFILTINFO_CB2005_37", %"struct.ccf::cbPKT_SS_DETECT_CB2005_37", %"struct.ccf::cbPKT_SS_ARTIF_REJECT_CB2005_37", [144 x %"struct.ccf::cbPKT_SS_NOISE_BOUNDARY_CB2005_37_type"], %"struct.ccf::cbPKT_SS_STATISTICS_CB2005_37_type", %"struct.ccf::cbPKT_SS_STATUS_CB2005_37", %"struct.ccf::cbPKT_SYSINFO_CB2005_37", [72 x %"struct.ccf::cbPKT_NTRODEINFO_CB2005_37"] }>
%struct.cbPKT_CHANINFO = type { %struct.cbPKT_HEADER, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.cbSCALING, %struct.cbFILTDESC, %struct.cbSCALING, %struct.cbFILTDESC, [16 x i8], i32, [4 x i32], %struct.cbSCALING, %struct.cbSCALING, i32, i32, i32, i32, %union.anon, i8, [2 x i8], i8, i16, i16, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, [5 x %struct.cbMANUALUNITMAPPING], [5 x [4 x %struct.cbHOOP]] }
%struct.cbPKT_HEADER = type { i64, i16, i16, i16, i8, i8 }
%struct.cbFILTDESC = type { [16 x i8], i32, i32, i32, i32, i32, i32 }
%struct.cbSCALING = type { i16, i16, i32, i32, i32, [8 x i8] }
%union.anon = type { %struct.anon }
%struct.anon = type { i16, i16, i32 }
%struct.cbMANUALUNITMAPPING = type { i16, [3 x i16], [3 x [3 x i16]], i16, i32 }
%struct.cbHOOP = type { i16, i16, i16, i16 }
%"struct.ccf::cbPKT_ADAPTFILTINFO_CB2005_37" = type { i32, i16, i8, i8, i32, i32, float, i32, i32 }
%"struct.ccf::cbPKT_SS_DETECT_CB2005_37" = type { i32, i16, i8, i8, float, float }
%"struct.ccf::cbPKT_SS_ARTIF_REJECT_CB2005_37" = type { i32, i16, i8, i8, i32, i32 }
%"struct.ccf::cbPKT_SS_NOISE_BOUNDARY_CB2005_37_type" = type { i32, i16, i8, i8, i32, [3 x float], [3 x [3 x float]] }
%"struct.ccf::cbPKT_SS_STATISTICS_CB2005_37_type" = type { i32, i16, i8, i8, i32, i32, i32, float, float, float, float, float, float, float, i32, i32 }
%"struct.ccf::cbPKT_SS_STATUS_CB2005_37" = type { i32, i16, i8, i8, %"struct.ccf::cbAdaptControl_37", %"struct.ccf::cbAdaptControl_37" }
%"struct.ccf::cbAdaptControl_37" = type { i32, float, float }
%"struct.ccf::cbPKT_SYSINFO_CB2005_37" = type { i32, i16, i8, i8, i32, i32, i32, i32, i32, i32 }
%"struct.ccf::cbPKT_NTRODEINFO_CB2005_37" = type { i32, i16, i8, i8, i32, [16 x i8], [6 x [5 x %"struct.ccf::cbMANUALUNITMAPPING_37"]], i16, i16, [4 x i16] }
%"struct.ccf::cbMANUALUNITMAPPING_37" = type { i16, [3 x i16], [3 x [3 x i16]], i16, i32 }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN14CCFUtilsBinary22ReadCCFData_cb2005_310EP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(189696) %0, ptr noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %37, %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 160
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %40

12:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %13 = getelementptr inbounds %class.CCFUtilsBinary, ptr %7, i32 0, i32 2
  %14 = getelementptr inbounds %"struct.ccf::ccfBinaryData", ptr %13, i32 0, i32 0
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [160 x %struct.cbPKT_CHANINFO], ptr %14, i64 0, i64 %16
  store ptr %17, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 1 %18, i8 0, i64 680, i1 false)
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call i64 @fread(ptr noundef %19, i64 noundef 1, i64 noundef 680, ptr noundef %20)
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.cbPKT_CHANINFO, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 1, !tbaa !11
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %36

26:                                               ; preds = %12
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.cbPKT_CHANINFO, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %28, i32 0, i32 1
  store i16 -32768, ptr %29, align 1, !tbaa !18
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.cbPKT_CHANINFO, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %31, i32 0, i32 2
  store i16 192, ptr %32, align 1, !tbaa !19
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.cbPKT_CHANINFO, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %34, i32 0, i32 3
  store i16 164, ptr %35, align 1, !tbaa !20
  br label %36

36:                                               ; preds = %26, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !21

40:                                               ; preds = %11
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN14CCFUtilsBinary13ReadAsPacketsEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(189696) %7, ptr noundef %41)
  ret i32 0
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14CCFUtilsBinary13ReadAsPacketsEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(189696), ptr noundef) #3 align 2

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTS14cbPKT_CHANINFO", !13, i64 0, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !16, i64 56, !17, i64 80, !16, i64 120, !17, i64 144, !7, i64 184, !10, i64 200, !7, i64 204, !16, i64 220, !16, i64 244, !10, i64 268, !10, i64 272, !10, i64 276, !10, i64 280, !7, i64 284, !7, i64 292, !7, i64 293, !7, i64 295, !15, i64 296, !15, i64 298, !10, i64 300, !10, i64 304, !10, i64 308, !10, i64 312, !10, i64 316, !10, i64 320, !10, i64 324, !10, i64 328, !10, i64 332, !10, i64 336, !10, i64 340, !10, i64 344, !10, i64 348, !15, i64 352, !15, i64 354, !10, i64 356, !7, i64 360, !7, i64 520}
!13 = !{!"_ZTS12cbPKT_HEADER", !14, i64 0, !15, i64 8, !15, i64 10, !15, i64 12, !7, i64 14, !7, i64 15}
!14 = !{!"long", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"_ZTS9cbSCALING", !15, i64 0, !15, i64 2, !10, i64 4, !10, i64 8, !10, i64 12, !7, i64 16}
!17 = !{!"_ZTS10cbFILTDESC", !7, i64 0, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36}
!18 = !{!12, !15, i64 8}
!19 = !{!12, !15, i64 10}
!20 = !{!12, !15, i64 12}
!21 = distinct !{!21, !22}
!22 = !{!"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.cbPKT_CHANINFO = type { %struct.cbPKT_HEADER, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.cbSCALING, %struct.cbFILTDESC, %struct.cbSCALING, %struct.cbFILTDESC, [16 x i8], i32, [4 x i32], %struct.cbSCALING, %struct.cbSCALING, i32, i32, i32, i32, %union.anon, i8, [2 x i8], i8, i16, i16, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, [5 x %struct.cbMANUALUNITMAPPING], [5 x [4 x %struct.cbHOOP]] }
%struct.cbPKT_HEADER = type { i64, i16, i16, i16, i8, i8 }
%struct.cbFILTDESC = type { [16 x i8], i32, i32, i32, i32, i32, i32 }
%struct.cbSCALING = type { i16, i16, i32, i32, i32, [8 x i8] }
%union.anon = type { %struct.anon }
%struct.anon = type { i16, i16, i32 }
%struct.cbMANUALUNITMAPPING = type { i16, [3 x i16], [3 x [3 x i16]], i16, i32 }
%struct.cbHOOP = type { i16, i16, i16, i16 }

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN14CCFUtilsBinary22ReadCCFData_cb2005_310EP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(189696) %0, ptr noundef %1) local_unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 76
  br label %5

4:                                                ; preds = %14
  tail call void @_ZN14CCFUtilsBinary13ReadAsPacketsEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(189696) %0, ptr noundef %1)
  ret i32 0

5:                                                ; preds = %2, %14
  %indvars.iv = phi i64 [ 0, %2 ], [ %indvars.iv.next, %14 ]
  %6 = getelementptr inbounds [160 x %struct.cbPKT_CHANINFO], ptr %3, i64 0, i64 %indvars.iv
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(680) %6, i8 0, i64 680, i1 false)
  %7 = tail call i64 @fread(ptr noundef nonnull %6, i64 noundef 1, i64 noundef 680, ptr noundef %1)
  %8 = getelementptr inbounds i8, ptr %6, i64 16
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %14, label %10

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %6, i64 8
  store i16 -32768, ptr %11, align 4, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %6, i64 10
  store i16 192, ptr %12, align 2, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %6, i64 12
  store i16 164, ptr %13, align 8, !tbaa !17
  br label %14

14:                                               ; preds = %10, %5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 160
  br i1 %exitcond.not, label %4, label %5, !llvm.loop !18
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14CCFUtilsBinary13ReadAsPacketsEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(189696), ptr noundef) local_unnamed_addr #2 align 2

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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" }
attributes #2 = { mustprogress 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, !12, i64 16}
!6 = !{!"_ZTS14cbPKT_CHANINFO", !7, i64 0, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !13, i64 56, !14, i64 80, !13, i64 120, !14, i64 144, !9, i64 184, !12, i64 200, !9, i64 204, !13, i64 220, !13, i64 244, !12, i64 268, !12, i64 272, !12, i64 276, !12, i64 280, !9, i64 284, !9, i64 292, !9, i64 293, !9, i64 295, !11, i64 296, !11, i64 298, !12, i64 300, !12, i64 304, !12, i64 308, !12, i64 312, !12, i64 316, !12, i64 320, !12, i64 324, !12, i64 328, !12, i64 332, !12, i64 336, !12, i64 340, !12, i64 344, !12, i64 348, !11, i64 352, !11, i64 354, !12, i64 356, !9, i64 360, !9, i64 520}
!7 = !{!"_ZTS12cbPKT_HEADER", !8, i64 0, !11, i64 8, !11, i64 10, !11, i64 12, !9, i64 14, !9, i64 15}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"short", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!"_ZTS9cbSCALING", !11, i64 0, !11, i64 2, !12, i64 4, !12, i64 8, !12, i64 12, !9, i64 16}
!14 = !{!"_ZTS10cbFILTDESC", !9, i64 0, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36}
!15 = !{!6, !11, i64 8}
!16 = !{!6, !11, i64 10}
!17 = !{!6, !11, i64 12}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass