; LLVM IR from jgaeddert/liquid-dsp :: src/optim/src (utilities)

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

@.str = external hidden unnamed_addr constant [80 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [56 x i8], align 1

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #0

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
define dso_local float @liquid_multimodal(ptr noundef %0, ptr noundef %1, i32 noundef %2) #4 {
  %4 = alloca float, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %3
  %15 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef @.str, i32 noundef 86, ptr noundef @.str.3)
  store float 0.000000e+00, ptr %4, align 4
  br label %61

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store float 1.000000e+00, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store float 0.000000e+00, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store float 4.000000e+00, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %51, %16
  %18 = load i32, ptr %11, align 4, !tbaa !9
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp ult i32 %18, %19
  br i1 %20, label %21, label %54

21:                                               ; preds = %17
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds float, ptr %22, i64 %24
  %26 = load float, ptr %25, align 4, !tbaa !11
  %27 = fpext float %26 to double
  %28 = fmul double 0x401921FB54442D18, %27
  %29 = fptrunc double %28 to float
  %30 = call float @cosf(float noundef %29) #5
  %31 = call float @llvm.fmuladd.f32(float 5.000000e-01, float %30, float 5.000000e-01)
  %32 = load float, ptr %8, align 4, !tbaa !11
  %33 = fmul float %32, %31
  store float %33, ptr %8, align 4, !tbaa !11
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds float, ptr %34, i64 %36
  %38 = load float, ptr %37, align 4, !tbaa !11
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds float, ptr %39, i64 %41
  %43 = load float, ptr %42, align 4, !tbaa !11
  %44 = fmul float %38, %43
  %45 = load float, ptr %10, align 4, !tbaa !11
  %46 = load float, ptr %10, align 4, !tbaa !11
  %47 = fmul float %45, %46
  %48 = fdiv float %44, %47
  %49 = load float, ptr %9, align 4, !tbaa !11
  %50 = fadd float %49, %48
  store float %50, ptr %9, align 4, !tbaa !11
  br label %51

51:                                               ; preds = %21
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = add i32 %52, 1
  store i32 %53, ptr %11, align 4, !tbaa !9
  br label %17, !llvm.loop !13

54:                                               ; preds = %17
  %55 = load float, ptr %8, align 4, !tbaa !11
  %56 = load float, ptr %9, align 4, !tbaa !11
  %57 = fneg float %56
  %58 = call float @expf(float noundef %57) #5, !tbaa !9
  %59 = fneg float %55
  %60 = call float @llvm.fmuladd.f32(float %59, float %58, float 1.000000e+00)
  store float %60, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %61

61:                                               ; preds = %54, %14
  %62 = load float, ptr %4, align 4
  ret float %62
}

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

attributes #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 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 #5 = { 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"}


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

@.str = external hidden unnamed_addr constant [80 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [56 x i8], align 1

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; 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 @expf(float noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local float @liquid_multimodal(ptr nocapture noundef readnone %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #3 {
  %4 = icmp eq i32 %2, 0
  br i1 %4, label %6, label %.preheader.preheader

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

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

6:                                                ; preds = %3
  %7 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef nonnull @.str, i32 noundef 86, ptr noundef nonnull @.str.3) #4
  br label %49

.preheader:                                       ; preds = %.preheader, %.preheader.preheader.new
  %indvars.iv = phi i64 [ 0, %.preheader.preheader.new ], [ %indvars.iv.next.1, %.preheader ]
  %.01721 = phi float [ 0.000000e+00, %.preheader.preheader.new ], [ %31, %.preheader ]
  %.01820 = phi float [ 1.000000e+00, %.preheader.preheader.new ], [ %27, %.preheader ]
  %niter = phi i64 [ 0, %.preheader.preheader.new ], [ %niter.next.1, %.preheader ]
  %8 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  %9 = load float, ptr %8, align 4, !tbaa !5
  %10 = fpext float %9 to double
  %11 = fmul double %10, 0x401921FB54442D18
  %12 = fptrunc double %11 to float
  %13 = tail call float @cosf(float noundef %12) #4
  %14 = tail call float @llvm.fmuladd.f32(float %13, float 5.000000e-01, float 5.000000e-01)
  %15 = fmul float %.01820, %14
  %16 = load float, ptr %8, align 4, !tbaa !5
  %17 = fmul float %16, %16
  %18 = fmul float %17, 6.250000e-02
  %19 = fadd float %.01721, %18
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %20 = getelementptr inbounds float, ptr %1, i64 %indvars.iv.next
  %21 = load float, ptr %20, align 4, !tbaa !5
  %22 = fpext float %21 to double
  %23 = fmul double %22, 0x401921FB54442D18
  %24 = fptrunc double %23 to float
  %25 = tail call float @cosf(float noundef %24) #4
  %26 = tail call float @llvm.fmuladd.f32(float %25, float 5.000000e-01, float 5.000000e-01)
  %27 = fmul float %15, %26
  %28 = load float, ptr %20, align 4, !tbaa !5
  %29 = fmul float %28, %28
  %30 = fmul float %29, 6.250000e-02
  %31 = fadd float %19, %30
  %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 %.unr-lcssa, label %.preheader, !llvm.loop !9

.unr-lcssa:                                       ; preds = %.preheader, %.preheader.preheader
  %.lcssa27.ph = phi float [ poison, %.preheader.preheader ], [ %27, %.preheader ]
  %.lcssa.ph = phi float [ poison, %.preheader.preheader ], [ %31, %.preheader ]
  %indvars.iv.unr = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next.1, %.preheader ]
  %.01721.unr = phi float [ 0.000000e+00, %.preheader.preheader ], [ %31, %.preheader ]
  %.01820.unr = phi float [ 1.000000e+00, %.preheader.preheader ], [ %27, %.preheader ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %44, label %.preheader.epil

.preheader.epil:                                  ; preds = %.unr-lcssa
  %32 = getelementptr inbounds float, ptr %1, i64 %indvars.iv.unr
  %33 = load float, ptr %32, align 4, !tbaa !5
  %34 = fpext float %33 to double
  %35 = fmul double %34, 0x401921FB54442D18
  %36 = fptrunc double %35 to float
  %37 = tail call float @cosf(float noundef %36) #4
  %38 = tail call float @llvm.fmuladd.f32(float %37, float 5.000000e-01, float 5.000000e-01)
  %39 = fmul float %.01820.unr, %38
  %40 = load float, ptr %32, align 4, !tbaa !5
  %41 = fmul float %40, %40
  %42 = fmul float %41, 6.250000e-02
  %43 = fadd float %.01721.unr, %42
  br label %44

44:                                               ; preds = %.unr-lcssa, %.preheader.epil
  %.lcssa27 = phi float [ %.lcssa27.ph, %.unr-lcssa ], [ %39, %.preheader.epil ]
  %.lcssa = phi float [ %.lcssa.ph, %.unr-lcssa ], [ %43, %.preheader.epil ]
  %45 = fneg float %.lcssa
  %46 = tail call float @expf(float noundef %45) #4, !tbaa !11
  %47 = fneg float %.lcssa27
  %48 = tail call float @llvm.fmuladd.f32(float %47, float %46, float 1.000000e+00)
  br label %49

49:                                               ; preds = %44, %6
  %.016 = phi float [ 0.000000e+00, %6 ], [ %48, %44 ]
  ret float %.016
}

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

attributes #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 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 #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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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