; LLVM IR from biroeniko/raytracer :: src/materials/perlin.ll (Z12perlinInterpPA2_A2_4Vec3fff)

; 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.Vec3 = type { [3 x float] }

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_Z12perlinInterpPA2_A2_4Vec3fff(ptr noundef %0, float noundef %1, float noundef %2, float noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca %class.Vec3, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !9
  store float %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %18 = load float, ptr %6, align 4, !tbaa !9
  %19 = load float, ptr %6, align 4, !tbaa !9
  %20 = fmul float %18, %19
  %21 = load float, ptr %6, align 4, !tbaa !9
  %22 = call float @llvm.fmuladd.f32(float -2.000000e+00, float %21, float 3.000000e+00)
  %23 = fmul float %20, %22
  store float %23, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %24 = load float, ptr %7, align 4, !tbaa !9
  %25 = load float, ptr %7, align 4, !tbaa !9
  %26 = fmul float %24, %25
  %27 = load float, ptr %7, align 4, !tbaa !9
  %28 = call float @llvm.fmuladd.f32(float -2.000000e+00, float %27, float 3.000000e+00)
  %29 = fmul float %26, %28
  store float %29, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %30 = load float, ptr %8, align 4, !tbaa !9
  %31 = load float, ptr %8, align 4, !tbaa !9
  %32 = fmul float %30, %31
  %33 = load float, ptr %8, align 4, !tbaa !9
  %34 = call float @llvm.fmuladd.f32(float -2.000000e+00, float %33, float 3.000000e+00)
  %35 = fmul float %32, %34
  store float %35, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store float 0.000000e+00, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %36

36:                                               ; preds = %116, %4
  %37 = load i32, ptr %13, align 4, !tbaa !11
  %38 = icmp slt i32 %37, 2
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %119

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  store i32 0, ptr %15, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %112, %40
  %42 = load i32, ptr %15, align 4, !tbaa !11
  %43 = icmp slt i32 %42, 2
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %115

45:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  store i32 0, ptr %16, align 4, !tbaa !11
  br label %46

46:                                               ; preds = %108, %45
  %47 = load i32, ptr %16, align 4, !tbaa !11
  %48 = icmp slt i32 %47, 2
  br i1 %48, label %50, label %49

49:                                               ; preds = %46
  store i32 8, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  br label %111

50:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 12, ptr %17) #5
  %51 = load float, ptr %6, align 4, !tbaa !9
  %52 = load i32, ptr %13, align 4, !tbaa !11
  %53 = sitofp i32 %52 to float
  %54 = fsub float %51, %53
  %55 = load float, ptr %7, align 4, !tbaa !9
  %56 = load i32, ptr %15, align 4, !tbaa !11
  %57 = sitofp i32 %56 to float
  %58 = fsub float %55, %57
  %59 = load float, ptr %8, align 4, !tbaa !9
  %60 = load i32, ptr %16, align 4, !tbaa !11
  %61 = sitofp i32 %60 to float
  %62 = fsub float %59, %61
  call void @_ZN4Vec3C2Efff(ptr noundef nonnull align 4 dereferenceable(12) %17, float noundef %54, float noundef %58, float noundef %62)
  %63 = load i32, ptr %13, align 4, !tbaa !11
  %64 = sitofp i32 %63 to float
  %65 = load float, ptr %9, align 4, !tbaa !9
  %66 = load i32, ptr %13, align 4, !tbaa !11
  %67 = sub nsw i32 1, %66
  %68 = sitofp i32 %67 to float
  %69 = load float, ptr %9, align 4, !tbaa !9
  %70 = fsub float 1.000000e+00, %69
  %71 = fmul float %68, %70
  %72 = call float @llvm.fmuladd.f32(float %64, float %65, float %71)
  %73 = load i32, ptr %15, align 4, !tbaa !11
  %74 = sitofp i32 %73 to float
  %75 = load float, ptr %10, align 4, !tbaa !9
  %76 = load i32, ptr %15, align 4, !tbaa !11
  %77 = sub nsw i32 1, %76
  %78 = sitofp i32 %77 to float
  %79 = load float, ptr %10, align 4, !tbaa !9
  %80 = fsub float 1.000000e+00, %79
  %81 = fmul float %78, %80
  %82 = call float @llvm.fmuladd.f32(float %74, float %75, float %81)
  %83 = fmul float %72, %82
  %84 = load i32, ptr %16, align 4, !tbaa !11
  %85 = sitofp i32 %84 to float
  %86 = load float, ptr %11, align 4, !tbaa !9
  %87 = load i32, ptr %16, align 4, !tbaa !11
  %88 = sub nsw i32 1, %87
  %89 = sitofp i32 %88 to float
  %90 = load float, ptr %11, align 4, !tbaa !9
  %91 = fsub float 1.000000e+00, %90
  %92 = fmul float %89, %91
  %93 = call float @llvm.fmuladd.f32(float %85, float %86, float %92)
  %94 = fmul float %83, %93
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = load i32, ptr %13, align 4, !tbaa !11
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [2 x [2 x %class.Vec3]], ptr %95, i64 %97
  %99 = load i32, ptr %15, align 4, !tbaa !11
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [2 x [2 x %class.Vec3]], ptr %98, i64 0, i64 %100
  %102 = load i32, ptr %16, align 4, !tbaa !11
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [2 x %class.Vec3], ptr %101, i64 0, i64 %103
  %105 = call noundef float @_Z3dotRK4Vec3S1_(ptr noundef nonnull align 4 dereferenceable(12) %104, ptr noundef nonnull align 4 dereferenceable(12) %17)
  %106 = load float, ptr %12, align 4, !tbaa !9
  %107 = call float @llvm.fmuladd.f32(float %94, float %105, float %106)
  store float %107, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 12, ptr %17) #5
  br label %108

