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

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

10:                                               ; preds = %2
  store i32 2, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %37

11:                                               ; preds = %2
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp eq i32 %12, 24
  br i1 %13, label %14, label %29

14:                                               ; preds = %11
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %25, %14
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 24
  br i1 %17, label %18, label %28

18:                                               ; preds = %15
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = load ptr, ptr @TA_Globals, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.TA_LibcPriv, ptr %20, i32 0, i32 7
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [24 x i32], ptr %21, i64 0, i64 %23
  store i32 %19, ptr %24, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %18
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %6, align 4, !tbaa !5
  br label %15, !llvm.loop !11

28:                                               ; preds = %15
  br label %36

29:                                               ; preds = %11
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = load ptr, ptr @TA_Globals, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.TA_LibcPriv, ptr %31, i32 0, i32 7
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [24 x i32], ptr %32, i64 0, i64 %34
  store i32 %30, ptr %35, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %29, %28
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %37

37:                                               ; preds = %36, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %38 = load i32, ptr %3, align 4
  ret i32 %38
}

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

; 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 = { 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 = distinct !{!11, !12}
!12 = !{!"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"

@TA_Globals = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 3) i32 @TA_SetUnstablePeriod(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %0, 24
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %2
  %5 = icmp eq i32 %0, 24
  %6 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 108
  br i1 %5, label %.preheader, label %18

.preheader:                                       ; preds = %4
  %8 = insertelement <4 x i32> poison, i32 %1, i64 0
  %9 = shufflevector <4 x i32> %8, <4 x i32> poison, <4 x i32> zeroinitializer
  store <4 x i32> %9, ptr %7, align 4, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %6, i64 124
  store <4 x i32> %9, ptr %10, align 4, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %6, i64 140
  store <4 x i32> %9, ptr %11, align 4, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %6, i64 156
  store <4 x i32> %9, ptr %12, align 4, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %6, i64 172
  store <4 x i32> %9, ptr %13, align 4, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %6, i64 188
  store i32 %1, ptr %14, align 4, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %6, i64 192
  store i32 %1, ptr %15, align 4, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %6, i64 196
  store i32 %1, ptr %16, align 4, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %6, i64 200
  br label %.loopexit.sink.split

18:                                               ; preds = %4
  %19 = sext i32 %0 to i64
  %20 = getelementptr inbounds [24 x i32], ptr %7, i64 0, i64 %19
  br label %.loopexit.sink.split

.loopexit.sink.split:                             ; preds = %18, %.preheader
  %.sink = phi ptr [ %17, %.preheader ], [ %20, %18 ]
  store i32 %1, ptr %.sink, align 4, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.sink.split, %2
  %.09 = phi i32 [ 2, %2 ], [ 0, %.loopexit.sink.split ]
  ret i32 %.09
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, 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" }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass