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

; 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_CandleSetting = type { i32, i32, i32, double }
%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 }

@TA_Globals = external dso_local global ptr, align 8
@__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings = external hidden unnamed_addr constant [11 x %struct.TA_CandleSetting], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @TA_RestoreCandleDefaultSettings(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca [11 x %struct.TA_CandleSetting], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 264, ptr %4) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 @__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings, i64 264, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp ugt i32 %7, 11
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i32 2, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %40

10:                                               ; preds = %1
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 11
  br i1 %12, label %13, label %30

13:                                               ; preds = %10
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %26, %13
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = icmp slt i32 %15, 11
  br i1 %16, label %17, label %29

17:                                               ; preds = %14
  %18 = load ptr, ptr @TA_Globals, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.TA_LibcPriv, ptr %18, i32 0, i32 8
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %19, i64 0, i64 %21
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %4, i64 0, i64 %24
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %22, ptr align 8 %25, i64 24, i1 false), !tbaa.struct !11
  br label %26

26:                                               ; preds = %17
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %5, align 4, !tbaa !5
  br label %14, !llvm.loop !14

29:                                               ; preds = %14
  br label %39

30:                                               ; preds = %10
  %31 = load ptr, ptr @TA_Globals, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.TA_LibcPriv, ptr %31, i32 0, i32 8
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %4, i64 0, i64 %37
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %35, ptr align 8 %38, i64 24, i1 false), !tbaa.struct !11
  br label %39

39:                                               ; preds = %30, %29
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %40

40:                                               ; preds = %39, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 264, ptr %4) #3
  %41 = load i32, ptr %2, align 4
  ret i32 %41
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 16, i64 8, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

%struct.TA_CandleSetting = type { i32, i32, i32, double }

@TA_Globals = external dso_local local_unnamed_addr global ptr, align 8
@__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings = external hidden unnamed_addr constant [11 x %struct.TA_CandleSetting], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 3) i32 @TA_RestoreCandleDefaultSettings(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp ugt i32 %0, 11
  br i1 %2, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = icmp eq i32 %0, 11
  %5 = load ptr, ptr @TA_Globals, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 208
  br i1 %4, label %.preheader.preheader, label %17

.preheader.preheader:                             ; preds = %3
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %6, ptr noundef nonnull align 16 dereferenceable(24) @__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings, i64 24, i1 false), !tbaa.struct !9
  %7 = getelementptr inbounds i8, ptr %5, i64 232
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %7, ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings, i64 24), i64 24, i1 false), !tbaa.struct !9
  %8 = getelementptr inbounds i8, ptr %5, i64 256
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %8, ptr noundef nonnull align 16 dereferenceable(24) getelementptr inbounds (i8, ptr @__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings, i64 48), i64 24, i1 false), !tbaa.struct !9
  %9 = getelementptr inbounds i8, ptr %5, i64 280
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %9, ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings, i64 72), i64 24, i1 false), !tbaa.struct !9
  %10 = getelementptr inbounds i8, ptr %5, i64 304
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %10, ptr noundef nonnull align 16 dereferenceable(24) getelementptr inbounds (i8, ptr @__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings, i64 96), i64 24, i1 false), !tbaa.struct !9
  %11 = getelementptr inbounds i8, ptr %5, i64 328
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %11, ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings, i64 120), i64 24, i1 false), !tbaa.struct !9
  %12 = getelementptr inbounds i8, ptr %5, i64 352
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %12, ptr noundef nonnull align 16 dereferenceable(24) getelementptr inbounds (i8, ptr @__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings, i64 144), i64 24, i1 false), !tbaa.struct !9
  %13 = getelementptr inbounds i8, ptr %5, i64 376
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %13, ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings, i64 168), i64 24, i1 false), !tbaa.struct !9
  %14 = getelementptr inbounds i8, ptr %5, i64 400
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %14, ptr noundef nonnull align 16 dereferenceable(24) getelementptr inbounds (i8, ptr @__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings, i64 192), i64 24, i1 false), !tbaa.struct !9
  %15 = getelementptr inbounds i8, ptr %5, i64 424
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %15, ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings, i64 216), i64 24, i1 false), !tbaa.struct !9
  %16 = getelementptr inbounds i8, ptr %5, i64 448
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %16, ptr noundef nonnull align 16 dereferenceable(24) getelementptr inbounds (i8, ptr @__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings, i64 240), i64 24, i1 false), !tbaa.struct !9
  br label %.loopexit

17:                                               ; preds = %3
  %18 = zext nneg i32 %0 to i64
  %19 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr %6, i64 0, i64 %18
  %20 = getelementptr inbounds [11 x %struct.TA_CandleSetting], ptr @__const.TA_RestoreCandleDefaultSettings.TA_CandleDefaultSettings, i64 0, i64 %18
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %19, ptr noundef nonnull align 8 dereferenceable(24) %20, i64 24, i1 false), !tbaa.struct !9
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.preheader, %17, %1
  %.09 = phi i32 [ 2, %1 ], [ 0, %17 ], [ 0, %.preheader.preheader ]
  ret i32 %.09
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

!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 = !{i64 0, i64 4, !10, i64 4, i64 4, !10, i64 8, i64 4, !10, i64 16, i64 8, !12}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}


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