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

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN3pgo11PerlinNoise11PerlinNoise24generatePermutationTableEv(ptr noundef nonnull align 8 dereferenceable(2496) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %18, %1
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 256
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %21

12:                                               ; preds = %8
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = getelementptr inbounds %"class.pgo::PerlinNoise::PerlinNoise", ptr %7, i32 0, i32 0
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [256 x i32], ptr %14, i64 0, i64 %16
  store i32 %13, ptr %17, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %12
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %3, align 4, !tbaa !9
  br label %8, !llvm.loop !11

21:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %48, %21
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 256
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %51

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %27 = getelementptr inbounds %"class.pgo::PerlinNoise::PerlinNoise", ptr %7, i32 0, i32 0
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [256 x i32], ptr %27, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !9
  store i32 %31, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %32 = call i32 @rand() #3
  %33 = srem i32 %32, 256
  store i32 %33, ptr %6, align 4, !tbaa !9
  %34 = getelementptr inbounds %"class.pgo::PerlinNoise::PerlinNoise", ptr %7, i32 0, i32 0
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [256 x i32], ptr %34, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = getelementptr inbounds %"class.pgo::PerlinNoise::PerlinNoise", ptr %7, i32 0, i32 0
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [256 x i32], ptr %39, i64 0, i64 %41
  store i32 %38, ptr %42, align 4, !tbaa !9
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = getelementptr inbounds %"class.pgo::PerlinNoise::PerlinNoise", ptr %7, i32 0, i32 0
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [256 x i32], ptr %44, i64 0, i64 %46
  store i32 %43, ptr %47, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %48

48:                                               ; preds = %26
  %49 = load i32, ptr %4, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %4, align 4, !tbaa !9
  br label %22, !llvm.loop !13

51:                                               ; preds = %25
  ret void
}

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

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

