; LLVM IR from Sonryle/JoePhys :: JoePhys/src/Particle.ll (ZN8Particle9ApplyDragEf)

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

%struct.vec2 = type { float, float }
%struct.Particle = type { i8, %struct.vec2, %struct.vec2, float, float, float, %struct.vec2, [2 x %struct.vec2] }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8Particle10AccelerateE4vec2(ptr noundef nonnull align 4 dereferenceable(56), <2 x float>) #0 align 2

; 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) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8Particle9ApplyDragEf(ptr noundef nonnull align 4 dereferenceable(56) %0, float noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca %struct.vec2, align 4
  %6 = alloca float, align 4
  %7 = alloca %struct.vec2, align 4
  %8 = alloca float, align 4
  %9 = alloca %struct.vec2, align 4
  %10 = alloca %struct.vec2, align 4
  %11 = alloca %struct.vec2, align 4
  %12 = alloca %struct.vec2, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !9
  %13 = load ptr, ptr %3, align 8
  %14 = getelementptr inbounds %struct.Particle, ptr %13, i32 0, i32 0
  %15 = load i8, ptr %14, align 4, !tbaa !11, !range !15, !noundef !16
  %16 = trunc i8 %15 to i1
  br i1 %16, label %22, label %17

17:                                               ; preds = %2
  %18 = getelementptr inbounds %struct.Particle, ptr %13, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 %18, i64 8, i1 false), !tbaa.struct !17
  %19 = load <2 x float>, ptr %5, align 4
  %20 = call noundef float @_Z6length4vec2(<2 x float> %19)
  %21 = fcmp olt float %20, 0x3F1A36E2E0000000
  br i1 %21, label %22, label %23

22:                                               ; preds = %17, %2
  br label %40

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %24 = getelementptr inbounds %struct.Particle, ptr %13, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %24, i64 8, i1 false), !tbaa.struct !17
  %25 = load <2 x float>, ptr %7, align 4
  %26 = call noundef float @_Z6length4vec2(<2 x float> %25)
  store float %26, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %27 = load float, ptr %6, align 4, !tbaa !9
  %28 = load float, ptr %6, align 4, !tbaa !9
  %29 = fmul float %27, %28
  %30 = load float, ptr %4, align 4, !tbaa !9
  %31 = fmul float %29, %30
  store float %31, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %32 = getelementptr inbounds %struct.Particle, ptr %13, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %32, i64 8, i1 false), !tbaa.struct !17
  %33 = load <2 x float>, ptr %11, align 4
  %34 = call <2 x float> @_Z9normalize4vec2(<2 x float> %33)
  store <2 x float> %34, ptr %10, align 4
  %35 = load float, ptr %8, align 4, !tbaa !9
  %36 = fneg float %35
  %37 = load <2 x float>, ptr %10, align 4
  %38 = call <2 x float> @_Zml4vec2f(<2 x float> %37, float noundef %36)
  store <2 x float> %38, ptr %9, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %9, i64 8, i1 false), !tbaa.struct !17
  %39 = load <2 x float>, ptr %12, align 4
  call void @_ZN8Particle10AccelerateE4vec2(ptr noundef nonnull align 4 dereferenceable(56) %13, <2 x float> %39)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %40

40:                                               ; preds = %23, %22
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_Z6length4vec2(<2 x float>) #2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_Zml4vec2f(<2 x float>, float noundef) #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_Z9normalize4vec2(<2 x float>) #4

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

attributes #0 = { mustprogress 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 #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint mustprogress 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 #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, !13, i64 0}
!12 = !{!"_ZTS8Particle", !13, i64 0, !14, i64 4, !14, i64 12, !10, i64 20, !10, i64 24, !10, i64 28, !14, i64 32, !7, i64 40}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTS4vec2", !10, i64 0, !10, i64 4}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{i64 0, i64 4, !9, i64 4, i64 4, !9}


; 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 uwtable
declare dso_local void @_ZN8Particle10AccelerateE4vec2(ptr noundef nonnull align 4 dereferenceable(56), <2 x float>) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8Particle9ApplyDragEf(ptr noundef nonnull align 4 dereferenceable(56) %0, float noundef %1) local_unnamed_addr #0 align 2 {
  %3 = load i8, ptr %0, align 4, !tbaa !5, !range !12, !noundef !13
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %16, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %.sroa.07.0.copyload = load <2 x float>, ptr %6, align 4
  %7 = tail call noundef float @_Z6length4vec2(<2 x float> %.sroa.07.0.copyload)
  %8 = fcmp olt float %7, 0x3F1A36E2E0000000
  br i1 %8, label %16, label %9

9:                                                ; preds = %5
  %.sroa.04.0.copyload = load <2 x float>, ptr %6, align 4
  %10 = tail call noundef float @_Z6length4vec2(<2 x float> %.sroa.04.0.copyload)
  %.sroa.01.0.copyload = load <2 x float>, ptr %6, align 4
  %11 = tail call <2 x float> @_Z9normalize4vec2(<2 x float> %.sroa.01.0.copyload)
  %12 = fneg float %10
  %13 = fmul float %10, %12
  %14 = fmul float %13, %1
  %15 = tail call <2 x float> @_Zml4vec2f(<2 x float> %11, float noundef %14)
  tail call void @_ZN8Particle10AccelerateE4vec2(ptr noundef nonnull align 4 dereferenceable(56) %0, <2 x float> %15)
  br label %16

16:                                               ; preds = %2, %5, %9
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_Z6length4vec2(<2 x float>) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_Zml4vec2f(<2 x float>, float noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_Z9normalize4vec2(<2 x float>) local_unnamed_addr #2

attributes #0 = { mustprogress 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 #1 = { inlinehint mustprogress 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 #2 = { inlinehint mustprogress 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)"}
!5 = !{!6, !7, i64 0}
!6 = !{!"_ZTS8Particle", !7, i64 0, !10, i64 4, !10, i64 12, !11, i64 20, !11, i64 24, !11, i64 28, !10, i64 32, !8, i64 40}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS4vec2", !11, i64 0, !11, i64 4}
!11 = !{!"float", !8, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}


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