; LLVM IR from eclipse-threadx/threadx :: utility/benchmarks/thread_metric (tm_basic_processing_test)

; 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"

@tm_basic_processing_array = external dso_local global [1024 x i64], align 16
@tm_basic_processing_counter = external dso_local global i64, align 8

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

2:                                                ; preds = %9, %0
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 1024
  br i1 %4, label %5, label %12

5:                                                ; preds = %2
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %7
  store volatile i64 0, ptr %8, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %5
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr %1, align 4, !tbaa !5
  br label %2, !llvm.loop !11

12:                                               ; preds = %2
  br label %13

13:                                               ; preds = %36, %12
  br label %14

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

15:                                               ; preds = %33, %14
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 1024
  br i1 %17, label %18, label %36

18:                                               ; preds = %15
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %20
  %22 = load volatile i64, ptr %21, align 8, !tbaa !9
  %23 = load i64, ptr @tm_basic_processing_counter, align 8, !tbaa !9
  %24 = add i64 %22, %23
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %26
  %28 = load volatile i64, ptr %27, align 8, !tbaa !9
  %29 = xor i64 %24, %28
  %30 = load i32, ptr %1, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %31
  store volatile i64 %29, ptr %32, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %18
  %34 = load i32, ptr %1, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %1, align 4, !tbaa !5
  br label %15, !llvm.loop !13

36:                                               ; preds = %15
  %37 = load i64, ptr @tm_basic_processing_counter, align 8, !tbaa !9
  %38 = add i64 %37, 1
  store i64 %38, ptr @tm_basic_processing_counter, align 8, !tbaa !9
  br label %13
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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"

@tm_basic_processing_array = external dso_local global [1024 x i64], align 16
@tm_basic_processing_counter = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: nofree norecurse noreturn nounwind memory(readwrite, argmem: none) uwtable
define dso_local void @tm_basic_processing_thread_0_entry() local_unnamed_addr #0 {
  br label %1

.preheader:                                       ; preds = %1
  %tm_basic_processing_counter.promoted = load i64, ptr @tm_basic_processing_counter, align 8, !tbaa !5
  br label %10

1:                                                ; preds = %1, %0
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next.7, %1 ]
  %2 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %indvars.iv
  store volatile i64 0, ptr %2, align 16, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %3 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %indvars.iv.next
  store volatile i64 0, ptr %3, align 8, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %4 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %indvars.iv.next.1
  store volatile i64 0, ptr %4, align 16, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %5 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %indvars.iv.next.2
  store volatile i64 0, ptr %5, align 8, !tbaa !5
  %indvars.iv.next.3 = or disjoint i64 %indvars.iv, 4
  %6 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %indvars.iv.next.3
  store volatile i64 0, ptr %6, align 16, !tbaa !5
  %indvars.iv.next.4 = or disjoint i64 %indvars.iv, 5
  %7 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %indvars.iv.next.4
  store volatile i64 0, ptr %7, align 8, !tbaa !5
  %indvars.iv.next.5 = or disjoint i64 %indvars.iv, 6
  %8 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %indvars.iv.next.5
  store volatile i64 0, ptr %8, align 16, !tbaa !5
  %indvars.iv.next.6 = or disjoint i64 %indvars.iv, 7
  %9 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %indvars.iv.next.6
  store volatile i64 0, ptr %9, align 8, !tbaa !5
  %indvars.iv.next.7 = add nuw nsw i64 %indvars.iv, 8
  %exitcond.not.7 = icmp eq i64 %indvars.iv.next.7, 1024
  br i1 %exitcond.not.7, label %.preheader, label %1, !llvm.loop !9

10:                                               ; preds = %.preheader, %23
  %11 = phi i64 [ %tm_basic_processing_counter.promoted, %.preheader ], [ %24, %23 ]
  br label %12

12:                                               ; preds = %12, %10
  %indvars.iv11 = phi i64 [ 0, %10 ], [ %indvars.iv.next12.1, %12 ]
  %13 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %indvars.iv11
  %14 = load volatile i64, ptr %13, align 16, !tbaa !5
  %15 = add i64 %11, %14
  %16 = load volatile i64, ptr %13, align 16, !tbaa !5
  %17 = xor i64 %15, %16
  store volatile i64 %17, ptr %13, align 16, !tbaa !5
  %indvars.iv.next12 = or disjoint i64 %indvars.iv11, 1
  %18 = getelementptr inbounds [1024 x i64], ptr @tm_basic_processing_array, i64 0, i64 %indvars.iv.next12
  %19 = load volatile i64, ptr %18, align 8, !tbaa !5
  %20 = add i64 %11, %19
  %21 = load volatile i64, ptr %18, align 8, !tbaa !5
  %22 = xor i64 %20, %21
  store volatile i64 %22, ptr %18, align 8, !tbaa !5
  %indvars.iv.next12.1 = add nuw nsw i64 %indvars.iv11, 2
  %exitcond14.not.1 = icmp eq i64 %indvars.iv.next12.1, 1024
  br i1 %exitcond14.not.1, label %23, label %12, !llvm.loop !11

23:                                               ; preds = %12
  %24 = add i64 %11, 1
  store i64 %24, ptr @tm_basic_processing_counter, align 8, !tbaa !5
  br label %10
}

attributes #0 = { nofree norecurse noreturn nounwind memory(readwrite, argmem: 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass