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

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN6Perlin15perlin_noise_3DEPf(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
  %26 = getelementptr inbounds %class.Perlin, ptr %9, i32 0, i32 1
  %27 = load float, ptr %26, align 4, !tbaa !17
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds float, ptr %28, i64 2
  %30 = load float, ptr %29, align 4, !tbaa !15
  %31 = fmul float %30, %27
  store float %31, ptr %29, 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 %32

32:                                               ; preds = %57, %2
  %33 = load i32, ptr %8, align 4, !tbaa !14
  %34 = load i32, ptr %5, align 4, !tbaa !14
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %37, label %36

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

37:                                               ; preds = %32
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = call noundef float @_ZN6Perlin6noise3EPf(ptr noundef nonnull align 4 dereferenceable(57417) %9, ptr noundef %38)
  %40 = load float, ptr %7, align 4, !tbaa !15
  %41 = load float, ptr %6, align 4, !tbaa !15
  %42 = call float @llvm.fmuladd.f32(float %39, float %40, float %41)
  store float %42, ptr %6, align 4, !tbaa !15
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds float, ptr %43, i64 0
  %45 = load float, ptr %44, align 4, !tbaa !15
  %46 = fmul float %45, 2.000000e+00
  store float %46, ptr %44, align 4, !tbaa !15
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds float, ptr %47, i64 1
  %49 = load float, ptr %48, align 4, !tbaa !15
  %50 = fmul float %49, 2.000000e+00
  store float %50, ptr %48, align 4, !tbaa !15
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds float, ptr %51, i64 2
  %53 = load float, ptr %52, align 4, !tbaa !15
  %54 = fmul float %53, 2.000000e+00
  store float %54, ptr %52, align 4, !tbaa !15
  %55 = load float, ptr %7, align 4, !tbaa !15
  %56 = fmul float %55, 5.000000e-01
  store float %56, ptr %7, align 4, !tbaa !15
  br label %57

57:                                               ; preds = %37
  %58 = load i32, ptr %8, align 4, !tbaa !14
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %8, align 4, !tbaa !14
  br label %32, !llvm.loop !18

60:                                               ; preds = %36
  %61 = 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 %61
}

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 @_ZN6Perlin6noise3EPf(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_3DEPf(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 = load float, ptr %6, align 4, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %1, i64 8
  %16 = load float, ptr %15, align 4, !tbaa !14
  %17 = fmul float %14, %16
  store float %17, ptr %15, align 4, !tbaa !14
  %18 = icmp sgt i32 %3, 0
  br i1 %18, label %.lr.ph, label %._crit_edge

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

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.018 = phi i32 [ %26, %.lr.ph ], [ 0, %2 ]
  %.01417 = phi float [ %25, %.lr.ph ], [ %5, %2 ]
  %.01516 = phi float [ %20, %.lr.ph ], [ 0.000000e+00, %2 ]
  %19 = tail call noundef float @_ZN6Perlin6noise3EPf(ptr noundef nonnull align 4 dereferenceable(57417) %0, ptr noundef nonnull %1)
  %20 = tail call float @llvm.fmuladd.f32(float %19, float %.01417, float %.01516)
  %21 = load <2 x float>, ptr %1, align 4, !tbaa !14
  %22 = fmul <2 x float> %21, <float 2.000000e+00, float 2.000000e+00>
  store <2 x float> %22, ptr %1, align 4, !tbaa !14
  %23 = load float, ptr %15, align 4, !tbaa !14
  %24 = fmul float %23, 2.000000e+00
  store float %24, ptr %15, align 4, !tbaa !14
  %25 = fmul float %.01417, 5.000000e-01
  %26 = add nuw nsw i32 %.018, 1
  %exitcond.not = icmp eq i32 %26, %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