; 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: mustprogress uwtable
define dso_local noundef double @_ZN3pgo11PerlinNoise10PerlinWind16GetPerlinNoise3DEPdiid(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, double noundef %4) #2 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 [3 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 24, ptr %14) #5
  call void @llvm.memset.p0.i64(ptr align 16 %14, i8 0, i64 24, 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 = %58, %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 %61

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 [3 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 [3 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 [3 x double], ptr %14, i64 0, i64 2
  store double %41, ptr %42, align 16, !tbaa !11
  %43 = getelementptr inbounds %"class.pgo::PerlinNoise::PerlinWind", ptr %16, i32 0, i32 3
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [4 x ptr], ptr %43, i64 0, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = getelementptr inbounds [3 x double], ptr %14, i64 0, i64 0
  %49 = call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise3DEPd(ptr noundef nonnull align 8 dereferenceable(2496) %47, ptr noundef %48)
  %50 = load double, ptr %13, align 8, !tbaa !11
  %51 = load double, ptr %11, align 8, !tbaa !11
  %52 = call double @llvm.fmuladd.f64(double %49, double %50, double %51)
  store double %52, ptr %11, align 8, !tbaa !11
  %53 = load double, ptr %12, align 8, !tbaa !11
  %54 = fmul double %53, 2.000000e+00
  store double %54, ptr %12, align 8, !tbaa !11
  %55 = load double, ptr %10, align 8, !tbaa !11
  %56 = load double, ptr %13, align 8, !tbaa !11
  %57 = fmul double %56, %55
  store double %57, ptr %13, align 8, !tbaa !11
  br label %58

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

61:                                               ; preds = %23
  %62 = load double, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 24, 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 %62
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise3DEPd(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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 @_ZN3pgo11PerlinNoise10PerlinWind16GetPerlinNoise3DEPdiid(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 [3 x double], align 16
  call void @llvm.lifetime.start.p0(i64 24, 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
  %.019.lcssa = phi double [ 0.000000e+00, %5 ], [ %23, %14 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #4
  ret double %.019.lcssa

14:                                               ; preds = %.lr.ph, %14
  %.023 = phi i32 [ 0, %.lr.ph ], [ %26, %14 ]
  %.01722 = phi double [ %4, %.lr.ph ], [ %25, %14 ]
  %.01821 = phi double [ 1.000000e+00, %.lr.ph ], [ %24, %14 ]
  %.01920 = 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 %.01821, 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 double, ptr %8, align 8, !tbaa !5
  %20 = fmul double %.01821, %19
  store double %20, ptr %9, align 16, !tbaa !5
  %21 = load ptr, ptr %12, align 8, !tbaa !9
  %22 = call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise3DEPd(ptr noundef nonnull align 8 dereferenceable(2496) %21, ptr noundef nonnull %6)
  %23 = call double @llvm.fmuladd.f64(double %22, double %.01722, double %.01920)
  %24 = fmul double %.01821, 2.000000e+00
  %25 = fmul double %.01722, %4
  %26 = add nuw nsw i32 %.023, 1
  %exitcond.not = icmp eq i32 %.023, %13
  br i1 %exitcond.not, label %._crit_edge, label %14, !llvm.loop !11
}

declare noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise3DEPd(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