; LLVM IR from drohmer/cgp :: library/third_party/src/simplexnoise/simplexnoise1234.ll (Z5grad3iddd)

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

16:                                               ; preds = %4
  %17 = load double, ptr %6, align 8, !tbaa !9
  br label %20

18:                                               ; preds = %4
  %19 = load double, ptr %7, align 8, !tbaa !9
  br label %20

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

24:                                               ; preds = %20
  %25 = load double, ptr %7, align 8, !tbaa !9
  br label %38

26:                                               ; preds = %20
  %27 = load i32, ptr %9, align 4, !tbaa !5
  %28 = icmp eq i32 %27, 12
  br i1 %28, label %32, label %29

29:                                               ; preds = %26
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 14
  br i1 %31, label %32, label %34

32:                                               ; preds = %29, %26
  %33 = load double, ptr %6, align 8, !tbaa !9
  br label %36

34:                                               ; preds = %29
  %35 = load double, ptr %8, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %34, %32
  %37 = phi double [ %33, %32 ], [ %35, %34 ]
  br label %38

38:                                               ; preds = %36, %24
  %39 = phi double [ %25, %24 ], [ %37, %36 ]
  store double %39, ptr %11, align 8, !tbaa !9
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = and i32 %40, 1
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %46

43:                                               ; preds = %38
  %44 = load double, ptr %10, align 8, !tbaa !9
  %45 = fneg double %44
  br label %48

46:                                               ; preds = %38
  %47 = load double, ptr %10, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %46, %43
  %49 = phi double [ %45, %43 ], [ %47, %46 ]
  %50 = load i32, ptr %9, align 4, !tbaa !5
  %51 = and i32 %50, 2
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %48
  %54 = load double, ptr %11, align 8, !tbaa !9
  %55 = fneg double %54
  br label %58

56:                                               ; preds = %48
  %57 = load double, ptr %11, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %56, %53
  %59 = phi double [ %55, %53 ], [ %57, %56 ]
  %60 = fadd double %49, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret double %60
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"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 @_Z5grad3iddd(i32 noundef %0, double noundef %1, double noundef %2, double noundef %3) local_unnamed_addr #0 {
  %5 = and i32 %0, 15
  %6 = icmp ult i32 %5, 4
  br i1 %6, label %10, label %7

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

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

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