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

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

@tableTest = external hidden global [53 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
@tableRefTest = external hidden global [9 x %struct.TA_RefTest], align 16
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @test_func_minmax(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, 53
  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 [53 x %struct.TA_Test], ptr @tableTest, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.TA_Test, ptr %14, i32 0, i32 9
  %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 [53 x %struct.TA_Test], ptr @tableTest, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.TA_Test, ptr %25, i32 0, i32 9
  %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 %78

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 [53 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 %78

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 %4, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %74, %49
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = zext i32 %51 to i64
  %53 = icmp ult i64 %52, 9
  br i1 %53, label %54, label %77

54:                                               ; preds = %50
  %55 = load i32, ptr %4, align 4, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds [9 x %struct.TA_RefTest], ptr @tableRefTest, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.TA_RefTest, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 16, !tbaa !18
  %60 = load i32, ptr %4, align 4, !tbaa !9
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds [9 x %struct.TA_RefTest], ptr @tableRefTest, i64 0, i64 %61
  %63 = getelementptr inbounds %struct.TA_RefTest, ptr %62, i32 0, i32 1
  %64 = load i32, ptr %63, align 8, !tbaa !20
  %65 = call i32 @testCompareToReference(ptr noundef %59, i32 noundef %64)
  store i32 %65, ptr %5, align 4, !tbaa !9
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %73

68:                                               ; preds = %54
  %69 = load i32, ptr %4, align 4, !tbaa !9
  %70 = load i32, ptr %5, align 4, !tbaa !9
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef %69, i32 noundef %70)
  %72 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %72, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %78

73:                                               ; preds = %54
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %4, align 4, !tbaa !9
  %76 = add i32 %75, 1
  store i32 %76, ptr %4, align 4, !tbaa !9
  br label %50, !llvm.loop !21

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

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

; 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: nounwind uwtable
declare hidden i32 @testCompareToReference(ptr noundef, i32 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 44}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !13, i64 32, !10, i64 40, !10, i64 44}
!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"}
!18 = !{!19, !6, i64 0}
!19 = !{!"", !6, i64 0, !10, i64 8}
!20 = !{!19, !10, i64 8}
!21 = distinct !{!21, !17}


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

@tableTest = external hidden global [53 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
@tableRefTest = external hidden local_unnamed_addr global [9 x %struct.TA_RefTest], align 16
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @test_func_minmax(ptr noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %1, %16
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %16 ]
  %3 = getelementptr inbounds [53 x %struct.TA_Test], ptr @tableTest, i64 0, i64 %indvars.iv
  %4 = getelementptr inbounds i8, ptr %3, i64 44
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = load i32, ptr %0, align 8, !tbaa !11
  %7 = icmp sgt i32 %5, %6
  br i1 %7, label %8, label %11

8:                                                ; preds = %2
  %9 = trunc nuw nsw i64 %indvars.iv to i32
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.1, i32 noundef %9, i32 noundef %5, i32 noundef %6)
  br label %.loopexit

11:                                               ; preds = %2
  %12 = tail call i32 @do_test(ptr noundef nonnull %0, ptr noundef nonnull %3)
  %.not28 = icmp eq i32 %12, 0
  br i1 %.not28, label %16, label %13

13:                                               ; preds = %11
  %14 = trunc nuw nsw i64 %indvars.iv to i32
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull @.str.1, i32 noundef %14, i32 noundef %12)
  br label %.loopexit

16:                                               ; preds = %11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 53
  br i1 %exitcond.not, label %.preheader.preheader, label %2, !llvm.loop !14

.preheader.preheader:                             ; preds = %16
  %17 = load ptr, ptr @tableRefTest, align 16, !tbaa !16
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 8), align 8, !tbaa !18
  %19 = tail call i32 @testCompareToReference(ptr noundef %17, i32 noundef %18)
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %.preheader.1, label %20

