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

; 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.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: 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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN14CCFUtilsBinary18SetChannelDefaultsER14cbPKT_CHANINFO(ptr noundef nonnull align 8 dereferenceable(189696) %0, ptr noundef nonnull align 1 dereferenceable(680) %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 1 %7, i8 0, i64 680, i1 false)
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.cbPKT_CHANINFO, ptr %8, i32 0, i32 0
  %10 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %9, i32 0, i32 0
  store i64 0, ptr %10, align 1, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.cbPKT_CHANINFO, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %12, i32 0, i32 1
  store i16 -32768, ptr %13, align 1, !tbaa !17
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.cbPKT_CHANINFO, ptr %14, i32 0, i32 0
  %16 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %15, i32 0, i32 2
  store i16 192, ptr %16, align 1, !tbaa !18
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.cbPKT_CHANINFO, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %18, i32 0, i32 3
  store i16 164, ptr %19, align 1, !tbaa !19
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.cbPKT_CHANINFO, ptr %20, i32 0, i32 38
  store i32 511, ptr %21, align 1, !tbaa !20
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.cbPKT_CHANINFO, ptr %22, i32 0, i32 45
  store i32 0, ptr %23, align 1, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !22
  br label %24

24:                                               ; preds = %37, %2
  %25 = load i32, ptr %5, align 4, !tbaa !22
  %26 = icmp slt i32 %25, 5
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %24
  %29 = load i32, ptr %5, align 4, !tbaa !22
  %30 = trunc i32 %29 to i16
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.cbPKT_CHANINFO, ptr %31, i32 0, i32 46
  %33 = load i32, ptr %5, align 4, !tbaa !22
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [5 x %struct.cbMANUALUNITMAPPING], ptr %32, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.cbMANUALUNITMAPPING, ptr %35, i32 0, i32 0
  store i16 %30, ptr %36, align 1, !tbaa !23
  br label %37

37:                                               ; preds = %28
  %38 = load i32, ptr %5, align 4, !tbaa !22
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !22
  br label %24, !llvm.loop !25

40:                                               ; preds = %27
  ret void
}

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

; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @_ZN14CCFUtilsBinary18SetChannelDefaultsER14cbPKT_CHANINFO(ptr nocapture noundef nonnull readnone align 8 dereferenceable(189696) %0, ptr nocapture noundef nonnull writeonly align 1 dereferenceable(680) %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(680) %1, i8 0, i64 680, i1 false)
  store i16 -32768, ptr %3, align 1, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 10
  store i16 192, ptr %4, align 1, !tbaa !15
  %5 = getelementptr inbounds i8, ptr %1, i64 12
  store i16 164, ptr %5, align 1, !tbaa !16
  %6 = getelementptr inbounds i8, ptr %1, i64 332
  store i32 511, ptr %6, align 1, !tbaa !17
  %7 = getelementptr inbounds i8, ptr %1, i64 360
  store i16 0, ptr %7, align 1, !tbaa !18
  %8 = getelementptr inbounds i8, ptr %1, i64 392
  store i16 1, ptr %8, align 1, !tbaa !18
  %9 = getelementptr inbounds i8, ptr %1, i64 424
  store i16 2, ptr %9, align 1, !tbaa !18
  %10 = getelementptr inbounds i8, ptr %1, i64 456
  store i16 3, ptr %10, align 1, !tbaa !18
  %11 = getelementptr inbounds i8, ptr %1, i64 488
  store i16 4, ptr %11, align 1, !tbaa !18
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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, !11, i64 8}
!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 10}
!16 = !{!6, !11, i64 12}
!17 = !{!6, !12, i64 332}
!18 = !{!19, !11, i64 0}
!19 = !{!"_ZTS19cbMANUALUNITMAPPING", !11, i64 0, !9, i64 2, !9, i64 8, !11, i64 26, !12, i64 28}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass