; LLVM IR from Firmament-Autopilot/FMT-Firmware :: target/pixhawk/fmt-io/libc/minilibc (math)

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

@sin_off_tbl = external hidden global [4 x double], align 16
@sin_sign_tbl = external hidden global [4 x double], align 16

; Function Attrs: nounwind uwtable
define dso_local double @sin(double noundef %0) #0 {
  %2 = alloca double, align 8
  %3 = alloca i32, align 4
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  store double %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %6 = load double, ptr %2, align 8, !tbaa !5
  %7 = fmul double %6, 0x3FE45F306DC9C883
  %8 = fptosi double %7 to i32
  store i32 %8, ptr %3, align 4, !tbaa !9
  %9 = load double, ptr %2, align 8, !tbaa !5
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = sitofp i32 %10 to double
  %12 = fneg double %11
  %13 = call double @llvm.fmuladd.f64(double %12, double 0x3FF921FB54442D18, double %9)
  store double %13, ptr %2, align 8, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = sub nsw i32 %14, 1
  %16 = and i32 %15, 3
  store i32 %16, ptr %3, align 4, !tbaa !9
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [4 x double], ptr @sin_off_tbl, i64 0, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = load double, ptr %2, align 8, !tbaa !5
  %22 = fadd double %21, %20
  store double %22, ptr %2, align 8, !tbaa !5
  %23 = load double, ptr %2, align 8, !tbaa !5
  %24 = load double, ptr %2, align 8, !tbaa !5
  %25 = fmul double %23, %24
  %26 = fneg double %25
  store double %26, ptr %4, align 8, !tbaa !5
  store double 0.000000e+00, ptr %5, align 8, !tbaa !5
  %27 = load double, ptr %5, align 8, !tbaa !5
  %28 = fadd double %27, 0x3CA6827863B97D97
  store double %28, ptr %5, align 8, !tbaa !5
  %29 = load double, ptr %4, align 8, !tbaa !5
  %30 = load double, ptr %5, align 8, !tbaa !5
  %31 = fmul double %30, %29
  store double %31, ptr %5, align 8, !tbaa !5
  %32 = load double, ptr %5, align 8, !tbaa !5
  %33 = fadd double %32, 0x3D2AE7F3E733B81F
  store double %33, ptr %5, align 8, !tbaa !5
  %34 = load double, ptr %4, align 8, !tbaa !5
  %35 = load double, ptr %5, align 8, !tbaa !5
  %36 = fmul double %35, %34
  store double %36, ptr %5, align 8, !tbaa !5
  %37 = load double, ptr %5, align 8, !tbaa !5
  %38 = fadd double %37, 0x3DA93974A8C07C9D
  store double %38, ptr %5, align 8, !tbaa !5
  %39 = load double, ptr %4, align 8, !tbaa !5
  %40 = load double, ptr %5, align 8, !tbaa !5
  %41 = fmul double %40, %39
  store double %41, ptr %5, align 8, !tbaa !5
  %42 = load double, ptr %5, align 8, !tbaa !5
  %43 = fadd double %42, 0x3E21EED8EFF8D898
  store double %43, ptr %5, align 8, !tbaa !5
  %44 = load double, ptr %4, align 8, !tbaa !5
  %45 = load double, ptr %5, align 8, !tbaa !5
  %46 = fmul double %45, %44
  store double %46, ptr %5, align 8, !tbaa !5
  %47 = load double, ptr %5, align 8, !tbaa !5
  %48 = fadd double %47, 0x3E927E4FB7789F5C
  store double %48, ptr %5, align 8, !tbaa !5
  %49 = load double, ptr %4, align 8, !tbaa !5
  %50 = load double, ptr %5, align 8, !tbaa !5
  %51 = fmul double %50, %49
  store double %51, ptr %5, align 8, !tbaa !5
  %52 = load double, ptr %5, align 8, !tbaa !5
  %53 = fadd double %52, 0x3EFA01A01A01A01A
  store double %53, ptr %5, align 8, !tbaa !5
  %54 = load double, ptr %4, align 8, !tbaa !5
  %55 = load double, ptr %5, align 8, !tbaa !5
  %56 = fmul double %55, %54
  store double %56, ptr %5, align 8, !tbaa !5
  %57 = load double, ptr %5, align 8, !tbaa !5
  %58 = fadd double %57, 0x3F56C16C16C16C17
  store double %58, ptr %5, align 8, !tbaa !5
  %59 = load double, ptr %4, align 8, !tbaa !5
  %60 = load double, ptr %5, align 8, !tbaa !5
  %61 = fmul double %60, %59
  store double %61, ptr %5, align 8, !tbaa !5
  %62 = load double, ptr %5, align 8, !tbaa !5
  %63 = fadd double %62, 0x3FA5555555555555
  store double %63, ptr %5, align 8, !tbaa !5
  %64 = load double, ptr %4, align 8, !tbaa !5
  %65 = load double, ptr %5, align 8, !tbaa !5
  %66 = fmul double %65, %64
  store double %66, ptr %5, align 8, !tbaa !5
  %67 = load double, ptr %5, align 8, !tbaa !5
  %68 = fadd double %67, 5.000000e-01
  store double %68, ptr %5, align 8, !tbaa !5
  %69 = load double, ptr %4, align 8, !tbaa !5
  %70 = load double, ptr %5, align 8, !tbaa !5
  %71 = fmul double %70, %69
  store double %71, ptr %5, align 8, !tbaa !5
  %72 = load double, ptr %5, align 8, !tbaa !5
  %73 = fadd double %72, 1.000000e+00
  store double %73, ptr %5, align 8, !tbaa !5
  %74 = load i32, ptr %3, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [4 x double], ptr @sin_sign_tbl, i64 0, i64 %75
  %77 = load double, ptr %76, align 8, !tbaa !5
  %78 = load double, ptr %5, align 8, !tbaa !5
  %79 = fmul double %78, %77
  store double %79, ptr %5, align 8, !tbaa !5
  %80 = load double, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret double %80
}

; 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 nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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"

@sin_off_tbl = external hidden local_unnamed_addr global [4 x double], align 16
@sin_sign_tbl = external hidden local_unnamed_addr global [4 x double], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local double @sin(double noundef %0) local_unnamed_addr #0 {
  %2 = fmul double %0, 0x3FE45F306DC9C883
  %3 = fptosi double %2 to i32
  %4 = sitofp i32 %3 to double
  %5 = fneg double %4
  %6 = tail call double @llvm.fmuladd.f64(double %5, double 0x3FF921FB54442D18, double %0)
  %7 = add i32 %3, 3
  %8 = and i32 %7, 3
  %9 = zext nneg i32 %8 to i64
  %10 = getelementptr inbounds [4 x double], ptr @sin_off_tbl, i64 0, i64 %9
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = fadd double %6, %11
  %13 = fneg double %12
  %14 = fmul double %12, %13
  %15 = fmul double %14, 0x3CA6827863B97D97
  %16 = fadd double %15, 0x3D2AE7F3E733B81F
  %17 = fmul double %14, %16
  %18 = fadd double %17, 0x3DA93974A8C07C9D
  %19 = fmul double %14, %18
  %20 = fadd double %19, 0x3E21EED8EFF8D898
  %21 = fmul double %14, %20
  %22 = fadd double %21, 0x3E927E4FB7789F5C
  %23 = fmul double %14, %22
  %24 = fadd double %23, 0x3EFA01A01A01A01A
  %25 = fmul double %14, %24
  %26 = fadd double %25, 0x3F56C16C16C16C17
  %27 = fmul double %14, %26
  %28 = fadd double %27, 0x3FA5555555555555
  %29 = fmul double %14, %28
  %30 = fadd double %29, 5.000000e-01
  %31 = fmul double %14, %30
  %32 = fadd double %31, 1.000000e+00
  %33 = getelementptr inbounds [4 x double], ptr @sin_sign_tbl, i64 0, i64 %9
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = fmul double %34, %32
  ret double %35
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: 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" }
attributes #1 = { mustprogress 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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