; LLVM IR from mesbahamin/star-sim :: src (star)

; 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.Star = type { float, float, float, float, float, float, i32 }

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

; Function Attrs: nounwind
declare float @atan2f(float noundef, float noundef) #1

; Function Attrs: nounwind
declare float @hypotf(float noundef, float noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @star_accelerate(ptr noundef, float noundef, float noundef) #2

; Function Attrs: nounwind
declare float @powf(float noundef, float noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @star_attract_to_mass(ptr noundef %0, float noundef %1, float noundef %2, float noundef %3) #2 {
  %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 float, 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) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Star, ptr %14, i32 0, i32 4
  %16 = load float, ptr %15, align 4, !tbaa !11
  %17 = load float, ptr %7, align 4, !tbaa !9
  %18 = fsub float %16, %17
  store float %18, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Star, ptr %19, i32 0, i32 5
  %21 = load float, ptr %20, align 4, !tbaa !14
  %22 = load float, ptr %8, align 4, !tbaa !9
  %23 = fsub float %21, %22
  store float %23, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %24 = load float, ptr %9, align 4, !tbaa !9
  %25 = load float, ptr %10, align 4, !tbaa !9
  %26 = call float @hypotf(float noundef %24, float noundef %25) #3
  store float %26, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %27 = load float, ptr %10, align 4, !tbaa !9
  %28 = load float, ptr %9, align 4, !tbaa !9
  %29 = call float @atan2f(float noundef %27, float noundef %28) #3
  store float %29, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Star, ptr %30, i32 0, i32 2
  %32 = load float, ptr %31, align 4, !tbaa !15
  %33 = load float, ptr %6, align 4, !tbaa !9
  %34 = fmul float %32, %33
  %35 = load float, ptr %11, align 4, !tbaa !9
  %36 = call float @powf(float noundef %35, float noundef 2.000000e+00) #3
  %37 = fdiv float %34, %36
  %38 = fmul float 0x3FB99999A0000000, %37
  store float %38, ptr %13, align 4, !tbaa !9
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load float, ptr %12, align 4, !tbaa !9
  %41 = fpext float %40 to double
  %42 = fsub double %41, 0x3FF921FB54442D18
  %43 = fptrunc double %42 to float
  %44 = load float, ptr %13, align 4, !tbaa !9
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Star, ptr %45, i32 0, i32 2
  %47 = load float, ptr %46, align 4, !tbaa !15
  %48 = fdiv float %44, %47
  call void @star_accelerate(ptr noundef %39, float noundef %43, float noundef %48)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { 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 = !{!"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, !10, i64 16}
!12 = !{!"Star", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !13, i64 24}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 20}
!15 = !{!12, !10, i64 8}


; 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 nofree nounwind willreturn memory(write)
declare float @atan2f(float noundef, float noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare float @hypotf(float noundef, float noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @star_accelerate(ptr noundef, float noundef, float noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @star_attract_to_mass(ptr noundef %0, float noundef %1, float noundef %2, float noundef %3) local_unnamed_addr #2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load float, ptr %5, align 4, !tbaa !5
  %7 = fsub float %6, %2
  %8 = getelementptr inbounds i8, ptr %0, i64 20
  %9 = load float, ptr %8, align 4, !tbaa !11
  %10 = fsub float %9, %3
  %11 = tail call float @hypotf(float noundef %7, float noundef %10) #3
  %12 = tail call float @atan2f(float noundef %10, float noundef %7) #3
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load float, ptr %13, align 4, !tbaa !12
  %15 = fmul float %14, %1
  %square = fmul float %11, %11
  %16 = fdiv float %15, %square
  %17 = fmul float %16, 0x3FB99999A0000000
  %18 = fpext float %12 to double
  %19 = fadd double %18, 0xBFF921FB54442D18
  %20 = fptrunc double %19 to float
  %21 = fdiv float %17, %14
  tail call void @star_accelerate(ptr noundef %0, float noundef %20, float noundef %21)
  ret void
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(write) "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 "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 = { 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, !7, i64 16}
!6 = !{!"Star", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !10, i64 24}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 20}
!12 = !{!6, !7, i64 8}


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