; LLVM IR from heroseh/cgm :: cgm (cgm_cubic_bezier_curve_interp_2d)

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

%union.CgmVec2 = type { %struct.anon }
%struct.anon = type { float, float }

; Function Attrs: nounwind uwtable
declare dso_local float @cgm_lerp(float noundef, float noundef, float 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local <2 x float> @cgm_cubic_bezier_curve_interp_2d(ptr noundef %0, float noundef %1) #3 {
  %3 = alloca %union.CgmVec2, align 4
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca [4 x %union.CgmVec2], align 16
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #4
  %9 = getelementptr inbounds [4 x %union.CgmVec2], ptr %6, i64 0, i64 0
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %9, ptr align 4 %10, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 4, ptr %7, align 8, !tbaa !11
  br label %11

11:                                               ; preds = %53, %2
  %12 = load i64, ptr %7, align 8, !tbaa !11
  %13 = icmp ugt i64 %12, 1
  br i1 %13, label %14, label %56

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

15:                                               ; preds = %50, %14
  %16 = load i64, ptr %8, align 8, !tbaa !11
  %17 = load i64, ptr %7, align 8, !tbaa !11
  %18 = sub i64 %17, 1
  %19 = icmp ult i64 %16, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %53

21:                                               ; preds = %15
  %22 = load i64, ptr %8, align 8, !tbaa !11
  %23 = getelementptr inbounds [4 x %union.CgmVec2], ptr %6, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.anon, ptr %23, i32 0, i32 0
  %25 = load float, ptr %24, align 8, !tbaa !13
  %26 = load i64, ptr %8, align 8, !tbaa !11
  %27 = add i64 %26, 1
  %28 = getelementptr inbounds [4 x %union.CgmVec2], ptr %6, i64 0, i64 %27
  %29 = getelementptr inbounds %struct.anon, ptr %28, i32 0, i32 0
  %30 = load float, ptr %29, align 8, !tbaa !13
  %31 = load float, ptr %5, align 4, !tbaa !9
  %32 = call float @cgm_lerp(float noundef %25, float noundef %30, float noundef %31)
  %33 = load i64, ptr %8, align 8, !tbaa !11
  %34 = getelementptr inbounds [4 x %union.CgmVec2], ptr %6, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.anon, ptr %34, i32 0, i32 0
  store float %32, ptr %35, align 8, !tbaa !13
  %36 = load i64, ptr %8, align 8, !tbaa !11
  %37 = getelementptr inbounds [4 x %union.CgmVec2], ptr %6, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.anon, ptr %37, i32 0, i32 1
  %39 = load float, ptr %38, align 4, !tbaa !13
  %40 = load i64, ptr %8, align 8, !tbaa !11
  %41 = add i64 %40, 1
  %42 = getelementptr inbounds [4 x %union.CgmVec2], ptr %6, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.anon, ptr %42, i32 0, i32 1
  %44 = load float, ptr %43, align 4, !tbaa !13
  %45 = load float, ptr %5, align 4, !tbaa !9
  %46 = call float @cgm_lerp(float noundef %39, float noundef %44, float noundef %45)
  %47 = load i64, ptr %8, align 8, !tbaa !11
  %48 = getelementptr inbounds [4 x %union.CgmVec2], ptr %6, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.anon, ptr %48, i32 0, i32 1
  store float %46, ptr %49, align 4, !tbaa !13
  br label %50

50:                                               ; preds = %21
  %51 = load i64, ptr %8, align 8, !tbaa !11
  %52 = add i64 %51, 1
  store i64 %52, ptr %8, align 8, !tbaa !11
  br label %15, !llvm.loop !14

53:                                               ; preds = %20
  %54 = load i64, ptr %7, align 8, !tbaa !11
  %55 = sub i64 %54, 1
  store i64 %55, ptr %7, align 8, !tbaa !11
  br label %11, !llvm.loop !16

56:                                               ; preds = %11
  %57 = getelementptr inbounds [4 x %union.CgmVec2], ptr %6, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 16 %57, i64 8, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #4
  %58 = getelementptr inbounds %union.CgmVec2, ptr %3, i32 0, i32 0
  %59 = load <2 x float>, ptr %58, align 4
  ret <2 x float> %59
}

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

attributes #0 = { 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 nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind uwtable "min-legal-vector-width"="64" "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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = !{i64 0, i64 8, !13}


; 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: nounwind uwtable
declare dso_local float @cgm_lerp(float noundef, float noundef, float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local <2 x float> @cgm_cubic_bezier_curve_interp_2d(ptr nocapture noundef readonly %0, float noundef %1) local_unnamed_addr #1 {
.loopexit.2:
  %.sroa.39.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 28
  %.sroa.39.0.copyload = load float, ptr %.sroa.39.0..sroa_idx, align 4
  %.sroa.38.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 24
  %.sroa.38.0.copyload = load float, ptr %.sroa.38.0..sroa_idx, align 4
  %.sroa.34.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 20
  %.sroa.34.0.copyload = load float, ptr %.sroa.34.0..sroa_idx, align 4
  %.sroa.30.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 16
  %.sroa.30.0.copyload = load float, ptr %.sroa.30.0..sroa_idx, align 4
  %.sroa.23.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 12
  %.sroa.23.0.copyload = load float, ptr %.sroa.23.0..sroa_idx, align 4
  %.sroa.16.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.16.0.copyload = load float, ptr %.sroa.16.0..sroa_idx, align 4
  %.sroa.0.0.copyload29 = load <2 x float>, ptr %0, align 4
  %.sroa.0.0.vec.extract28 = extractelement <2 x float> %.sroa.0.0.copyload29, i64 0
  %2 = tail call float @cgm_lerp(float noundef %.sroa.0.0.vec.extract28, float noundef %.sroa.16.0.copyload, float noundef %1)
  %.sroa.0.4.vec.extract38 = extractelement <2 x float> %.sroa.0.0.copyload29, i64 1
  %3 = tail call float @cgm_lerp(float noundef %.sroa.0.4.vec.extract38, float noundef %.sroa.23.0.copyload, float noundef %1)
  %4 = tail call float @cgm_lerp(float noundef %.sroa.16.0.copyload, float noundef %.sroa.30.0.copyload, float noundef %1)
  %5 = tail call float @cgm_lerp(float noundef %.sroa.23.0.copyload, float noundef %.sroa.34.0.copyload, float noundef %1)
  %6 = tail call float @cgm_lerp(float noundef %.sroa.30.0.copyload, float noundef %.sroa.38.0.copyload, float noundef %1)
  %7 = tail call float @cgm_lerp(float noundef %.sroa.34.0.copyload, float noundef %.sroa.39.0.copyload, float noundef %1)
  %8 = tail call float @cgm_lerp(float noundef %2, float noundef %4, float noundef %1)
  %9 = tail call float @cgm_lerp(float noundef %3, float noundef %5, float noundef %1)
  %10 = tail call float @cgm_lerp(float noundef %4, float noundef %6, float noundef %1)
  %11 = tail call float @cgm_lerp(float noundef %5, float noundef %7, float noundef %1)
  %12 = tail call float @cgm_lerp(float noundef %8, float noundef %10, float noundef %1)
  %13 = tail call float @cgm_lerp(float noundef %9, float noundef %11, float noundef %1)
  %14 = insertelement <2 x float> poison, float %12, i64 0
  %.sroa.0.4.vec.insert = insertelement <2 x float> %14, float %13, i64 1
  ret <2 x float> %.sroa.0.4.vec.insert
}

attributes #0 = { 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 uwtable "min-legal-vector-width"="64" "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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass