; 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.1 = 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_spiral(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 float, align 4
  %12 = 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
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %17

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

17:                                               ; preds = %3
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %28

20:                                               ; preds = %17
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds float, ptr %21, i64 0
  %23 = load float, ptr %22, align 4, !tbaa !11
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds float, ptr %24, i64 0
  %26 = load float, ptr %25, align 4, !tbaa !11
  %27 = fmul float %23, %26
  store float %27, ptr %4, align 4
  br label %113

28:                                               ; preds = %17
  br label %29

29:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds float, ptr %30, i64 0
  %32 = load float, ptr %31, align 4, !tbaa !11
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds float, ptr %33, i64 0
  %35 = load float, ptr %34, align 4, !tbaa !11
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds float, ptr %36, i64 1
  %38 = load float, ptr %37, align 4, !tbaa !11
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds float, ptr %39, i64 1
  %41 = load float, ptr %40, align 4, !tbaa !11
  %42 = fmul float %38, %41
  %43 = call float @llvm.fmuladd.f32(float %32, float %35, float %42)
  %44 = call float @sqrtf(float noundef %43) #5
  store float %44, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds float, ptr %45, i64 1
  %47 = load float, ptr %46, align 4, !tbaa !11
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds float, ptr %48, i64 0
  %50 = load float, ptr %49, align 4, !tbaa !11
  %51 = call float @atan2f(float noundef %47, float noundef %50) #5
  store float %51, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %52 = load float, ptr %9, align 4, !tbaa !11
  %53 = load float, ptr %8, align 4, !tbaa !11
  %54 = fneg float %53
  %55 = call float @llvm.fmuladd.f32(float %54, float 1.000000e+01, float %52)
  store float %55, ptr %10, align 4, !tbaa !11
  br label %56

56:                                               ; preds = %60, %29
  %57 = load float, ptr %10, align 4, !tbaa !11
  %58 = fpext float %57 to double
  %59 = fcmp ogt double %58, 0x400921FB54442D18
  br i1 %59, label %60, label %65

60:                                               ; preds = %56
  %61 = load float, ptr %10, align 4, !tbaa !11
  %62 = fpext float %61 to double
  %63 = fsub double %62, 0x401921FB54442D18
  %64 = fptrunc double %63 to float
  store float %64, ptr %10, align 4, !tbaa !11
  br label %56, !llvm.loop !13

65:                                               ; preds = %56
  br label %66

66:                                               ; preds = %70, %65
  %67 = load float, ptr %10, align 4, !tbaa !11
  %68 = fpext float %67 to double
  %69 = fcmp olt double %68, 0xC00921FB54442D18
  br i1 %69, label %70, label %75

70:                                               ; preds = %66
  %71 = load float, ptr %10, align 4, !tbaa !11
  %72 = fpext float %71 to double
  %73 = fadd double %72, 0x401921FB54442D18
  %74 = fptrunc double %73 to float
  store float %74, ptr %10, align 4, !tbaa !11
  br label %66, !llvm.loop !15

75:                                               ; preds = %66
  %76 = load float, ptr %10, align 4, !tbaa !11
  %77 = fpext float %76 to double
  %78 = fdiv double %77, 0x400921FB54442D18
  %79 = fptrunc double %78 to float
  store float %79, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %80 = load float, ptr %10, align 4, !tbaa !11
  %81 = load float, ptr %10, align 4, !tbaa !11
  %82 = fmul float %80, %81
  %83 = load float, ptr %8, align 4, !tbaa !11
  %84 = fneg float %83
  %85 = load float, ptr %8, align 4, !tbaa !11
  %86 = fmul float %84, %85
  %87 = fdiv float %86, 1.000000e+01
  %88 = call float @expf(float noundef %87) #5, !tbaa !9
  %89 = fneg float %82
  %90 = call float @llvm.fmuladd.f32(float %89, float %88, float 1.000000e+00)
  store float %90, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 2, ptr %12, align 4, !tbaa !9
  br label %91

91:                                               ; preds = %108, %75
  %92 = load i32, ptr %12, align 4, !tbaa !9
  %93 = load i32, ptr %7, align 4, !tbaa !9
  %94 = icmp ult i32 %92, %93
  br i1 %94, label %95, label %111

95:                                               ; preds = %91
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = load i32, ptr %12, align 4, !tbaa !9
  %98 = zext i32 %97 to i64
  %99 = getelementptr inbounds float, ptr %96, i64 %98
  %100 = load float, ptr %99, align 4, !tbaa !11
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  %102 = load i32, ptr %12, align 4, !tbaa !9
  %103 = zext i32 %102 to i64
  %104 = getelementptr inbounds float, ptr %101, i64 %103
  %105 = load float, ptr %104, align 4, !tbaa !11
  %106 = load float, ptr %11, align 4, !tbaa !11
  %107 = call float @llvm.fmuladd.f32(float %100, float %105, float %106)
  store float %107, ptr %11, align 4, !tbaa !11
  br label %108

108:                                              ; preds = %95
  %109 = load i32, ptr %12, align 4, !tbaa !9
  %110 = add i32 %109, 1
  store i32 %110, ptr %12, align 4, !tbaa !9
  br label %91, !llvm.loop !16

111:                                              ; preds = %91
  %112 = load float, ptr %11, align 4, !tbaa !11
  store float %112, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  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 %113

113:                                              ; preds = %111, %20, %15
  %114 = load float, ptr %4, align 4
  ret float %114
}

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

