; 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(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Star, ptr %10, i32 0, i32 4
  %12 = load float, ptr %11, align 4, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Star, ptr %13, i32 0, i32 4
  %15 = load float, ptr %14, align 4, !tbaa !9
  %16 = fsub float %12, %15
  store float %16, ptr %5, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Star, ptr %17, i32 0, i32 5
  %19 = load float, ptr %18, align 4, !tbaa !14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Star, ptr %20, i32 0, i32 5
  %22 = load float, ptr %21, align 4, !tbaa !14
  %23 = fsub float %19, %22
  store float %23, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %24 = load float, ptr %5, align 4, !tbaa !13
  %25 = load float, ptr %6, align 4, !tbaa !13
  %26 = call float @hypotf(float noundef %24, float noundef %25) #3
  store float %26, ptr %7, align 4, !tbaa !13
  %27 = load float, ptr %7, align 4, !tbaa !13
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Star, ptr %28, i32 0, i32 3
  %30 = load float, ptr %29, align 4, !tbaa !15
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Star, ptr %31, i32 0, i32 3
  %33 = load float, ptr %32, align 4, !tbaa !15
  %34 = fadd float %30, %33
  %35 = fcmp ogt float %27, %34
  br i1 %35, label %36, label %71

36:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %37 = load float, ptr %6, align 4, !tbaa !13
  %38 = load float, ptr %5, align 4, !tbaa !13
  %39 = call float @atan2f(float noundef %37, float noundef %38) #3
  store float %39, ptr %8, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Star, ptr %40, i32 0, i32 2
  %42 = load float, ptr %41, align 4, !tbaa !16
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.Star, ptr %43, i32 0, i32 2
  %45 = load float, ptr %44, align 4, !tbaa !16
  %46 = fmul float %42, %45
  %47 = load float, ptr %7, align 4, !tbaa !13
  %48 = call float @powf(float noundef %47, float noundef 2.000000e+00) #3
  %49 = fdiv float %46, %48
  %50 = fmul float 0x3FB99999A0000000, %49
  store float %50, ptr %9, align 4, !tbaa !13
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = load float, ptr %8, align 4, !tbaa !13
  %53 = fpext float %52 to double
  %54 = fsub double %53, 0x3FF921FB54442D18
  %55 = fptrunc double %54 to float
  %56 = load float, ptr %9, align 4, !tbaa !13
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Star, ptr %57, i32 0, i32 2
  %59 = load float, ptr %58, align 4, !tbaa !16
  %60 = fdiv float %56, %59
  call void @star_accelerate(ptr noundef %51, float noundef %55, float noundef %60)
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = load float, ptr %8, align 4, !tbaa !13
  %63 = fpext float %62 to double
  %64 = fadd double %63, 0x3FF921FB54442D18
  %65 = fptrunc double %64 to float
  %66 = load float, ptr %9, align 4, !tbaa !13
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.Star, ptr %67, i32 0, i32 2
  %69 = load float, ptr %68, align 4, !tbaa !16
  %70 = fdiv float %66, %69
  call void @star_accelerate(ptr noundef %61, float noundef %65, float noundef %70)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %71

71:                                               ; preds = %36, %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #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, !11, i64 16}
!10 = !{!"Star", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !12, i64 24}
!11 = !{!"float", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 20}
!15 = !{!10, !11, i64 12}
!16 = !{!10, !11, 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(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load float, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load float, ptr %5, align 4, !tbaa !5
  %7 = fsub float %4, %6
  %8 = getelementptr inbounds i8, ptr %0, i64 20
  %9 = load float, ptr %8, align 4, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %1, i64 20
  %11 = load float, ptr %10, align 4, !tbaa !11
  %12 = fsub float %9, %11
  %13 = tail call float @hypotf(float noundef %7, float noundef %12) #3
  %14 = getelementptr inbounds i8, ptr %0, i64 12
  %15 = load float, ptr %14, align 4, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %1, i64 12
  %17 = load float, ptr %16, align 4, !tbaa !12
  %18 = fadd float %15, %17
  %19 = fcmp ogt float %13, %18
  br i1 %19, label %20, label %37

20:                                               ; preds = %2
  %21 = tail call float @atan2f(float noundef %12, float noundef %7) #3
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = load float, ptr %22, align 4, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %1, i64 8
  %25 = load float, ptr %24, align 4, !tbaa !13
  %26 = fmul float %23, %25
  %square = fmul float %13, %13
  %27 = fdiv float %26, %square
  %28 = fmul float %27, 0x3FB99999A0000000
  %29 = fpext float %21 to double
  %30 = fadd double %29, 0xBFF921FB54442D18
  %31 = fptrunc double %30 to float
  %32 = fdiv float %28, %23
  tail call void @star_accelerate(ptr noundef nonnull %0, float noundef %31, float noundef %32)
  %33 = fadd double %29, 0x3FF921FB54442D18
  %34 = fptrunc double %33 to float
  %35 = load float, ptr %24, align 4, !tbaa !13
  %36 = fdiv float %28, %35
  tail call void @star_accelerate(ptr noundef nonnull %1, float noundef %34, float noundef %36)
  br label %37

37:                                               ; preds = %20, %2
  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 12}
!13 = !{!6, !7, i64 8}


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