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

; 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"

@perm = external dso_local global [512 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z5grad1id(i32 noundef, double noundef) #0

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

13:                                               ; preds = %1
  %14 = load double, ptr %2, align 8, !tbaa !5
  %15 = fptosi double %14 to i32
  br label %20

16:                                               ; preds = %1
  %17 = load double, ptr %2, align 8, !tbaa !5
  %18 = fptosi double %17 to i32
  %19 = sub nsw i32 %18, 1
  br label %20

20:                                               ; preds = %16, %13
  %21 = phi i32 [ %15, %13 ], [ %19, %16 ]
  store i32 %21, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %24 = load double, ptr %2, align 8, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = sitofp i32 %25 to double
  %27 = fsub double %24, %26
  store double %27, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %28 = load double, ptr %5, align 8, !tbaa !5
  %29 = fsub double %28, 1.000000e+00
  store double %29, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %30 = load double, ptr %5, align 8, !tbaa !5
  %31 = load double, ptr %5, align 8, !tbaa !5
  %32 = fneg double %30
  %33 = call double @llvm.fmuladd.f64(double %32, double %31, double 1.000000e+00)
  store double %33, ptr %9, align 8, !tbaa !5
  %34 = load double, ptr %9, align 8, !tbaa !5
  %35 = load double, ptr %9, align 8, !tbaa !5
  %36 = fmul double %35, %34
  store double %36, ptr %9, align 8, !tbaa !5
  %37 = load double, ptr %9, align 8, !tbaa !5
  %38 = load double, ptr %9, align 8, !tbaa !5
  %39 = fmul double %37, %38
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = and i32 %40, 255
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [512 x i8], ptr @perm, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = zext i8 %44 to i32
  %46 = load double, ptr %5, align 8, !tbaa !5
  %47 = call noundef double @_Z5grad1id(i32 noundef %45, double noundef %46)
  %48 = fmul double %39, %47
  store double %48, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %49 = load double, ptr %6, align 8, !tbaa !5
  %50 = load double, ptr %6, align 8, !tbaa !5
  %51 = fneg double %49
  %52 = call double @llvm.fmuladd.f64(double %51, double %50, double 1.000000e+00)
  store double %52, ptr %10, align 8, !tbaa !5
  %53 = load double, ptr %10, align 8, !tbaa !5
  %54 = load double, ptr %10, align 8, !tbaa !5
  %55 = fmul double %54, %53
  store double %55, ptr %10, align 8, !tbaa !5
  %56 = load double, ptr %10, align 8, !tbaa !5
  %57 = load double, ptr %10, align 8, !tbaa !5
  %58 = fmul double %56, %57
  %59 = load i32, ptr %4, align 4, !tbaa !9
  %60 = and i32 %59, 255
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [512 x i8], ptr @perm, i64 0, i64 %61
  %63 = load i8, ptr %62, align 1, !tbaa !11
  %64 = zext i8 %63 to i32
  %65 = load double, ptr %6, align 8, !tbaa !5
  %66 = call noundef double @_Z5grad1id(i32 noundef %64, double noundef %65)
  %67 = fmul double %58, %66
  store double %67, ptr %8, align 8, !tbaa !5
  %68 = load double, ptr %7, align 8, !tbaa !5
  %69 = load double, ptr %8, align 8, !tbaa !5
  %70 = fadd double %68, %69
  %71 = fmul double 2.500000e-01, %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret double %71
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !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"

@perm = external dso_local local_unnamed_addr global [512 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z5grad1id(i32 noundef, double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z7snoise1d(double noundef %0) local_unnamed_addr #0 {
  %2 = fcmp ule double %0, 0.000000e+00
  %3 = fptosi double %0 to i32
  %4 = sext i1 %2 to i32
  %5 = add nsw i32 %4, %3
  %6 = add nsw i32 %5, 1
  %7 = sitofp i32 %5 to double
  %8 = fsub double %0, %7
  %9 = fadd double %8, -1.000000e+00
  %10 = and i32 %5, 255
  %11 = zext nneg i32 %10 to i64
  %12 = getelementptr inbounds [512 x i8], ptr @perm, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = zext i8 %13 to i32
  %15 = tail call noundef double @_Z5grad1id(i32 noundef %14, double noundef %8)
  %16 = and i32 %6, 255
  %17 = zext nneg i32 %16 to i64
  %18 = getelementptr inbounds [512 x i8], ptr @perm, i64 0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = zext i8 %19 to i32
  %21 = tail call noundef double @_Z5grad1id(i32 noundef %20, double noundef %9)
  %22 = insertelement <2 x double> poison, double %8, i64 0
  %23 = insertelement <2 x double> %22, double %9, i64 1
  %24 = fneg <2 x double> %23
  %25 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %24, <2 x double> %23, <2 x double> <double 1.000000e+00, double 1.000000e+00>)
  %26 = fmul <2 x double> %25, %25
  %27 = fmul <2 x double> %26, %26
  %28 = insertelement <2 x double> poison, double %15, i64 0
  %29 = insertelement <2 x double> %28, double %21, i64 1
  %30 = fmul <2 x double> %27, %29
  %shift = shufflevector <2 x double> %30, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %31 = fadd <2 x double> %30, %shift
  %32 = extractelement <2 x double> %31, i64 0
  %33 = fmul double %32, 2.500000e-01
  ret double %33
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass