; LLVM IR from ebirenbaum/ParticleSolver :: gpu/src/particlesystem.ll (ZN14ParticleSystem12addParticlesEv)

; 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.float4 = type { float, float, float, float }
%class.ParticleSystem = type <{ i8, [3 x i8], float, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr, %struct.SimParams, %struct.uint3, i32, i32, %"class.std::deque", %"class.std::deque", %"class.std::vector", %"class.std::vector.3", %struct.int3, %struct.int3, i32, [4 x i8] }>
%struct.SimParams = type { %struct.float3, float, float, %struct.uint3, i32, %struct.float3, %struct.float3, i32, i32 }
%struct.float3 = type { float, float, float }
%struct.uint3 = type { i32, i32, i32 }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<float4, std::allocator<float4>>::_Deque_impl" }
%"struct.std::_Deque_base<float4, std::allocator<float4>>::_Deque_impl" = type { %"struct.std::_Deque_base<float4, std::allocator<float4>>::_Deque_impl_data" }
%"struct.std::_Deque_base<float4, std::allocator<float4>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int2, std::allocator<int2>>::_Vector_impl" }
%"struct.std::_Vector_base<int2, std::allocator<int2>>::_Vector_impl" = type { %"struct.std::_Vector_base<int2, std::allocator<int2>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int2, std::allocator<int2>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.3" = type { %"struct.std::_Vector_base.4" }
%"struct.std::_Vector_base.4" = type { %"struct.std::_Vector_base<float4, std::allocator<float4>>::_Vector_impl" }
%"struct.std::_Vector_base<float4, std::allocator<float4>>::_Vector_impl" = type { %"struct.std::_Vector_base<float4, std::allocator<float4>>::_Vector_impl_data" }
%"struct.std::_Vector_base<float4, std::allocator<float4>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.int3 = type { i32, i32, i32 }

; 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) #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 uwtable
define dso_local void @_ZN14ParticleSystem12addParticlesEv(ptr noundef nonnull align 8 dereferenceable(412) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca %struct.float4, align 16
  %5 = alloca %struct.float4, align 16
  %6 = alloca i32, align 4
  %7 = alloca %struct.float4, align 16
  %8 = alloca %struct.float4, align 16
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8
  %10 = getelementptr inbounds %class.ParticleSystem, ptr %9, i32 0, i32 19
  %11 = call noundef zeroext i1 @_ZNKSt5dequeI6float4SaIS0_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80) %10) #5
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  br label %55

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %14 = getelementptr inbounds %class.ParticleSystem, ptr %9, i32 0, i32 19
  %15 = call noundef i64 @_ZNKSt5dequeI6float4SaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(80) %14) #5
  %16 = udiv i64 %15, 2
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %51, %13
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = icmp ult i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %54

23:                                               ; preds = %18
  %24 = getelementptr inbounds %class.ParticleSystem, ptr %9, i32 0, i32 19
  %25 = call noundef nonnull align 16 dereferenceable(16) ptr @_ZNSt5dequeI6float4SaIS0_EE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) %24) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 %25, i64 16, i1 false), !tbaa.struct !11
  %26 = getelementptr inbounds %class.ParticleSystem, ptr %9, i32 0, i32 19
  call void @_ZNSt5dequeI6float4SaIS0_EE9pop_frontEv(ptr noundef nonnull align 8 dereferenceable(80) %26) #5
  %27 = getelementptr inbounds %class.ParticleSystem, ptr %9, i32 0, i32 19
  %28 = call noundef nonnull align 16 dereferenceable(16) ptr @_ZNSt5dequeI6float4SaIS0_EE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) %27) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %5, ptr align 16 %28, i64 16, i1 false), !tbaa.struct !11
  %29 = getelementptr inbounds %class.ParticleSystem, ptr %9, i32 0, i32 19
  call void @_ZNSt5dequeI6float4SaIS0_EE9pop_frontEv(ptr noundef nonnull align 8 dereferenceable(80) %29) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %7, ptr align 16 %4, i64 16, i1 false), !tbaa.struct !11
  %30 = getelementptr inbounds %struct.float4, ptr %5, i32 0, i32 0
  %31 = load float, ptr %30, align 16, !tbaa !14
  %32 = getelementptr inbounds %struct.float4, ptr %5, i32 0, i32 1
  %33 = load float, ptr %32, align 4, !tbaa !16
  %34 = getelementptr inbounds %struct.float4, ptr %5, i32 0, i32 2
  %35 = load float, ptr %34, align 8, !tbaa !17
  %36 = call { <2 x float>, <2 x float> } @_ZL11make_float4ffff(float noundef %31, float noundef %33, float noundef %35, float noundef 0.000000e+00)
  %37 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %8, i32 0, i32 0
  %38 = extractvalue { <2 x float>, <2 x float> } %36, 0
  store <2 x float> %38, ptr %37, align 16
  %39 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %8, i32 0, i32 1
  %40 = extractvalue { <2 x float>, <2 x float> } %36, 1
  store <2 x float> %40, ptr %39, align 8
  %41 = getelementptr inbounds %struct.float4, ptr %5, i32 0, i32 3
  %42 = load float, ptr %41, align 4, !tbaa !18
  %43 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %7, i32 0, i32 0
  %44 = load <2 x float>, ptr %43, align 16
  %45 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %7, i32 0, i32 1
  %46 = load <2 x float>, ptr %45, align 8
  %47 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %8, i32 0, i32 0
  %48 = load <2 x float>, ptr %47, align 16
  %49 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %8, i32 0, i32 1
  %50 = load <2 x float>, ptr %49, align 8
  call void @_ZN14ParticleSystem11addParticleE6float4S0_ffi(ptr noundef nonnull align 8 dereferenceable(412) %9, <2 x float> %44, <2 x float> %46, <2 x float> %48, <2 x float> %50, float noundef %42, float noundef 1.500000e+00, i32 noundef 3)
  br label %51

