; LLVM IR from erayzesen/QuarkPhysics :: QuarkPhysics/qvector.ll (ZN7QVector13GetVectorSideES_S_f)

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN7QVector22AngleBetweenTwoVectorsES_S_(<2 x float>, <2 x float>) #0 align 2

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; 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 noundef i32 @_ZN7QVector13GetVectorSideES_S_f(<2 x float> %0, <2 x float> %1, float noundef %2) #0 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca %struct.QVector, align 4
  %6 = alloca %struct.QVector, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca %struct.QVector, align 4
  %10 = alloca %struct.QVector, align 4
  %11 = alloca i32, align 4
  store <2 x float> %0, ptr %5, align 4
  store <2 x float> %1, ptr %6, align 4
  store float %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %5, i64 8, i1 false), !tbaa.struct !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !9
  %12 = load <2 x float>, ptr %9, align 4
  %13 = load <2 x float>, ptr %10, align 4
  %14 = call noundef float @_ZN7QVector22AngleBetweenTwoVectorsES_S_(<2 x float> %12, <2 x float> %13)
  store float %14, ptr %8, align 4, !tbaa !5
  %15 = load float, ptr %8, align 4, !tbaa !5
  %16 = call noundef float @_ZSt3absf(float noundef %15)
  %17 = load float, ptr %7, align 4, !tbaa !5
  %18 = fcmp olt float %16, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %65

20:                                               ; preds = %3
  %21 = load float, ptr %8, align 4, !tbaa !5
  %22 = fpext float %21 to double
  %23 = load float, ptr %7, align 4, !tbaa !5
  %24 = fpext float %23 to double
  %25 = fsub double 0x3FF921FB54442D18, %24
  %26 = fcmp ogt double %22, %25
  br i1 %26, label %27, label %35

27:                                               ; preds = %20
  %28 = load float, ptr %8, align 4, !tbaa !5
  %29 = fpext float %28 to double
  %30 = load float, ptr %7, align 4, !tbaa !5
  %31 = fpext float %30 to double
  %32 = fadd double 0x3FF921FB54442D18, %31
  %33 = fcmp olt double %29, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %27
  store i32 1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %65

35:                                               ; preds = %27, %20
  %36 = load float, ptr %8, align 4, !tbaa !5
  %37 = fpext float %36 to double
  %38 = load float, ptr %7, align 4, !tbaa !5
  %39 = fpext float %38 to double
  %40 = fsub double 0x3FF921FB54442D18, %39
  %41 = fneg double %40
  %42 = fcmp olt double %37, %41
  br i1 %42, label %43, label %52

43:                                               ; preds = %35
  %44 = load float, ptr %8, align 4, !tbaa !5
  %45 = fpext float %44 to double
  %46 = load float, ptr %7, align 4, !tbaa !5
  %47 = fpext float %46 to double
  %48 = fadd double 0x3FF921FB54442D18, %47
  %49 = fneg double %48
  %50 = fcmp ogt double %45, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %43
  store i32 3, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %65

52:                                               ; preds = %43, %35
  %53 = load float, ptr %8, align 4, !tbaa !5
  %54 = call noundef float @_ZSt3absf(float noundef %53)
  %55 = fpext float %54 to double
  %56 = load float, ptr %7, align 4, !tbaa !5
  %57 = fpext float %56 to double
  %58 = fsub double 0x400921FB54442D18, %57
  %59 = fcmp ogt double %55, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %52
  store i32 2, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %65

61:                                               ; preds = %52
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  store i32 4, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %65

65:                                               ; preds = %64, %60, %51, %34, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %66 = load i32, ptr %4, align 4
  ret i32 %66
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3absf(float noundef) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = !{i64 0, i64 4, !5, i64 4, i64 4, !5}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 5) i32 @_ZN7QVector13GetVectorSideES_S_f(<2 x float> %0, <2 x float> %1, float noundef %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noundef float @_ZN7QVector22AngleBetweenTwoVectorsES_S_(<2 x float> %0, <2 x float> %1)
  %5 = tail call noundef float @_ZSt3absf(float noundef %4)
  %6 = fcmp olt float %5, %2
  br i1 %6, label %24, label %7

7:                                                ; preds = %3
  %8 = fpext float %4 to double
  %9 = fpext float %2 to double
  %10 = fsub double 0x3FF921FB54442D18, %9
  %11 = fcmp olt double %10, %8
  %12 = fadd double %9, 0x3FF921FB54442D18
  %13 = fcmp ogt double %12, %8
  %or.cond = and i1 %11, %13
  br i1 %or.cond, label %24, label %14

14:                                               ; preds = %7
  %15 = fneg double %10
  %16 = fcmp olt double %8, %15
  %17 = fneg double %12
  %18 = fcmp ogt double %8, %17
  %or.cond19 = and i1 %16, %18
  br i1 %or.cond19, label %24, label %19

19:                                               ; preds = %14
  %20 = tail call noundef float @_ZSt3absf(float noundef %4)
  %21 = fpext float %20 to double
  %22 = fsub double 0x400921FB54442D18, %9
  %23 = fcmp olt double %22, %21
  %. = select i1 %23, i32 2, i32 4
  br label %24

24:                                               ; preds = %14, %19, %7, %3
  %.0 = phi i32 [ 0, %3 ], [ 1, %7 ], [ %., %19 ], [ 3, %14 ]
  ret i32 %.0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3absf(float noundef) local_unnamed_addr #1

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 = { 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" }

!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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass