; LLVM IR from sp-nitech/SPTK :: third_party/REAPER/wave/wave.ll (ZN4sptk6reaper4Wave13AmplifyBufferEfPsj)

; 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: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN4sptk6reaper4Wave13AmplifyBufferEfPsj(float noundef %0, ptr noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca float, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  store float %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  store i8 0, ptr %7, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %39, %3
  %11 = load i32, ptr %8, align 4, !tbaa !11
  %12 = load i32, ptr %6, align 4, !tbaa !11
  %13 = icmp ult i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %42

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = load i32, ptr %8, align 4, !tbaa !11
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds i16, ptr %16, i64 %18
  %20 = load i16, ptr %19, align 2, !tbaa !15
  %21 = sitofp i16 %20 to float
  %22 = load float, ptr %4, align 4, !tbaa !5
  %23 = fmul float %21, %22
  store float %23, ptr %9, align 4, !tbaa !5
  %24 = load float, ptr %9, align 4, !tbaa !5
  %25 = fcmp ogt float %24, 3.276600e+04
  br i1 %25, label %26, label %27

26:                                               ; preds = %15
  store float 3.276600e+04, ptr %9, align 4, !tbaa !5
  store i8 1, ptr %7, align 1, !tbaa !13
  br label %32

27:                                               ; preds = %15
  %28 = load float, ptr %9, align 4, !tbaa !5
  %29 = fcmp olt float %28, -3.276700e+04
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  store float -3.276700e+04, ptr %9, align 4, !tbaa !5
  store i8 1, ptr %7, align 1, !tbaa !13
  br label %31

31:                                               ; preds = %30, %27
  br label %32

32:                                               ; preds = %31, %26
  %33 = load float, ptr %9, align 4, !tbaa !5
  %34 = fptosi float %33 to i16
  %35 = load ptr, ptr %5, align 8, !tbaa !9
  %36 = load i32, ptr %8, align 4, !tbaa !11
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds i16, ptr %35, i64 %37
  store i16 %34, ptr %38, align 2, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %39

39:                                               ; preds = %32
  %40 = load i32, ptr %8, align 4, !tbaa !11
  %41 = add i32 %40, 1
  store i32 %41, ptr %8, align 4, !tbaa !11
  br label %10, !llvm.loop !17

42:                                               ; preds = %14
  %43 = load i8, ptr %7, align 1, !tbaa !13, !range !19, !noundef !20
  %44 = trunc i8 %43 to i1
  %45 = xor i1 %44, true
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  ret i1 %45
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{i8 0, i8 2}
!20 = !{}


; 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 memory(argmem: readwrite) uwtable
define dso_local noundef zeroext i1 @_ZN4sptk6reaper4Wave13AmplifyBufferEfPsj(float noundef %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %4 = icmp eq i32 %2, 1
  br i1 %4, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %32, %.lr.ph.preheader
  %.1.lcssa.ph = phi i1 [ poison, %.lr.ph.preheader ], [ %.1.1, %32 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %32 ]
  %.01214.unr = phi i1 [ false, %.lr.ph.preheader ], [ %.1.1, %32 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %5 = getelementptr inbounds i16, ptr %1, i64 %indvars.iv.unr
  %6 = load i16, ptr %5, align 2, !tbaa !5
  %7 = sitofp i16 %6 to float
  %8 = fmul float %7, %0
  %9 = fcmp ogt float %8, 3.276600e+04
  br i1 %9, label %._crit_edge.loopexit.epilog-lcssa, label %10

10:                                               ; preds = %.lr.ph.epil
  %11 = fcmp olt float %8, -3.276700e+04
  br i1 %11, label %12, label %._crit_edge.loopexit.epilog-lcssa

12:                                               ; preds = %10
  br label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %12, %10, %.lr.ph.epil
  %.1.epil = phi i1 [ true, %12 ], [ %.01214.unr, %10 ], [ true, %.lr.ph.epil ]
  %.0.epil = phi float [ -3.276700e+04, %12 ], [ %8, %10 ], [ 3.276600e+04, %.lr.ph.epil ]
  %13 = fptosi float %.0.epil to i16
  store i16 %13, ptr %5, align 2, !tbaa !5
  br label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %._crit_edge.loopexit.unr-lcssa, %._crit_edge.loopexit.epilog-lcssa
  %.1.lcssa = phi i1 [ %.1.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.1.epil, %._crit_edge.loopexit.epilog-lcssa ]
  %14 = xor i1 %.1.lcssa, true
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %3
  %.012.lcssa = phi i1 [ true, %3 ], [ %14, %._crit_edge.loopexit ]
  ret i1 %.012.lcssa

.lr.ph:                                           ; preds = %32, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %32 ]
  %.01214 = phi i1 [ false, %.lr.ph.preheader.new ], [ %.1.1, %32 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %32 ]
  %15 = getelementptr inbounds i16, ptr %1, i64 %indvars.iv
  %16 = load i16, ptr %15, align 2, !tbaa !5
  %17 = sitofp i16 %16 to float
  %18 = fmul float %17, %0
  %19 = fcmp ogt float %18, 3.276600e+04
  br i1 %19, label %.lr.ph.1, label %20

20:                                               ; preds = %.lr.ph
  %21 = fcmp olt float %18, -3.276700e+04
  br i1 %21, label %22, label %.lr.ph.1

22:                                               ; preds = %20
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %20, %22
  %.1 = phi i1 [ true, %22 ], [ %.01214, %20 ], [ true, %.lr.ph ]
  %.0 = phi float [ -3.276700e+04, %22 ], [ %18, %20 ], [ 3.276600e+04, %.lr.ph ]
  %23 = fptosi float %.0 to i16
  store i16 %23, ptr %15, align 2, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %24 = getelementptr inbounds i16, ptr %1, i64 %indvars.iv.next
  %25 = load i16, ptr %24, align 2, !tbaa !5
  %26 = sitofp i16 %25 to float
  %27 = fmul float %26, %0
  %28 = fcmp ogt float %27, 3.276600e+04
  br i1 %28, label %32, label %29

29:                                               ; preds = %.lr.ph.1
  %30 = fcmp olt float %27, -3.276700e+04
  br i1 %30, label %31, label %32

31:                                               ; preds = %29
  br label %32

32:                                               ; preds = %31, %29, %.lr.ph.1
  %.1.1 = phi i1 [ true, %31 ], [ %.1, %29 ], [ true, %.lr.ph.1 ]
  %.0.1 = phi float [ -3.276700e+04, %31 ], [ %27, %29 ], [ 3.276600e+04, %.lr.ph.1 ]
  %33 = fptosi float %.0.1 to i16
  store i16 %33, ptr %24, align 2, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind 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, !6, i64 0}
!6 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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