51:                                               ; preds = %23
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = add i32 %52, 1
  store i32 %53, ptr %6, align 4, !tbaa !9
  br label %18, !llvm.loop !19

54:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %55

55:                                               ; preds = %54, %12
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt5dequeI6float4SaIS0_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt5dequeI6float4SaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(80)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 16 dereferenceable(16) ptr @_ZNSt5dequeI6float4SaIS0_EE5frontEv(ptr noundef nonnull align 8 dereferenceable(80)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt5dequeI6float4SaIS0_EE9pop_frontEv(ptr noundef nonnull align 8 dereferenceable(80)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14ParticleSystem11addParticleE6float4S0_ffi(ptr noundef nonnull align 8 dereferenceable(412), <2 x float>, <2 x float>, <2 x float>, <2 x float>, float noundef, float noundef, i32 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden { <2 x float>, <2 x float> } @_ZL11make_float4ffff(float noundef, float noundef, float noundef, float noundef) #4

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !12, i64 4, i64 4, !12, i64 8, i64 4, !12, i64 12, i64 4, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"_ZTS6float4", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12}
!16 = !{!15, !13, i64 4}
!17 = !{!15, !13, i64 8}
!18 = !{!15, !13, i64 12}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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
define dso_local void @_ZN14ParticleSystem12addParticlesEv(ptr noundef nonnull align 8 dereferenceable(412) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 176
  %3 = tail call noundef zeroext i1 @_ZNKSt5dequeI6float4SaIS0_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80) %2) #3
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %1
  %5 = tail call noundef i64 @_ZNKSt5dequeI6float4SaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(80) %2) #3
  %6 = lshr i64 %5, 1
  %7 = trunc i64 %6 to i32
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.08 = phi i32 [ %13, %.lr.ph ], [ 0, %4 ]
  %8 = tail call noundef nonnull align 16 dereferenceable(16) ptr @_ZNSt5dequeI6float4SaIS0_EE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) %2) #3
  %.sroa.05.0.copyload = load <2 x float>, ptr %8, align 16
  %.sroa.46.0..sroa_idx = getelementptr inbounds i8, ptr %8, i64 8
  %.sroa.46.0.copyload = load <2 x float>, ptr %.sroa.46.0..sroa_idx, align 8
  tail call void @_ZNSt5dequeI6float4SaIS0_EE9pop_frontEv(ptr noundef nonnull align 8 dereferenceable(80) %2) #3
  %9 = tail call noundef nonnull align 16 dereferenceable(16) ptr @_ZNSt5dequeI6float4SaIS0_EE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) %2) #3
  %.sroa.04.0.copyload = load float, ptr %9, align 16, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %9, i64 4
  %.sroa.4.0.copyload = load float, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %9, i64 8
  %.sroa.5.0.copyload = load float, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !5
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %9, i64 12
  %.sroa.6.0.copyload = load float, ptr %.sroa.6.0..sroa_idx, align 4, !tbaa !5
  tail call void @_ZNSt5dequeI6float4SaIS0_EE9pop_frontEv(ptr noundef nonnull align 8 dereferenceable(80) %2) #3
  %10 = tail call { <2 x float>, <2 x float> } @_ZL11make_float4ffff(float noundef %.sroa.04.0.copyload, float noundef %.sroa.4.0.copyload, float noundef %.sroa.5.0.copyload, float noundef 0.000000e+00)
  %11 = extractvalue { <2 x float>, <2 x float> } %10, 0
  %12 = extractvalue { <2 x float>, <2 x float> } %10, 1
  tail call void @_ZN14ParticleSystem11addParticleE6float4S0_ffi(ptr noundef nonnull align 8 dereferenceable(412) %0, <2 x float> %.sroa.05.0.copyload, <2 x float> %.sroa.46.0.copyload, <2 x float> %11, <2 x float> %12, float noundef %.sroa.6.0.copyload, float noundef 1.500000e+00, i32 noundef 3)
  %13 = add nuw i32 %.08, 1
  %exitcond.not = icmp eq i32 %13, %7
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph, %4, %1
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt5dequeI6float4SaIS0_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt5dequeI6float4SaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 16 dereferenceable(16) ptr @_ZNSt5dequeI6float4SaIS0_EE5frontEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt5dequeI6float4SaIS0_EE9pop_frontEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14ParticleSystem11addParticleE6float4S0_ffi(ptr noundef nonnull align 8 dereferenceable(412), <2 x float>, <2 x float>, <2 x float>, <2 x float>, float noundef, float noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden { <2 x float>, <2 x float> } @_ZL11make_float4ffff(float noundef, float noundef, float noundef, float noundef) 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 = { 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 = { 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 #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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass