; 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_f16 = external dso_local constant [91 x i16], 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 signext i16 @F16_sin(i16 noundef signext %0) #1 {
  %2 = alloca i16, align 2
  %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, 6
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [91 x i16], ptr @trigtab_f16, i64 0, i64 %15
  %17 = load i16, ptr %16, align 2, !tbaa !5
  store i16 %17, ptr %2, align 2
  store i32 1, ptr %5, align 4
  br label %56

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, 6
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [91 x i16], ptr @trigtab_f16, i64 0, i64 %27
  %29 = load i16, ptr %28, align 2, !tbaa !5
  store i16 %29, ptr %2, align 2
  store i32 1, ptr %5, align 4
  br label %56

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 %45

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, 6
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [91 x i16], ptr @trigtab_f16, i64 0, i64 %39
  %41 = load i16, ptr %40, align 2, !tbaa !5
  %42 = sext i16 %41 to i32
  %43 = sub nsw i32 0, %42
  %44 = trunc i32 %43 to i16
  store i16 %44, ptr %2, align 2
  store i32 1, ptr %5, align 4
  br label %56

45:                                               ; preds = %30
  %46 = load i16, ptr %4, align 2, !tbaa !5
  %47 = sext i16 %46 to i32
  %48 = sub nsw i32 23040, %47
  %49 = ashr i32 %48, 6
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [91 x i16], ptr @trigtab_f16, i64 0, i64 %50
  %52 = load i16, ptr %51, align 2, !tbaa !5
  %53 = sext i16 %52 to i32
  %54 = sub nsw i32 0, %53
  %55 = trunc i32 %54 to i16
  store i16 %55, ptr %2, align 2
  store i32 1, ptr %5, align 4
  br label %56

56:                                               ; preds = %45, %34, %22, %11
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #2
  %57 = load i16, ptr %2, align 2
  ret i16 %57
}

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


; 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_f16 = external dso_local local_unnamed_addr constant [91 x i16], 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 signext i16 @F16_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, 6
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [91 x i16], ptr @trigtab_f16, i64 0, i64 %7
  %9 = load i16, ptr %8, align 2, !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, 6
  %15 = zext nneg i32 %14 to i64
  %16 = getelementptr inbounds [91 x i16], ptr @trigtab_f16, i64 0, i64 %15
  %17 = load i16, ptr %16, align 2, !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, 6
  %23 = zext nneg i32 %22 to i64
  %24 = getelementptr inbounds [91 x i16], ptr @trigtab_f16, i64 0, i64 %23
  %25 = load i16, ptr %24, align 2, !tbaa !5
  %26 = sub i16 0, %25
  br label %34

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

34:                                               ; preds = %27, %20, %12, %5
  %.0 = phi i16 [ %9, %5 ], [ %17, %12 ], [ %26, %20 ], [ %33, %27 ]
  ret i16 %.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 = !{!"short", !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