; LLVM IR from dbry/wavpack-stream :: src (entropy_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.WavpackStream = type { %struct.WavpackHeader, %struct.words_data, ptr, ptr, ptr, ptr, ptr, i64, i64, i32, i32, i32, i8, i8, i8, i8, i8, i8, i8, i32, i32, i32, i32, i32, i32, i32, i32, %struct.bs, %struct.bs, %struct.bs, float, i8, i8, i8, i8, i8, i8, i8, i8, %struct.anon, [16 x %struct.decorr_pass], %struct.decorr_pass, ptr, %struct.anon.0 }
%struct.WavpackHeader = type { [4 x i8], i16, i16, i32 }
%struct.words_data = type { [2 x i32], [2 x i32], i32, i32, i32, i32, i32, [2 x %struct.entropy_data] }
%struct.entropy_data = type { [3 x i32], i32, i32 }
%struct.bs = type { ptr, ptr, ptr, ptr, i32, i32, i32 }
%struct.anon = type { [2 x i32], [2 x i32], [2 x i32], double, double, double, ptr, ptr, i32 }
%struct.decorr_pass = type { i32, i32, i32, i32, [8 x i32], [8 x i32], i32, i32, i32, i32 }
%struct.anon.0 = type { ptr, ptr, ptr, ptr, ptr, i8, i8, i32, i32, i32, ptr, i32, i32, i32, [2 x %struct.DSDfilters], ptr }
%struct.DSDfilters = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; 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 @word_set_bitrate(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.WavpackStream, ptr %5, i32 0, i32 0
  %7 = getelementptr inbounds %struct.WavpackHeader, ptr %6, i32 0, i32 3
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = and i32 %8, 512
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %96

11:                                               ; preds = %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.WavpackStream, ptr %12, i32 0, i32 0
  %14 = getelementptr inbounds %struct.WavpackHeader, ptr %13, i32 0, i32 3
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = and i32 %15, 1073741824
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %35

18:                                               ; preds = %11
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.WavpackStream, ptr %19, i32 0, i32 9
  %21 = load i32, ptr %20, align 8, !tbaa !22
  %22 = mul nsw i32 %21, 2
  %23 = sub nsw i32 %22, 512
  %24 = icmp slt i32 %23, 568
  br i1 %24, label %25, label %26

25:                                               ; preds = %18
  br label %33

26:                                               ; preds = %18
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.WavpackStream, ptr %27, i32 0, i32 9
  %29 = load i32, ptr %28, align 8, !tbaa !22
  %30 = mul nsw i32 %29, 2
  %31 = sub nsw i32 %30, 512
  %32 = sub nsw i32 %31, 568
  br label %33

33:                                               ; preds = %26, %25
  %34 = phi i32 [ 0, %25 ], [ %32, %26 ]
  store i32 %34, ptr %3, align 4, !tbaa !23
  br label %48

35:                                               ; preds = %11
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.WavpackStream, ptr %36, i32 0, i32 9
  %38 = load i32, ptr %37, align 8, !tbaa !22
  %39 = icmp slt i32 %38, 568
  br i1 %39, label %40, label %41

40:                                               ; preds = %35
  br label %46

41:                                               ; preds = %35
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.WavpackStream, ptr %42, i32 0, i32 9
  %44 = load i32, ptr %43, align 8, !tbaa !22
  %45 = sub nsw i32 %44, 568
  br label %46

46:                                               ; preds = %41, %40
  %47 = phi i32 [ 0, %40 ], [ %45, %41 ]
  store i32 %47, ptr %3, align 4, !tbaa !23
  br label %48

48:                                               ; preds = %46, %33
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.WavpackStream, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds %struct.WavpackHeader, ptr %50, i32 0, i32 3
  %52 = load i32, ptr %51, align 8, !tbaa !9
  %53 = and i32 %52, 1073741828
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %94, label %55

55:                                               ; preds = %48
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.WavpackStream, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds %struct.WavpackHeader, ptr %57, i32 0, i32 3
  %59 = load i32, ptr %58, align 8, !tbaa !9
  %60 = and i32 %59, 1024
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %71

62:                                               ; preds = %55
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.WavpackStream, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds %struct.WavpackHeader, ptr %64, i32 0, i32 3
  %66 = load i32, ptr %65, align 8, !tbaa !9
  %67 = and i32 %66, 16
  %68 = icmp ne i32 %67, 0
  %69 = zext i1 %68 to i64
  %70 = select i1 %68, i32 256, i32 0
  store i32 %70, ptr %4, align 4, !tbaa !23
  br label %93

71:                                               ; preds = %55
  %72 = load i32, ptr %3, align 4, !tbaa !23
  store i32 %72, ptr %4, align 4, !tbaa !23
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.WavpackStream, ptr %73, i32 0, i32 0
  %75 = getelementptr inbounds %struct.WavpackHeader, ptr %74, i32 0, i32 3
  %76 = load i32, ptr %75, align 8, !tbaa !9
  %77 = and i32 %76, 16
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %92

79:                                               ; preds = %71
  %80 = load i32, ptr %3, align 4, !tbaa !23
  %81 = icmp slt i32 %80, 128
  br i1 %81, label %82, label %86

82:                                               ; preds = %79
  %83 = load i32, ptr %3, align 4, !tbaa !23
  %84 = load i32, ptr %4, align 4, !tbaa !23
  %85 = add nsw i32 %84, %83
  store i32 %85, ptr %4, align 4, !tbaa !23
  store i32 0, ptr %3, align 4, !tbaa !23
  br label %91

86:                                               ; preds = %79
  %87 = load i32, ptr %3, align 4, !tbaa !23
  %88 = sub nsw i32 %87, 128
  store i32 %88, ptr %3, align 4, !tbaa !23
  %89 = load i32, ptr %4, align 4, !tbaa !23
  %90 = add nsw i32 %89, 128
  store i32 %90, ptr %4, align 4, !tbaa !23
  br label %91

91:                                               ; preds = %86, %82
  br label %92

92:                                               ; preds = %91, %71
  br label %93

93:                                               ; preds = %92, %62
  br label %95

94:                                               ; preds = %48
  store i32 0, ptr %4, align 4, !tbaa !23
  br label %95

95:                                               ; preds = %94, %93
  br label %97

96:                                               ; preds = %1
  store i32 0, ptr %4, align 4, !tbaa !23
  store i32 0, ptr %3, align 4, !tbaa !23
  br label %97

97:                                               ; preds = %96, %95
  %98 = load i32, ptr %3, align 4, !tbaa !23
  %99 = shl i32 %98, 16
  %100 = load ptr, ptr %2, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.WavpackStream, ptr %100, i32 0, i32 1
  %102 = getelementptr inbounds %struct.words_data, ptr %101, i32 0, i32 1
  %103 = getelementptr inbounds [2 x i32], ptr %102, i64 0, i64 0
  store i32 %99, ptr %103, align 4, !tbaa !23
  %104 = load i32, ptr %4, align 4, !tbaa !23
  %105 = shl i32 %104, 16
  %106 = load ptr, ptr %2, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.WavpackStream, ptr %106, i32 0, i32 1
  %108 = getelementptr inbounds %struct.words_data, ptr %107, i32 0, i32 1
  %109 = getelementptr inbounds [2 x i32], ptr %108, i64 0, i64 1
  store i32 %105, ptr %109, align 4, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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

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 8}
!10 = !{!"", !11, i64 0, !14, i64 12, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !15, i64 128, !15, i64 136, !13, i64 144, !13, i64 148, !13, i64 152, !7, i64 156, !7, i64 157, !7, i64 158, !7, i64 159, !7, i64 160, !7, i64 161, !7, i64 162, !13, i64 164, !13, i64 168, !13, i64 172, !13, i64 176, !13, i64 180, !13, i64 184, !13, i64 188, !13, i64 192, !16, i64 200, !16, i64 248, !16, i64 296, !17, i64 344, !7, i64 348, !7, i64 349, !7, i64 350, !7, i64 351, !7, i64 352, !7, i64 353, !7, i64 354, !7, i64 355, !18, i64 360, !7, i64 432, !20, i64 1968, !6, i64 2064, !21, i64 2072}
!11 = !{!"", !7, i64 0, !12, i64 4, !12, i64 6, !13, i64 8}
!12 = !{!"short", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"words_data", !7, i64 0, !7, i64 8, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !7, i64 36}
!15 = !{!"long", !7, i64 0}
!16 = !{!"bs", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !13, i64 36, !13, i64 40}
!17 = !{!"float", !7, i64 0}
!18 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !19, i64 24, !19, i64 32, !19, i64 40, !6, i64 48, !6, i64 56, !13, i64 64}
!19 = !{!"double", !7, i64 0}
!20 = !{!"decorr_pass", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !7, i64 16, !7, i64 48, !13, i64 80, !13, i64 84, !13, i64 88, !13, i64 92}
!21 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !7, i64 41, !13, i64 44, !13, i64 48, !13, i64 52, !6, i64 56, !13, i64 64, !13, i64 68, !13, i64 72, !7, i64 76, !6, i64 160}
!22 = !{!10, !13, i64 144}
!23 = !{!13, !13, i64 0}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @word_set_bitrate(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = and i32 %3, 512
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %33, label %5

5:                                                ; preds = %1
  %6 = and i32 %3, 1073741824
  %.not22 = icmp eq i32 %6, 0
  %7 = getelementptr inbounds i8, ptr %0, i64 144
  %8 = load i32, ptr %7, align 8, !tbaa !21
  br i1 %.not22, label %14, label %9

9:                                                ; preds = %5
  %10 = icmp slt i32 %8, 540
  %11 = shl nuw nsw i32 %8, 1
  %12 = add nsw i32 %11, -1080
  %13 = select i1 %10, i32 0, i32 %12
  br label %17

14:                                               ; preds = %5
  %15 = icmp slt i32 %8, 568
  %16 = add nsw i32 %8, -568
  %spec.select = select i1 %15, i32 0, i32 %16
  br label %17

17:                                               ; preds = %14, %9
  %.019 = phi i32 [ %13, %9 ], [ %spec.select, %14 ]
  %18 = and i32 %3, 1073741828
  %.not23 = icmp eq i32 %18, 0
  br i1 %.not23, label %19, label %33

19:                                               ; preds = %17
  %20 = and i32 %3, 1024
  %.not24 = icmp eq i32 %20, 0
  br i1 %.not24, label %24, label %21

21:                                               ; preds = %19
  %22 = shl i32 %3, 4
  %23 = and i32 %22, 256
  br label %33

24:                                               ; preds = %19
  %25 = and i32 %3, 16
  %.not25 = icmp eq i32 %25, 0
  br i1 %.not25, label %33, label %26

26:                                               ; preds = %24
  %27 = icmp slt i32 %.019, 128
  br i1 %27, label %28, label %30

28:                                               ; preds = %26
  %29 = shl nuw nsw i32 %.019, 1
  br label %33

30:                                               ; preds = %26
  %31 = add nsw i32 %.019, -128
  %32 = add nuw nsw i32 %.019, 128
  br label %33

33:                                               ; preds = %1, %17, %24, %30, %28, %21
  %.1 = phi i32 [ %.019, %21 ], [ 0, %28 ], [ %31, %30 ], [ %.019, %24 ], [ %.019, %17 ], [ 0, %1 ]
  %.0 = phi i32 [ %23, %21 ], [ %29, %28 ], [ %32, %30 ], [ %.019, %24 ], [ 0, %17 ], [ 0, %1 ]
  %34 = shl i32 %.1, 16
  %35 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %34, ptr %35, align 4, !tbaa !22
  %36 = shl i32 %.0, 16
  %37 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %36, ptr %37, align 4, !tbaa !22
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 = !{!"", !7, i64 0, !12, i64 12, !13, i64 88, !13, i64 96, !13, i64 104, !13, i64 112, !13, i64 120, !14, i64 128, !14, i64 136, !11, i64 144, !11, i64 148, !11, i64 152, !8, i64 156, !8, i64 157, !8, i64 158, !8, i64 159, !8, i64 160, !8, i64 161, !8, i64 162, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176, !11, i64 180, !11, i64 184, !11, i64 188, !11, i64 192, !15, i64 200, !15, i64 248, !15, i64 296, !16, i64 344, !8, i64 348, !8, i64 349, !8, i64 350, !8, i64 351, !8, i64 352, !8, i64 353, !8, i64 354, !8, i64 355, !17, i64 360, !8, i64 432, !19, i64 1968, !13, i64 2064, !20, i64 2072}
!7 = !{!"", !8, i64 0, !10, i64 4, !10, i64 6, !11, i64 8}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"words_data", !8, i64 0, !8, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !8, i64 36}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"long", !8, i64 0}
!15 = !{!"bs", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !11, i64 32, !11, i64 36, !11, i64 40}
!16 = !{!"float", !8, i64 0}
!17 = !{!"", !8, i64 0, !8, i64 8, !8, i64 16, !18, i64 24, !18, i64 32, !18, i64 40, !13, i64 48, !13, i64 56, !11, i64 64}
!18 = !{!"double", !8, i64 0}
!19 = !{!"decorr_pass", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !8, i64 16, !8, i64 48, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92}
!20 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !8, i64 40, !8, i64 41, !11, i64 44, !11, i64 48, !11, i64 52, !13, i64 56, !11, i64 64, !11, i64 68, !11, i64 72, !8, i64 76, !13, i64 160}
!21 = !{!6, !11, i64 144}
!22 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass