; LLVM IR from drohmer/cgp :: library/cgp/08_random_noise/noise (noise)

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

%"struct.cgp::numarray_stack.0" = type { float, float, float }

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

14:                                               ; preds = %51, %4
  %15 = load i32, ptr %12, align 4, !tbaa !9
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %54

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.cgp::numarray_stack.0", ptr %20, i32 0, i32 0
  %22 = load float, ptr %21, align 4, !tbaa !13
  %23 = load float, ptr %11, align 4, !tbaa !11
  %24 = fmul float %22, %23
  %25 = fpext float %24 to double
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.cgp::numarray_stack.0", ptr %26, i32 0, i32 1
  %28 = load float, ptr %27, align 4, !tbaa !15
  %29 = load float, ptr %11, align 4, !tbaa !11
  %30 = fmul float %28, %29
  %31 = fpext float %30 to double
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.cgp::numarray_stack.0", ptr %32, i32 0, i32 2
  %34 = load float, ptr %33, align 4, !tbaa !16
  %35 = load float, ptr %11, align 4, !tbaa !11
  %36 = fmul float %34, %35
  %37 = fpext float %36 to double
  %38 = call noundef double @_Z7snoise3ddd(double noundef %25, double noundef %31, double noundef %37)
  %39 = fptrunc double %38 to float
  store float %39, ptr %13, align 4, !tbaa !11
  %40 = load float, ptr %10, align 4, !tbaa !11
  %41 = load float, ptr %13, align 4, !tbaa !11
  %42 = call float @llvm.fmuladd.f32(float 5.000000e-01, float %41, float 5.000000e-01)
  %43 = load float, ptr %9, align 4, !tbaa !11
  %44 = call float @llvm.fmuladd.f32(float %40, float %42, float %43)
  store float %44, ptr %9, align 4, !tbaa !11
  %45 = load float, ptr %8, align 4, !tbaa !11
  %46 = load float, ptr %11, align 4, !tbaa !11
  %47 = fmul float %46, %45
  store float %47, ptr %11, align 4, !tbaa !11
  %48 = load float, ptr %7, align 4, !tbaa !11
  %49 = load float, ptr %10, align 4, !tbaa !11
  %50 = fmul float %49, %48
  store float %50, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %51

51:                                               ; preds = %19
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %12, align 4, !tbaa !9
  br label %14, !llvm.loop !17

54:                                               ; preds = %18
  %55 = load float, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret float %55
}

declare noundef double @_Z7snoise3ddd(double noundef, double noundef, double noundef) #3

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 = { "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 #4 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTSN3cgp14numarray_stackIfLi3EEE", !12, i64 0, !12, i64 4, !12, i64 8}
!15 = !{!14, !12, i64 4}
!16 = !{!14, !12, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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
define dso_local noundef float @_ZN3cgp12noise_perlinERKNS_14numarray_stackIfLi3EEEiff(ptr nocapture noundef nonnull readonly align 4 dereferenceable(12) %0, i32 noundef %1, float noundef %2, float noundef %3) local_unnamed_addr #1 {
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  br label %8

._crit_edge:                                      ; preds = %8, %4
  %.0.lcssa = phi float [ 0.000000e+00, %4 ], [ %21, %8 ]
  ret float %.0.lcssa

8:                                                ; preds = %.lr.ph, %8
  %.022 = phi float [ 0.000000e+00, %.lr.ph ], [ %21, %8 ]
  %.01621 = phi i32 [ 0, %.lr.ph ], [ %24, %8 ]
  %.01720 = phi float [ 1.000000e+00, %.lr.ph ], [ %22, %8 ]
  %.01819 = phi float [ 1.000000e+00, %.lr.ph ], [ %23, %8 ]
  %9 = load float, ptr %0, align 4, !tbaa !5
  %10 = fmul float %.01720, %9
  %11 = fpext float %10 to double
  %12 = load float, ptr %6, align 4, !tbaa !10
  %13 = fmul float %.01720, %12
  %14 = fpext float %13 to double
  %15 = load float, ptr %7, align 4, !tbaa !11
  %16 = fmul float %.01720, %15
  %17 = fpext float %16 to double
  %18 = tail call noundef double @_Z7snoise3ddd(double noundef %11, double noundef %14, double noundef %17)
  %19 = fptrunc double %18 to float
  %20 = tail call float @llvm.fmuladd.f32(float %19, float 5.000000e-01, float 5.000000e-01)
  %21 = tail call float @llvm.fmuladd.f32(float %.01819, float %20, float %.022)
  %22 = fmul float %.01720, %3
  %23 = fmul float %.01819, %2
  %24 = add nuw nsw i32 %.01621, 1
  %exitcond.not = icmp eq i32 %24, %1
  br i1 %exitcond.not, label %._crit_edge, label %8, !llvm.loop !12
}

declare noundef double @_Z7snoise3ddd(double noundef, double noundef, double noundef) local_unnamed_addr #2

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" }
attributes #2 = { "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 = !{!"_ZTSN3cgp14numarray_stackIfLi3EEE", !7, i64 0, !7, i64 4, !7, i64 8}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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