; LLVM IR from bbenligiray/stag :: src/ED/MyMath.ll (Z7myAtan2dd)

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

@_ZZ7myAtan2ddE11tableInited = external hidden global i8, align 1
@_ZL3LUT = external hidden global [1025 x double], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z7myAtan2dd(double noundef %0, double noundef %1) #0 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  store double %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !5
  %14 = load i8, ptr @_ZZ7myAtan2ddE11tableInited, align 1, !tbaa !9, !range !11, !noundef !12
  %15 = trunc i8 %14 to i1
  br i1 %15, label %33, label %16

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

17:                                               ; preds = %29, %16
  %18 = load i32, ptr %6, align 4, !tbaa !13
  %19 = icmp sle i32 %18, 1024
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %32

21:                                               ; preds = %17
  %22 = load i32, ptr %6, align 4, !tbaa !13
  %23 = sitofp i32 %22 to double
  %24 = fdiv double %23, 1.024000e+03
  %25 = call double @atan(double noundef %24) #4
  %26 = load i32, ptr %6, align 4, !tbaa !13
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1025 x double], ptr @_ZL3LUT, i64 0, i64 %27
  store double %25, ptr %28, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %21
  %30 = load i32, ptr %6, align 4, !tbaa !13
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %6, align 4, !tbaa !13
  br label %17, !llvm.loop !15

32:                                               ; preds = %20
  store i8 1, ptr @_ZZ7myAtan2ddE11tableInited, align 1, !tbaa !9
  br label %33

33:                                               ; preds = %32, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %34 = load double, ptr %4, align 8, !tbaa !5
  %35 = call double @llvm.fabs.f64(double %34)
  store double %35, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %36 = load double, ptr %5, align 8, !tbaa !5
  %37 = call double @llvm.fabs.f64(double %36)
  store double %37, ptr %8, align 8, !tbaa !5
  %38 = load double, ptr %8, align 8, !tbaa !5
  %39 = fcmp olt double %38, 1.000000e-04
  br i1 %39, label %40, label %45

40:                                               ; preds = %33
  %41 = load double, ptr %7, align 8, !tbaa !5
  %42 = fcmp olt double %41, 1.000000e-04
  br i1 %42, label %43, label %44

43:                                               ; preds = %40
  store double 0.000000e+00, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %113

44:                                               ; preds = %40
  store double 0x3FF921FB54442D18, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %113

45:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  store i8 0, ptr %10, align 1, !tbaa !9
  %46 = load double, ptr %7, align 8, !tbaa !5
  %47 = load double, ptr %8, align 8, !tbaa !5
  %48 = fcmp ogt double %46, %47
  br i1 %48, label %49, label %53

49:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %50 = load double, ptr %8, align 8, !tbaa !5
  store double %50, ptr %11, align 8, !tbaa !5
  %51 = load double, ptr %7, align 8, !tbaa !5
  store double %51, ptr %8, align 8, !tbaa !5
  %52 = load double, ptr %11, align 8, !tbaa !5
  store double %52, ptr %7, align 8, !tbaa !5
  store i8 1, ptr %10, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %53

53:                                               ; preds = %49, %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %54 = load double, ptr %7, align 8, !tbaa !5
  %55 = load double, ptr %8, align 8, !tbaa !5
  %56 = fdiv double %54, %55
  store double %56, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %57 = load double, ptr %12, align 8, !tbaa !5
  %58 = fmul double %57, 1.024000e+03
  %59 = fptosi double %58 to i32
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1025 x double], ptr @_ZL3LUT, i64 0, i64 %60
  %62 = load double, ptr %61, align 8, !tbaa !5
  store double %62, ptr %13, align 8, !tbaa !5
  %63 = load double, ptr %5, align 8, !tbaa !5
  %64 = fcmp oge double %63, 0.000000e+00
  br i1 %64, label %65, label %88

65:                                               ; preds = %53
  %66 = load double, ptr %4, align 8, !tbaa !5
  %67 = fcmp oge double %66, 0.000000e+00
  br i1 %67, label %68, label %75

68:                                               ; preds = %65
  %69 = load i8, ptr %10, align 1, !tbaa !9, !range !11, !noundef !12
  %70 = trunc i8 %69 to i1
  br i1 %70, label %71, label %74

71:                                               ; preds = %68
  %72 = load double, ptr %13, align 8, !tbaa !5
  %73 = fsub double 0x3FF921FB54442D18, %72
  store double %73, ptr %13, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %71, %68
  br label %87

75:                                               ; preds = %65
  %76 = load i8, ptr %10, align 1, !tbaa !9, !range !11, !noundef !12
  %77 = trunc i8 %76 to i1
  %78 = zext i1 %77 to i32
  %79 = icmp eq i32 %78, 0
  br i1 %79, label %80, label %83

80:                                               ; preds = %75
  %81 = load double, ptr %13, align 8, !tbaa !5
  %82 = fsub double 0x400921FB54442D18, %81
  store double %82, ptr %13, align 8, !tbaa !5
  br label %86

83:                                               ; preds = %75
  %84 = load double, ptr %13, align 8, !tbaa !5
  %85 = fadd double 0x3FF921FB54442D18, %84
  store double %85, ptr %13, align 8, !tbaa !5
  br label %86

86:                                               ; preds = %83, %80
  br label %87

87:                                               ; preds = %86, %74
  br label %111

88:                                               ; preds = %53
  %89 = load double, ptr %4, align 8, !tbaa !5
  %90 = fcmp oge double %89, 0.000000e+00
  br i1 %90, label %91, label %103

91:                                               ; preds = %88
  %92 = load i8, ptr %10, align 1, !tbaa !9, !range !11, !noundef !12
  %93 = trunc i8 %92 to i1
  %94 = zext i1 %93 to i32
  %95 = icmp eq i32 %94, 0
  br i1 %95, label %96, label %99

96:                                               ; preds = %91
  %97 = load double, ptr %13, align 8, !tbaa !5
  %98 = fsub double 0x400921FB54442D18, %97
  store double %98, ptr %13, align 8, !tbaa !5
  br label %102

99:                                               ; preds = %91
  %100 = load double, ptr %13, align 8, !tbaa !5
  %101 = fadd double 0x3FF921FB54442D18, %100
  store double %101, ptr %13, align 8, !tbaa !5
  br label %102

102:                                              ; preds = %99, %96
  br label %110

103:                                              ; preds = %88
  %104 = load i8, ptr %10, align 1, !tbaa !9, !range !11, !noundef !12
  %105 = trunc i8 %104 to i1
  br i1 %105, label %106, label %109

106:                                              ; preds = %103
  %107 = load double, ptr %13, align 8, !tbaa !5
  %108 = fsub double 0x3FF921FB54442D18, %107
  store double %108, ptr %13, align 8, !tbaa !5
  br label %109

109:                                              ; preds = %106, %103
  br label %110

110:                                              ; preds = %109, %102
  br label %111

111:                                              ; preds = %110, %87
  %112 = load double, ptr %13, align 8, !tbaa !5
  store double %112, ptr %3, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  br label %113

113:                                              ; preds = %111, %44, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %114 = load double, ptr %3, align 8
  ret double %114
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind
declare double @atan(double noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #3

attributes #0 = { mustprogress 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 "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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@_ZZ7myAtan2ddE11tableInited = external hidden local_unnamed_addr global i8, align 1
@_ZL3LUT = external hidden local_unnamed_addr global [1025 x double], align 16

; Function Attrs: mustprogress nofree nounwind memory(readwrite, argmem: write, inaccessiblemem: write) uwtable
define dso_local noundef double @_Z7myAtan2dd(double noundef %0, double noundef %1) local_unnamed_addr #0 {
  %3 = load i8, ptr @_ZZ7myAtan2ddE11tableInited, align 1, !tbaa !5, !range !9, !noundef !10
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %11, label %.preheader

5:                                                ; preds = %.preheader
  store i8 1, ptr @_ZZ7myAtan2ddE11tableInited, align 1, !tbaa !5
  br label %11

.preheader:                                       ; preds = %2, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader ], [ 0, %2 ]
  %6 = trunc nuw nsw i64 %indvars.iv to i32
  %7 = uitofp nneg i32 %6 to double
  %8 = fmul double %7, 0x3F50000000000000
  %9 = tail call double @atan(double noundef %8) #3
  %10 = getelementptr inbounds [1025 x double], ptr @_ZL3LUT, i64 0, i64 %indvars.iv
  store double %9, ptr %10, align 8, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1025
  br i1 %exitcond.not, label %5, label %.preheader, !llvm.loop !13

11:                                               ; preds = %5, %2
  %12 = tail call double @llvm.fabs.f64(double %0)
  %13 = tail call double @llvm.fabs.f64(double %1)
  %14 = fcmp olt double %13, 1.000000e-04
  br i1 %14, label %15, label %17

15:                                               ; preds = %11
  %16 = fcmp olt double %12, 1.000000e-04
  %. = select i1 %16, double 0.000000e+00, double 0x3FF921FB54442D18
  br label %45

17:                                               ; preds = %11
  %18 = fcmp ule double %12, %13
  %.034 = select i1 %18, double %12, double %13
  %.033 = select i1 %18, double %13, double %12
  %19 = fdiv double %.034, %.033
  %20 = fmul double %19, 1.024000e+03
  %21 = fptosi double %20 to i32
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1025 x double], ptr @_ZL3LUT, i64 0, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !11
  %25 = fcmp ult double %1, 0.000000e+00
  %26 = fcmp ult double %0, 0.000000e+00
  br i1 %25, label %36, label %27

27:                                               ; preds = %17
  br i1 %26, label %31, label %28

28:                                               ; preds = %27
  br i1 %18, label %45, label %29

29:                                               ; preds = %28
  %30 = fsub double 0x3FF921FB54442D18, %24
  br label %45

31:                                               ; preds = %27
  br i1 %18, label %32, label %34

32:                                               ; preds = %31
  %33 = fsub double 0x400921FB54442D18, %24
  br label %45

34:                                               ; preds = %31
  %35 = fadd double %24, 0x3FF921FB54442D18
  br label %45

36:                                               ; preds = %17
  br i1 %26, label %42, label %37

37:                                               ; preds = %36
  br i1 %18, label %38, label %40

38:                                               ; preds = %37
  %39 = fsub double 0x400921FB54442D18, %24
  br label %45

40:                                               ; preds = %37
  %41 = fadd double %24, 0x3FF921FB54442D18
  br label %45

42:                                               ; preds = %36
  br i1 %18, label %45, label %43

43:                                               ; preds = %42
  %44 = fsub double 0x3FF921FB54442D18, %24
  br label %45

45:                                               ; preds = %32, %34, %28, %29, %42, %43, %38, %40, %15
  %.030 = phi double [ %., %15 ], [ %30, %29 ], [ %24, %28 ], [ %33, %32 ], [ %35, %34 ], [ %39, %38 ], [ %41, %40 ], [ %44, %43 ], [ %24, %42 ]
  ret double %.030
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @atan(double noundef) local_unnamed_addr #1

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

attributes #0 = { mustprogress nofree nounwind memory(readwrite, argmem: write, inaccessiblemem: write) 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 nofree nounwind willreturn memory(write) "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 = { mustprogress 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass