; LLVM IR from dbry/wavpack-stream :: src (common_utils)

; 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.WavpackContext = type { %struct.WavpackStreamConfig, ptr, i32, i32, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, i64, i64, i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, i8, ptr, ptr, i32, i32, ptr, [8 x i8], ptr, [80 x i8] }
%struct.WavpackStreamConfig = type { float, float, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x i8], i8, i32, ptr }

; 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 void @WavpackStreamGetChannelIdentities(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.WavpackContext, ptr %9, i32 0, i32 0
  %11 = getelementptr inbounds %struct.WavpackStreamConfig, ptr %10, i32 0, i32 7
  %12 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %12, ptr %5, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1, ptr %6, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.WavpackContext, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.WavpackStreamConfig, ptr %14, i32 0, i32 13
  %16 = load i32, ptr %15, align 4, !tbaa !16
  store i32 %16, ptr %7, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.WavpackContext, ptr %17, i32 0, i32 40
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  store ptr %19, ptr %8, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %64, %2
  %21 = load i32, ptr %5, align 4, !tbaa !15
  %22 = add nsw i32 %21, -1
  store i32 %22, ptr %5, align 4, !tbaa !15
  %23 = icmp ne i32 %21, 0
  br i1 %23, label %24, label %65

24:                                               ; preds = %20
  %25 = load i32, ptr %7, align 4, !tbaa !15
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %46

27:                                               ; preds = %24
  br label %28

28:                                               ; preds = %33, %27
  %29 = load i32, ptr %7, align 4, !tbaa !15
  %30 = and i32 %29, 1
  %31 = icmp ne i32 %30, 0
  %32 = xor i1 %31, true
  br i1 %32, label %33, label %38

33:                                               ; preds = %28
  %34 = load i32, ptr %7, align 4, !tbaa !15
  %35 = lshr i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !15
  %36 = load i32, ptr %6, align 4, !tbaa !15
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %6, align 4, !tbaa !15
  br label %28, !llvm.loop !18

38:                                               ; preds = %28
  %39 = load i32, ptr %6, align 4, !tbaa !15
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %6, align 4, !tbaa !15
  %41 = trunc i32 %39 to i8
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i32 1
  store ptr %43, ptr %4, align 8, !tbaa !5
  store i8 %41, ptr %42, align 1, !tbaa !20
  %44 = load i32, ptr %7, align 4, !tbaa !15
  %45 = lshr i32 %44, 1
  store i32 %45, ptr %7, align 4, !tbaa !15
  br label %64

46:                                               ; preds = %24
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %60

49:                                               ; preds = %46
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load i8, ptr %50, align 1, !tbaa !20
  %52 = zext i8 %51 to i32
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %60

54:                                               ; preds = %49
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i32 1
  store ptr %56, ptr %8, align 8, !tbaa !5
  %57 = load i8, ptr %55, align 1, !tbaa !20
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i32 1
  store ptr %59, ptr %4, align 8, !tbaa !5
  store i8 %57, ptr %58, align 1, !tbaa !20
  br label %63

60:                                               ; preds = %49, %46
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i32 1
  store ptr %62, ptr %4, align 8, !tbaa !5
  store i8 -1, ptr %61, align 1, !tbaa !20
  br label %63

63:                                               ; preds = %60, %54
  br label %64

64:                                               ; preds = %63, %38
  br label %20, !llvm.loop !21

65:                                               ; preds = %20
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  store i8 0, ptr %66, align 1, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

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 = { 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, !13, i64 28}
!10 = !{!"WavpackContext", !11, i64 0, !6, i64 88, !13, i64 96, !13, i64 100, !6, i64 104, !13, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !14, i64 168, !14, i64 176, !14, i64 184, !14, i64 192, !14, i64 200, !14, i64 208, !13, i64 216, !13, i64 220, !13, i64 224, !13, i64 228, !13, i64 232, !13, i64 236, !13, i64 240, !13, i64 244, !13, i64 248, !13, i64 252, !13, i64 256, !13, i64 260, !13, i64 264, !13, i64 268, !13, i64 272, !13, i64 276, !13, i64 280, !13, i64 284, !6, i64 288, !6, i64 296, !7, i64 304, !6, i64 312, !6, i64 320, !13, i64 328, !13, i64 332, !6, i64 336, !7, i64 344, !6, i64 352, !7, i64 360}
!11 = !{!"", !12, i64 0, !12, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !7, i64 56, !7, i64 72, !13, i64 76, !6, i64 80}
!12 = !{!"float", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!10, !13, i64 52}
!17 = !{!10, !6, i64 320}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !19}


