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

; 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_CDLINVERTEDHAMMER_Lookback() #0 {
  %1 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %2 = getelementptr inbounds %struct.TA_LibcPriv, ptr %1, i32 0, i32 8
  %3 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %2, i64 0, i64 2
  %4 = getelementptr inbounds %struct.TA_CandleSetting, ptr %3, i32 0, i32 2
  %5 = load i32, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.TA_LibcPriv, ptr %6, i32 0, i32 8
  %8 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %7, i64 0, i64 4
  %9 = getelementptr inbounds %struct.TA_CandleSetting, ptr %8, i32 0, i32 2
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp sgt i32 %5, %10
  br i1 %11, label %12, label %18

12:                                               ; preds = %0
  %13 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.TA_LibcPriv, ptr %13, i32 0, i32 8
  %15 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %14, i64 0, i64 2
  %16 = getelementptr inbounds %struct.TA_CandleSetting, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !9
  br label %24

18:                                               ; preds = %0
  %19 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TA_LibcPriv, ptr %19, i32 0, i32 8
  %21 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %20, i64 0, i64 4
  %22 = getelementptr inbounds %struct.TA_CandleSetting, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %18, %12
  %25 = phi i32 [ %17, %12 ], [ %23, %18 ]
  %26 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TA_LibcPriv, ptr %26, i32 0, i32 8
  %28 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %27, i64 0, i64 7
  %29 = getelementptr inbounds %struct.TA_CandleSetting, ptr %28, i32 0, i32 2
  %30 = load i32, ptr %29, align 8, !tbaa !9
  %31 = icmp sgt i32 %25, %30
  br i1 %31, label %32, label %58

32:                                               ; preds = %24
  %33 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.TA_LibcPriv, ptr %33, i32 0, i32 8
  %35 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %34, i64 0, i64 2
  %36 = getelementptr inbounds %struct.TA_CandleSetting, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 8, !tbaa !9
  %38 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.TA_LibcPriv, ptr %38, i32 0, i32 8
  %40 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %39, i64 0, i64 4
  %41 = getelementptr inbounds %struct.TA_CandleSetting, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !9
  %43 = icmp sgt i32 %37, %42
  br i1 %43, label %44, label %50

44:                                               ; preds = %32
  %45 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.TA_LibcPriv, ptr %45, i32 0, i32 8
  %47 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %46, i64 0, i64 2
  %48 = getelementptr inbounds %struct.TA_CandleSetting, ptr %47, i32 0, i32 2
  %49 = load i32, ptr %48, align 8, !tbaa !9
  br label %56

50:                                               ; preds = %32
  %51 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.TA_LibcPriv, ptr %51, i32 0, i32 8
  %53 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %52, i64 0, i64 4
  %54 = getelementptr inbounds %struct.TA_CandleSetting, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %50, %44
  %57 = phi i32 [ %49, %44 ], [ %55, %50 ]
  br label %64

58:                                               ; preds = %24
  %59 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.TA_LibcPriv, ptr %59, i32 0, i32 8
  %61 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %60, i64 0, i64 7
  %62 = getelementptr inbounds %struct.TA_CandleSetting, ptr %61, i32 0, i32 2
  %63 = load i32, ptr %62, align 8, !tbaa !9
  br label %64

64:                                               ; preds = %58, %56
  %65 = phi i32 [ %57, %56 ], [ %63, %58 ]
  %66 = add nsw i32 %65, 1
  ret i32 %66
}

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


; 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 -2147483647, -2147483648) i32 @TA_CDLINVERTEDHAMMER_Lookback() local_unnamed_addr #0 {
  %1 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %1, i64 264
  %3 = load i32, ptr %2, align 8, !tbaa !9
  %4 = getelementptr inbounds i8, ptr %1, i64 312
  %5 = load i32, ptr %4, align 8, !tbaa !9
  %. = tail call i32 @llvm.smax.i32(i32 %3, i32 %5)
  %6 = getelementptr inbounds i8, ptr %1, i64 384
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %spec.select = tail call i32 @llvm.smax.i32(i32 %., i32 %7)
  %8 = add nsw i32 %spec.select, 1
  ret i32 %8
}

; 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,SimplifyCFGPass,TailCallElimPass