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

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

18:                                               ; preds = %43, %5
  %19 = load i8, ptr %15, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = load i8, ptr %10, align 1, !tbaa !9
  %22 = zext i8 %21 to i32
  %23 = icmp slt i32 %20, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #3
  br label %46

25:                                               ; preds = %18
  %26 = load float, ptr %7, align 4, !tbaa !5
  %27 = load float, ptr %12, align 4, !tbaa !5
  %28 = fmul float %26, %27
  %29 = load float, ptr %8, align 4, !tbaa !5
  %30 = load float, ptr %12, align 4, !tbaa !5
  %31 = fmul float %29, %30
  %32 = load float, ptr %9, align 4, !tbaa !5
  %33 = load float, ptr %12, align 4, !tbaa !5
  %34 = fmul float %32, %33
  %35 = call noundef float @_ZN3Raz11PerlinNoise12_GLOBAL__N_112computeValueEfff(float noundef %28, float noundef %31, float noundef %34)
  %36 = load float, ptr %13, align 4, !tbaa !5
  %37 = load float, ptr %14, align 4, !tbaa !5
  %38 = call float @llvm.fmuladd.f32(float %35, float %36, float %37)
  store float %38, ptr %14, align 4, !tbaa !5
  %39 = load float, ptr %13, align 4, !tbaa !5
  %40 = fmul float %39, 5.000000e-01
  store float %40, ptr %13, align 4, !tbaa !5
  %41 = load float, ptr %12, align 4, !tbaa !5
  %42 = fmul float %41, 2.000000e+00
  store float %42, ptr %12, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %25
  %44 = load i8, ptr %15, align 1, !tbaa !9
  %45 = add i8 %44, 1
  store i8 %45, ptr %15, align 1, !tbaa !9
  br label %18, !llvm.loop !12

46:                                               ; preds = %24
  %47 = load i8, ptr %11, align 1, !tbaa !10, !range !14, !noundef !15
  %48 = trunc i8 %47 to i1
  br i1 %48, label %49, label %53

49:                                               ; preds = %46
  %50 = load float, ptr %14, align 4, !tbaa !5
  %51 = fadd float %50, 1.000000e+00
  %52 = fdiv float %51, 2.000000e+00
  store float %52, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %55

53:                                               ; preds = %46
  %54 = load float, ptr %14, align 4, !tbaa !5
  store float %54, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %55

55:                                               ; preds = %53, %49
  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
  %56 = load float, ptr %6, align 4
  ret float %56
}

; Function Attrs: mustprogress uwtable
declare hidden noundef float @_ZN3Raz11PerlinNoise12_GLOBAL__N_112computeValueEfff(float noundef, 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 @_ZN3Raz11PerlinNoise9compute3DEfffhb(float noundef %0, float noundef %1, float noundef %2, i8 noundef zeroext %3, i1 noundef zeroext %4) local_unnamed_addr #1 {
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.016.lcssa = phi float [ 0.000000e+00, %5 ], [ %15, %.lr.ph ]
  %6 = fadd float %.016.lcssa, 1.000000e+00
  %7 = fmul float %6, 5.000000e-01
  %.019 = select i1 %4, float %7, float %.016.lcssa
  ret float %.019

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

; Function Attrs: mustprogress uwtable
declare hidden noundef float @_ZN3Raz11PerlinNoise12_GLOBAL__N_112computeValueEfff(float noundef, 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