; Function Attrs: nounwind
declare float @atan2f(float noundef, 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"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !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"

@.str = external hidden unnamed_addr constant [80 x i8], align 1
@.str.1 = 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_spiral(ptr nocapture noundef readnone %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #3 {
  switch i32 %2, label %9 [
    i32 0, label %4
    i32 1, label %6
  ]

4:                                                ; preds = %3
  %5 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef nonnull @.str, i32 noundef 113, ptr noundef nonnull @.str.1) #5
  br label %.loopexit

6:                                                ; preds = %3
  %7 = load float, ptr %1, align 4, !tbaa !5
  %8 = fmul float %7, %7
  br label %.loopexit

9:                                                ; preds = %3
  %10 = load float, ptr %1, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %1, i64 4
  %12 = load float, ptr %11, align 4, !tbaa !5
  %13 = fmul float %12, %12
  %14 = tail call float @llvm.fmuladd.f32(float %10, float %10, float %13)
  %sqrt = tail call float @llvm.sqrt.f32(float %14)
  %15 = tail call float @atan2f(float noundef %12, float noundef %10) #5
  %16 = fneg float %sqrt
  %17 = tail call float @llvm.fmuladd.f32(float %16, float 1.000000e+01, float %15)
  %18 = fpext float %17 to double
  %19 = fcmp ogt double %18, 0x400921FB54442D18
  br i1 %19, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %9
  %.pre-phi = phi double [ %18, %9 ], [ %24, %.lr.ph ]
  %20 = fcmp olt double %.pre-phi, 0xC00921FB54442D18
  br i1 %20, label %.lr.ph37, label %._crit_edge

.lr.ph:                                           ; preds = %9, %.lr.ph
  %21 = phi double [ %24, %.lr.ph ], [ %18, %9 ]
  %22 = fadd double %21, 0xC01921FB54442D18
  %23 = fptrunc double %22 to float
  %24 = fpext float %23 to double
  %25 = fcmp ogt double %24, 0x400921FB54442D18
  br i1 %25, label %.lr.ph, label %.preheader, !llvm.loop !9

.lr.ph37:                                         ; preds = %.preheader, %.lr.ph37
  %26 = phi double [ %29, %.lr.ph37 ], [ %.pre-phi, %.preheader ]
  %27 = fadd double %26, 0x401921FB54442D18
  %28 = fptrunc double %27 to float
  %29 = fpext float %28 to double
  %30 = fcmp olt double %29, 0xC00921FB54442D18
  br i1 %30, label %.lr.ph37, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph37, %.preheader
  %.lcssa = phi double [ %.pre-phi, %.preheader ], [ %29, %.lr.ph37 ]
  %31 = fdiv double %.lcssa, 0x400921FB54442D18
  %32 = fptrunc double %31 to float
  %33 = fmul float %sqrt, %16
  %34 = fdiv float %33, 1.000000e+01
  %35 = tail call float @expf(float noundef %34) #5, !tbaa !12
  %36 = fneg float %32
  %37 = fmul float %36, %32
  %38 = tail call float @llvm.fmuladd.f32(float %37, float %35, float 1.000000e+00)
  %39 = icmp ugt i32 %2, 2
  br i1 %39, label %.lr.ph42.preheader, label %.loopexit

.lr.ph42.preheader:                               ; preds = %._crit_edge
  %wide.trip.count = zext i32 %2 to i64
  %40 = add nsw i64 %wide.trip.count, -2
  %41 = add nsw i64 %wide.trip.count, -3
  %xtraiter = and i64 %40, 3
  %42 = icmp ult i64 %41, 3
  br i1 %42, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph42.preheader.new

.lr.ph42.preheader.new:                           ; preds = %.lr.ph42.preheader
  %unroll_iter = and i64 %40, -4
  %invariant.gep = getelementptr inbounds i8, ptr %1, i64 8
  %invariant.gep62 = getelementptr inbounds i8, ptr %1, i64 12
  br label %.lr.ph42

.lr.ph42:                                         ; preds = %.lr.ph42, %.lr.ph42.preheader.new
  %indvars.iv = phi i64 [ 2, %.lr.ph42.preheader.new ], [ %indvars.iv.next.3, %.lr.ph42 ]
  %.03039 = phi float [ %38, %.lr.ph42.preheader.new ], [ %52, %.lr.ph42 ]
  %niter = phi i64 [ 0, %.lr.ph42.preheader.new ], [ %niter.next.3, %.lr.ph42 ]
  %43 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  %44 = load float, ptr %43, align 4, !tbaa !5
  %45 = tail call float @llvm.fmuladd.f32(float %44, float %44, float %.03039)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %46 = getelementptr inbounds float, ptr %1, i64 %indvars.iv.next
  %47 = load float, ptr %46, align 4, !tbaa !5
  %48 = tail call float @llvm.fmuladd.f32(float %47, float %47, float %45)
  %gep = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv
  %49 = load float, ptr %gep, align 4, !tbaa !5
  %50 = tail call float @llvm.fmuladd.f32(float %49, float %49, float %48)
  %gep63 = getelementptr inbounds float, ptr %invariant.gep62, i64 %indvars.iv
  %51 = load float, ptr %gep63, align 4, !tbaa !5
  %52 = tail call float @llvm.fmuladd.f32(float %51, float %51, float %50)
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph42, !llvm.loop !14

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph42, %.lr.ph42.preheader
  %.lcssa54.ph = phi float [ poison, %.lr.ph42.preheader ], [ %52, %.lr.ph42 ]
  %indvars.iv.unr = phi i64 [ 2, %.lr.ph42.preheader ], [ %indvars.iv.next.3, %.lr.ph42 ]
  %.03039.unr = phi float [ %38, %.lr.ph42.preheader ], [ %52, %.lr.ph42 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph42.epil

.lr.ph42.epil:                                    ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph42.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph42.epil ], [ %indvars.iv.unr, %.loopexit.loopexit.unr-lcssa ]
  %.03039.epil = phi float [ %55, %.lr.ph42.epil ], [ %.03039.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph42.epil ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %53 = getelementptr inbounds float, ptr %1, i64 %indvars.iv.epil
  %54 = load float, ptr %53, align 4, !tbaa !5
  %55 = tail call float @llvm.fmuladd.f32(float %54, float %54, float %.03039.epil)
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.loopexit, label %.lr.ph42.epil, !llvm.loop !15

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph42.epil, %._crit_edge, %6, %4
  %.032 = phi float [ 0.000000e+00, %4 ], [ %8, %6 ], [ %38, %._crit_edge ], [ %.lcssa54.ph, %.loopexit.loopexit.unr-lcssa ], [ %55, %.lr.ph42.epil ]
  ret float %.032
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.sqrt.f32(float) #4

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


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