; LLVM IR from ZJU-FAST-Lab/GCOPTER :: map_gen/mockamap/src/perlinnoise.ll (ZN11PerlinNoise4gradEiddd)

; 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
define dso_local noundef double @_ZN11PerlinNoise4gradEiddd(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, double noundef %2, double noundef %3, double noundef %4) #1 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store double %2, ptr %8, align 8, !tbaa !11
  store double %3, ptr %9, align 8, !tbaa !11
  store double %4, ptr %10, align 8, !tbaa !11
  %14 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = and i32 %15, 15
  store i32 %16, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %17 = load i32, ptr %11, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 8
  br i1 %18, label %19, label %21

19:                                               ; preds = %5
  %20 = load double, ptr %8, align 8, !tbaa !11
  br label %23

21:                                               ; preds = %5
  %22 = load double, ptr %9, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %21, %19
  %24 = phi double [ %20, %19 ], [ %22, %21 ]
  store double %24, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %25 = load i32, ptr %11, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 4
  br i1 %26, label %27, label %29

27:                                               ; preds = %23
  %28 = load double, ptr %9, align 8, !tbaa !11
  br label %41

29:                                               ; preds = %23
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 12
  br i1 %31, label %35, label %32

32:                                               ; preds = %29
  %33 = load i32, ptr %11, align 4, !tbaa !9
  %34 = icmp eq i32 %33, 14
  br i1 %34, label %35, label %37

35:                                               ; preds = %32, %29
  %36 = load double, ptr %8, align 8, !tbaa !11
  br label %39

37:                                               ; preds = %32
  %38 = load double, ptr %10, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %37, %35
  %40 = phi double [ %36, %35 ], [ %38, %37 ]
  br label %41

41:                                               ; preds = %39, %27
  %42 = phi double [ %28, %27 ], [ %40, %39 ]
  store double %42, ptr %13, align 8, !tbaa !11
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = and i32 %43, 1
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %48

46:                                               ; preds = %41
  %47 = load double, ptr %12, align 8, !tbaa !11
  br label %51

48:                                               ; preds = %41
  %49 = load double, ptr %12, align 8, !tbaa !11
  %50 = fneg double %49
  br label %51

51:                                               ; preds = %48, %46
  %52 = phi double [ %47, %46 ], [ %50, %48 ]
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = and i32 %53, 2
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %58

56:                                               ; preds = %51
  %57 = load double, ptr %13, align 8, !tbaa !11
  br label %61

58:                                               ; preds = %51
  %59 = load double, ptr %13, align 8, !tbaa !11
  %60 = fneg double %59
  br label %61

61:                                               ; preds = %58, %56
  %62 = phi double [ %57, %56 ], [ %60, %58 ]
  %63 = fadd double %52, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret double %63
}

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}


; 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 nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef double @_ZN11PerlinNoise4gradEiddd(ptr nocapture noundef nonnull readnone align 8 dereferenceable(24) %0, i32 noundef %1, double noundef %2, double noundef %3, double noundef %4) local_unnamed_addr #0 align 2 {
  %6 = and i32 %1, 15
  %7 = icmp ult i32 %6, 4
  br i1 %7, label %11, label %8

8:                                                ; preds = %5
  %9 = and i32 %1, 13
  %or.cond = icmp eq i32 %9, 12
  %10 = select i1 %or.cond, double %2, double %4
  br label %11

11:                                               ; preds = %5, %8
  %12 = phi double [ %10, %8 ], [ %3, %5 ]
  %13 = icmp ult i32 %6, 8
  %14 = select i1 %13, double %2, double %3
  %15 = insertelement <2 x i32> poison, i32 %1, i64 0
  %16 = shufflevector <2 x i32> %15, <2 x i32> poison, <2 x i32> zeroinitializer
  %17 = and <2 x i32> %16, <i32 1, i32 2>
  %18 = icmp eq <2 x i32> %17, zeroinitializer
  %19 = insertelement <2 x double> poison, double %14, i64 0
  %20 = insertelement <2 x double> %19, double %12, i64 1
  %21 = fneg <2 x double> %20
  %22 = select <2 x i1> %18, <2 x double> %20, <2 x double> %21
  %shift = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %23 = fadd <2 x double> %22, %shift
  %24 = extractelement <2 x double> %23, i64 0
  ret double %24
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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)"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,VectorCombinePass