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

; 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 @TA_MACD_Lookback(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = icmp eq i32 %10, -2147483648
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store i32 12, ptr %5, align 4, !tbaa !5
  br label %21

13:                                               ; preds = %3
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp slt i32 %14, 2
  br i1 %15, label %19, label %16

16:                                               ; preds = %13
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = icmp sgt i32 %17, 100000
  br i1 %18, label %19, label %20

19:                                               ; preds = %16, %13
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %59

20:                                               ; preds = %16
  br label %21

21:                                               ; preds = %20, %12
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = icmp eq i32 %22, -2147483648
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i32 26, ptr %6, align 4, !tbaa !5
  br label %33

25:                                               ; preds = %21
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 2
  br i1 %27, label %31, label %28

28:                                               ; preds = %25
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = icmp sgt i32 %29, 100000
  br i1 %30, label %31, label %32

31:                                               ; preds = %28, %25
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %59

32:                                               ; preds = %28
  br label %33

33:                                               ; preds = %32, %24
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = icmp eq i32 %34, -2147483648
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  store i32 9, ptr %7, align 4, !tbaa !5
  br label %45

37:                                               ; preds = %33
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = icmp slt i32 %38, 1
  br i1 %39, label %43, label %40

40:                                               ; preds = %37
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = icmp sgt i32 %41, 100000
  br i1 %42, label %43, label %44

43:                                               ; preds = %40, %37
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %59

44:                                               ; preds = %40
  br label %45

45:                                               ; preds = %44, %36
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = icmp slt i32 %46, %47
  br i1 %48, label %49, label %53

49:                                               ; preds = %45
  %50 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %50, ptr %8, align 4, !tbaa !5
  %51 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %51, ptr %6, align 4, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %52, ptr %5, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %49, %45
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = call i32 @TA_EMA_Lookback(i32 noundef %54)
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = call i32 @TA_EMA_Lookback(i32 noundef %56)
  %58 = add nsw i32 %55, %57
  store i32 %58, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %59

59:                                               ; preds = %53, %43, %31, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %60 = load i32, ptr %4, align 4
  ret i32 %60
}

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

declare i32 @TA_EMA_Lookback(i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
attributes #2 = { "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"}


; 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 i32 @TA_MACD_Lookback(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %0, -2147483648
  br i1 %4, label %7, label %5

5:                                                ; preds = %3
  %6 = add i32 %0, -100001
  %or.cond = icmp ult i32 %6, -99999
  br i1 %or.cond, label %19, label %7

7:                                                ; preds = %3, %5
  %.024 = phi i32 [ %0, %5 ], [ 12, %3 ]
  %8 = icmp eq i32 %1, -2147483648
  br i1 %8, label %11, label %9

9:                                                ; preds = %7
  %10 = add i32 %1, -100001
  %or.cond3 = icmp ult i32 %10, -99999
  br i1 %or.cond3, label %19, label %11

11:                                               ; preds = %7, %9
  %.023 = phi i32 [ %1, %9 ], [ 26, %7 ]
  %12 = icmp eq i32 %2, -2147483648
  br i1 %12, label %15, label %13

13:                                               ; preds = %11
  %14 = add i32 %2, -100001
  %or.cond5 = icmp ult i32 %14, -100000
  br i1 %or.cond5, label %19, label %15

15:                                               ; preds = %11, %13
  %.022 = phi i32 [ %2, %13 ], [ 9, %11 ]
  %spec.select = tail call i32 @llvm.umax.i32(i32 %.023, i32 %.024)
  %16 = tail call i32 @TA_EMA_Lookback(i32 noundef %spec.select) #3
  %17 = tail call i32 @TA_EMA_Lookback(i32 noundef %.022) #3
  %18 = add nsw i32 %17, %16
  br label %19

19:                                               ; preds = %13, %9, %5, %15
  %.0 = phi i32 [ %18, %15 ], [ -1, %5 ], [ -1, %9 ], [ -1, %13 ]
  ret i32 %.0
}

declare i32 @TA_EMA_Lookback(i32 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #2

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 = { "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 = { 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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass