; LLVM IR from robinrodricks/InspiritImage :: Inspirit.Assurf/clib/rpp/rpp_vecmat.ll (cos)

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

; 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 double @llvm.fmuladd.f64(double, double, double) #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 double @_cos(double noundef %0) #2 {
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  store double %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %11 = load double, ptr %2, align 8, !tbaa !5
  %12 = fmul double %11, 0x3FE45F306DC9C883
  store double %12, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %13 = load double, ptr %3, align 8, !tbaa !5
  %14 = fadd double %13, 5.000000e-01
  %15 = load double, ptr %3, align 8, !tbaa !5
  %16 = fcmp olt double %15, 0.000000e+00
  %17 = zext i1 %16 to i64
  %18 = select i1 %16, i32 1, i32 0
  %19 = sitofp i32 %18 to double
  %20 = fsub double %14, %19
  %21 = fptosi double %20 to i32
  store i32 %21, ptr %4, align 4, !tbaa !9
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = sitofp i32 %22 to double
  %24 = load double, ptr %3, align 8, !tbaa !5
  %25 = fsub double %24, %23
  store double %25, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %26 = load double, ptr %3, align 8, !tbaa !5
  %27 = load double, ptr %3, align 8, !tbaa !5
  %28 = fmul double %26, %27
  store double %28, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %29 = load double, ptr %5, align 8, !tbaa !5
  %30 = load double, ptr %5, align 8, !tbaa !5
  %31 = load double, ptr %5, align 8, !tbaa !5
  %32 = call double @llvm.fmuladd.f64(double 0xBF94EAE0E5425D5D, double %31, double 0x3FD03B17AA3CACF1)
  %33 = call double @llvm.fmuladd.f64(double %30, double %32, double 0xBFF3BD3A1904D7C8)
  %34 = call double @llvm.fmuladd.f64(double %29, double %33, double 1.000000e+00)
  store double %34, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %35 = load double, ptr %3, align 8, !tbaa !5
  %36 = load double, ptr %5, align 8, !tbaa !5
  %37 = load double, ptr %5, align 8, !tbaa !5
  %38 = load double, ptr %5, align 8, !tbaa !5
  %39 = call double @llvm.fmuladd.f64(double 0xBF72D7B114F2306F, double %38, double 0x3FB465E3AECDA20E)
  %40 = call double @llvm.fmuladd.f64(double %37, double %39, double 0xBFE4ABBB9CF92A21)
  %41 = call double @llvm.fmuladd.f64(double %36, double %40, double 0x3FF921FB54442D18)
  %42 = fmul double %35, %41
  store double %42, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = and i32 %43, 1
  %45 = sitofp i32 %44 to double
  store double %45, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = and i32 %46, 2
  %48 = sitofp i32 %47 to double
  store double %48, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %49 = load double, ptr %9, align 8, !tbaa !5
  %50 = fsub double 1.000000e+00, %49
  store double %50, ptr %10, align 8, !tbaa !5
  %51 = load double, ptr %8, align 8, !tbaa !5
  %52 = load double, ptr %10, align 8, !tbaa !5
  %53 = fmul double %51, %52
  store double %53, ptr %9, align 8, !tbaa !5
  %54 = load double, ptr %8, align 8, !tbaa !5
  %55 = fsub double 1.000000e+00, %54
  %56 = load double, ptr %10, align 8, !tbaa !5
  %57 = fmul double %55, %56
  store double %57, ptr %8, align 8, !tbaa !5
  %58 = load double, ptr %8, align 8, !tbaa !5
  %59 = load double, ptr %6, align 8, !tbaa !5
  %60 = load double, ptr %9, align 8, !tbaa !5
  %61 = load double, ptr %7, align 8, !tbaa !5
  %62 = fmul double %60, %61
  %63 = fneg double %62
  %64 = call double @llvm.fmuladd.f64(double %58, double %59, double %63)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret double %64
}

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"="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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local double @_cos(double noundef %0) local_unnamed_addr #1 {
  %2 = fmul double %0, 0x3FE45F306DC9C883
  %3 = fadd double %2, 5.000000e-01
  %4 = fcmp olt double %2, 0.000000e+00
  %5 = uitofp i1 %4 to double
  %6 = fsub double %3, %5
  %7 = fptosi double %6 to i32
  %8 = sitofp i32 %7 to double
  %9 = fsub double %2, %8
  %10 = fmul double %9, %9
  %11 = tail call double @llvm.fmuladd.f64(double %10, double 0xBF94EAE0E5425D5D, double 0x3FD03B17AA3CACF1)
  %12 = tail call double @llvm.fmuladd.f64(double %10, double %11, double 0xBFF3BD3A1904D7C8)
  %13 = tail call double @llvm.fmuladd.f64(double %10, double %12, double 1.000000e+00)
  %14 = tail call double @llvm.fmuladd.f64(double %10, double 0xBF72D7B114F2306F, double 0x3FB465E3AECDA20E)
  %15 = tail call double @llvm.fmuladd.f64(double %10, double %14, double 0xBFE4ABBB9CF92A21)
  %16 = tail call double @llvm.fmuladd.f64(double %10, double %15, double 0x3FF921FB54442D18)
  %17 = fmul double %9, %16
  %18 = and i32 %7, 1
  %19 = uitofp nneg i32 %18 to double
  %20 = and i32 %7, 2
  %21 = uitofp nneg i32 %20 to double
  %22 = fsub double 1.000000e+00, %21
  %23 = fsub double 1.000000e+00, %19
  %24 = fmul double %23, %22
  %25 = fneg double %22
  %26 = fmul double %19, %25
  %27 = fmul double %26, %17
  %28 = tail call double @llvm.fmuladd.f64(double %24, double %13, double %27)
  ret double %28
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass