; LLVM IR from Xingyu-Lin/softgym :: PyFlex/core/perlin.ll (Z8Perlin2Dffif)

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_Z8Perlin2Dffif(float noundef %0, float noundef %1, i32 noundef %2, float noundef %3) #2 {
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %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
  %12 = alloca i32, align 4
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  store float %0, ptr %5, align 4, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store float %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store float 0.000000e+00, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store float 1.000000e+00, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 1, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %40, %4
  %16 = load i32, ptr %12, align 4, !tbaa !9
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %43

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %21 = load float, ptr %5, align 4, !tbaa !5
  %22 = load i32, ptr %11, align 4, !tbaa !9
  %23 = sitofp i32 %22 to float
  %24 = fmul float %21, %23
  store float %24, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %25 = load float, ptr %6, align 4, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = sitofp i32 %26 to float
  %28 = fmul float %25, %27
  store float %28, ptr %14, align 4, !tbaa !5
  %29 = load float, ptr %13, align 4, !tbaa !5
  %30 = load float, ptr %14, align 4, !tbaa !5
  %31 = call noundef float @_ZN6PerlinL21PerlinNoise2DFunctionEff(float noundef %29, float noundef %30)
  %32 = load float, ptr %10, align 4, !tbaa !5
  %33 = load float, ptr %9, align 4, !tbaa !5
  %34 = call float @llvm.fmuladd.f32(float %31, float %32, float %33)
  store float %34, ptr %9, align 4, !tbaa !5
  %35 = load float, ptr %8, align 4, !tbaa !5
  %36 = load float, ptr %10, align 4, !tbaa !5
  %37 = fmul float %36, %35
  store float %37, ptr %10, align 4, !tbaa !5
  %38 = load i32, ptr %12, align 4, !tbaa !9
  %39 = shl i32 2, %38
  store i32 %39, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %40

40:                                               ; preds = %20
  %41 = load i32, ptr %12, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %12, align 4, !tbaa !9
  br label %15, !llvm.loop !11

43:                                               ; preds = %19
  %44 = load float, ptr %9, align 4, !tbaa !5
  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
  ret float %44
}

; Function Attrs: mustprogress uwtable
declare hidden noundef float @_ZN6PerlinL21PerlinNoise2DFunctionEff(float noundef, float noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = !{!"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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

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

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.0.lcssa = phi float [ 0.000000e+00, %4 ], [ %10, %.lr.ph ]
  ret float %.0.lcssa

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.020 = phi float [ %10, %.lr.ph ], [ 0.000000e+00, %4 ]
  %.01419 = phi float [ %11, %.lr.ph ], [ 1.000000e+00, %4 ]
  %.01518 = phi i32 [ %13, %.lr.ph ], [ 0, %4 ]
  %.01617 = phi i32 [ %12, %.lr.ph ], [ 1, %4 ]
  %6 = sitofp i32 %.01617 to float
  %7 = fmul float %6, %0
  %8 = fmul float %6, %1
  %9 = tail call noundef float @_ZN6PerlinL21PerlinNoise2DFunctionEff(float noundef %7, float noundef %8)
  %10 = tail call float @llvm.fmuladd.f32(float %9, float %.01419, float %.020)
  %11 = fmul float %.01419, %3
  %12 = shl i32 2, %.01518
  %13 = add nuw nsw i32 %.01518, 1
  %exitcond.not = icmp eq i32 %13, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5
}

; Function Attrs: mustprogress uwtable
declare hidden noundef float @_ZN6PerlinL21PerlinNoise2DFunctionEff(float noundef, float noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass