; LLVM IR from mkmarek/forex.analytics :: lib/ta-lib/src/tools/ta_regtest/ta_test_func (test_avgdev)

; 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_Test = type { i32, i32, i32, i32, i32, i32, double, i32, i32 }
%struct.TA_History = type { i32, ptr, ptr, ptr, ptr, ptr, ptr }

@tableTest = external hidden global [3 x %struct.TA_Test], align 16
@.str = external hidden unnamed_addr constant [46 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [116 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1

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

7:                                                ; preds = %46, %1
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = zext i32 %8 to i64
  %10 = icmp ult i64 %9, 3
  br i1 %10, label %11, label %49

11:                                               ; preds = %7
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds [3 x %struct.TA_Test], ptr @tableTest, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.TA_Test, ptr %14, i32 0, i32 8
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TA_History, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %20 = icmp sgt i32 %16, %19
  br i1 %20, label %21, label %32

21:                                               ; preds = %11
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds [3 x %struct.TA_Test], ptr @tableTest, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.TA_Test, ptr %25, i32 0, i32 8
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TA_History, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !14
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef %22, i32 noundef %27, i32 noundef %30)
  store i32 120, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %50

32:                                               ; preds = %11
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [3 x %struct.TA_Test], ptr @tableTest, i64 0, i64 %35
  %37 = call i32 @do_test(ptr noundef %33, ptr noundef %36)
  store i32 %37, ptr %5, align 4, !tbaa !9
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %45

40:                                               ; preds = %32
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef %41, i32 noundef %42)
  %44 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %44, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %50

45:                                               ; preds = %32
  br label %46

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

49:                                               ; preds = %7
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %50

50:                                               ; preds = %49, %40, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %51 = load i32, ptr %2, align 4
  ret i32 %51
}

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

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @do_test(ptr noundef, ptr noundef) #0

; 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 = { "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 #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 = !{!"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}
!11 = !{!12, !10, i64 36}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !13, i64 24, !10, i64 32, !10, i64 36}
!13 = !{!"double", !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!16 = distinct !{!16, !17}
!17 = !{!"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_Test = type { i32, i32, i32, i32, i32, i32, double, i32, i32 }

@tableTest = external hidden global [3 x %struct.TA_Test], align 16
@.str = external hidden unnamed_addr constant [46 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [116 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @test_func_avgdev(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @tableTest, i64 36), align 4, !tbaa !5
  %3 = load i32, ptr %0, align 8, !tbaa !11
  %4 = icmp sgt i32 %2, %3
  br i1 %4, label %5, label %7

5:                                                ; preds = %17, %11, %1
  %.01324.lcssa.wide = phi i32 [ 0, %1 ], [ 1, %11 ], [ 2, %17 ]
  %.lcssa27 = phi i32 [ %2, %1 ], [ %12, %11 ], [ %18, %17 ]
  %.lcssa = phi i32 [ %3, %1 ], [ %13, %11 ], [ %19, %17 ]
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.1, i32 noundef %.01324.lcssa.wide, i32 noundef %.lcssa27, i32 noundef %.lcssa)
  br label %.loopexit

7:                                                ; preds = %1
  %8 = tail call i32 @do_test(ptr noundef nonnull %0, ptr noundef nonnull @tableTest)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %11, label %9

9:                                                ; preds = %21, %15, %7
  %.lcssa32 = phi i32 [ %8, %7 ], [ %16, %15 ], [ %22, %21 ]
  %.01324.lcssa30.wide = phi i32 [ 0, %7 ], [ 1, %15 ], [ 2, %21 ]
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull @.str.1, i32 noundef %.01324.lcssa30.wide, i32 noundef %.lcssa32)
  br label %.loopexit

11:                                               ; preds = %7
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @tableTest, i64 76), align 4, !tbaa !5
  %13 = load i32, ptr %0, align 8, !tbaa !11
  %14 = icmp sgt i32 %12, %13
  br i1 %14, label %5, label %15

15:                                               ; preds = %11
  %16 = tail call i32 @do_test(ptr noundef nonnull %0, ptr noundef nonnull getelementptr inbounds (i8, ptr @tableTest, i64 40))
  %.not.1 = icmp eq i32 %16, 0
  br i1 %.not.1, label %17, label %9

17:                                               ; preds = %15
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @tableTest, i64 116), align 4, !tbaa !5
  %19 = load i32, ptr %0, align 8, !tbaa !11
  %20 = icmp sgt i32 %18, %19
  br i1 %20, label %5, label %21

21:                                               ; preds = %17
  %22 = tail call i32 @do_test(ptr noundef nonnull %0, ptr noundef nonnull getelementptr inbounds (i8, ptr @tableTest, i64 80))
  %.not.2 = icmp eq i32 %22, 0
  br i1 %.not.2, label %.loopexit, label %9

.loopexit:                                        ; preds = %21, %9, %5
  %.0 = phi i32 [ 120, %5 ], [ %.lcssa32, %9 ], [ 0, %21 ]
  ret i32 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @do_test(ptr noundef, ptr noundef) local_unnamed_addr #0

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 = { nofree nounwind "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 36}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !10, i64 24, !7, i64 32, !7, i64 36}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"", !7, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48}
!13 = !{!"any pointer", !8, i64 0}


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