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

; 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_InternalRetCodeInfo = type { i32, ptr, ptr }
%struct.TA_RetCodeInfo = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [18 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [47 x i8], align 1
@retCodeInfoTable = external hidden global [19 x %struct.TA_InternalRetCodeInfo], align 16

; Function Attrs: nounwind uwtable
define dso_local void @TA_SetRetCodeInfo(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp uge i32 %7, 5000
  br i1 %8, label %9, label %17

9:                                                ; preds = %2
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp ule i32 %10, 5999
  br i1 %11, label %12, label %17

12:                                               ; preds = %9
  %13 = load ptr, ptr %4, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.TA_RetCodeInfo, ptr %13, i32 0, i32 0
  store ptr @.str, ptr %14, align 8, !tbaa !11
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.TA_RetCodeInfo, ptr %15, i32 0, i32 1
  store ptr @.str.1, ptr %16, align 8, !tbaa !13
  store i32 1, ptr %6, align 4
  br label %64

17:                                               ; preds = %9, %2
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %46, %17
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = zext i32 %19 to i64
  %21 = icmp ult i64 %20, 18
  br i1 %21, label %22, label %49

22:                                               ; preds = %18
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds [19 x %struct.TA_InternalRetCodeInfo], ptr @retCodeInfoTable, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.TA_InternalRetCodeInfo, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !14
  %29 = icmp eq i32 %23, %28
  br i1 %29, label %30, label %45

30:                                               ; preds = %22
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds [19 x %struct.TA_InternalRetCodeInfo], ptr @retCodeInfoTable, i64 0, i64 %32
  %34 = getelementptr inbounds %struct.TA_InternalRetCodeInfo, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = load ptr, ptr %4, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.TA_RetCodeInfo, ptr %36, i32 0, i32 0
  store ptr %35, ptr %37, align 8, !tbaa !11
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds [19 x %struct.TA_InternalRetCodeInfo], ptr @retCodeInfoTable, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.TA_InternalRetCodeInfo, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.TA_RetCodeInfo, ptr %43, i32 0, i32 1
  store ptr %42, ptr %44, align 8, !tbaa !13
  store i32 1, ptr %6, align 4
  br label %64

45:                                               ; preds = %22
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = add i32 %47, 1
  store i32 %48, ptr %5, align 4, !tbaa !5
  br label %18, !llvm.loop !18

49:                                               ; preds = %18
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds [19 x %struct.TA_InternalRetCodeInfo], ptr @retCodeInfoTable, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.TA_InternalRetCodeInfo, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = load ptr, ptr %4, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.TA_RetCodeInfo, ptr %55, i32 0, i32 0
  store ptr %54, ptr %56, align 8, !tbaa !11
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds [19 x %struct.TA_InternalRetCodeInfo], ptr @retCodeInfoTable, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.TA_InternalRetCodeInfo, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !17
  %62 = load ptr, ptr %4, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.TA_RetCodeInfo, ptr %62, i32 0, i32 1
  store ptr %61, ptr %63, align 8, !tbaa !13
  store i32 0, ptr %6, align 4
  br label %64

64:                                               ; preds = %49, %30, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  %65 = load i32, ptr %6, align 4
  switch i32 %65, label %67 [
    i32 0, label %66
    i32 1, label %66
  ]

66:                                               ; preds = %64, %64
  ret void

67:                                               ; preds = %64
  unreachable
}

; 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 = !{!12, !10, i64 0}
!12 = !{!"TA_RetCodeInfo", !10, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = !{!15, !6, i64 0}
!15 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16}
!16 = !{!15, !10, i64 8}
!17 = !{!15, !10, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"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_InternalRetCodeInfo = type { i32, ptr, ptr }

@.str = external hidden unnamed_addr constant [18 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [47 x i8], align 1
@retCodeInfoTable = external hidden local_unnamed_addr global [19 x %struct.TA_InternalRetCodeInfo], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @TA_SetRetCodeInfo(i32 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = add i32 %0, -5000
  %or.cond = icmp ult i32 %3, 1000
  br i1 %or.cond, label %6, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %4 = load i32, ptr @retCodeInfoTable, align 16, !tbaa !5
  %5 = icmp eq i32 %4, %0
  br i1 %5, label %44, label %.preheader.1

6:                                                ; preds = %2
  store ptr @.str, ptr %1, align 8, !tbaa !11
  br label %49

.preheader.1:                                     ; preds = %.preheader.preheader
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 24), align 8, !tbaa !5
  %8 = icmp eq i32 %7, %0
  br i1 %8, label %44, label %.preheader.2

.preheader.2:                                     ; preds = %.preheader.1
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 48), align 16, !tbaa !5
  %10 = icmp eq i32 %9, %0
  br i1 %10, label %44, label %.preheader.3

.preheader.3:                                     ; preds = %.preheader.2
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 72), align 8, !tbaa !5
  %12 = icmp eq i32 %11, %0
  br i1 %12, label %44, label %.preheader.4

.preheader.4:                                     ; preds = %.preheader.3
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 96), align 16, !tbaa !5
  %14 = icmp eq i32 %13, %0
  br i1 %14, label %44, label %.preheader.5

