; LLVM IR from Stephane-D/SGDK :: src (maths)

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

@trigtab_f32 = external dso_local constant [361 x i64], align 16

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: alwaysinline nounwind uwtable
declare dso_local signext i16 @F16_normalizeAngle(i16 noundef signext) #1

; Function Attrs: alwaysinline nounwind uwtable
define dso_local i64 @F32_sin(i16 noundef signext %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i16, align 2
  %4 = alloca i16, align 2
  %5 = alloca i32, align 4
  store i16 %0, ptr %3, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #2
  %6 = load i16, ptr %3, align 2, !tbaa !5
  %7 = call signext i16 @F16_normalizeAngle(i16 noundef signext %6)
  store i16 %7, ptr %4, align 2, !tbaa !5
  %8 = load i16, ptr %4, align 2, !tbaa !5
  %9 = sext i16 %8 to i32
  %10 = icmp sle i32 %9, 5760
  br i1 %10, label %11, label %18

11:                                               ; preds = %1
  %12 = load i16, ptr %4, align 2, !tbaa !5
  %13 = sext i16 %12 to i32
  %14 = ashr i32 %13, 4
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [361 x i64], ptr @trigtab_f32, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !9
  store i64 %17, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %52

18:                                               ; preds = %1
  %19 = load i16, ptr %4, align 2, !tbaa !5
  %20 = sext i16 %19 to i32
  %21 = icmp sle i32 %20, 11520
  br i1 %21, label %22, label %30

22:                                               ; preds = %18
  %23 = load i16, ptr %4, align 2, !tbaa !5
  %24 = sext i16 %23 to i32
  %25 = sub nsw i32 11520, %24
  %26 = ashr i32 %25, 4
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [361 x i64], ptr @trigtab_f32, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !9
  store i64 %29, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %52

30:                                               ; preds = %18
  %31 = load i16, ptr %4, align 2, !tbaa !5
  %32 = sext i16 %31 to i32
  %33 = icmp sle i32 %32, 17280
  br i1 %33, label %34, label %43

34:                                               ; preds = %30
  %35 = load i16, ptr %4, align 2, !tbaa !5
  %36 = sext i16 %35 to i32
  %37 = sub nsw i32 %36, 11520
  %38 = ashr i32 %37, 4
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [361 x i64], ptr @trigtab_f32, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = sub nsw i64 0, %41
  store i64 %42, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %52

43:                                               ; preds = %30
  %44 = load i16, ptr %4, align 2, !tbaa !5
  %45 = sext i16 %44 to i32
  %46 = sub nsw i32 23040, %45
  %47 = ashr i32 %46, 4
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [361 x i64], ptr @trigtab_f32, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !9
  %51 = sub nsw i64 0, %50
  store i64 %51, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %52

52:                                               ; preds = %43, %34, %22, %11
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #2
  %53 = load i64, ptr %2, align 8
  ret i64 %53
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 #2 = { 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !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"

@trigtab_f32 = external dso_local local_unnamed_addr constant [361 x i64], align 16

; Function Attrs: alwaysinline nounwind uwtable
declare dso_local signext i16 @F16_normalizeAngle(i16 noundef signext) local_unnamed_addr #0

; Function Attrs: alwaysinline nounwind uwtable
define dso_local i64 @F32_sin(i16 noundef signext %0) local_unnamed_addr #0 {
  %2 = tail call signext i16 @F16_normalizeAngle(i16 noundef signext %0)
  %3 = sext i16 %2 to i32
  %4 = icmp slt i16 %2, 5761
  br i1 %4, label %5, label %10

5:                                                ; preds = %1
  %6 = ashr i32 %3, 4
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [361 x i64], ptr @trigtab_f32, i64 0, i64 %7
  %9 = load i64, ptr %8, align 8, !tbaa !5
  br label %34

10:                                               ; preds = %1
  %11 = icmp ult i16 %2, 11521
  br i1 %11, label %12, label %18

12:                                               ; preds = %10
  %13 = sub nuw nsw i32 11520, %3
  %14 = lshr i32 %13, 4
  %15 = zext nneg i32 %14 to i64
  %16 = getelementptr inbounds [361 x i64], ptr @trigtab_f32, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !5
  br label %34

18:                                               ; preds = %10
  %19 = icmp ult i16 %2, 17281
  br i1 %19, label %20, label %27

20:                                               ; preds = %18
  %21 = add nsw i32 %3, -11520
  %22 = lshr i32 %21, 4
  %23 = zext nneg i32 %22 to i64
  %24 = getelementptr inbounds [361 x i64], ptr @trigtab_f32, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = sub nsw i64 0, %25
  br label %34

27:                                               ; preds = %18
  %28 = sub nsw i32 23040, %3
  %29 = ashr i32 %28, 4
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [361 x i64], ptr @trigtab_f32, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = sub nsw i64 0, %32
  br label %34

34:                                               ; preds = %27, %20, %12, %5
  %.0 = phi i64 [ %9, %5 ], [ %17, %12 ], [ %26, %20 ], [ %33, %27 ]
  ret i64 %.0
}

attributes #0 = { alwaysinline 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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