; 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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @WavpackStreamGetChannelIdentities(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 28
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not32 = icmp eq i32 %4, 0
  br i1 %.not32, label %._crit_edge39, label %.lr.ph38.preheader

.lr.ph38.preheader:                               ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 320
  %6 = load ptr, ptr %5, align 8, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %0, i64 52
  %8 = load i32, ptr %7, align 4, !tbaa !15
  br label %.lr.ph38

.lr.ph38:                                         ; preds = %.lr.ph38.preheader, %22
  %.in = phi i32 [ %9, %22 ], [ %4, %.lr.ph38.preheader ]
  %.036 = phi ptr [ %.1, %22 ], [ %6, %.lr.ph38.preheader ]
  %.01635 = phi i32 [ %.2, %22 ], [ %8, %.lr.ph38.preheader ]
  %.01834 = phi i8 [ %.220, %22 ], [ 1, %.lr.ph38.preheader ]
  %.02233 = phi ptr [ %.123, %22 ], [ %1, %.lr.ph38.preheader ]
  %9 = add nsw i32 %.in, -1
  %.not24 = icmp eq i32 %.01635, 0
  br i1 %.not24, label %16, label %.preheader

.preheader:                                       ; preds = %.lr.ph38
  %10 = and i32 %.01635, 1
  %.not2728 = icmp eq i32 %10, 0
  br i1 %.not2728, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.11730 = phi i32 [ %11, %.lr.ph ], [ %.01635, %.preheader ]
  %.11929 = phi i8 [ %12, %.lr.ph ], [ %.01834, %.preheader ]
  %11 = lshr exact i32 %.11730, 1
  %12 = add i8 %.11929, 1
  %13 = and i32 %.11730, 2
  %.not27 = icmp eq i32 %13, 0
  br i1 %.not27, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.119.lcssa = phi i8 [ %.01834, %.preheader ], [ %12, %.lr.ph ]
  %.117.lcssa = phi i32 [ %.01635, %.preheader ], [ %11, %.lr.ph ]
  %14 = add i8 %.119.lcssa, 1
  store i8 %.119.lcssa, ptr %.02233, align 1, !tbaa !18
  %15 = lshr i32 %.117.lcssa, 1
  br label %22

16:                                               ; preds = %.lr.ph38
  %.not25 = icmp eq ptr %.036, null
  br i1 %.not25, label %21, label %17

17:                                               ; preds = %16
  %18 = load i8, ptr %.036, align 1, !tbaa !18
  %.not26 = icmp eq i8 %18, 0
  br i1 %.not26, label %21, label %19

19:                                               ; preds = %17
  %20 = getelementptr inbounds i8, ptr %.036, i64 1
  store i8 %18, ptr %.02233, align 1, !tbaa !18
  br label %22

21:                                               ; preds = %17, %16
  store i8 -1, ptr %.02233, align 1, !tbaa !18
  br label %22

22:                                               ; preds = %19, %21, %._crit_edge
  %.220 = phi i8 [ %14, %._crit_edge ], [ %.01834, %19 ], [ %.01834, %21 ]
  %.2 = phi i32 [ %15, %._crit_edge ], [ 0, %19 ], [ 0, %21 ]
  %.1 = phi ptr [ %.036, %._crit_edge ], [ %20, %19 ], [ %.036, %21 ]
  %.123 = getelementptr inbounds i8, ptr %.02233, i64 1
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %._crit_edge39, label %.lr.ph38, !llvm.loop !19

._crit_edge39:                                    ; preds = %22, %2
  %.022.lcssa = phi ptr [ %1, %2 ], [ %.123, %22 ]
  store i8 0, ptr %.022.lcssa, align 1, !tbaa !18
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 28}
!6 = !{!"WavpackContext", !7, i64 0, !12, i64 88, !11, i64 96, !11, i64 100, !12, i64 104, !11, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !13, i64 168, !13, i64 176, !13, i64 184, !13, i64 192, !13, i64 200, !13, i64 208, !11, i64 216, !11, i64 220, !11, i64 224, !11, i64 228, !11, i64 232, !11, i64 236, !11, i64 240, !11, i64 244, !11, i64 248, !11, i64 252, !11, i64 256, !11, i64 260, !11, i64 264, !11, i64 268, !11, i64 272, !11, i64 276, !11, i64 280, !11, i64 284, !12, i64 288, !12, i64 296, !9, i64 304, !12, i64 312, !12, i64 320, !11, i64 328, !11, i64 332, !12, i64 336, !9, i64 344, !12, i64 352, !9, i64 360}
!7 = !{!"", !8, i64 0, !8, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !9, i64 56, !9, i64 72, !11, i64 76, !12, i64 80}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"long", !9, i64 0}
!14 = !{!6, !12, i64 320}
!15 = !{!6, !11, i64 52}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!9, !9, i64 0}
!19 = distinct !{!19, !17}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass