; LLVM IR from jgaeddert/liquid-dsp :: src/vector/src/vectorf_norm.port (liquid_vectorf_norm)

; 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: nounwind uwtable
define dso_local float @liquid_vectorf_norm(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = lshr i32 %8, 2
  %10 = shl i32 %9, 2
  store i32 %10, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store float 0.000000e+00, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %74, %2
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp ult i32 %12, %13
  br i1 %14, label %15, label %77

15:                                               ; preds = %11
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds float, ptr %16, i64 %18
  %20 = load float, ptr %19, align 4, !tbaa !11
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds float, ptr %21, i64 %23
  %25 = load float, ptr %24, align 4, !tbaa !11
  %26 = fmul float %20, -0.000000e+00
  %27 = load float, ptr %6, align 4, !tbaa !11
  %28 = call float @llvm.fmuladd.f32(float %20, float %25, float %27)
  store float %28, ptr %6, align 4, !tbaa !11
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = add i32 %30, 1
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds float, ptr %29, i64 %32
  %34 = load float, ptr %33, align 4, !tbaa !11
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = add i32 %36, 1
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds float, ptr %35, i64 %38
  %40 = load float, ptr %39, align 4, !tbaa !11
  %41 = fmul float %34, -0.000000e+00
  %42 = load float, ptr %6, align 4, !tbaa !11
  %43 = call float @llvm.fmuladd.f32(float %34, float %40, float %42)
  store float %43, ptr %6, align 4, !tbaa !11
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = add i32 %45, 2
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds float, ptr %44, i64 %47
  %49 = load float, ptr %48, align 4, !tbaa !11
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = add i32 %51, 2
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds float, ptr %50, i64 %53
  %55 = load float, ptr %54, align 4, !tbaa !11
  %56 = fmul float %49, -0.000000e+00
  %57 = load float, ptr %6, align 4, !tbaa !11
  %58 = call float @llvm.fmuladd.f32(float %49, float %55, float %57)
  store float %58, ptr %6, align 4, !tbaa !11
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = add i32 %60, 3
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds float, ptr %59, i64 %62
  %64 = load float, ptr %63, align 4, !tbaa !11
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = add i32 %66, 3
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds float, ptr %65, i64 %68
  %70 = load float, ptr %69, align 4, !tbaa !11
  %71 = fmul float %64, -0.000000e+00
  %72 = load float, ptr %6, align 4, !tbaa !11
  %73 = call float @llvm.fmuladd.f32(float %64, float %70, float %72)
  store float %73, ptr %6, align 4, !tbaa !11
  br label %74

74:                                               ; preds = %15
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = add i32 %75, 4
  store i32 %76, ptr %7, align 4, !tbaa !9
  br label %11, !llvm.loop !13

77:                                               ; preds = %11
  br label %78

78:                                               ; preds = %96, %77
  %79 = load i32, ptr %7, align 4, !tbaa !9
  %80 = load i32, ptr %4, align 4, !tbaa !9
  %81 = icmp ult i32 %79, %80
  br i1 %81, label %82, label %99

82:                                               ; preds = %78
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = load i32, ptr %7, align 4, !tbaa !9
  %85 = zext i32 %84 to i64
  %86 = getelementptr inbounds float, ptr %83, i64 %85
  %87 = load float, ptr %86, align 4, !tbaa !11
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = load i32, ptr %7, align 4, !tbaa !9
  %90 = zext i32 %89 to i64
  %91 = getelementptr inbounds float, ptr %88, i64 %90
  %92 = load float, ptr %91, align 4, !tbaa !11
  %93 = fmul float %87, -0.000000e+00
  %94 = load float, ptr %6, align 4, !tbaa !11
  %95 = call float @llvm.fmuladd.f32(float %87, float %92, float %94)
  store float %95, ptr %6, align 4, !tbaa !11
  br label %96

96:                                               ; preds = %82
  %97 = load i32, ptr %7, align 4, !tbaa !9
  %98 = add i32 %97, 1
  store i32 %98, ptr %7, align 4, !tbaa !9
  br label %78, !llvm.loop !15

99:                                               ; preds = %78
  %100 = load float, ptr %6, align 4, !tbaa !11
  %101 = call float @sqrtf(float noundef %100) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret float %101
}