.preheader.5:                                     ; preds = %.preheader.4
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 120), align 8, !tbaa !5
  %16 = icmp eq i32 %15, %0
  br i1 %16, label %44, label %.preheader.6

.preheader.6:                                     ; preds = %.preheader.5
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 144), align 16, !tbaa !5
  %18 = icmp eq i32 %17, %0
  br i1 %18, label %44, label %.preheader.7

.preheader.7:                                     ; preds = %.preheader.6
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 168), align 8, !tbaa !5
  %20 = icmp eq i32 %19, %0
  br i1 %20, label %44, label %.preheader.8

.preheader.8:                                     ; preds = %.preheader.7
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 192), align 16, !tbaa !5
  %22 = icmp eq i32 %21, %0
  br i1 %22, label %44, label %.preheader.9

.preheader.9:                                     ; preds = %.preheader.8
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 216), align 8, !tbaa !5
  %24 = icmp eq i32 %23, %0
  br i1 %24, label %44, label %.preheader.10

.preheader.10:                                    ; preds = %.preheader.9
  %25 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 240), align 16, !tbaa !5
  %26 = icmp eq i32 %25, %0
  br i1 %26, label %44, label %.preheader.11

.preheader.11:                                    ; preds = %.preheader.10
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 264), align 8, !tbaa !5
  %28 = icmp eq i32 %27, %0
  br i1 %28, label %44, label %.preheader.12

.preheader.12:                                    ; preds = %.preheader.11
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 288), align 16, !tbaa !5
  %30 = icmp eq i32 %29, %0
  br i1 %30, label %44, label %.preheader.13

.preheader.13:                                    ; preds = %.preheader.12
  %31 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 312), align 8, !tbaa !5
  %32 = icmp eq i32 %31, %0
  br i1 %32, label %44, label %.preheader.14

.preheader.14:                                    ; preds = %.preheader.13
  %33 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 336), align 16, !tbaa !5
  %34 = icmp eq i32 %33, %0
  br i1 %34, label %44, label %.preheader.15

.preheader.15:                                    ; preds = %.preheader.14
  %35 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 360), align 8, !tbaa !5
  %36 = icmp eq i32 %35, %0
  br i1 %36, label %44, label %.preheader.16

.preheader.16:                                    ; preds = %.preheader.15
  %37 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 384), align 16, !tbaa !5
  %38 = icmp eq i32 %37, %0
  br i1 %38, label %44, label %.preheader.17

.preheader.17:                                    ; preds = %.preheader.16
  %39 = load i32, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 408), align 8, !tbaa !5
  %40 = icmp eq i32 %39, %0
  br i1 %40, label %44, label %41

41:                                               ; preds = %.preheader.17
  %42 = load ptr, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 440), align 8, !tbaa !13
  store ptr %42, ptr %1, align 8, !tbaa !11
  %43 = load ptr, ptr getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 448), align 16, !tbaa !14
  br label %49

44:                                               ; preds = %.preheader.17, %.preheader.16, %.preheader.15, %.preheader.14, %.preheader.13, %.preheader.12, %.preheader.11, %.preheader.10, %.preheader.9, %.preheader.8, %.preheader.7, %.preheader.6, %.preheader.5, %.preheader.4, %.preheader.3, %.preheader.2, %.preheader.1, %.preheader.preheader
  %.lcssa = phi ptr [ @retCodeInfoTable, %.preheader.preheader ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 24), %.preheader.1 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 48), %.preheader.2 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 72), %.preheader.3 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 96), %.preheader.4 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 120), %.preheader.5 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 144), %.preheader.6 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 168), %.preheader.7 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 192), %.preheader.8 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 216), %.preheader.9 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 240), %.preheader.10 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 264), %.preheader.11 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 288), %.preheader.12 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 312), %.preheader.13 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 336), %.preheader.14 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 360), %.preheader.15 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 384), %.preheader.16 ], [ getelementptr inbounds (i8, ptr @retCodeInfoTable, i64 408), %.preheader.17 ]
  %45 = getelementptr inbounds i8, ptr %.lcssa, i64 8
  %46 = load ptr, ptr %45, align 8, !tbaa !13
  store ptr %46, ptr %1, align 8, !tbaa !11
  %47 = getelementptr inbounds i8, ptr %.lcssa, i64 16
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  br label %49

49:                                               ; preds = %41, %44, %6
  %.sink = phi ptr [ %43, %41 ], [ %48, %44 ], [ @.str.1, %6 ]
  %50 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %.sink, ptr %50, align 8, !tbaa !15
  ret void
}

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

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


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