; LLVM IR from erincatto/box2d :: src (math_functions)

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #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
define dso_local <2 x float> @b2ComputeCosSin(float noundef %0) #2 {
  %2 = alloca %struct.b2CosSin, align 4
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %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 float, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  store float %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %16 = load float, ptr %3, align 4, !tbaa !5
  %17 = call float @b2UnwindLargeAngle(float noundef %16)
  store float %17, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store float 0x4023BD3CE0000000, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %18 = load float, ptr %4, align 4, !tbaa !5
  %19 = fcmp olt float %18, 0xBFF921FB60000000
  br i1 %19, label %20, label %34

20:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %21 = load float, ptr %4, align 4, !tbaa !5
  %22 = fadd float %21, 0x400921FB60000000
  store float %22, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %23 = load float, ptr %7, align 4, !tbaa !5
  %24 = load float, ptr %7, align 4, !tbaa !5
  %25 = fmul float %23, %24
  store float %25, ptr %8, align 4, !tbaa !5
  %26 = load float, ptr %5, align 4, !tbaa !5
  %27 = load float, ptr %8, align 4, !tbaa !5
  %28 = call float @llvm.fmuladd.f32(float -4.000000e+00, float %27, float %26)
  %29 = fneg float %28
  %30 = load float, ptr %5, align 4, !tbaa !5
  %31 = load float, ptr %8, align 4, !tbaa !5
  %32 = fadd float %30, %31
  %33 = fdiv float %29, %32
  store float %33, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %63

34:                                               ; preds = %1
  %35 = load float, ptr %4, align 4, !tbaa !5
  %36 = fcmp ogt float %35, 0x3FF921FB60000000
  br i1 %36, label %37, label %51

37:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %38 = load float, ptr %4, align 4, !tbaa !5
  %39 = fsub float %38, 0x400921FB60000000
  store float %39, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %40 = load float, ptr %9, align 4, !tbaa !5
  %41 = load float, ptr %9, align 4, !tbaa !5
  %42 = fmul float %40, %41
  store float %42, ptr %10, align 4, !tbaa !5
  %43 = load float, ptr %5, align 4, !tbaa !5
  %44 = load float, ptr %10, align 4, !tbaa !5
  %45 = call float @llvm.fmuladd.f32(float -4.000000e+00, float %44, float %43)
  %46 = fneg float %45
  %47 = load float, ptr %5, align 4, !tbaa !5
  %48 = load float, ptr %10, align 4, !tbaa !5
  %49 = fadd float %47, %48
  %50 = fdiv float %46, %49
  store float %50, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %62

51:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %52 = load float, ptr %4, align 4, !tbaa !5
  %53 = load float, ptr %4, align 4, !tbaa !5
  %54 = fmul float %52, %53
  store float %54, ptr %11, align 4, !tbaa !5
  %55 = load float, ptr %5, align 4, !tbaa !5
  %56 = load float, ptr %11, align 4, !tbaa !5
  %57 = call float @llvm.fmuladd.f32(float -4.000000e+00, float %56, float %55)
  %58 = load float, ptr %5, align 4, !tbaa !5
  %59 = load float, ptr %11, align 4, !tbaa !5
  %60 = fadd float %58, %59
  %61 = fdiv float %57, %60
  store float %61, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %62

62:                                               ; preds = %51, %37
  br label %63

63:                                               ; preds = %62, %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %64 = load float, ptr %4, align 4, !tbaa !5
  %65 = fcmp olt float %64, 0.000000e+00
  br i1 %65, label %66, label %83

66:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %67 = load float, ptr %4, align 4, !tbaa !5
  %68 = fadd float %67, 0x400921FB60000000
  store float %68, ptr %13, align 4, !tbaa !5
  %69 = load float, ptr %13, align 4, !tbaa !5
  %70 = fmul float -1.600000e+01, %69
  %71 = load float, ptr %13, align 4, !tbaa !5
  %72 = fsub float 0x400921FB60000000, %71
  %73 = fmul float %70, %72
  %74 = load float, ptr %5, align 4, !tbaa !5
  %75 = load float, ptr %13, align 4, !tbaa !5
  %76 = fmul float 4.000000e+00, %75
  %77 = load float, ptr %13, align 4, !tbaa !5
  %78 = fsub float 0x400921FB60000000, %77
  %79 = fmul float %76, %78
  %80 = fneg float %79
  %81 = call float @llvm.fmuladd.f32(float 5.000000e+00, float %74, float %80)
  %82 = fdiv float %73, %81
  store float %82, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %98

83:                                               ; preds = %63
  %84 = load float, ptr %4, align 4, !tbaa !5
  %85 = fmul float 1.600000e+01, %84
  %86 = load float, ptr %4, align 4, !tbaa !5
  %87 = fsub float 0x400921FB60000000, %86
  %88 = fmul float %85, %87
  %89 = load float, ptr %5, align 4, !tbaa !5
  %90 = load float, ptr %4, align 4, !tbaa !5
  %91 = fmul float 4.000000e+00, %90
  %92 = load float, ptr %4, align 4, !tbaa !5
  %93 = fsub float 0x400921FB60000000, %92
  %94 = fmul float %91, %93
  %95 = fneg float %94
  %96 = call float @llvm.fmuladd.f32(float 5.000000e+00, float %89, float %95)
  %97 = fdiv float %88, %96
  store float %97, ptr %12, align 4, !tbaa !5
  br label %98

