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

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

14:                                               ; preds = %33, %3
  %15 = load i8, ptr %11, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  %17 = load i8, ptr %6, align 1, !tbaa !9
  %18 = zext i8 %17 to i32
  %19 = icmp slt i32 %16, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  br label %36

21:                                               ; preds = %14
  %22 = load float, ptr %5, align 4, !tbaa !5
  %23 = load float, ptr %8, align 4, !tbaa !5
  %24 = fmul float %22, %23
  %25 = call noundef float @_ZN3Raz11PerlinNoise12_GLOBAL__N_112computeValueEf(float noundef %24)
  %26 = load float, ptr %9, align 4, !tbaa !5
  %27 = load float, ptr %10, align 4, !tbaa !5
  %28 = call float @llvm.fmuladd.f32(float %25, float %26, float %27)
  store float %28, ptr %10, align 4, !tbaa !5
  %29 = load float, ptr %9, align 4, !tbaa !5
  %30 = fmul float %29, 5.000000e-01
  store float %30, ptr %9, align 4, !tbaa !5
  %31 = load float, ptr %8, align 4, !tbaa !5
  %32 = fmul float %31, 2.000000e+00
  store float %32, ptr %8, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %21
  %34 = load i8, ptr %11, align 1, !tbaa !9
  %35 = add i8 %34, 1
  store i8 %35, ptr %11, align 1, !tbaa !9
  br label %14, !llvm.loop !12

36:                                               ; preds = %20
  %37 = load i8, ptr %7, align 1, !tbaa !10, !range !14, !noundef !15
  %38 = trunc i8 %37 to i1
  br i1 %38, label %39, label %43

39:                                               ; preds = %36
  %40 = load float, ptr %10, align 4, !tbaa !5
  %41 = fadd float %40, 1.000000e+00
  %42 = fdiv float %41, 2.000000e+00
  store float %42, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %45

43:                                               ; preds = %36
  %44 = load float, ptr %10, align 4, !tbaa !5
  store float %44, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %45

45:                                               ; preds = %43, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %46 = load float, ptr %4, align 4
  ret float %46
}

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

; Function Attrs: mustprogress uwtable
declare hidden noundef float @_ZN3Raz11PerlinNoise12_GLOBAL__N_112computeValueEf(float noundef) #0

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

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.012.lcssa = phi float [ 0.000000e+00, %3 ], [ %11, %.lr.ph ]
  %4 = fadd float %.012.lcssa, 1.000000e+00
  %5 = fmul float %4, 5.000000e-01
  %.015 = select i1 %2, float %5, float %.012.lcssa
  ret float %.015

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

; Function Attrs: mustprogress uwtable
declare hidden noundef float @_ZN3Raz11PerlinNoise12_GLOBAL__N_112computeValueEf(float noundef) local_unnamed_addr #0

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

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 = { mustprogress 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 = 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