; LLVM IR from jordan4ibanez/tinyphysicsengine :: old (test)

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

@TPE_sinTable = external hidden constant [128 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @TPE_clamp(i32 noundef, i32 noundef, i32 noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @TPE_asin(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i16, align 2
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = call i32 @TPE_clamp(i32 noundef %9, i32 noundef -512, i32 noundef 512)
  store i32 %10, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #2
  store i8 1, ptr %3, align 1, !tbaa !9
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %13, label %16

13:                                               ; preds = %1
  store i8 -1, ptr %3, align 1, !tbaa !9
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = mul nsw i32 %14, -1
  store i32 %15, ptr %2, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %13, %1
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #2
  store i16 0, ptr %4, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  store i16 127, ptr %5, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #2
  br label %17

17:                                               ; preds = %57, %16
  %18 = load i16, ptr %4, align 2, !tbaa !10
  %19 = sext i16 %18 to i32
  %20 = load i16, ptr %5, align 2, !tbaa !10
  %21 = sext i16 %20 to i32
  %22 = icmp sle i32 %19, %21
  br i1 %22, label %23, label %58

23:                                               ; preds = %17
  %24 = load i16, ptr %4, align 2, !tbaa !10
  %25 = sext i16 %24 to i32
  %26 = load i16, ptr %5, align 2, !tbaa !10
  %27 = sext i16 %26 to i32
  %28 = add nsw i32 %25, %27
  %29 = sdiv i32 %28, 2
  %30 = trunc i32 %29 to i16
  store i16 %30, ptr %6, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %31 = load i16, ptr %6, align 2, !tbaa !10
  %32 = sext i16 %31 to i64
  %33 = getelementptr inbounds [128 x i32], ptr @TPE_sinTable, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  store i32 %34, ptr %7, align 4, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = icmp sgt i32 %35, %36
  br i1 %37, label %38, label %43

38:                                               ; preds = %23
  %39 = load i16, ptr %6, align 2, !tbaa !10
  %40 = sext i16 %39 to i32
  %41 = sub nsw i32 %40, 1
  %42 = trunc i32 %41 to i16
  store i16 %42, ptr %5, align 2, !tbaa !10
  br label %54

43:                                               ; preds = %23
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %47, label %52

47:                                               ; preds = %43
  %48 = load i16, ptr %6, align 2, !tbaa !10
  %49 = sext i16 %48 to i32
  %50 = add nsw i32 %49, 1
  %51 = trunc i32 %50 to i16
  store i16 %51, ptr %4, align 2, !tbaa !10
  br label %53

52:                                               ; preds = %43
  store i32 3, ptr %8, align 4
  br label %55

53:                                               ; preds = %47
  br label %54

54:                                               ; preds = %53, %38
  store i32 0, ptr %8, align 4
  br label %55

55:                                               ; preds = %54, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %56 = load i32, ptr %8, align 4
  switch i32 %56, label %68 [
    i32 0, label %57
    i32 3, label %58
  ]

57:                                               ; preds = %55
  br label %17, !llvm.loop !12

58:                                               ; preds = %55, %17
  %59 = load i16, ptr %6, align 2, !tbaa !10
  %60 = sext i16 %59 to i32
  %61 = mul nsw i32 %60, 1
  %62 = trunc i32 %61 to i16
  store i16 %62, ptr %6, align 2, !tbaa !10
  %63 = load i8, ptr %3, align 1, !tbaa !9
  %64 = sext i8 %63 to i32
  %65 = load i16, ptr %6, align 2, !tbaa !10
  %66 = sext i16 %65 to i32
  %67 = mul nsw i32 %64, %66
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #2
  ret i32 %67

68:                                               ; preds = %55
  unreachable
}

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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

@TPE_sinTable = external hidden local_unnamed_addr constant [128 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @TPE_clamp(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -32768, 32769) i32 @TPE_asin(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @TPE_clamp(i32 noundef %0, i32 noundef -512, i32 noundef 512)
  %spec.select31 = tail call i32 @llvm.abs.i32(i32 %2, i1 true)
  br label %3

3:                                                ; preds = %1, %20
  %.02038 = phi i16 [ 127, %1 ], [ %.2, %20 ]
  %.02237 = phi i16 [ 0, %1 ], [ %.224, %20 ]
  %4 = sext i16 %.02038 to i32
  %5 = sext i16 %.02237 to i32
  %6 = add nsw i32 %4, %5
  %7 = sdiv i32 %6, 2
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [128 x i32], ptr @TPE_sinTable, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, %spec.select31
  br i1 %11, label %12, label %15

12:                                               ; preds = %3
  %13 = trunc nsw i32 %7 to i16
  %14 = add i16 %13, -1
  br label %20

15:                                               ; preds = %3
  %16 = icmp slt i32 %10, %spec.select31
  br i1 %16, label %17, label %.thread

17:                                               ; preds = %15
  %18 = trunc nsw i32 %7 to i16
  %19 = add i16 %18, 1
  br label %20

20:                                               ; preds = %12, %17
  %.224 = phi i16 [ %.02237, %12 ], [ %19, %17 ]
  %.2 = phi i16 [ %14, %12 ], [ %.02038, %17 ]
  %.not = icmp sgt i16 %.224, %.2
  br i1 %.not, label %.thread, label %3

.thread:                                          ; preds = %15, %20
  %21 = sub nsw i32 0, %7
  %.inv36 = icmp slt i32 %2, 0
  %22 = select i1 %.inv36, i32 %21, i32 %7
  ret i32 %22
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass