; LLVM IR from ubaldot/defrecs :: stm32f4x/ADC_Readings/Drivers/CMSIS/DSP/Source/FastMathFunctions (q31)

; 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: nounwind uwtable
define dso_local i32 @arm_atan2_q31(i32 noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  %8 = load i32, ptr %6, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %10, label %15

10:                                               ; preds = %3
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = call i32 @arm_atan_q31(i32 noundef %11, i32 noundef %12)
  %14 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %13, ptr %14, align 4, !tbaa !5
  store i32 0, ptr %4, align 4
  br label %61

15:                                               ; preds = %3
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %46

18:                                               ; preds = %15
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %21, label %27

21:                                               ; preds = %18
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = call i32 @arm_atan_q31(i32 noundef %22, i32 noundef %23)
  %25 = add nsw i32 %24, 1686629713
  %26 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %25, ptr %26, align 4, !tbaa !5
  br label %45

27:                                               ; preds = %18
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %30, label %36

30:                                               ; preds = %27
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = call i32 @arm_atan_q31(i32 noundef %31, i32 noundef %32)
  %34 = sub nsw i32 %33, 1686629713
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %34, ptr %35, align 4, !tbaa !5
  br label %44

36:                                               ; preds = %27
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = icmp slt i32 %37, 0
  br i1 %38, label %39, label %41

39:                                               ; preds = %36
  %40 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 -1686629713, ptr %40, align 4, !tbaa !5
  br label %43

41:                                               ; preds = %36
  %42 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 1686629713, ptr %42, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %41, %39
  br label %44

44:                                               ; preds = %43, %30
  br label %45

45:                                               ; preds = %44, %21
  store i32 0, ptr %4, align 4
  br label %61

46:                                               ; preds = %15
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %60

49:                                               ; preds = %46
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = icmp sgt i32 %50, 0
  br i1 %51, label %52, label %54

52:                                               ; preds = %49
  %53 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 843314857, ptr %53, align 4, !tbaa !5
  store i32 0, ptr %4, align 4
  br label %61

54:                                               ; preds = %49
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = icmp slt i32 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %54
  %58 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 -843314857, ptr %58, align 4, !tbaa !5
  store i32 0, ptr %4, align 4
  br label %61

59:                                               ; preds = %54
  br label %60

60:                                               ; preds = %59, %46
  store i32 -4, ptr %4, align 4
  br label %61

61:                                               ; preds = %60, %57, %52, %45, %10
  %62 = load i32, ptr %4, align 4
  ret i32 %62
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @arm_atan_q31(i32 noundef, i32 noundef) #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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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: nounwind uwtable
define dso_local range(i32 -4, 1) i32 @arm_atan2_q31(i32 noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %1, 0
  br i1 %4, label %5, label %7

5:                                                ; preds = %3
  %6 = tail call i32 @arm_atan_q31(i32 noundef %0, i32 noundef %1)
  br label %.sink.split

7:                                                ; preds = %3
  %8 = icmp slt i32 %1, 0
  %9 = icmp sgt i32 %0, 0
  br i1 %8, label %10, label %19

10:                                               ; preds = %7
  br i1 %9, label %11, label %14

11:                                               ; preds = %10
  %12 = tail call i32 @arm_atan_q31(i32 noundef %0, i32 noundef %1)
  %13 = add nsw i32 %12, 1686629713
  br label %.sink.split

14:                                               ; preds = %10
  %15 = icmp slt i32 %0, 0
  br i1 %15, label %16, label %.sink.split

16:                                               ; preds = %14
  %17 = tail call i32 @arm_atan_q31(i32 noundef %0, i32 noundef %1)
  %18 = add nsw i32 %17, -1686629713
  br label %.sink.split

19:                                               ; preds = %7
  br i1 %9, label %.sink.split, label %20

20:                                               ; preds = %19
  %21 = icmp slt i32 %0, 0
  br i1 %21, label %.sink.split, label %22

.sink.split:                                      ; preds = %20, %19, %14, %5, %16, %11
  %.sink = phi i32 [ %13, %11 ], [ %18, %16 ], [ %6, %5 ], [ 1686629713, %14 ], [ 843314857, %19 ], [ -843314857, %20 ]
  store i32 %.sink, ptr %2, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %.sink.split, %20
  %.0 = phi i32 [ -4, %20 ], [ 0, %.sink.split ]
  ret i32 %.0
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @arm_atan_q31(i32 noundef, i32 noundef) local_unnamed_addr #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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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