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

; 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: mustprogress uwtable
define dso_local noundef double @_ZN3pgo11PerlinNoise10PerlinWind16GetPerlinNoise1DEdid(ptr noundef nonnull align 8 dereferenceable(72) %0, double noundef %1, i32 noundef %2, double noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  store double %3, ptr %8, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store double 0.000000e+00, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store double 1.000000e+00, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %14 = load double, ptr %8, align 8, !tbaa !9
  store double %14, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %15

15:                                               ; preds = %37, %4
  %16 = load i32, ptr %12, align 4, !tbaa !11
  %17 = load i32, ptr %7, align 4, !tbaa !11
  %18 = sub nsw i32 %17, 1
  %19 = icmp slt i32 %16, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %40

21:                                               ; preds = %15
  %22 = getelementptr inbounds %"class.pgo::PerlinNoise::PerlinWind", ptr %13, i32 0, i32 3
  %23 = getelementptr inbounds [4 x ptr], ptr %22, i64 0, i64 3
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = load double, ptr %6, align 8, !tbaa !9
  %26 = load double, ptr %10, align 8, !tbaa !9
  %27 = fmul double %25, %26
  %28 = call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise1DEd(ptr noundef nonnull align 8 dereferenceable(2496) %24, double noundef %27)
  %29 = load double, ptr %11, align 8, !tbaa !9
  %30 = load double, ptr %9, align 8, !tbaa !9
  %31 = call double @llvm.fmuladd.f64(double %28, double %29, double %30)
  store double %31, ptr %9, align 8, !tbaa !9
  %32 = load double, ptr %10, align 8, !tbaa !9
  %33 = fmul double %32, 2.000000e+00
  store double %33, ptr %10, align 8, !tbaa !9
  %34 = load double, ptr %8, align 8, !tbaa !9
  %35 = load double, ptr %11, align 8, !tbaa !9
  %36 = fmul double %35, %34
  store double %36, ptr %11, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %21
  %38 = load i32, ptr %12, align 4, !tbaa !11
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %12, align 4, !tbaa !11
  br label %15, !llvm.loop !13

40:                                               ; preds = %20
  %41 = load double, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret double %41
}

declare noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise1DEd(ptr noundef nonnull align 8 dereferenceable(2496), double noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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 uwtable
define dso_local noundef double @_ZN3pgo11PerlinNoise10PerlinWind16GetPerlinNoise1DEdid(ptr nocapture noundef nonnull readonly align 8 dereferenceable(72) %0, double noundef %1, i32 noundef %2, double noundef %3) local_unnamed_addr #0 align 2 {
  %5 = icmp sgt i32 %2, 1
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = add nsw i32 %2, -2
  br label %8

._crit_edge:                                      ; preds = %8, %4
  %.014.lcssa = phi double [ 0.000000e+00, %4 ], [ %12, %8 ]
  ret double %.014.lcssa

8:                                                ; preds = %.lr.ph, %8
  %.018 = phi i32 [ 0, %.lr.ph ], [ %15, %8 ]
  %.01217 = phi double [ %3, %.lr.ph ], [ %14, %8 ]
  %.01316 = phi double [ 1.000000e+00, %.lr.ph ], [ %13, %8 ]
  %.01415 = phi double [ 0.000000e+00, %.lr.ph ], [ %12, %8 ]
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = fmul double %.01316, %1
  %11 = tail call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise1DEd(ptr noundef nonnull align 8 dereferenceable(2496) %9, double noundef %10)
  %12 = tail call double @llvm.fmuladd.f64(double %11, double %.01217, double %.01415)
  %13 = fmul double %.01316, 2.000000e+00
  %14 = fmul double %.01217, %3
  %15 = add nuw nsw i32 %.018, 1
  %exitcond.not = icmp eq i32 %.018, %7
  br i1 %exitcond.not, label %._crit_edge, label %8, !llvm.loop !9
}

declare noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise1DEd(ptr noundef nonnull align 8 dereferenceable(2496), double noundef) local_unnamed_addr #1

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

attributes #0 = { 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 #1 = { "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 = { mustprogress 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 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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