20:                                               ; preds = %.preheader.8, %.preheader.7, %.preheader.6, %.preheader.5, %.preheader.4, %.preheader.3, %.preheader.2, %.preheader.1, %.preheader.preheader
  %.138.lcssa.wide = phi i32 [ 0, %.preheader.preheader ], [ 1, %.preheader.1 ], [ 2, %.preheader.2 ], [ 3, %.preheader.3 ], [ 4, %.preheader.4 ], [ 5, %.preheader.5 ], [ 6, %.preheader.6 ], [ 7, %.preheader.7 ], [ 8, %.preheader.8 ]
  %.lcssa = phi i32 [ %19, %.preheader.preheader ], [ %24, %.preheader.1 ], [ %27, %.preheader.2 ], [ %30, %.preheader.3 ], [ %33, %.preheader.4 ], [ %36, %.preheader.5 ], [ %39, %.preheader.6 ], [ %42, %.preheader.7 ], [ %45, %.preheader.8 ]
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull @.str.1, i32 noundef %.138.lcssa.wide, i32 noundef %.lcssa)
  br label %.loopexit

.preheader.1:                                     ; preds = %.preheader.preheader
  %22 = load ptr, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 16), align 16, !tbaa !16
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 24), align 8, !tbaa !18
  %24 = tail call i32 @testCompareToReference(ptr noundef %22, i32 noundef %23)
  %.not.1 = icmp eq i32 %24, 0
  br i1 %.not.1, label %.preheader.2, label %20

.preheader.2:                                     ; preds = %.preheader.1
  %25 = load ptr, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 32), align 16, !tbaa !16
  %26 = load i32, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 40), align 8, !tbaa !18
  %27 = tail call i32 @testCompareToReference(ptr noundef %25, i32 noundef %26)
  %.not.2 = icmp eq i32 %27, 0
  br i1 %.not.2, label %.preheader.3, label %20

.preheader.3:                                     ; preds = %.preheader.2
  %28 = load ptr, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 48), align 16, !tbaa !16
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 56), align 8, !tbaa !18
  %30 = tail call i32 @testCompareToReference(ptr noundef %28, i32 noundef %29)
  %.not.3 = icmp eq i32 %30, 0
  br i1 %.not.3, label %.preheader.4, label %20

.preheader.4:                                     ; preds = %.preheader.3
  %31 = load ptr, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 64), align 16, !tbaa !16
  %32 = load i32, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 72), align 8, !tbaa !18
  %33 = tail call i32 @testCompareToReference(ptr noundef %31, i32 noundef %32)
  %.not.4 = icmp eq i32 %33, 0
  br i1 %.not.4, label %.preheader.5, label %20

.preheader.5:                                     ; preds = %.preheader.4
  %34 = load ptr, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 80), align 16, !tbaa !16
  %35 = load i32, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 88), align 8, !tbaa !18
  %36 = tail call i32 @testCompareToReference(ptr noundef %34, i32 noundef %35)
  %.not.5 = icmp eq i32 %36, 0
  br i1 %.not.5, label %.preheader.6, label %20

.preheader.6:                                     ; preds = %.preheader.5
  %37 = load ptr, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 96), align 16, !tbaa !16
  %38 = load i32, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 104), align 8, !tbaa !18
  %39 = tail call i32 @testCompareToReference(ptr noundef %37, i32 noundef %38)
  %.not.6 = icmp eq i32 %39, 0
  br i1 %.not.6, label %.preheader.7, label %20

.preheader.7:                                     ; preds = %.preheader.6
  %40 = load ptr, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 112), align 16, !tbaa !16
  %41 = load i32, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 120), align 8, !tbaa !18
  %42 = tail call i32 @testCompareToReference(ptr noundef %40, i32 noundef %41)
  %.not.7 = icmp eq i32 %42, 0
  br i1 %.not.7, label %.preheader.8, label %20

.preheader.8:                                     ; preds = %.preheader.7
  %43 = load ptr, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 128), align 16, !tbaa !16
  %44 = load i32, ptr getelementptr inbounds (i8, ptr @tableRefTest, i64 136), align 8, !tbaa !18
  %45 = tail call i32 @testCompareToReference(ptr noundef %43, i32 noundef %44)
  %.not.8 = icmp eq i32 %45, 0
  br i1 %.not.8, label %.loopexit, label %20

.loopexit:                                        ; preds = %.preheader.8, %20, %13, %8
  %.021 = phi i32 [ 120, %8 ], [ %12, %13 ], [ %.lcssa, %20 ], [ 0, %.preheader.8 ]
  ret i32 %.021
}

; 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

; Function Attrs: nounwind uwtable
declare hidden i32 @testCompareToReference(ptr noundef, i32 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 44}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !10, i64 32, !7, i64 40, !7, i64 44}
!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}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !13, i64 0}
!17 = !{!"", !13, i64 0, !7, i64 8}
!18 = !{!17, !7, i64 8}


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