; 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 speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: nounwind
declare float @sqrtf(float noundef) #3

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 nounwind memory(write, argmem: readwrite) uwtable
define dso_local float @liquid_vectorf_norm(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = and i32 %1, -4
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %4 = zext i32 %3 to i64
  br label %.lr.ph

.preheader.loopexit:                              ; preds = %.lr.ph
  %5 = trunc nuw i64 %indvars.iv.next to i32
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %2
  %.032.lcssa = phi float [ 0.000000e+00, %2 ], [ %28, %.preheader.loopexit ]
  %.0.lcssa = phi i32 [ 0, %2 ], [ %5, %.preheader.loopexit ]
  %6 = icmp ult i32 %.0.lcssa, %1
  br i1 %6, label %.lr.ph39.preheader, label %._crit_edge

.lr.ph39.preheader:                               ; preds = %.preheader
  %7 = zext i32 %.0.lcssa to i64
  %wide.trip.count = zext i32 %1 to i64
  %8 = sub nsw i64 %wide.trip.count, %7
  %xtraiter = and i64 %8, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph39.prol.loopexit, label %.lr.ph39.prol

.lr.ph39.prol:                                    ; preds = %.lr.ph39.preheader, %.lr.ph39.prol
  %indvars.iv44.prol = phi i64 [ %indvars.iv.next45.prol, %.lr.ph39.prol ], [ %7, %.lr.ph39.preheader ]
  %.13337.prol = phi float [ %11, %.lr.ph39.prol ], [ %.032.lcssa, %.lr.ph39.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph39.prol ], [ 0, %.lr.ph39.preheader ]
  %9 = getelementptr inbounds float, ptr %0, i64 %indvars.iv44.prol
  %10 = load float, ptr %9, align 4, !tbaa !5
  %11 = tail call float @llvm.fmuladd.f32(float %10, float %10, float %.13337.prol)
  %indvars.iv.next45.prol = add nuw nsw i64 %indvars.iv44.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph39.prol.loopexit, label %.lr.ph39.prol, !llvm.loop !9

.lr.ph39.prol.loopexit:                           ; preds = %.lr.ph39.prol, %.lr.ph39.preheader
  %.lcssa.unr = phi float [ poison, %.lr.ph39.preheader ], [ %11, %.lr.ph39.prol ]
  %indvars.iv44.unr = phi i64 [ %7, %.lr.ph39.preheader ], [ %indvars.iv.next45.prol, %.lr.ph39.prol ]
  %.13337.unr = phi float [ %.032.lcssa, %.lr.ph39.preheader ], [ %11, %.lr.ph39.prol ]
  %12 = sub nsw i64 %7, %wide.trip.count
  %13 = icmp ugt i64 %12, -4
  br i1 %13, label %._crit_edge, label %.lr.ph39.preheader.new

.lr.ph39.preheader.new:                           ; preds = %.lr.ph39.prol.loopexit
  %invariant.gep = getelementptr i8, ptr %0, i64 4
  %invariant.gep53 = getelementptr i8, ptr %0, i64 8
  %invariant.gep55 = getelementptr i8, ptr %0, i64 12
  br label %.lr.ph39

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.03234 = phi float [ 0.000000e+00, %.lr.ph.preheader ], [ %28, %.lr.ph ]
  %14 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  %15 = load float, ptr %14, align 4, !tbaa !5
  %16 = tail call float @llvm.fmuladd.f32(float %15, float %15, float %.03234)
  %17 = or disjoint i64 %indvars.iv, 1
  %18 = getelementptr inbounds float, ptr %0, i64 %17
  %19 = load float, ptr %18, align 4, !tbaa !5
  %20 = tail call float @llvm.fmuladd.f32(float %19, float %19, float %16)
  %21 = or disjoint i64 %indvars.iv, 2
  %22 = getelementptr inbounds float, ptr %0, i64 %21
  %23 = load float, ptr %22, align 4, !tbaa !5
  %24 = tail call float @llvm.fmuladd.f32(float %23, float %23, float %20)
  %25 = or disjoint i64 %indvars.iv, 3
  %26 = getelementptr inbounds float, ptr %0, i64 %25
  %27 = load float, ptr %26, align 4, !tbaa !5
  %28 = tail call float @llvm.fmuladd.f32(float %27, float %27, float %24)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 4
  %29 = icmp ult i64 %indvars.iv.next, %4
  br i1 %29, label %.lr.ph, label %.preheader.loopexit, !llvm.loop !11

.lr.ph39:                                         ; preds = %.lr.ph39, %.lr.ph39.preheader.new
  %indvars.iv44 = phi i64 [ %indvars.iv44.unr, %.lr.ph39.preheader.new ], [ %indvars.iv.next45.3, %.lr.ph39 ]
  %.13337 = phi float [ %.13337.unr, %.lr.ph39.preheader.new ], [ %38, %.lr.ph39 ]
  %30 = getelementptr inbounds float, ptr %0, i64 %indvars.iv44
  %31 = load float, ptr %30, align 4, !tbaa !5
  %32 = tail call float @llvm.fmuladd.f32(float %31, float %31, float %.13337)
  %gep = getelementptr float, ptr %invariant.gep, i64 %indvars.iv44
  %33 = load float, ptr %gep, align 4, !tbaa !5
  %34 = tail call float @llvm.fmuladd.f32(float %33, float %33, float %32)
  %gep54 = getelementptr float, ptr %invariant.gep53, i64 %indvars.iv44
  %35 = load float, ptr %gep54, align 4, !tbaa !5
  %36 = tail call float @llvm.fmuladd.f32(float %35, float %35, float %34)
  %gep56 = getelementptr float, ptr %invariant.gep55, i64 %indvars.iv44
  %37 = load float, ptr %gep56, align 4, !tbaa !5
  %38 = tail call float @llvm.fmuladd.f32(float %37, float %37, float %36)
  %indvars.iv.next45.3 = add nuw nsw i64 %indvars.iv44, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next45.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph39, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph39.prol.loopexit, %.lr.ph39, %.preheader
  %.133.lcssa = phi float [ %.032.lcssa, %.preheader ], [ %.lcssa.unr, %.lr.ph39.prol.loopexit ], [ %38, %.lr.ph39 ]
  %39 = tail call float @sqrtf(float noundef %.133.lcssa) #3
  ret float %39
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @sqrtf(float noundef) local_unnamed_addr #2

attributes #0 = { nofree nounwind memory(write, 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(write) "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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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