; LLVM IR from parallella/pal :: src/math (p_cbrt_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_cbrt_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 float, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca float, align 4
  %13 = alloca i32, align 4
  %14 = alloca float, align 4
  %15 = alloca i32, align 4
  %16 = alloca float, 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 %17

17:                                               ; preds = %85, %3
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %88

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

85:                                               ; preds = %21
  %86 = load i32, ptr %7, align 4, !tbaa !9
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %7, align 4, !tbaa !9
  br label %17, !llvm.loop !13

88:                                               ; preds = %17
  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_cbrt_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
  %5 = ptrtoint ptr %1 to i64
  %6 = ptrtoint ptr %0 to i64
  %wide.trip.count = zext nneg i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 4
  %7 = sub i64 %5, %6
  %diff.check = icmp ult i64 %7, 16
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %.lr.ph.preheader38, 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 ]
  %8 = getelementptr inbounds float, ptr %0, i64 %index
  %wide.load = load <4 x float>, ptr %8, align 4, !tbaa !5
  %9 = bitcast <4 x float> %wide.load to <4 x i32>
  %10 = and <4 x i32> %9, <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>
  %11 = tail call <4 x float> @llvm.fabs.v4f32(<4 x float> %wide.load)
  %12 = bitcast <4 x float> %11 to <4 x i32>
  %13 = lshr <4 x i32> %12, <i32 11, i32 11, i32 11, i32 11>
  %14 = mul nsw <4 x i32> %13, <i32 -683, i32 -683, i32 -683, i32 -683>
  %15 = add nsw <4 x i32> %14, <i32 1419967118, i32 1419967118, i32 1419967118, i32 1419967118>
  %16 = bitcast <4 x i32> %15 to <4 x float>
  %17 = fmul <4 x float> %11, <float 0xBFD5555560000000, float 0xBFD5555560000000, float 0xBFD5555560000000, float 0xBFD5555560000000>
  %18 = fmul <4 x float> %17, %16
  %19 = fmul <4 x float> %18, %16
  %20 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %19, <4 x float> %16, <4 x float> <float 0x3FF5555560000000, float 0x3FF5555560000000, float 0x3FF5555560000000, float 0x3FF5555560000000>)
  %21 = fmul <4 x float> %20, %16
  %22 = fmul <4 x float> %17, %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 = fmul <4 x float> %17, %25
  %27 = fmul <4 x float> %25, %26
  %28 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %27, <4 x float> %25, <4 x float> <float 0x3FF5555560000000, float 0x3FF5555560000000, float 0x3FF5555560000000, float 0x3FF5555560000000>)
  %29 = fmul <4 x float> %25, %28
  %30 = bitcast <4 x float> %29 to <4 x i32>
  %31 = or <4 x i32> %10, %30
  %32 = bitcast <4 x i32> %31 to <4 x float>
  %33 = fmul <4 x float> %wide.load, %32
  %34 = fmul <4 x float> %33, %32
  %35 = getelementptr inbounds float, ptr %1, i64 %index
  store <4 x float> %34, ptr %35, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %36 = icmp eq i64 %index.next, %n.vec
  br i1 %36, label %middle.block, label %vector.body, !llvm.loop !9

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.preheader38

.lr.ph.preheader38:                               ; 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.preheader38, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader38 ]
  %37 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  %38 = load float, ptr %37, align 4, !tbaa !5
  %39 = bitcast float %38 to i32
  %40 = and i32 %39, -2147483648
  %41 = tail call float @llvm.fabs.f32(float %38)
  %42 = bitcast float %41 to i32
  %43 = lshr i32 %42, 11
  %.neg = mul nsw i32 %43, -683
  %44 = add nsw i32 %.neg, 1419967118
  %45 = bitcast i32 %44 to float
  %46 = fmul float %41, 0xBFD5555560000000
  %47 = fmul float %46, %45
  %48 = fmul float %47, %45
  %49 = tail call float @llvm.fmuladd.f32(float %48, float %45, float 0x3FF5555560000000)
  %50 = fmul float %49, %45
  %51 = fmul float %46, %50
  %52 = fmul float %50, %51
  %53 = tail call float @llvm.fmuladd.f32(float %52, float %50, float 0x3FF5555560000000)
  %54 = fmul float %50, %53
  %55 = fmul float %46, %54
  %56 = fmul float %54, %55
  %57 = tail call float @llvm.fmuladd.f32(float %56, float %54, float 0x3FF5555560000000)
  %58 = fmul float %54, %57
  %59 = bitcast float %58 to i32
  %60 = or i32 %40, %59
  %61 = bitcast i32 %60 to float
  %62 = fmul float %38, %61
  %63 = fmul float %62, %61
  %64 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  store float %63, ptr %64, align 4, !tbaa !5
  %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 !13

._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 float @llvm.fabs.f32(float) #2

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

; 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !11}


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