; LLVM IR from Lut1n/ImpGears :: src/ImpGears/Core/Noise.ll (ZN3imp9fbmPerlinEdddjddd)

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZN3imp6perlinEdddi(double noundef, double noundef, double noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN3imp9fbmPerlinEdddjddd(double noundef %0, double noundef %1, double noundef %2, i32 noundef %3, double noundef %4, double noundef %5, double noundef %6) #2 {
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  store double %0, ptr %8, align 8, !tbaa !5
  store double %1, ptr %9, align 8, !tbaa !5
  store double %2, ptr %10, align 8, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !9
  store double %4, ptr %12, align 8, !tbaa !5
  store double %5, ptr %13, align 8, !tbaa !5
  store double %6, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store double 0.000000e+00, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %21 = load double, ptr %13, align 8, !tbaa !5
  store double %21, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  store double 1.000000e+00, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  store double 0.000000e+00, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %58, %7
  %23 = load i32, ptr %19, align 4, !tbaa !9
  %24 = load i32, ptr %11, align 4, !tbaa !9
  %25 = icmp ult i32 %23, %24
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  %28 = load double, ptr %16, align 8, !tbaa !5
  %29 = load double, ptr %14, align 8, !tbaa !5
  %30 = fmul double %28, %29
  %31 = fptosi double %30 to i32
  store i32 %31, ptr %20, align 4, !tbaa !9
  %32 = load i32, ptr %20, align 4, !tbaa !9
  %33 = icmp sle i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %27
  store i32 1, ptr %20, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %34, %27
  %36 = load double, ptr %8, align 8, !tbaa !5
  %37 = load double, ptr %16, align 8, !tbaa !5
  %38 = fmul double %36, %37
  %39 = load double, ptr %9, align 8, !tbaa !5
  %40 = load double, ptr %16, align 8, !tbaa !5
  %41 = fmul double %39, %40
  %42 = load double, ptr %10, align 8, !tbaa !5
  %43 = load double, ptr %16, align 8, !tbaa !5
  %44 = fmul double %42, %43
  %45 = load i32, ptr %20, align 4, !tbaa !9
  %46 = call noundef double @_ZN3imp6perlinEdddi(double noundef %38, double noundef %41, double noundef %44, i32 noundef %45)
  %47 = load double, ptr %17, align 8, !tbaa !5
  %48 = load double, ptr %15, align 8, !tbaa !5
  %49 = call double @llvm.fmuladd.f64(double %46, double %47, double %48)
  store double %49, ptr %15, align 8, !tbaa !5
  %50 = load double, ptr %17, align 8, !tbaa !5
  %51 = load double, ptr %18, align 8, !tbaa !5
  %52 = fadd double %51, %50
  store double %52, ptr %18, align 8, !tbaa !5
  %53 = load double, ptr %12, align 8, !tbaa !5
  %54 = load double, ptr %17, align 8, !tbaa !5
  %55 = fmul double %54, %53
  store double %55, ptr %17, align 8, !tbaa !5
  %56 = load double, ptr %16, align 8, !tbaa !5
  %57 = fmul double %56, 2.000000e+00
  store double %57, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  br label %58

58:                                               ; preds = %35
  %59 = load i32, ptr %19, align 4, !tbaa !9
  %60 = add i32 %59, 1
  store i32 %60, ptr %19, align 4, !tbaa !9
  br label %22, !llvm.loop !11

61:                                               ; preds = %26
  %62 = load double, ptr %15, align 8, !tbaa !5
  %63 = load double, ptr %18, align 8, !tbaa !5
  %64 = fdiv double %62, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  ret double %64
}

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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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 double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZN3imp6perlinEdddi(double noundef, double noundef, double noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN3imp9fbmPerlinEdddjddd(double noundef %0, double noundef %1, double noundef %2, i32 noundef %3, double noundef %4, double noundef %5, double noundef %6) local_unnamed_addr #1 {
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %8 = fdiv double %16, %17
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %7
  %9 = phi double [ 0x7FF8000000000000, %7 ], [ %8, %._crit_edge.loopexit ]
  ret double %9

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.030 = phi double [ %16, %.lr.ph ], [ 0.000000e+00, %7 ]
  %.02229 = phi i32 [ %20, %.lr.ph ], [ 0, %7 ]
  %.02328 = phi double [ %17, %.lr.ph ], [ 0.000000e+00, %7 ]
  %.02427 = phi double [ %18, %.lr.ph ], [ 1.000000e+00, %7 ]
  %.02526 = phi double [ %19, %.lr.ph ], [ %5, %7 ]
  %10 = fmul double %.02526, %6
  %11 = fptosi double %10 to i32
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %11, i32 1)
  %12 = fmul double %.02526, %0
  %13 = fmul double %.02526, %1
  %14 = fmul double %.02526, %2
  %15 = tail call noundef double @_ZN3imp6perlinEdddi(double noundef %12, double noundef %13, double noundef %14, i32 noundef %spec.store.select)
  %16 = tail call double @llvm.fmuladd.f64(double %15, double %.02427, double %.030)
  %17 = fadd double %.02427, %.02328
  %18 = fmul double %.02427, %4
  %19 = fmul double %.02526, 2.000000e+00
  %20 = add nuw i32 %.02229, 1
  %exitcond.not = icmp eq i32 %20, %3
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !5
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #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 = { 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,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass