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

; 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 @WavpackStreamFloatNormalize(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %10, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %14, label %13

13:                                               ; preds = %3
  store i32 1, ptr %9, align 4
  br label %70

14:                                               ; preds = %3
  br label %15

15:                                               ; preds = %66, %14
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = add nsw i32 %16, -1
  store i32 %17, ptr %5, align 4, !tbaa !9
  %18 = icmp ne i32 %16, 0
  br i1 %18, label %19, label %69

19:                                               ; preds = %15
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = ashr i32 %21, 23
  %23 = and i32 %22, 255
  store i32 %23, ptr %8, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %30, label %25

25:                                               ; preds = %19
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = add nsw i32 %26, %27
  %29 = icmp sle i32 %28, 0
  br i1 %29, label %30, label %32

30:                                               ; preds = %25, %19
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %31, align 4, !tbaa !9
  br label %66

32:                                               ; preds = %25
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = icmp eq i32 %33, 255
  br i1 %34, label %40, label %35

35:                                               ; preds = %32
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = add nsw i32 %37, %36
  store i32 %38, ptr %8, align 4, !tbaa !9
  %39 = icmp sge i32 %38, 255
  br i1 %39, label %40, label %55

40:                                               ; preds = %35, %32
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = xor i32 %42, 2139095040
  %44 = and i32 %43, 2139095040
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = xor i32 %46, %44
  store i32 %47, ptr %45, align 4, !tbaa !9
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = xor i32 %49, 0
  %51 = and i32 %50, 8388607
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = xor i32 %53, %51
  store i32 %54, ptr %52, align 4, !tbaa !9
  br label %65

55:                                               ; preds = %35
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = shl i32 %58, 23
  %60 = xor i32 %57, %59
  %61 = and i32 %60, 2139095040
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = load i32, ptr %62, align 4, !tbaa !9
  %64 = xor i32 %63, %61
  store i32 %64, ptr %62, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %55, %40
  br label %66

66:                                               ; preds = %65, %30
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds i32, ptr %67, i32 1
  store ptr %68, ptr %7, align 8, !tbaa !5
  br label %15, !llvm.loop !11

69:                                               ; preds = %15
  store i32 0, ptr %9, align 4
  br label %70

70:                                               ; preds = %69, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  %71 = load i32, ptr %9, align 4
  switch i32 %71, label %73 [
    i32 0, label %72
    i32 1, label %72
  ]

72:                                               ; preds = %70, %70
  ret void

73:                                               ; preds = %70
  unreachable
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @WavpackStreamFloatNormalize(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i32 %2, 0
  %.not2022 = icmp eq i32 %1, 0
  %or.cond24 = or i1 %.not, %.not2022
  br i1 %or.cond24, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %4 = zext i32 %1 to i64
  %min.iters.check = icmp ult i32 %1, 4
  br i1 %min.iters.check, label %.lr.ph.preheader32, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %4, 4294967292
  %.cast = trunc nuw i64 %n.vec to i32
  %ind.end = sub i32 %1, %.cast
  %5 = shl nuw nsw i64 %n.vec, 2
  %ind.end25 = getelementptr i8, ptr %0, i64 %5
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %2, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %0, i64 %offset.idx
  %wide.load = load <4 x i32>, ptr %next.gep, align 4, !tbaa !5
  %6 = lshr <4 x i32> %wide.load, <i32 23, i32 23, i32 23, i32 23>
  %7 = and <4 x i32> %6, <i32 255, i32 255, i32 255, i32 255>
  %8 = icmp ne <4 x i32> %7, zeroinitializer
  %9 = add nsw <4 x i32> %7, %broadcast.splat
  %10 = icmp slt <4 x i32> %9, <i32 1, i32 1, i32 1, i32 1>
  %11 = xor <4 x i1> %10, <i1 true, i1 true, i1 true, i1 true>
  %12 = select <4 x i1> %8, <4 x i1> %11, <4 x i1> zeroinitializer
  %13 = icmp ne <4 x i32> %7, <i32 255, i32 255, i32 255, i32 255>
  %14 = icmp ult <4 x i32> %9, <i32 255, i32 255, i32 255, i32 255>
  %.not31 = and <4 x i1> %13, %14
  %15 = select <4 x i1> %12, <4 x i1> %.not31, <4 x i1> zeroinitializer
  %16 = shl nuw nsw <4 x i32> %9, <i32 23, i32 23, i32 23, i32 23>
  %17 = and <4 x i32> %wide.load, <i32 -2139095041, i32 -2139095041, i32 -2139095041, i32 -2139095041>
  %18 = or disjoint <4 x i32> %16, %17
  %19 = and <4 x i32> %wide.load, <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>
  %20 = or disjoint <4 x i32> %19, <i32 2139095040, i32 2139095040, i32 2139095040, i32 2139095040>
  %21 = select <4 x i1> %8, <4 x i1> %10, <4 x i1> zeroinitializer
  %predphi = select <4 x i1> %15, <4 x i32> %18, <4 x i32> %20
  %predphi27 = select <4 x i1> %21, <4 x i32> zeroinitializer, <4 x i32> %predphi
  %predphi28 = select <4 x i1> %8, <4 x i32> %predphi27, <4 x i32> zeroinitializer
  store <4 x i32> %predphi28, ptr %next.gep, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %4
  br i1 %cmp.n, label %.loopexit, label %.lr.ph.preheader32

.lr.ph.preheader32:                               ; preds = %middle.block, %.lr.ph.preheader
  %.in.ph = phi i32 [ %1, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.023.ph = phi ptr [ %0, %.lr.ph.preheader ], [ %ind.end25, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader32, %39
  %.in = phi i32 [ %23, %39 ], [ %.in.ph, %.lr.ph.preheader32 ]
  %.023 = phi ptr [ %40, %39 ], [ %.023.ph, %.lr.ph.preheader32 ]
  %23 = add nsw i32 %.in, -1
  %24 = load i32, ptr %.023, align 4, !tbaa !5
  %25 = lshr i32 %24, 23
  %26 = and i32 %25, 255
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %39, label %28

28:                                               ; preds = %.lr.ph
  %29 = add nsw i32 %26, %2
  %30 = icmp slt i32 %29, 1
  br i1 %30, label %39, label %31

31:                                               ; preds = %28
  %32 = icmp eq i32 %26, 255
  %33 = icmp ugt i32 %29, 254
  %or.cond = or i1 %32, %33
  br i1 %or.cond, label %34, label %36

34:                                               ; preds = %31
  %and.ra21 = and i32 %24, -2147483648
  %35 = or disjoint i32 %and.ra21, 2139095040
  br label %39

36:                                               ; preds = %31
  %37 = shl nuw nsw i32 %29, 23
  %and.ra = and i32 %24, -2139095041
  %38 = or disjoint i32 %37, %and.ra
  br label %39

39:                                               ; preds = %.lr.ph, %28, %34, %36
  %.sink = phi i32 [ %35, %34 ], [ %38, %36 ], [ 0, %28 ], [ 0, %.lr.ph ]
  store i32 %.sink, ptr %.023, align 4, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %.023, i64 4
  %.not20 = icmp eq i32 %23, 0
  br i1 %.not20, label %.loopexit, label %.lr.ph, !llvm.loop !13

.loopexit:                                        ; preds = %39, %middle.block, %3
  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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass