; LLVM IR from yangfengzzz/Arche-webgpu :: vox.math/perlin.ll (ZN3vox22perlinTurbulenceNoise3Efffffiiii)

; 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: mustprogress uwtable
declare dso_local noundef float @_ZN3vox12perlinNoise3Efffiii(float noundef, float noundef, float noundef, i32 noundef, i32 noundef, i32 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN3vox22perlinTurbulenceNoise3Efffffiiii(float noundef %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8) #0 {
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca float, align 4
  %21 = alloca float, align 4
  %22 = alloca float, align 4
  %23 = alloca float, align 4
  store float %0, ptr %10, align 4, !tbaa !5
  store float %1, ptr %11, align 4, !tbaa !5
  store float %2, ptr %12, align 4, !tbaa !5
  store float %3, ptr %13, align 4, !tbaa !5
  store float %4, ptr %14, align 4, !tbaa !5
  store i32 %5, ptr %15, align 4, !tbaa !9
  store i32 %6, ptr %16, align 4, !tbaa !9
  store i32 %7, ptr %17, align 4, !tbaa !9
  store i32 %8, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #2
  store float 1.000000e+00, ptr %20, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #2
  store float 1.000000e+00, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #2
  store float 0.000000e+00, ptr %22, align 4, !tbaa !5
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %62, %9
  %25 = load i32, ptr %19, align 4, !tbaa !9
  %26 = load i32, ptr %15, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %65

28:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #2
  %29 = load float, ptr %10, align 4, !tbaa !5
  %30 = load float, ptr %20, align 4, !tbaa !5
  %31 = fmul float %29, %30
  %32 = load float, ptr %11, align 4, !tbaa !5
  %33 = load float, ptr %20, align 4, !tbaa !5
  %34 = fmul float %32, %33
  %35 = load float, ptr %12, align 4, !tbaa !5
  %36 = load float, ptr %20, align 4, !tbaa !5
  %37 = fmul float %35, %36
  %38 = load i32, ptr %16, align 4, !tbaa !9
  %39 = load i32, ptr %17, align 4, !tbaa !9
  %40 = load i32, ptr %18, align 4, !tbaa !9
  %41 = call noundef float @_ZN3vox12perlinNoise3Efffiii(float noundef %31, float noundef %34, float noundef %37, i32 noundef %38, i32 noundef %39, i32 noundef %40)
  %42 = load float, ptr %21, align 4, !tbaa !5
  %43 = fmul float %41, %42
  store float %43, ptr %23, align 4, !tbaa !5
  %44 = load float, ptr %23, align 4, !tbaa !5
  %45 = fcmp olt float %44, 0.000000e+00
  br i1 %45, label %46, label %49

46:                                               ; preds = %28
  %47 = load float, ptr %23, align 4, !tbaa !5
  %48 = fneg float %47
  br label %51

49:                                               ; preds = %28
  %50 = load float, ptr %23, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %49, %46
  %52 = phi float [ %48, %46 ], [ %50, %49 ]
  store float %52, ptr %23, align 4, !tbaa !5
  %53 = load float, ptr %23, align 4, !tbaa !5
  %54 = load float, ptr %22, align 4, !tbaa !5
  %55 = fadd float %54, %53
  store float %55, ptr %22, align 4, !tbaa !5
  %56 = load float, ptr %13, align 4, !tbaa !5
  %57 = load float, ptr %20, align 4, !tbaa !5
  %58 = fmul float %57, %56
  store float %58, ptr %20, align 4, !tbaa !5
  %59 = load float, ptr %14, align 4, !tbaa !5
  %60 = load float, ptr %21, align 4, !tbaa !5
  %61 = fmul float %60, %59
  store float %61, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #2
  br label %62

62:                                               ; preds = %51
  %63 = load i32, ptr %19, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %19, align 4, !tbaa !9
  br label %24, !llvm.loop !11

65:                                               ; preds = %24
  %66 = load float, ptr %22, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #2
  ret float %66
}

attributes #0 = { mustprogress 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 = { 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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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: mustprogress uwtable
declare dso_local noundef float @_ZN3vox12perlinNoise3Efffiii(float noundef, float noundef, float noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN3vox22perlinTurbulenceNoise3Efffffiiii(float noundef %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8) local_unnamed_addr #0 {
  %10 = icmp sgt i32 %5, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9, %.lr.ph
  %.028 = phi i32 [ %22, %.lr.ph ], [ 0, %9 ]
  %.02227 = phi float [ %19, %.lr.ph ], [ 0.000000e+00, %9 ]
  %.02326 = phi float [ %21, %.lr.ph ], [ 1.000000e+00, %9 ]
  %.02425 = phi float [ %20, %.lr.ph ], [ 1.000000e+00, %9 ]
  %11 = fmul float %.02425, %0
  %12 = fmul float %.02425, %1
  %13 = fmul float %.02425, %2
  %14 = tail call noundef float @_ZN3vox12perlinNoise3Efffiii(float noundef %11, float noundef %12, float noundef %13, i32 noundef %6, i32 noundef %7, i32 noundef %8)
  %15 = fmul float %.02326, %14
  %16 = fcmp olt float %15, 0.000000e+00
  %17 = fneg float %15
  %18 = select i1 %16, float %17, float %15
  %19 = fadd float %.02227, %18
  %20 = fmul float %.02425, %3
  %21 = fmul float %.02326, %4
  %22 = add nuw nsw i32 %.028, 1
  %exitcond.not = icmp eq i32 %22, %5
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %9
  %.022.lcssa = phi float [ 0.000000e+00, %9 ], [ %19, %.lr.ph ]
  ret float %.022.lcssa
}

attributes #0 = { mustprogress 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass