; LLVM IR from ashishzero/karma :: src/modules/core/lin_maths.ll (Z25vec2_signed_angle_between4Vec2S_)

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

%union.Vec2 = type { %struct.anon.1 }
%struct.anon.1 = type { float, float }

; 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: mustprogress nounwind uwtable
declare dso_local noundef float @_Z8vec2_dot4Vec2S_(<2 x float>, <2 x float>) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: nounwind
declare float @acosf(float noundef) #4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_Z25vec2_signed_angle_between4Vec2S_(<2 x float> %0, <2 x float> %1) #1 {
  %3 = alloca %union.Vec2, align 4
  %4 = alloca %union.Vec2, align 4
  %5 = alloca float, align 4
  %6 = alloca %union.Vec2, align 4
  %7 = alloca %union.Vec2, align 4
  %8 = alloca %union.Vec2, align 4
  %9 = alloca %union.Vec2, align 4
  %10 = alloca %union.Vec2, align 4
  %11 = alloca %union.Vec2, align 4
  %12 = alloca %union.Vec2, align 4
  %13 = alloca %union.Vec2, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  %16 = getelementptr inbounds %union.Vec2, ptr %3, i32 0, i32 0
  store <2 x float> %0, ptr %16, align 4
  %17 = getelementptr inbounds %union.Vec2, ptr %4, i32 0, i32 0
  store <2 x float> %1, ptr %17, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %3, i64 8, i1 false), !tbaa.struct !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !5
  %18 = getelementptr inbounds %union.Vec2, ptr %6, i32 0, i32 0
  %19 = load <2 x float>, ptr %18, align 4
  %20 = getelementptr inbounds %union.Vec2, ptr %7, i32 0, i32 0
  %21 = load <2 x float>, ptr %20, align 4
  %22 = call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %19, <2 x float> %21)
  %23 = fcmp ogt float -1.000000e+00, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %2
  br label %31

25:                                               ; preds = %2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %3, i64 8, i1 false), !tbaa.struct !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !5
  %26 = getelementptr inbounds %union.Vec2, ptr %8, i32 0, i32 0
  %27 = load <2 x float>, ptr %26, align 4
  %28 = getelementptr inbounds %union.Vec2, ptr %9, i32 0, i32 0
  %29 = load <2 x float>, ptr %28, align 4
  %30 = call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %27, <2 x float> %29)
  br label %31

31:                                               ; preds = %25, %24
  %32 = phi float [ -1.000000e+00, %24 ], [ %30, %25 ]
  %33 = fcmp olt float 1.000000e+00, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %31
  br label %51

35:                                               ; preds = %31
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %3, i64 8, i1 false), !tbaa.struct !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !5
  %36 = getelementptr inbounds %union.Vec2, ptr %10, i32 0, i32 0
  %37 = load <2 x float>, ptr %36, align 4
  %38 = getelementptr inbounds %union.Vec2, ptr %11, i32 0, i32 0
  %39 = load <2 x float>, ptr %38, align 4
  %40 = call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %37, <2 x float> %39)
  %41 = fcmp ogt float -1.000000e+00, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %35
  br label %49

43:                                               ; preds = %35
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %3, i64 8, i1 false), !tbaa.struct !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !5
  %44 = getelementptr inbounds %union.Vec2, ptr %12, i32 0, i32 0
  %45 = load <2 x float>, ptr %44, align 4
  %46 = getelementptr inbounds %union.Vec2, ptr %13, i32 0, i32 0
  %47 = load <2 x float>, ptr %46, align 4
  %48 = call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %45, <2 x float> %47)
  br label %49

49:                                               ; preds = %43, %42
  %50 = phi float [ -1.000000e+00, %42 ], [ %48, %43 ]
  br label %51

51:                                               ; preds = %49, %34
  %52 = phi float [ 1.000000e+00, %34 ], [ %50, %49 ]
  store float %52, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %53 = load float, ptr %5, align 4, !tbaa !9
  %54 = call float @acosf(float noundef %53) #5
  store float %54, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %55 = getelementptr inbounds %struct.anon.1, ptr %3, i32 0, i32 0
  %56 = load float, ptr %55, align 4, !tbaa !6
  %57 = getelementptr inbounds %struct.anon.1, ptr %4, i32 0, i32 1
  %58 = load float, ptr %57, align 4, !tbaa !6
  %59 = getelementptr inbounds %struct.anon.1, ptr %3, i32 0, i32 1
  %60 = load float, ptr %59, align 4, !tbaa !6
  %61 = getelementptr inbounds %struct.anon.1, ptr %4, i32 0, i32 0
  %62 = load float, ptr %61, align 4, !tbaa !6
  %63 = fmul float %60, %62
  %64 = fneg float %63
  %65 = call float @llvm.fmuladd.f32(float %56, float %58, float %64)
  store float %65, ptr %15, align 4, !tbaa !9
  %66 = load float, ptr %15, align 4, !tbaa !9
  %67 = fcmp olt float %66, 0.000000e+00
  br i1 %67, label %68, label %71

68:                                               ; preds = %51
  %69 = load float, ptr %14, align 4, !tbaa !9
  %70 = fneg float %69
  store float %70, ptr %14, align 4, !tbaa !9
  br label %71

71:                                               ; preds = %68, %51
  %72 = load float, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret float %72
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

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


; 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 nounwind uwtable
declare dso_local noundef float @_Z8vec2_dot4Vec2S_(<2 x float>, <2 x float>) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_Z25vec2_signed_angle_between4Vec2S_(<2 x float> %0, <2 x float> %1) local_unnamed_addr #0 {
  %3 = tail call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %0, <2 x float> %1)
  %4 = fcmp olt float %3, -1.000000e+00
  br i1 %4, label %.critedge, label %5

5:                                                ; preds = %2
  %6 = tail call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %0, <2 x float> %1)
  %7 = fcmp ogt float %6, 1.000000e+00
  br i1 %7, label %12, label %.critedge

.critedge:                                        ; preds = %2, %5
  %8 = tail call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %0, <2 x float> %1)
  %9 = fcmp olt float %8, -1.000000e+00
  br i1 %9, label %12, label %10

10:                                               ; preds = %.critedge
  %11 = tail call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %0, <2 x float> %1)
  br label %12

12:                                               ; preds = %10, %.critedge, %5
  %13 = phi float [ 1.000000e+00, %5 ], [ %11, %10 ], [ -1.000000e+00, %.critedge ]
  %14 = tail call float @acosf(float noundef %13) #3
  %.sroa.016.0.vec.extract = extractelement <2 x float> %0, i64 0
  %.sroa.011.4.vec.extract = extractelement <2 x float> %1, i64 1
  %.sroa.016.4.vec.extract = extractelement <2 x float> %0, i64 1
  %.sroa.011.0.vec.extract = extractelement <2 x float> %1, i64 0
  %15 = fneg float %.sroa.016.4.vec.extract
  %16 = fmul float %.sroa.011.0.vec.extract, %15
  %17 = tail call float @llvm.fmuladd.f32(float %.sroa.016.0.vec.extract, float %.sroa.011.4.vec.extract, float %16)
  %18 = fcmp olt float %17, 0.000000e+00
  %19 = fneg float %14
  %.0 = select i1 %18, float %19, float %14
  ret float %.0
}

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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)"}


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