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

; 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: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3pgo11PerlinNoise11PerlinNoise17computeFadeCurvesEd(ptr noundef nonnull align 8 dereferenceable(2496), double noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3pgo11PerlinNoise11PerlinNoise19linearInterpolationEddd(ptr noundef nonnull align 8 dereferenceable(2496), double noundef, double noundef, double noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496), i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3pgo11PerlinNoise11PerlinNoise10gradient2DEidd(ptr noundef nonnull align 8 dereferenceable(2496), i32 noundef, double noundef, double noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise2DEPd(ptr noundef nonnull align 8 dereferenceable(2496) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [2 x i32], align 4
  %6 = alloca [2 x double], align 16
  %7 = alloca [2 x double], align 16
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %67, %2
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 2
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds double, ptr %17, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !11
  %22 = fcmp ogt double %21, 0.000000e+00
  br i1 %22, label %23, label %33

23:                                               ; preds = %16
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds double, ptr %24, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !11
  %29 = fptosi double %28 to i32
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2 x i32], ptr %5, i64 0, i64 %31
  store i32 %29, ptr %32, align 4, !tbaa !9
  br label %44

33:                                               ; preds = %16
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds double, ptr %34, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !11
  %39 = fsub double %38, 1.000000e+00
  %40 = fptosi double %39 to i32
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [2 x i32], ptr %5, i64 0, i64 %42
  store i32 %40, ptr %43, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %33, %23
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %45, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [2 x i32], ptr %5, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = sitofp i32 %53 to double
  %55 = fsub double %49, %54
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [2 x double], ptr %6, i64 0, i64 %57
  store double %55, ptr %58, align 8, !tbaa !11
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [2 x double], ptr %6, i64 0, i64 %60
  %62 = load double, ptr %61, align 8, !tbaa !11
  %63 = call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise17computeFadeCurvesEd(ptr noundef nonnull align 8 dereferenceable(2496) %11, double noundef %62)
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [2 x double], ptr %7, i64 0, i64 %65
  store double %63, ptr %66, align 8, !tbaa !11
  br label %67

67:                                               ; preds = %44
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %8, align 4, !tbaa !9
  br label %12, !llvm.loop !13

70:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %71 = getelementptr inbounds [2 x i32], ptr %5, i64 0, i64 0
  %72 = load i32, ptr %71, align 4, !tbaa !9
  %73 = call noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496) %11, i32 noundef %72)
  %74 = getelementptr inbounds [2 x i32], ptr %5, i64 0, i64 1
  %75 = load i32, ptr %74, align 4, !tbaa !9
  %76 = add nsw i32 %73, %75
  store i32 %76, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %77 = getelementptr inbounds [2 x i32], ptr %5, i64 0, i64 0
  %78 = load i32, ptr %77, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  %80 = call noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496) %11, i32 noundef %79)
  %81 = getelementptr inbounds [2 x i32], ptr %5, i64 0, i64 1
  %82 = load i32, ptr %81, align 4, !tbaa !9
  %83 = add nsw i32 %80, %82
  store i32 %83, ptr %10, align 4, !tbaa !9
  %84 = getelementptr inbounds [2 x double], ptr %7, i64 0, i64 1
  %85 = load double, ptr %84, align 8, !tbaa !11
  %86 = getelementptr inbounds [2 x double], ptr %7, i64 0, i64 0
  %87 = load double, ptr %86, align 16, !tbaa !11
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = call noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496) %11, i32 noundef %88)
  %90 = getelementptr inbounds [2 x double], ptr %6, i64 0, i64 0
  %91 = load double, ptr %90, align 16, !tbaa !11
  %92 = getelementptr inbounds [2 x double], ptr %6, i64 0, i64 1
  %93 = load double, ptr %92, align 8, !tbaa !11
  %94 = call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise10gradient2DEidd(ptr noundef nonnull align 8 dereferenceable(2496) %11, i32 noundef %89, double noundef %91, double noundef %93)
  %95 = load i32, ptr %10, align 4, !tbaa !9
  %96 = call noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496) %11, i32 noundef %95)
  %97 = getelementptr inbounds [2 x double], ptr %6, i64 0, i64 0
  %98 = load double, ptr %97, align 16, !tbaa !11
  %99 = fsub double %98, 1.000000e+00
  %100 = getelementptr inbounds [2 x double], ptr %6, i64 0, i64 1
  %101 = load double, ptr %100, align 8, !tbaa !11
  %102 = call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise10gradient2DEidd(ptr noundef nonnull align 8 dereferenceable(2496) %11, i32 noundef %96, double noundef %99, double noundef %101)
  %103 = call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise19linearInterpolationEddd(ptr noundef nonnull align 8 dereferenceable(2496) %11, double noundef %87, double noundef %94, double noundef %102)
  %104 = getelementptr inbounds [2 x double], ptr %7, i64 0, i64 0
  %105 = load double, ptr %104, align 16, !tbaa !11
  %106 = load i32, ptr %9, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  %108 = call noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496) %11, i32 noundef %107)
  %109 = getelementptr inbounds [2 x double], ptr %6, i64 0, i64 0
  %110 = load double, ptr %109, align 16, !tbaa !11
  %111 = getelementptr inbounds [2 x double], ptr %6, i64 0, i64 1
  %112 = load double, ptr %111, align 8, !tbaa !11
  %113 = fsub double %112, 1.000000e+00
  %114 = call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise10gradient2DEidd(ptr noundef nonnull align 8 dereferenceable(2496) %11, i32 noundef %108, double noundef %110, double noundef %113)
  %115 = load i32, ptr %10, align 4, !tbaa !9
  %116 = add nsw i32 %115, 1
  %117 = call noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496) %11, i32 noundef %116)
  %118 = getelementptr inbounds [2 x double], ptr %6, i64 0, i64 0
  %119 = load double, ptr %118, align 16, !tbaa !11
  %120 = fsub double %119, 1.000000e+00
  %121 = getelementptr inbounds [2 x double], ptr %6, i64 0, i64 1
  %122 = load double, ptr %121, align 8, !tbaa !11
  %123 = fsub double %122, 1.000000e+00
  %124 = call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise10gradient2DEidd(ptr noundef nonnull align 8 dereferenceable(2496) %11, i32 noundef %117, double noundef %120, double noundef %123)
  %125 = call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise19linearInterpolationEddd(ptr noundef nonnull align 8 dereferenceable(2496) %11, double noundef %105, double noundef %114, double noundef %124)
  %126 = call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise19linearInterpolationEddd(ptr noundef nonnull align 8 dereferenceable(2496) %11, double noundef %85, double noundef %103, double noundef %125)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret double %126
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 nounwind uwtable
declare dso_local noundef double @_ZN3pgo11PerlinNoise11PerlinNoise17computeFadeCurvesEd(ptr noundef nonnull align 8 dereferenceable(2496), double noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3pgo11PerlinNoise11PerlinNoise19linearInterpolationEddd(ptr noundef nonnull align 8 dereferenceable(2496), double noundef, double noundef, double noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3pgo11PerlinNoise11PerlinNoise10gradient2DEidd(ptr noundef nonnull align 8 dereferenceable(2496), i32 noundef, double noundef, double noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN3pgo11PerlinNoise11PerlinNoise7noise2DEPd(ptr noundef nonnull align 8 dereferenceable(2496) %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 align 2 {
  %3 = load double, ptr %1, align 8, !tbaa !5
  %4 = fcmp ogt double %3, 0.000000e+00
  %5 = fadd double %3, -1.000000e+00
  %.sroa.025.0.in = select i1 %4, double %3, double %5
  %.sroa.025.0 = fptosi double %.sroa.025.0.in to i32
  %6 = sitofp i32 %.sroa.025.0 to double
  %7 = fsub double %3, %6
  %8 = tail call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise17computeFadeCurvesEd(ptr noundef nonnull align 8 dereferenceable(2496) %0, double noundef %7)
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = fcmp ogt double %10, 0.000000e+00
  %12 = fadd double %10, -1.000000e+00
  %.sroa.6.0.in = select i1 %11, double %10, double %12
  %.sroa.6.0 = fptosi double %.sroa.6.0.in to i32
  %13 = sitofp i32 %.sroa.6.0 to double
  %14 = fsub double %10, %13
  %15 = tail call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise17computeFadeCurvesEd(ptr noundef nonnull align 8 dereferenceable(2496) %0, double noundef %14)
  %16 = tail call noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496) %0, i32 noundef %.sroa.025.0)
  %17 = add nsw i32 %16, %.sroa.6.0
  %18 = add nsw i32 %.sroa.025.0, 1
  %19 = tail call noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496) %0, i32 noundef %18)
  %20 = add nsw i32 %19, %.sroa.6.0
  %21 = tail call noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496) %0, i32 noundef %17)
  %22 = tail call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise10gradient2DEidd(ptr noundef nonnull align 8 dereferenceable(2496) %0, i32 noundef %21, double noundef %7, double noundef %14)
  %23 = tail call noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496) %0, i32 noundef %20)
  %24 = fadd double %7, -1.000000e+00
  %25 = tail call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise10gradient2DEidd(ptr noundef nonnull align 8 dereferenceable(2496) %0, i32 noundef %23, double noundef %24, double noundef %14)
  %26 = tail call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise19linearInterpolationEddd(ptr noundef nonnull align 8 dereferenceable(2496) %0, double noundef %8, double noundef %22, double noundef %25)
  %27 = add nsw i32 %17, 1
  %28 = tail call noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496) %0, i32 noundef %27)
  %29 = fadd double %14, -1.000000e+00
  %30 = tail call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise10gradient2DEidd(ptr noundef nonnull align 8 dereferenceable(2496) %0, i32 noundef %28, double noundef %7, double noundef %29)
  %31 = add nsw i32 %20, 1
  %32 = tail call noundef i32 @_ZN3pgo11PerlinNoise11PerlinNoise14getPermutationEi(ptr noundef nonnull align 8 dereferenceable(2496) %0, i32 noundef %31)
  %33 = tail call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise10gradient2DEidd(ptr noundef nonnull align 8 dereferenceable(2496) %0, i32 noundef %32, double noundef %24, double noundef %29)
  %34 = tail call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise19linearInterpolationEddd(ptr noundef nonnull align 8 dereferenceable(2496) %0, double noundef %8, double noundef %30, double noundef %33)
  %35 = tail call noundef double @_ZN3pgo11PerlinNoise11PerlinNoise19linearInterpolationEddd(ptr noundef nonnull align 8 dereferenceable(2496) %0, double noundef %15, double noundef %26, double noundef %34)
  ret double %35
}

attributes #0 = { 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" }

!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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass