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

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

%struct.TA_LibcPriv = type { i32, [3 x %struct.TA_ModuleControl], i32, i32, ptr, ptr, i32, [24 x i32], [11 x %struct.TA_CandleSetting] }
%struct.TA_ModuleControl = type { i32, ptr, ptr }
%struct.TA_CandleSetting = type { i32, i32, i32, double }

@TA_Globals = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @TA_CDLEVENINGSTAR_Lookback(double noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca double, align 8
  store double %0, ptr %3, align 8, !tbaa !5
  %4 = load double, ptr %3, align 8, !tbaa !5
  %5 = fcmp oeq double %4, -4.000000e+37
  br i1 %5, label %6, label %7

6:                                                ; preds = %1
  store double 3.000000e-01, ptr %3, align 8, !tbaa !5
  br label %15

7:                                                ; preds = %1
  %8 = load double, ptr %3, align 8, !tbaa !5
  %9 = fcmp olt double %8, 0.000000e+00
  br i1 %9, label %13, label %10

10:                                               ; preds = %7
  %11 = load double, ptr %3, align 8, !tbaa !5
  %12 = fcmp ogt double %11, 3.000000e+37
  br i1 %12, label %13, label %14

13:                                               ; preds = %10, %7
  store i32 -1, ptr %2, align 4
  br label %43

14:                                               ; preds = %10
  br label %15

15:                                               ; preds = %14, %6
  %16 = load double, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr @TA_Globals, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.TA_LibcPriv, ptr %17, i32 0, i32 8
  %19 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %18, i64 0, i64 2
  %20 = getelementptr inbounds %struct.TA_CandleSetting, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = load ptr, ptr @TA_Globals, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.TA_LibcPriv, ptr %22, i32 0, i32 8
  %24 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %23, i64 0, i64 0
  %25 = getelementptr inbounds %struct.TA_CandleSetting, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = icmp sgt i32 %21, %26
  br i1 %27, label %28, label %34

28:                                               ; preds = %15
  %29 = load ptr, ptr @TA_Globals, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.TA_LibcPriv, ptr %29, i32 0, i32 8
  %31 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %30, i64 0, i64 2
  %32 = getelementptr inbounds %struct.TA_CandleSetting, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !11
  br label %40

34:                                               ; preds = %15
  %35 = load ptr, ptr @TA_Globals, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.TA_LibcPriv, ptr %35, i32 0, i32 8
  %37 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %36, i64 0, i64 0
  %38 = getelementptr inbounds %struct.TA_CandleSetting, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !11
  br label %40

40:                                               ; preds = %34, %28
  %41 = phi i32 [ %33, %28 ], [ %39, %34 ]
  %42 = add nsw i32 %41, 2
  store i32 %42, ptr %2, align 4
  br label %43

43:                                               ; preds = %40, %13
  %44 = load i32, ptr %2, align 4
  ret i32 %44
}

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

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !6, i64 16}
!13 = !{!"int", !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"

@TA_Globals = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local range(i32 -2147483646, -2147483648) i32 @TA_CDLEVENINGSTAR_Lookback(double noundef %0) local_unnamed_addr #0 {
  %2 = fcmp oeq double %0, -4.000000e+37
  br i1 %2, label %6, label %3

3:                                                ; preds = %1
  %4 = fcmp olt double %0, 0.000000e+00
  %5 = fcmp ogt double %0, 3.000000e+37
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %13, label %6

6:                                                ; preds = %1, %3
  %7 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 264
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %7, i64 216
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %. = tail call i32 @llvm.smax.i32(i32 %9, i32 %11)
  %12 = add nsw i32 %., 2
  br label %13

13:                                               ; preds = %3, %6
  %.05 = phi i32 [ %12, %6 ], [ -1, %3 ]
  ret i32 %.05
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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 speculatable willreturn memory(none) }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}


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