; Function Attrs: nounwind
declare i32 @rand() #2

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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
define dso_local void @_ZN3pgo11PerlinNoise11PerlinNoise24generatePermutationTableEv(ptr nocapture noundef nonnull align 8 dereferenceable(2496) %0) local_unnamed_addr #0 align 2 {
vector.ph:
  %1 = getelementptr inbounds i8, ptr %0, i64 16
  store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, ptr %0, align 8, !tbaa !5
  store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, ptr %1, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  store <4 x i32> <i32 8, i32 9, i32 10, i32 11>, ptr %2, align 8, !tbaa !5
  store <4 x i32> <i32 12, i32 13, i32 14, i32 15>, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = getelementptr inbounds i8, ptr %0, i64 80
  store <4 x i32> <i32 16, i32 17, i32 18, i32 19>, ptr %4, align 8, !tbaa !5
  store <4 x i32> <i32 20, i32 21, i32 22, i32 23>, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 96
  %7 = getelementptr inbounds i8, ptr %0, i64 112
  store <4 x i32> <i32 24, i32 25, i32 26, i32 27>, ptr %6, align 8, !tbaa !5
  store <4 x i32> <i32 28, i32 29, i32 30, i32 31>, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 128
  %9 = getelementptr inbounds i8, ptr %0, i64 144
  store <4 x i32> <i32 32, i32 33, i32 34, i32 35>, ptr %8, align 8, !tbaa !5
  store <4 x i32> <i32 36, i32 37, i32 38, i32 39>, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 160
  %11 = getelementptr inbounds i8, ptr %0, i64 176
  store <4 x i32> <i32 40, i32 41, i32 42, i32 43>, ptr %10, align 8, !tbaa !5
  store <4 x i32> <i32 44, i32 45, i32 46, i32 47>, ptr %11, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 192
  %13 = getelementptr inbounds i8, ptr %0, i64 208
  store <4 x i32> <i32 48, i32 49, i32 50, i32 51>, ptr %12, align 8, !tbaa !5
  store <4 x i32> <i32 52, i32 53, i32 54, i32 55>, ptr %13, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 224
  %15 = getelementptr inbounds i8, ptr %0, i64 240
  store <4 x i32> <i32 56, i32 57, i32 58, i32 59>, ptr %14, align 8, !tbaa !5
  store <4 x i32> <i32 60, i32 61, i32 62, i32 63>, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 256
  %17 = getelementptr inbounds i8, ptr %0, i64 272
  store <4 x i32> <i32 64, i32 65, i32 66, i32 67>, ptr %16, align 8, !tbaa !5
  store <4 x i32> <i32 68, i32 69, i32 70, i32 71>, ptr %17, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 288
  %19 = getelementptr inbounds i8, ptr %0, i64 304
  store <4 x i32> <i32 72, i32 73, i32 74, i32 75>, ptr %18, align 8, !tbaa !5
  store <4 x i32> <i32 76, i32 77, i32 78, i32 79>, ptr %19, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %0, i64 320
  %21 = getelementptr inbounds i8, ptr %0, i64 336
  store <4 x i32> <i32 80, i32 81, i32 82, i32 83>, ptr %20, align 8, !tbaa !5
  store <4 x i32> <i32 84, i32 85, i32 86, i32 87>, ptr %21, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %0, i64 352
  %23 = getelementptr inbounds i8, ptr %0, i64 368
  store <4 x i32> <i32 88, i32 89, i32 90, i32 91>, ptr %22, align 8, !tbaa !5
  store <4 x i32> <i32 92, i32 93, i32 94, i32 95>, ptr %23, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %0, i64 384
  %25 = getelementptr inbounds i8, ptr %0, i64 400
  store <4 x i32> <i32 96, i32 97, i32 98, i32 99>, ptr %24, align 8, !tbaa !5
  store <4 x i32> <i32 100, i32 101, i32 102, i32 103>, ptr %25, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %0, i64 416
  %27 = getelementptr inbounds i8, ptr %0, i64 432
  store <4 x i32> <i32 104, i32 105, i32 106, i32 107>, ptr %26, align 8, !tbaa !5
  store <4 x i32> <i32 108, i32 109, i32 110, i32 111>, ptr %27, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %0, i64 448
  %29 = getelementptr inbounds i8, ptr %0, i64 464
  store <4 x i32> <i32 112, i32 113, i32 114, i32 115>, ptr %28, align 8, !tbaa !5
  store <4 x i32> <i32 116, i32 117, i32 118, i32 119>, ptr %29, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %0, i64 480
  %31 = getelementptr inbounds i8, ptr %0, i64 496
  store <4 x i32> <i32 120, i32 121, i32 122, i32 123>, ptr %30, align 8, !tbaa !5
  store <4 x i32> <i32 124, i32 125, i32 126, i32 127>, ptr %31, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %0, i64 512
  %33 = getelementptr inbounds i8, ptr %0, i64 528
  store <4 x i32> <i32 128, i32 129, i32 130, i32 131>, ptr %32, align 8, !tbaa !5
  store <4 x i32> <i32 132, i32 133, i32 134, i32 135>, ptr %33, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %0, i64 544
  %35 = getelementptr inbounds i8, ptr %0, i64 560
  store <4 x i32> <i32 136, i32 137, i32 138, i32 139>, ptr %34, align 8, !tbaa !5
  store <4 x i32> <i32 140, i32 141, i32 142, i32 143>, ptr %35, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %0, i64 576
  %37 = getelementptr inbounds i8, ptr %0, i64 592
  store <4 x i32> <i32 144, i32 145, i32 146, i32 147>, ptr %36, align 8, !tbaa !5
  store <4 x i32> <i32 148, i32 149, i32 150, i32 151>, ptr %37, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %0, i64 608
  %39 = getelementptr inbounds i8, ptr %0, i64 624
  store <4 x i32> <i32 152, i32 153, i32 154, i32 155>, ptr %38, align 8, !tbaa !5
  store <4 x i32> <i32 156, i32 157, i32 158, i32 159>, ptr %39, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %0, i64 640
  %41 = getelementptr inbounds i8, ptr %0, i64 656
  store <4 x i32> <i32 160, i32 161, i32 162, i32 163>, ptr %40, align 8, !tbaa !5
  store <4 x i32> <i32 164, i32 165, i32 166, i32 167>, ptr %41, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %0, i64 672
  %43 = getelementptr inbounds i8, ptr %0, i64 688
  store <4 x i32> <i32 168, i32 169, i32 170, i32 171>, ptr %42, align 8, !tbaa !5
  store <4 x i32> <i32 172, i32 173, i32 174, i32 175>, ptr %43, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %0, i64 704
  %45 = getelementptr inbounds i8, ptr %0, i64 720
  store <4 x i32> <i32 176, i32 177, i32 178, i32 179>, ptr %44, align 8, !tbaa !5
  store <4 x i32> <i32 180, i32 181, i32 182, i32 183>, ptr %45, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %0, i64 736
  %47 = getelementptr inbounds i8, ptr %0, i64 752
  store <4 x i32> <i32 184, i32 185, i32 186, i32 187>, ptr %46, align 8, !tbaa !5
  store <4 x i32> <i32 188, i32 189, i32 190, i32 191>, ptr %47, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %0, i64 768
  %49 = getelementptr inbounds i8, ptr %0, i64 784
  store <4 x i32> <i32 192, i32 193, i32 194, i32 195>, ptr %48, align 8, !tbaa !5
  store <4 x i32> <i32 196, i32 197, i32 198, i32 199>, ptr %49, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %0, i64 800
  %51 = getelementptr inbounds i8, ptr %0, i64 816
  store <4 x i32> <i32 200, i32 201, i32 202, i32 203>, ptr %50, align 8, !tbaa !5
  store <4 x i32> <i32 204, i32 205, i32 206, i32 207>, ptr %51, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %0, i64 832
  %53 = getelementptr inbounds i8, ptr %0, i64 848
  store <4 x i32> <i32 208, i32 209, i32 210, i32 211>, ptr %52, align 8, !tbaa !5
  store <4 x i32> <i32 212, i32 213, i32 214, i32 215>, ptr %53, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %0, i64 864
  %55 = getelementptr inbounds i8, ptr %0, i64 880
  store <4 x i32> <i32 216, i32 217, i32 218, i32 219>, ptr %54, align 8, !tbaa !5
  store <4 x i32> <i32 220, i32 221, i32 222, i32 223>, ptr %55, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %0, i64 896
  %57 = getelementptr inbounds i8, ptr %0, i64 912
  store <4 x i32> <i32 224, i32 225, i32 226, i32 227>, ptr %56, align 8, !tbaa !5
  store <4 x i32> <i32 228, i32 229, i32 230, i32 231>, ptr %57, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %0, i64 928
  %59 = getelementptr inbounds i8, ptr %0, i64 944
  store <4 x i32> <i32 232, i32 233, i32 234, i32 235>, ptr %58, align 8, !tbaa !5
  store <4 x i32> <i32 236, i32 237, i32 238, i32 239>, ptr %59, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %0, i64 960
  %61 = getelementptr inbounds i8, ptr %0, i64 976
  store <4 x i32> <i32 240, i32 241, i32 242, i32 243>, ptr %60, align 8, !tbaa !5
  store <4 x i32> <i32 244, i32 245, i32 246, i32 247>, ptr %61, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %0, i64 992
  %63 = getelementptr inbounds i8, ptr %0, i64 1008
  store <4 x i32> <i32 248, i32 249, i32 250, i32 251>, ptr %62, align 8, !tbaa !5
  store <4 x i32> <i32 252, i32 253, i32 254, i32 255>, ptr %63, align 8, !tbaa !5
  br label %.preheader

64:                                               ; preds = %.preheader
  ret void

.preheader:                                       ; preds = %vector.ph, %.preheader
  %indvars.iv15 = phi i64 [ %indvars.iv.next16, %.preheader ], [ 0, %vector.ph ]
  %65 = getelementptr inbounds [256 x i32], ptr %0, i64 0, i64 %indvars.iv15
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = tail call i32 @rand() #2
  %68 = srem i32 %67, 256
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [256 x i32], ptr %0, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  store i32 %71, ptr %65, align 4, !tbaa !5
  store i32 %66, ptr %70, align 4, !tbaa !5
  %indvars.iv.next16 = add nuw nsw i64 %indvars.iv15, 1
  %exitcond18.not = icmp eq i64 %indvars.iv.next16, 256
  br i1 %exitcond18.not, label %64, label %.preheader, !llvm.loop !9
}

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #1

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass