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

; 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: 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_MEDPRICE(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #1 {
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store i32 %0, ptr %9, align 4, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !9
  store ptr %4, ptr %13, align 8, !tbaa !9
  store ptr %5, ptr %14, align 8, !tbaa !9
  store ptr %6, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #2
  %19 = load i32, ptr %9, align 4, !tbaa !5
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %7
  store i32 12, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %74

22:                                               ; preds = %7
  %23 = load i32, ptr %10, align 4, !tbaa !5
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %29, label %25

25:                                               ; preds = %22
  %26 = load i32, ptr %10, align 4, !tbaa !5
  %27 = load i32, ptr %9, align 4, !tbaa !5
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %25, %22
  store i32 13, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %74

30:                                               ; preds = %25
  %31 = load ptr, ptr %11, align 8, !tbaa !9
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %36

33:                                               ; preds = %30
  %34 = load ptr, ptr %12, align 8, !tbaa !9
  %35 = icmp ne ptr %34, null
  br i1 %35, label %37, label %36

36:                                               ; preds = %33, %30
  store i32 2, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %74

37:                                               ; preds = %33
  %38 = load ptr, ptr %15, align 8, !tbaa !9
  %39 = icmp ne ptr %38, null
  br i1 %39, label %41, label %40

40:                                               ; preds = %37
  store i32 2, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %74

41:                                               ; preds = %37
  store i32 0, ptr %16, align 4, !tbaa !5
  %42 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %42, ptr %17, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %66, %41
  %44 = load i32, ptr %17, align 4, !tbaa !5
  %45 = load i32, ptr %10, align 4, !tbaa !5
  %46 = icmp sle i32 %44, %45
  br i1 %46, label %47, label %69

47:                                               ; preds = %43
  %48 = load ptr, ptr %11, align 8, !tbaa !9
  %49 = load i32, ptr %17, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds float, ptr %48, i64 %50
  %52 = load float, ptr %51, align 4, !tbaa !11
  %53 = load ptr, ptr %12, align 8, !tbaa !9
  %54 = load i32, ptr %17, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds float, ptr %53, i64 %55
  %57 = load float, ptr %56, align 4, !tbaa !11
  %58 = fadd float %52, %57
  %59 = fpext float %58 to double
  %60 = fdiv double %59, 2.000000e+00
  %61 = load ptr, ptr %15, align 8, !tbaa !9
  %62 = load i32, ptr %16, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %16, align 4, !tbaa !5
  %64 = sext i32 %62 to i64
  %65 = getelementptr inbounds double, ptr %61, i64 %64
  store double %60, ptr %65, align 8, !tbaa !13
  br label %66

66:                                               ; preds = %47
  %67 = load i32, ptr %17, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %17, align 4, !tbaa !5
  br label %43, !llvm.loop !15

69:                                               ; preds = %43
  %70 = load i32, ptr %16, align 4, !tbaa !5
  %71 = load ptr, ptr %14, align 8, !tbaa !9
  store i32 %70, ptr %71, align 4, !tbaa !5
  %72 = load i32, ptr %9, align 4, !tbaa !5
  %73 = load ptr, ptr %13, align 8, !tbaa !9
  store i32 %72, ptr %73, align 4, !tbaa !5
  store i32 0, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %74

74:                                               ; preds = %69, %40, %36, %29, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  %75 = load i32, ptr %8, align 4
  ret i32 %75
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = !{!"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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local range(i32 0, 14) i32 @TA_S_MEDPRICE(i32 noundef %0, i32 noundef %1, ptr noundef readonly %2, ptr noundef readonly %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef writeonly %5, ptr noundef writeonly %6) local_unnamed_addr #0 {
  %8 = icmp slt i32 %0, 0
  br i1 %8, label %38, label %9

9:                                                ; preds = %7
  %10 = icmp slt i32 %1, %0
  br i1 %10, label %38, label %11

11:                                               ; preds = %9
  %12 = icmp eq ptr %2, null
  %13 = icmp eq ptr %3, null
  %or.cond.not34 = or i1 %12, %13
  %.not = icmp eq ptr %6, null
  %or.cond31 = or i1 %or.cond.not34, %.not
  br i1 %or.cond31, label %38, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %11
  %14 = zext nneg i32 %0 to i64
  %15 = add nuw i32 %1, 1
  %16 = sub i32 %15, %0
  %wide.trip.count = zext i32 %16 to i64
  %min.iters.check = icmp ult i32 %16, 4
  br i1 %min.iters.check, label %.lr.ph.preheader47, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 4294967292
  %ind.end = add nuw nsw i64 %n.vec, %14
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = add i64 %index, %14
  %17 = getelementptr inbounds float, ptr %2, i64 %offset.idx
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  %wide.load = load <2 x float>, ptr %17, align 4, !tbaa !5
  %wide.load44 = load <2 x float>, ptr %18, align 4, !tbaa !5
  %19 = getelementptr inbounds float, ptr %3, i64 %offset.idx
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %wide.load45 = load <2 x float>, ptr %19, align 4, !tbaa !5
  %wide.load46 = load <2 x float>, ptr %20, align 4, !tbaa !5
  %21 = fadd <2 x float> %wide.load, %wide.load45
  %22 = fadd <2 x float> %wide.load44, %wide.load46
  %23 = fpext <2 x float> %21 to <2 x double>
  %24 = fpext <2 x float> %22 to <2 x double>
  %25 = fmul <2 x double> %23, <double 5.000000e-01, double 5.000000e-01>
  %26 = fmul <2 x double> %24, <double 5.000000e-01, double 5.000000e-01>
  %27 = getelementptr inbounds double, ptr %6, i64 %index
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  store <2 x double> %25, ptr %27, align 8, !tbaa !9
  store <2 x double> %26, ptr %28, align 8, !tbaa !9
  %index.next = add nuw i64 %index, 4
  %29 = icmp eq i64 %index.next, %n.vec
  br i1 %29, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader47

.lr.ph.preheader47:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv38.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %indvars.iv.ph = phi i64 [ %14, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader47, %.lr.ph
  %indvars.iv38 = phi i64 [ %indvars.iv.next39, %.lr.ph ], [ %indvars.iv38.ph, %.lr.ph.preheader47 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader47 ]
  %30 = getelementptr inbounds float, ptr %2, i64 %indvars.iv
  %31 = load float, ptr %30, align 4, !tbaa !5
  %32 = getelementptr inbounds float, ptr %3, i64 %indvars.iv
  %33 = load float, ptr %32, align 4, !tbaa !5
  %34 = fadd float %31, %33
  %35 = fpext float %34 to double
  %36 = fmul double %35, 5.000000e-01
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %37 = getelementptr inbounds double, ptr %6, i64 %indvars.iv38
  store double %36, ptr %37, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %middle.block
  store i32 %16, ptr %5, align 4, !tbaa !16
  store i32 %0, ptr %4, align 4, !tbaa !16
  br label %38

38:                                               ; preds = %11, %9, %7, %._crit_edge
  %.023 = phi i32 [ 0, %._crit_edge ], [ 12, %7 ], [ 13, %9 ], [ 2, %11 ]
  ret i32 %.023
}

attributes #0 = { nofree norecurse nosync nounwind memory(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" }

!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, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !14, !13}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}


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