108:                                              ; preds = %50
  %109 = load i32, ptr %16, align 4, !tbaa !11
  %110 = add nsw i32 %109, 1
  store i32 %110, ptr %16, align 4, !tbaa !11
  br label %46, !llvm.loop !13

111:                                              ; preds = %49
  br label %112

112:                                              ; preds = %111
  %113 = load i32, ptr %15, align 4, !tbaa !11
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %15, align 4, !tbaa !11
  br label %41, !llvm.loop !15

115:                                              ; preds = %44
  br label %116

116:                                              ; preds = %115
  %117 = load i32, ptr %13, align 4, !tbaa !11
  %118 = add nsw i32 %117, 1
  store i32 %118, ptr %13, align 4, !tbaa !11
  br label %36, !llvm.loop !16

119:                                              ; preds = %39
  %120 = load float, ptr %12, align 4, !tbaa !9
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret float %120
}

; 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 speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Vec3C2Efff(ptr noundef nonnull align 4 dereferenceable(12), float noundef, float noundef, float noundef) unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_Z3dotRK4Vec3S1_(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12)) #4

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

attributes #0 = { mustprogress 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 = { 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 #4 = { inlinehint 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 #5 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

%class.Vec3 = type { [3 x float] }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_Z12perlinInterpPA2_A2_4Vec3fff(ptr noundef %0, float noundef %1, float noundef %2, float noundef %3) local_unnamed_addr #0 {
.preheader41:
  %4 = alloca %class.Vec3, align 4
  %5 = insertelement <2 x float> poison, float %1, i64 0
  %6 = insertelement <2 x float> %5, float %2, i64 1
  %7 = fmul <2 x float> %6, %6
  %8 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %6, <2 x float> <float -2.000000e+00, float -2.000000e+00>, <2 x float> <float 3.000000e+00, float 3.000000e+00>)
  %9 = fmul float %3, %3
  %10 = tail call float @llvm.fmuladd.f32(float %3, float -2.000000e+00, float 3.000000e+00)
  %11 = fmul float %9, %10
  %12 = fsub float 1.000000e+00, %11
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #5
  call void @_ZN4Vec3C2Efff(ptr noundef nonnull align 4 dereferenceable(12) %4, float noundef %1, float noundef %2, float noundef %3)
  %13 = call float @llvm.fmuladd.f32(float %11, float 0.000000e+00, float %12)
  %14 = call noundef float @_Z3dotRK4Vec3S1_(ptr noundef nonnull align 4 dereferenceable(12) %0, ptr noundef nonnull align 4 dereferenceable(12) %4)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #5
  %15 = fadd float %3, -1.000000e+00
  call void @_ZN4Vec3C2Efff(ptr noundef nonnull align 4 dereferenceable(12) %4, float noundef %1, float noundef %2, float noundef %15)
  %16 = fmul float %12, 0.000000e+00
  %17 = fadd float %11, %16
  %18 = getelementptr inbounds i8, ptr %0, i64 12
  %19 = call noundef float @_Z3dotRK4Vec3S1_(ptr noundef nonnull align 4 dereferenceable(12) %18, ptr noundef nonnull align 4 dereferenceable(12) %4)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #5
  %20 = fadd float %2, -1.000000e+00
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #5
  call void @_ZN4Vec3C2Efff(ptr noundef nonnull align 4 dereferenceable(12) %4, float noundef %1, float noundef %20, float noundef %3)
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = call noundef float @_Z3dotRK4Vec3S1_(ptr noundef nonnull align 4 dereferenceable(12) %21, ptr noundef nonnull align 4 dereferenceable(12) %4)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #5
  call void @_ZN4Vec3C2Efff(ptr noundef nonnull align 4 dereferenceable(12) %4, float noundef %1, float noundef %20, float noundef %15)
  %23 = getelementptr inbounds i8, ptr %0, i64 36
  %24 = call noundef float @_Z3dotRK4Vec3S1_(ptr noundef nonnull align 4 dereferenceable(12) %23, ptr noundef nonnull align 4 dereferenceable(12) %4)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #5
  %25 = fadd float %1, -1.000000e+00
  %26 = fmul <2 x float> %7, %8
  %27 = fsub <2 x float> <float 1.000000e+00, float 1.000000e+00>, %26
  %28 = call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %26, <2 x float> zeroinitializer, <2 x float> %27)
  %29 = extractelement <2 x float> %28, i64 0
  %30 = extractelement <2 x float> %28, i64 1
  %31 = fmul float %29, %30
  %32 = fmul float %31, %13
  %33 = call float @llvm.fmuladd.f32(float %32, float %14, float 0.000000e+00)
  %34 = fmul float %31, %17
  %35 = call float @llvm.fmuladd.f32(float %34, float %19, float %33)
  %36 = fmul <2 x float> %27, zeroinitializer
  %37 = fadd <2 x float> %26, %36
  %38 = extractelement <2 x float> %37, i64 1
  %39 = fmul float %29, %38
  %40 = fmul float %39, %13
  %41 = call float @llvm.fmuladd.f32(float %40, float %22, float %35)
  %42 = fmul float %39, %17
  %43 = call float @llvm.fmuladd.f32(float %42, float %24, float %41)
  %44 = extractelement <2 x float> %37, i64 0
  %45 = fmul float %44, %30
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #5
  call void @_ZN4Vec3C2Efff(ptr noundef nonnull align 4 dereferenceable(12) %4, float noundef %25, float noundef %2, float noundef %3)
  %46 = fmul float %45, %13
  %47 = getelementptr inbounds i8, ptr %0, i64 48
  %48 = call noundef float @_Z3dotRK4Vec3S1_(ptr noundef nonnull align 4 dereferenceable(12) %47, ptr noundef nonnull align 4 dereferenceable(12) %4)
  %49 = call float @llvm.fmuladd.f32(float %46, float %48, float %43)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #5
  call void @_ZN4Vec3C2Efff(ptr noundef nonnull align 4 dereferenceable(12) %4, float noundef %25, float noundef %2, float noundef %15)
  %50 = fmul float %45, %17
  %51 = getelementptr inbounds i8, ptr %0, i64 60
  %52 = call noundef float @_Z3dotRK4Vec3S1_(ptr noundef nonnull align 4 dereferenceable(12) %51, ptr noundef nonnull align 4 dereferenceable(12) %4)
  %53 = call float @llvm.fmuladd.f32(float %50, float %52, float %49)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #5
  %54 = fmul float %44, %38
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #5
  call void @_ZN4Vec3C2Efff(ptr noundef nonnull align 4 dereferenceable(12) %4, float noundef %25, float noundef %20, float noundef %3)
  %55 = fmul float %54, %13
  %56 = getelementptr inbounds i8, ptr %0, i64 72
  %57 = call noundef float @_Z3dotRK4Vec3S1_(ptr noundef nonnull align 4 dereferenceable(12) %56, ptr noundef nonnull align 4 dereferenceable(12) %4)
  %58 = call float @llvm.fmuladd.f32(float %55, float %57, float %53)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #5
  call void @_ZN4Vec3C2Efff(ptr noundef nonnull align 4 dereferenceable(12) %4, float noundef %25, float noundef %20, float noundef %15)
  %59 = fmul float %54, %17
  %60 = getelementptr inbounds i8, ptr %0, i64 84
  %61 = call noundef float @_Z3dotRK4Vec3S1_(ptr noundef nonnull align 4 dereferenceable(12) %60, ptr noundef nonnull align 4 dereferenceable(12) %4)
  %62 = call float @llvm.fmuladd.f32(float %59, float %61, float %58)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #5
  ret float %62
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Vec3C2Efff(ptr noundef nonnull align 4 dereferenceable(12), float noundef, float noundef, float noundef) unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_Z3dotRK4Vec3S1_(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #3

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x float> @llvm.fmuladd.v2f32(<2 x float>, <2 x float>, <2 x float>) #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { inlinehint 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass