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

; Function Attrs: nounwind uwtable
define dso_local ptr @vec2d_add(float noundef %0, float noundef %1, float noundef %2, float noundef %3) #0 {
  %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
  %10 = alloca float, align 4
  %11 = alloca ptr, align 8
  store float %0, ptr %5, align 4, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !5
  store float %2, ptr %7, align 4, !tbaa !5
  store float %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %12 = load float, ptr %5, align 4, !tbaa !5
  %13 = call float @sinf(float noundef %12) #5
  %14 = load float, ptr %6, align 4, !tbaa !5
  %15 = load float, ptr %7, align 4, !tbaa !5
  %16 = call float @sinf(float noundef %15) #5
  %17 = load float, ptr %8, align 4, !tbaa !5
  %18 = fmul float %16, %17
  %19 = call float @llvm.fmuladd.f32(float %13, float %14, float %18)
  store float %19, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %20 = load float, ptr %5, align 4, !tbaa !5
  %21 = call float @cosf(float noundef %20) #5
  %22 = load float, ptr %6, align 4, !tbaa !5
  %23 = load float, ptr %7, align 4, !tbaa !5
  %24 = call float @cosf(float noundef %23) #5
  %25 = load float, ptr %8, align 4, !tbaa !5
  %26 = fmul float %24, %25
  %27 = call float @llvm.fmuladd.f32(float %21, float %22, float %26)
  store float %27, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %28 = call noalias ptr @malloc(i64 noundef 8) #6
  store ptr %28, ptr %11, align 8, !tbaa !9
  %29 = load float, ptr %10, align 4, !tbaa !5
  %30 = load float, ptr %9, align 4, !tbaa !5
  %31 = call float @atan2f(float noundef %29, float noundef %30) #5
  %32 = fpext float %31 to double
  %33 = fsub double 0x3FF921FB54442D18, %32
  %34 = fptrunc double %33 to float
  %35 = load ptr, ptr %11, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.Vec2d, ptr %35, i32 0, i32 0
  store float %34, ptr %36, align 4, !tbaa !11
  %37 = load float, ptr %9, align 4, !tbaa !5
  %38 = load float, ptr %10, align 4, !tbaa !5
  %39 = call float @hypotf(float noundef %37, float noundef %38) #5
  %40 = load ptr, ptr %11, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.Vec2d, ptr %40, i32 0, i32 1
  store float %39, ptr %41, align 4, !tbaa !13
  %42 = load ptr, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret ptr %42
}

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

; Function Attrs: nounwind
declare float @sinf(float noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

; Function Attrs: nounwind
declare float @cosf(float noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

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

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

; 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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind allocsize(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 }
attributes #6 = { nounwind allocsize(0) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"Vec2d", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 4}


; 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
define dso_local noalias noundef ptr @vec2d_add(float noundef %0, float noundef %1, float noundef %2, float noundef %3) local_unnamed_addr #0 {
  %5 = tail call float @sinf(float noundef %0) #5
  %6 = tail call float @sinf(float noundef %2) #5
  %7 = fmul float %6, %3
  %8 = tail call float @llvm.fmuladd.f32(float %5, float %1, float %7)
  %9 = tail call float @cosf(float noundef %0) #5
  %10 = tail call float @cosf(float noundef %2) #5
  %11 = fmul float %10, %3
  %12 = tail call float @llvm.fmuladd.f32(float %9, float %1, float %11)
  %13 = tail call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8) #6
  %14 = tail call float @atan2f(float noundef %12, float noundef %8) #5
  %15 = fpext float %14 to double
  %16 = fsub double 0x3FF921FB54442D18, %15
  %17 = fptrunc double %16 to float
  store float %17, ptr %13, align 4, !tbaa !5
  %18 = tail call float @hypotf(float noundef %8, float noundef %12) #5
  %19 = getelementptr inbounds i8, ptr %13, i64 4
  store float %18, ptr %19, align 4, !tbaa !10
  ret ptr %13
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @sinf(float noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @cosf(float noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @atan2f(float noundef, float noundef) local_unnamed_addr #1

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

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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 "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 }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"Vec2d", !7, i64 0, !7, i64 4}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}


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