98:                                               ; preds = %83, %66
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %99 = load float, ptr %12, align 4, !tbaa !5
  %100 = load float, ptr %12, align 4, !tbaa !5
  %101 = load float, ptr %6, align 4, !tbaa !5
  %102 = load float, ptr %6, align 4, !tbaa !5
  %103 = fmul float %101, %102
  %104 = call float @llvm.fmuladd.f32(float %99, float %100, float %103)
  %105 = call float @sqrtf(float noundef %104) #5
  store float %105, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %106 = load float, ptr %14, align 4, !tbaa !5
  %107 = fpext float %106 to double
  %108 = fcmp ogt double %107, 0.000000e+00
  br i1 %108, label %109, label %112

109:                                              ; preds = %98
  %110 = load float, ptr %14, align 4, !tbaa !5
  %111 = fdiv float 1.000000e+00, %110
  br label %113

112:                                              ; preds = %98
  br label %113

113:                                              ; preds = %112, %109
  %114 = phi float [ %111, %109 ], [ 0.000000e+00, %112 ]
  store float %114, ptr %15, align 4, !tbaa !5
  %115 = getelementptr inbounds %struct.b2CosSin, ptr %2, i32 0, i32 0
  %116 = load float, ptr %6, align 4, !tbaa !5
  %117 = load float, ptr %15, align 4, !tbaa !5
  %118 = fmul float %116, %117
  store float %118, ptr %115, align 4, !tbaa !9
  %119 = getelementptr inbounds %struct.b2CosSin, ptr %2, i32 0, i32 1
  %120 = load float, ptr %12, align 4, !tbaa !5
  %121 = load float, ptr %15, align 4, !tbaa !5
  %122 = fmul float %120, %121
  store float %122, ptr %119, align 4, !tbaa !11
  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 %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %123 = load <2 x float>, ptr %2, align 4
  ret <2 x float> %123
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @b2UnwindLargeAngle(float noundef) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { inlinehint 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 "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 = !{!6, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"b2CosSin", !6, i64 0, !6, i64 4}
!11 = !{!10, !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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: nounwind uwtable
define dso_local <2 x float> @b2ComputeCosSin(float noundef %0) local_unnamed_addr #1 {
  %2 = tail call float @b2UnwindLargeAngle(float noundef %0)
  %3 = fcmp olt float %2, 0xBFF921FB60000000
  br i1 %3, label %4, label %9

4:                                                ; preds = %1
  %5 = fadd float %2, 0x400921FB60000000
  %6 = fmul float %5, %5
  %7 = tail call float @llvm.fmuladd.f32(float %6, float -4.000000e+00, float 0x4023BD3CE0000000)
  %8 = fneg float %7
  br label %19

9:                                                ; preds = %1
  %10 = fcmp ogt float %2, 0x3FF921FB60000000
  br i1 %10, label %11, label %16

11:                                               ; preds = %9
  %12 = fadd float %2, 0xC00921FB60000000
  %13 = fmul float %12, %12
  %14 = tail call float @llvm.fmuladd.f32(float %13, float -4.000000e+00, float 0x4023BD3CE0000000)
  %15 = fneg float %14
  br label %19

16:                                               ; preds = %9
  %17 = fmul float %2, %2
  %18 = tail call float @llvm.fmuladd.f32(float %17, float -4.000000e+00, float 0x4023BD3CE0000000)
  br label %19

19:                                               ; preds = %11, %16, %4
  %.sink49 = phi float [ %13, %11 ], [ %17, %16 ], [ %6, %4 ]
  %.sink = phi float [ %15, %11 ], [ %18, %16 ], [ %8, %4 ]
  %20 = fadd float %.sink49, 0x4023BD3CE0000000
  %21 = fcmp olt float %2, 0.000000e+00
  %22 = fmul float %2, 1.600000e+01
  %23 = fadd float %2, 0x400921FB60000000
  %24 = fmul float %23, -1.600000e+01
  %.sink58 = select i1 %21, float %23, float %2
  %.sink56 = select i1 %21, float %24, float %22
  %25 = fsub float 0x400921FB60000000, %.sink58
  %26 = fmul float %.sink56, %25
  %27 = fmul float %.sink58, 4.000000e+00
  %28 = fmul float %27, %25
  %29 = fsub float 0x4048AC8C20000000, %28
  %30 = insertelement <2 x float> poison, float %.sink, i64 0
  %31 = insertelement <2 x float> %30, float %26, i64 1
  %32 = insertelement <2 x float> poison, float %20, i64 0
  %33 = insertelement <2 x float> %32, float %29, i64 1
  %34 = fdiv <2 x float> %31, %33
  %35 = fmul <2 x float> %34, %34
  %36 = extractelement <2 x float> %35, i64 0
  %37 = extractelement <2 x float> %34, i64 1
  %38 = tail call float @llvm.fmuladd.f32(float %37, float %37, float %36)
  %sqrt = tail call float @llvm.sqrt.f32(float %38)
  %39 = fcmp ogt float %sqrt, 0.000000e+00
  %40 = fdiv float 1.000000e+00, %sqrt
  %41 = select i1 %39, float %40, float 0.000000e+00
  %42 = insertelement <2 x float> poison, float %41, i64 0
  %43 = shufflevector <2 x float> %42, <2 x float> poison, <2 x i32> zeroinitializer
  %44 = fmul <2 x float> %34, %43
  ret <2 x float> %44
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @b2UnwindLargeAngle(float noundef) local_unnamed_addr #2

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

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

!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: AggressiveInstCombinePass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass