; LLVM IR from Razakhel/RaZ :: src/RaZ/Math/PerlinNoise.ll (ZN3Raz11PerlinNoise9compute2DEffhb)

; 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 @_ZN3Raz11PerlinNoise9compute2DEffhb(float noundef %0, float noundef %1, i8 noundef zeroext %2, i1 noundef zeroext %3) #2 {
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  %13 = alloca i8, align 1
  %14 = alloca i32, align 4
  store float %0, ptr %6, align 4, !tbaa !5
  store float %1, ptr %7, align 4, !tbaa !5
  store i8 %2, ptr %8, align 1, !tbaa !9
  %15 = zext i1 %3 to i8
  store i8 %15, ptr %9, align 1, !tbaa !10
  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 float 1.000000e+00, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store float 0.000000e+00, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #3
  store i8 0, ptr %13, align 1, !tbaa !9
  br label %16

16:                                               ; preds = %38, %4
  %17 = load i8, ptr %13, align 1, !tbaa !9
  %18 = zext i8 %17 to i32
  %19 = load i8, ptr %8, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = icmp slt i32 %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #3
  br label %41

23:                                               ; preds = %16
  %24 = load float, ptr %6, align 4, !tbaa !5
  %25 = load float, ptr %10, align 4, !tbaa !5
  %26 = fmul float %24, %25
  %27 = load float, ptr %7, align 4, !tbaa !5
  %28 = load float, ptr %10, align 4, !tbaa !5
  %29 = fmul float %27, %28
  %30 = call noundef float @_ZN3Raz11PerlinNoise12_GLOBAL__N_112computeValueEff(float noundef %26, float noundef %29)
  %31 = load float, ptr %11, align 4, !tbaa !5
  %32 = load float, ptr %12, align 4, !tbaa !5
  %33 = call float @llvm.fmuladd.f32(float %30, float %31, float %32)
  store float %33, ptr %12, align 4, !tbaa !5
  %34 = load float, ptr %11, align 4, !tbaa !5
  %35 = fmul float %34, 5.000000e-01
  store float %35, ptr %11, align 4, !tbaa !5
  %36 = load float, ptr %10, align 4, !tbaa !5
  %37 = fmul float %36, 2.000000e+00
  store float %37, ptr %10, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %23
  %39 = load i8, ptr %13, align 1, !tbaa !9
  %40 = add i8 %39, 1
  store i8 %40, ptr %13, align 1, !tbaa !9
  br label %16, !llvm.loop !12

41:                                               ; preds = %22
  %42 = load i8, ptr %9, align 1, !tbaa !10, !range !14, !noundef !15
  %43 = trunc i8 %42 to i1
  br i1 %43, label %44, label %48

44:                                               ; preds = %41
  %45 = load float, ptr %12, align 4, !tbaa !5
  %46 = fadd float %45, 1.000000e+00
  %47 = fdiv float %46, 2.000000e+00
  store float %47, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %50

48:                                               ; preds = %41
  %49 = load float, ptr %12, align 4, !tbaa !5
  store float %49, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %50

50:                                               ; preds = %48, %44
  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
  %51 = load float, ptr %5, align 4
  ret float %51
}

; Function Attrs: mustprogress uwtable
declare hidden noundef float @_ZN3Raz11PerlinNoise12_GLOBAL__N_112computeValueEff(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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"bool", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{i8 0, i8 2}
!15 = !{}


; 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 @_ZN3Raz11PerlinNoise9compute2DEffhb(float noundef %0, float noundef %1, i8 noundef zeroext %2, i1 noundef zeroext %3) local_unnamed_addr #1 {
  %.not = icmp eq i8 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.014.lcssa = phi float [ 0.000000e+00, %4 ], [ %13, %.lr.ph ]
  %5 = fadd float %.014.lcssa, 1.000000e+00
  %6 = fmul float %5, 5.000000e-01
  %.017 = select i1 %3, float %6, float %.014.lcssa
  ret float %.017

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.021 = phi i8 [ %15, %.lr.ph ], [ 0, %4 ]
  %.01420 = phi float [ %13, %.lr.ph ], [ 0.000000e+00, %4 ]
  %7 = phi <2 x float> [ %14, %.lr.ph ], [ <float 1.000000e+00, float 1.000000e+00>, %4 ]
  %8 = extractelement <2 x float> %7, i64 1
  %9 = fmul float %8, %0
  %10 = fmul float %8, %1
  %11 = tail call noundef float @_ZN3Raz11PerlinNoise12_GLOBAL__N_112computeValueEff(float noundef %9, float noundef %10)
  %12 = extractelement <2 x float> %7, i64 0
  %13 = tail call float @llvm.fmuladd.f32(float %11, float %12, float %.01420)
  %14 = fmul <2 x float> %7, <float 5.000000e-01, float 2.000000e+00>
  %15 = add nuw i8 %.021, 1
  %exitcond.not = icmp eq i8 %15, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5
}

; Function Attrs: mustprogress uwtable
declare hidden noundef float @_ZN3Raz11PerlinNoise12_GLOBAL__N_112computeValueEff(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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass