; LLVM IR from mkmarek/forex.analytics :: lib/ta-lib/src/ta_func (ta_ACOS)

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

; Function Attrs: nounwind
declare double @acos(double noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @TA_S_ACOS(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %6
  store i32 12, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %64

20:                                               ; preds = %6
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %27, label %23

23:                                               ; preds = %20
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %23, %20
  store i32 13, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %64

28:                                               ; preds = %23
  %29 = load ptr, ptr %10, align 8, !tbaa !9
  %30 = icmp ne ptr %29, null
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  store i32 2, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %64

32:                                               ; preds = %28
  %33 = load ptr, ptr %13, align 8, !tbaa !9
  %34 = icmp ne ptr %33, null
  br i1 %34, label %36, label %35

35:                                               ; preds = %32
  store i32 2, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %64

36:                                               ; preds = %32
  %37 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %37, ptr %15, align 4, !tbaa !5
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %54, %36
  %39 = load i32, ptr %15, align 4, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %42, label %59

42:                                               ; preds = %38
  %43 = load ptr, ptr %10, align 8, !tbaa !9
  %44 = load i32, ptr %15, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds float, ptr %43, i64 %45
  %47 = load float, ptr %46, align 4, !tbaa !11
  %48 = fpext float %47 to double
  %49 = call double @acos(double noundef %48) #3
  %50 = load ptr, ptr %13, align 8, !tbaa !9
  %51 = load i32, ptr %14, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %50, i64 %52
  store double %49, ptr %53, align 8, !tbaa !13
  br label %54

54:                                               ; preds = %42
  %55 = load i32, ptr %15, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %15, align 4, !tbaa !5
  %57 = load i32, ptr %14, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %14, align 4, !tbaa !5
  br label %38, !llvm.loop !15

59:                                               ; preds = %38
  %60 = load i32, ptr %14, align 4, !tbaa !5
  %61 = load ptr, ptr %12, align 8, !tbaa !9
  store i32 %60, ptr %61, align 4, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = load ptr, ptr %11, align 8, !tbaa !9
  store i32 %62, ptr %63, align 4, !tbaa !5
  store i32 0, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %64

64:                                               ; preds = %59, %35, %31, %27, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %65 = load i32, ptr %7, align 4
  ret i32 %65
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = !{!"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}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !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"

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

; Function Attrs: nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local range(i32 0, 14) i32 @TA_S_ACOS(i32 noundef %0, i32 noundef %1, ptr noundef readonly %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4, ptr noundef writeonly %5) local_unnamed_addr #1 {
  %7 = icmp slt i32 %0, 0
  br i1 %7, label %19, label %8

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

10:                                               ; preds = %8
  %.not = icmp eq ptr %2, null
  %.not25 = icmp eq ptr %5, null
  %or.cond27 = or i1 %.not, %.not25
  br i1 %or.cond27, label %19, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %10
  %11 = zext nneg i32 %0 to i64
  %12 = add nuw i32 %1, 1
  %13 = sub i32 %12, %0
  %wide.trip.count = zext i32 %13 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv31 = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next32, %.lr.ph ]
  %indvars.iv = phi i64 [ %11, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %14 = getelementptr inbounds float, ptr %2, i64 %indvars.iv
  %15 = load float, ptr %14, align 4, !tbaa !5
  %16 = fpext float %15 to double
  %17 = tail call double @acos(double noundef %16) #2
  %18 = getelementptr inbounds double, ptr %5, i64 %indvars.iv31
  store double %17, ptr %18, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next32, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph
  store i32 %13, ptr %4, align 4, !tbaa !13
  store i32 %0, ptr %3, align 4, !tbaa !13
  br label %19

19:                                               ; preds = %10, %8, %6, %._crit_edge
  %.020 = phi i32 [ 0, %._crit_edge ], [ 12, %6 ], [ 13, %8 ], [ 2, %10 ]
  ret i32 %.020
}

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


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass