; LLVM IR from bohanwang/libpgo :: src/core/perlinNoise/perlinNoise.ll (ZN3pgo11PerlinNoise11PerlinNoise10gradient4DEidddd)

; 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.pgo::PerlinNoise::PerlinNoise" = type { [256 x i32], [4 x [2 x double]], [16 x [3 x double]], [32 x [4 x double]] }

; 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 nounwind uwtable
define dso_local noundef double @_ZN3pgo11PerlinNoise11PerlinNoise10gradient4DEidddd(ptr noundef nonnull align 8 dereferenceable(2496) %0, i32 noundef %1, double noundef %2, double noundef %3, double noundef %4, double noundef %5) #2 align 2 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store double %2, ptr %9, align 8, !tbaa !11
  store double %3, ptr %10, align 8, !tbaa !11
  store double %4, ptr %11, align 8, !tbaa !11
  store double %5, ptr %12, align 8, !tbaa !11
  %14 = load ptr, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = and i32 %15, 31
  store i32 %16, ptr %13, align 4, !tbaa !9
  %17 = getelementptr inbounds %"class.pgo::PerlinNoise::PerlinNoise", ptr %14, i32 0, i32 3
  %18 = load i32, ptr %13, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [32 x [4 x double]], ptr %17, i64 0, i64 %19
  %21 = getelementptr inbounds [4 x double], ptr %20, i64 0, i64 0
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = load double, ptr %9, align 8, !tbaa !11
  %24 = getelementptr inbounds %"class.pgo::PerlinNoise::PerlinNoise", ptr %14, i32 0, i32 3
  %25 = load i32, ptr %13, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [32 x [4 x double]], ptr %24, i64 0, i64 %26
  %28 = getelementptr inbounds [4 x double], ptr %27, i64 0, i64 1
  %29 = load double, ptr %28, align 8, !tbaa !11
  %30 = load double, ptr %10, align 8, !tbaa !11
  %31 = fmul double %29, %30
  %32 = call double @llvm.fmuladd.f64(double %22, double %23, double %31)
  %33 = getelementptr inbounds %"class.pgo::PerlinNoise::PerlinNoise", ptr %14, i32 0, i32 3
  %34 = load i32, ptr %13, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [32 x [4 x double]], ptr %33, i64 0, i64 %35
  %37 = getelementptr inbounds [4 x double], ptr %36, i64 0, i64 2
  %38 = load double, ptr %37, align 8, !tbaa !11
  %39 = load double, ptr %11, align 8, !tbaa !11
  %40 = call double @llvm.fmuladd.f64(double %38, double %39, double %32)
  %41 = getelementptr inbounds %"class.pgo::PerlinNoise::PerlinNoise", ptr %14, i32 0, i32 3
  %42 = load i32, ptr %13, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [32 x [4 x double]], ptr %41, i64 0, i64 %43
  %45 = getelementptr inbounds [4 x double], ptr %44, i64 0, i64 3
  %46 = load double, ptr %45, align 8, !tbaa !11
  %47 = load double, ptr %12, align 8, !tbaa !11
  %48 = call double @llvm.fmuladd.f64(double %46, double %47, double %40)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret double %48
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nounwind 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef double @_ZN3pgo11PerlinNoise11PerlinNoise10gradient4DEidddd(ptr nocapture noundef nonnull readonly align 8 dereferenceable(2496) %0, i32 noundef %1, double noundef %2, double noundef %3, double noundef %4, double noundef %5) local_unnamed_addr #1 align 2 {
  %7 = and i32 %1, 31
  %8 = getelementptr inbounds i8, ptr %0, i64 1472
  %9 = zext nneg i32 %7 to i64
  %10 = getelementptr inbounds [32 x [4 x double]], ptr %8, i64 0, i64 %9
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %10, i64 8
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = fmul double %13, %3
  %15 = tail call double @llvm.fmuladd.f64(double %11, double %2, double %14)
  %16 = getelementptr inbounds i8, ptr %10, i64 16
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = tail call double @llvm.fmuladd.f64(double %17, double %4, double %15)
  %19 = getelementptr inbounds i8, ptr %10, i64 24
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = tail call double @llvm.fmuladd.f64(double %20, double %5, double %18)
  ret double %21
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass