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

; 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 @_ZN3imp7simplexEddi(double noundef, double noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN3imp10fbmSimplexEdddjddd(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 = %55, %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 %58

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 i32, ptr %20, align 4, !tbaa !9
  %43 = call noundef double @_ZN3imp7simplexEddi(double noundef %38, double noundef %41, i32 noundef %42)
  %44 = load double, ptr %17, align 8, !tbaa !5
  %45 = load double, ptr %15, align 8, !tbaa !5
  %46 = call double @llvm.fmuladd.f64(double %43, double %44, double %45)
  store double %46, ptr %15, align 8, !tbaa !5
  %47 = load double, ptr %17, align 8, !tbaa !5
  %48 = load double, ptr %18, align 8, !tbaa !5
  %49 = fadd double %48, %47
  store double %49, ptr %18, align 8, !tbaa !5
  %50 = load double, ptr %12, align 8, !tbaa !5
  %51 = load double, ptr %17, align 8, !tbaa !5
  %52 = fmul double %51, %50
  store double %52, ptr %17, align 8, !tbaa !5
  %53 = load double, ptr %16, align 8, !tbaa !5
  %54 = fmul double %53, 2.000000e+00
  store double %54, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  br label %55

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

58:                                               ; preds = %26
  %59 = load double, ptr %15, align 8, !tbaa !5
  %60 = load double, ptr %18, align 8, !tbaa !5
  %61 = fdiv double %59, %60
  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 %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 = !{!"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 @_ZN3imp7simplexEddi(double noundef, double noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN3imp10fbmSimplexEdddjddd(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 %15, %16
  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
  %.028 = phi double [ %15, %.lr.ph ], [ 0.000000e+00, %7 ]
  %.02027 = phi i32 [ %19, %.lr.ph ], [ 0, %7 ]
  %.02126 = phi double [ %16, %.lr.ph ], [ 0.000000e+00, %7 ]
  %.02225 = phi double [ %17, %.lr.ph ], [ 1.000000e+00, %7 ]
  %.02324 = phi double [ %18, %.lr.ph ], [ %5, %7 ]
  %10 = fmul double %.02324, %6
  %11 = fptosi double %10 to i32
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %11, i32 1)
  %12 = fmul double %.02324, %0
  %13 = fmul double %.02324, %1
  %14 = tail call noundef double @_ZN3imp7simplexEddi(double noundef %12, double noundef %13, i32 noundef %spec.store.select)
  %15 = tail call double @llvm.fmuladd.f64(double %14, double %.02225, double %.028)
  %16 = fadd double %.02225, %.02126
  %17 = fmul double %.02225, %4
  %18 = fmul double %.02324, 2.000000e+00
  %19 = add nuw i32 %.02027, 1
  %exitcond.not = icmp eq i32 %19, %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