; LLVM IR from parallella/pal :: src/math (p_invcbrt_f32)

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

15:                                               ; preds = %77, %3
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %80

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds float, ptr %20, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  store i32 %24, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = and i32 -2147483648, %25
  store i32 %26, ptr %10, align 4, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = and i32 %27, 2147483647
  store i32 %28, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %29 = load float, ptr %9, align 4, !tbaa !11
  %30 = fmul float 0x3FD5555560000000, %29
  store float %30, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = ashr i32 %31, 11
  %33 = mul nsw i32 683, %32
  %34 = sub nsw i32 1419967118, %33
  store i32 %34, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %35 = load float, ptr %12, align 4, !tbaa !11
  store float %35, ptr %13, align 4, !tbaa !11
  %36 = load float, ptr %8, align 4, !tbaa !11
  %37 = load float, ptr %11, align 4, !tbaa !11
  %38 = load float, ptr %13, align 4, !tbaa !11
  %39 = fmul float %37, %38
  %40 = load float, ptr %13, align 4, !tbaa !11
  %41 = fmul float %39, %40
  %42 = load float, ptr %13, align 4, !tbaa !11
  %43 = fneg float %41
  %44 = call float @llvm.fmuladd.f32(float %43, float %42, float %36)
  %45 = load float, ptr %13, align 4, !tbaa !11
  %46 = fmul float %45, %44
  store float %46, ptr %13, align 4, !tbaa !11
  %47 = load float, ptr %8, align 4, !tbaa !11
  %48 = load float, ptr %11, align 4, !tbaa !11
  %49 = load float, ptr %13, align 4, !tbaa !11
  %50 = fmul float %48, %49
  %51 = load float, ptr %13, align 4, !tbaa !11
  %52 = fmul float %50, %51
  %53 = load float, ptr %13, align 4, !tbaa !11
  %54 = fneg float %52
  %55 = call float @llvm.fmuladd.f32(float %54, float %53, float %47)
  %56 = load float, ptr %13, align 4, !tbaa !11
  %57 = fmul float %56, %55
  store float %57, ptr %13, align 4, !tbaa !11
  %58 = load float, ptr %8, align 4, !tbaa !11
  %59 = load float, ptr %11, align 4, !tbaa !11
  %60 = load float, ptr %13, align 4, !tbaa !11
  %61 = fmul float %59, %60
  %62 = load float, ptr %13, align 4, !tbaa !11
  %63 = fmul float %61, %62
  %64 = load float, ptr %13, align 4, !tbaa !11
  %65 = fneg float %63
  %66 = call float @llvm.fmuladd.f32(float %65, float %64, float %58)
  %67 = load float, ptr %13, align 4, !tbaa !11
  %68 = fmul float %67, %66
  store float %68, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = load i32, ptr %13, align 4, !tbaa !9
  %71 = or i32 %69, %70
  store i32 %71, ptr %14, align 4, !tbaa !9
  %72 = load float, ptr %14, align 4, !tbaa !11
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds float, ptr %73, i64 %75
  store float %72, ptr %76, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %77

77:                                               ; preds = %19
  %78 = load i32, ptr %7, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %7, align 4, !tbaa !9
  br label %15, !llvm.loop !13

80:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; 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

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 }

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

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @p_invcbrt_f32(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %2, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext nneg i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 4
  br i1 %min.iters.check, label %.lr.ph.preheader34, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %5 = getelementptr inbounds float, ptr %0, i64 %index
  %wide.load = load <4 x i32>, ptr %5, align 4, !tbaa !5
  %6 = and <4 x i32> %wide.load, <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>
  %7 = and <4 x i32> %wide.load, <i32 2147483647, i32 2147483647, i32 2147483647, i32 2147483647>
  %8 = bitcast <4 x i32> %7 to <4 x float>
  %9 = lshr <4 x i32> %7, <i32 11, i32 11, i32 11, i32 11>
  %10 = mul nsw <4 x i32> %9, <i32 -683, i32 -683, i32 -683, i32 -683>
  %11 = add nsw <4 x i32> %10, <i32 1419967118, i32 1419967118, i32 1419967118, i32 1419967118>
  %12 = bitcast <4 x i32> %11 to <4 x float>
  %13 = fmul <4 x float> %8, <float 0xBFD5555560000000, float 0xBFD5555560000000, float 0xBFD5555560000000, float 0xBFD5555560000000>
  %14 = fmul <4 x float> %13, %12
  %15 = fmul <4 x float> %14, %12
  %16 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %15, <4 x float> %12, <4 x float> <float 0x3FF5555560000000, float 0x3FF5555560000000, float 0x3FF5555560000000, float 0x3FF5555560000000>)
  %17 = fmul <4 x float> %16, %12
  %18 = fmul <4 x float> %13, %17
  %19 = fmul <4 x float> %17, %18
  %20 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %19, <4 x float> %17, <4 x float> <float 0x3FF5555560000000, float 0x3FF5555560000000, float 0x3FF5555560000000, float 0x3FF5555560000000>)
  %21 = fmul <4 x float> %17, %20
  %22 = fmul <4 x float> %13, %21
  %23 = fmul <4 x float> %21, %22
  %24 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %23, <4 x float> %21, <4 x float> <float 0x3FF5555560000000, float 0x3FF5555560000000, float 0x3FF5555560000000, float 0x3FF5555560000000>)
  %25 = fmul <4 x float> %21, %24
  %26 = bitcast <4 x float> %25 to <4 x i32>
  %27 = or <4 x i32> %6, %26
  %28 = getelementptr inbounds float, ptr %1, i64 %index
  store <4 x i32> %27, ptr %28, align 4, !tbaa !9
  %index.next = add nuw i64 %index, 4
  %29 = icmp eq i64 %index.next, %n.vec
  br i1 %29, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader34

.lr.ph.preheader34:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader34, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader34 ]
  %30 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = and i32 %31, -2147483648
  %33 = and i32 %31, 2147483647
  %34 = bitcast i32 %33 to float
  %35 = lshr i32 %33, 11
  %.neg = mul nsw i32 %35, -683
  %36 = add nsw i32 %.neg, 1419967118
  %37 = bitcast i32 %36 to float
  %38 = fmul float %34, 0xBFD5555560000000
  %39 = fmul float %38, %37
  %40 = fmul float %39, %37
  %41 = tail call float @llvm.fmuladd.f32(float %40, float %37, float 0x3FF5555560000000)
  %42 = fmul float %41, %37
  %43 = fmul float %38, %42
  %44 = fmul float %42, %43
  %45 = tail call float @llvm.fmuladd.f32(float %44, float %42, float 0x3FF5555560000000)
  %46 = fmul float %42, %45
  %47 = fmul float %38, %46
  %48 = fmul float %46, %47
  %49 = tail call float @llvm.fmuladd.f32(float %48, float %46, float 0x3FF5555560000000)
  %50 = fmul float %46, %49
  %51 = bitcast float %50 to i32
  %52 = or i32 %32, %51
  %53 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  store i32 %52, ptr %53, align 4, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %3
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.fmuladd.v4f32(<4 x float>, <4 x float>, <4 x float>) #2

attributes #0 = { 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !14, !13}


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