; LLVM IR from bohanwang/libpgo :: src/core/perlinNoise (perlinWind)

; 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::PerlinWind" = type { ptr, double, [3 x double], [4 x ptr] }

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN3pgo11PerlinNoise10PerlinWind16GetPerlinNoise4DEPdiid(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, double noundef %4) #3 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca [4 x double], align 16
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store double %4, ptr %10, align 8, !tbaa !11
  %16 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store double 0.000000e+00, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store double 1.000000e+00, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %17 = load double, ptr %10, align 8, !tbaa !11
  store double %17, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 32, ptr %14) #5
  call void @llvm.memset.p0.i64(ptr align 16 %14, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %64, %5
  %19 = load i32, ptr %15, align 4, !tbaa !9
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = sub nsw i32 %20, 1
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %67

24:                                               ; preds = %18
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds double, ptr %25, i64 0
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = load double, ptr %12, align 8, !tbaa !11
  %29 = fmul double %27, %28
  %30 = getelementptr inbounds [4 x double], ptr %14, i64 0, i64 0
  store double %29, ptr %30, align 16, !tbaa !11
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds double, ptr %31, i64 1
  %33 = load double, ptr %32, align 8, !tbaa !11
  %34 = load double, ptr %12, align 8, !tbaa !11
  %35 = fmul double %33, %34
  %36 = getelementptr inbounds [4 x double], ptr %14, i64 0, i64 1
  store double %35, ptr %36, align 8, !tbaa !11
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds double, ptr %37, i64 2
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = load double, ptr %12, align 8, !tbaa !11
  %41 = fmul double %39, %40
  %42 = getelementptr inbounds [4 x double], ptr %14, i64 0, i64 2
  store double %41, ptr %42, align 16, !tbaa !11
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds double, ptr %43, i64 3
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = load double, ptr %12, align 8, !tbaa !11
  %47 = fmul double %45, %46
  %48 = getelementptr inbounds [4 x double], ptr %14, i64 0, i64 3
  store double %47, ptr %48, align 8, !tbaa !11
  %49 = getelementptr inbounds %"class.pgo::PerlinNoise::PerlinWind", ptr %16, i32 0, i32 3
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [4 x ptr], ptr %49, i64 0, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  %54 = getelementptr inbounds [4 x double], ptr %14, i64 0, i64 0
  %55 = call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise4DEPd(ptr noundef nonnull align 8 dereferenceable(2496) %53, ptr noundef %54)
  %56 = load double, ptr %13, align 8, !tbaa !11
  %57 = load double, ptr %11, align 8, !tbaa !11
  %58 = call double @llvm.fmuladd.f64(double %55, double %56, double %57)
  store double %58, ptr %11, align 8, !tbaa !11
  %59 = load double, ptr %12, align 8, !tbaa !11
  %60 = fmul double %59, 2.000000e+00
  store double %60, ptr %12, align 8, !tbaa !11
  %61 = load double, ptr %10, align 8, !tbaa !11
  %62 = load double, ptr %13, align 8, !tbaa !11
  %63 = fmul double %62, %61
  store double %63, ptr %13, align 8, !tbaa !11
  br label %64

64:                                               ; preds = %24
  %65 = load i32, ptr %15, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %15, align 4, !tbaa !9
  br label %18, !llvm.loop !13

67:                                               ; preds = %23
  %68 = load double, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 32, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  ret double %68
}

declare noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise4DEPd(ptr noundef nonnull align 8 dereferenceable(2496), ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { "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 #5 = { 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}
!13 = distinct !{!13, !14}
!14 = !{!"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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN3pgo11PerlinNoise10PerlinWind16GetPerlinNoise4DEPdiid(ptr nocapture noundef nonnull readonly align 8 dereferenceable(72) %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3, double noundef %4) local_unnamed_addr #2 align 2 {
  %6 = alloca [4 x double], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #4
  %7 = icmp sgt i32 %3, 1
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = getelementptr inbounds i8, ptr %6, i64 16
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = sext i32 %2 to i64
  %12 = getelementptr inbounds [4 x ptr], ptr %10, i64 0, i64 %11
  %13 = add nsw i32 %3, -2
  br label %14

._crit_edge:                                      ; preds = %14, %5
  %.021.lcssa = phi double [ 0.000000e+00, %5 ], [ %23, %14 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #4
  ret double %.021.lcssa

14:                                               ; preds = %.lr.ph, %14
  %.025 = phi i32 [ 0, %.lr.ph ], [ %26, %14 ]
  %.01924 = phi double [ %4, %.lr.ph ], [ %25, %14 ]
  %.02023 = phi double [ 1.000000e+00, %.lr.ph ], [ %24, %14 ]
  %.02122 = phi double [ 0.000000e+00, %.lr.ph ], [ %23, %14 ]
  %15 = load <2 x double>, ptr %1, align 8, !tbaa !5
  %16 = insertelement <2 x double> poison, double %.02023, i64 0
  %17 = shufflevector <2 x double> %16, <2 x double> poison, <2 x i32> zeroinitializer
  %18 = fmul <2 x double> %17, %15
  store <2 x double> %18, ptr %6, align 16, !tbaa !5
  %19 = load <2 x double>, ptr %8, align 8, !tbaa !5
  %20 = fmul <2 x double> %17, %19
  store <2 x double> %20, ptr %9, align 16, !tbaa !5
  %21 = load ptr, ptr %12, align 8, !tbaa !9
  %22 = call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise4DEPd(ptr noundef nonnull align 8 dereferenceable(2496) %21, ptr noundef nonnull %6)
  %23 = call double @llvm.fmuladd.f64(double %22, double %.01924, double %.02122)
  %24 = fmul double %.02023, 2.000000e+00
  %25 = fmul double %.01924, %4
  %26 = add nuw nsw i32 %.025, 1
  %exitcond.not = icmp eq i32 %.025, %13
  br i1 %exitcond.not, label %._crit_edge, label %14, !llvm.loop !11
}

declare noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise4DEPd(ptr noundef nonnull align 8 dereferenceable(2496), ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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