; LLVM IR from phisko/kengine :: kengine/render/polyvox/libs/polyvox/examples/Paging (Perlin)

; 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"

%class.Perlin = type <{ i32, float, float, i32, [2050 x i32], [2050 x [3 x float]], [2050 x [2 x float]], [2050 x float], i8, [3 x i8] }>

; 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
declare dso_local noundef float @_ZN6Perlin6noise2EPf(ptr noundef nonnull align 4 dereferenceable(57417), ptr noundef) #2 align 2

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

26:                                               ; preds = %47, %2
  %27 = load i32, ptr %8, align 4, !tbaa !14
  %28 = load i32, ptr %5, align 4, !tbaa !14
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %50

31:                                               ; preds = %26
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = call noundef float @_ZN6Perlin6noise2EPf(ptr noundef nonnull align 4 dereferenceable(57417) %9, ptr noundef %32)
  %34 = load float, ptr %7, align 4, !tbaa !15
  %35 = load float, ptr %6, align 4, !tbaa !15
  %36 = call float @llvm.fmuladd.f32(float %33, float %34, float %35)
  store float %36, ptr %6, align 4, !tbaa !15
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds float, ptr %37, i64 0
  %39 = load float, ptr %38, align 4, !tbaa !15
  %40 = fmul float %39, 2.000000e+00
  store float %40, ptr %38, align 4, !tbaa !15
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds float, ptr %41, i64 1
  %43 = load float, ptr %42, align 4, !tbaa !15
  %44 = fmul float %43, 2.000000e+00
  store float %44, ptr %42, align 4, !tbaa !15
  %45 = load float, ptr %7, align 4, !tbaa !15
  %46 = fmul float %45, 5.000000e-01
  store float %46, ptr %7, align 4, !tbaa !15
  br label %47

47:                                               ; preds = %31
  %48 = load i32, ptr %8, align 4, !tbaa !14
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %8, align 4, !tbaa !14
  br label %26, !llvm.loop !18

50:                                               ; preds = %30
  %51 = load float, ptr %6, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret float %51
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS6Perlin", !11, i64 0, !12, i64 4, !12, i64 8, !11, i64 12, !7, i64 16, !7, i64 8216, !7, i64 32816, !7, i64 49216, !13, i64 57416}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !12, i64 8}
!17 = !{!10, !12, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"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
declare dso_local noundef float @_ZN6Perlin6noise2EPf(ptr noundef nonnull align 4 dereferenceable(57417), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN6Perlin15perlin_noise_2DEPf(ptr noundef nonnull align 4 dereferenceable(57417) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = load i32, ptr %0, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load float, ptr %4, align 4, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load float, ptr %6, align 4, !tbaa !13
  %8 = load float, ptr %1, align 4, !tbaa !14
  %9 = fmul float %7, %8
  store float %9, ptr %1, align 4, !tbaa !14
  %10 = load float, ptr %6, align 4, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %1, i64 4
  %12 = load float, ptr %11, align 4, !tbaa !14
  %13 = fmul float %10, %12
  store float %13, ptr %11, align 4, !tbaa !14
  %14 = icmp sgt i32 %3, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.013.lcssa = phi float [ 0.000000e+00, %2 ], [ %16, %.lr.ph ]
  ret float %.013.lcssa

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.016 = phi i32 [ %20, %.lr.ph ], [ 0, %2 ]
  %.01215 = phi float [ %19, %.lr.ph ], [ %5, %2 ]
  %.01314 = phi float [ %16, %.lr.ph ], [ 0.000000e+00, %2 ]
  %15 = tail call noundef float @_ZN6Perlin6noise2EPf(ptr noundef nonnull align 4 dereferenceable(57417) %0, ptr noundef nonnull %1)
  %16 = tail call float @llvm.fmuladd.f32(float %15, float %.01215, float %.01314)
  %17 = load <2 x float>, ptr %1, align 4, !tbaa !14
  %18 = fmul <2 x float> %17, <float 2.000000e+00, float 2.000000e+00>
  store <2 x float> %18, ptr %1, align 4, !tbaa !14
  %19 = fmul float %.01215, 5.000000e-01
  %20 = add nuw nsw i32 %.016, 1
  %exitcond.not = icmp eq i32 %20, %3
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15
}

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 = !{!6, !7, i64 0}
!6 = !{!"_ZTS6Perlin", !7, i64 0, !10, i64 4, !10, i64 8, !7, i64 12, !8, i64 16, !8, i64 8216, !8, i64 32816, !8, i64 49216, !11, i64 57416}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !10, i64 4}
!14 = !{!10, !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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