; LLVM IR from eclipse-threadx/threadx :: utility/benchmarks/thread_metric (tm_cooperative_scheduling_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_cooperative_thread_0_counter = external dso_local global i64, align 8
@tm_cooperative_thread_1_counter = external dso_local global i64, align 8
@tm_cooperative_thread_2_counter = external dso_local global i64, align 8
@tm_cooperative_thread_3_counter = external dso_local global i64, align 8
@tm_cooperative_thread_4_counter = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [72 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [109 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [26 x i8], align 1

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

5:                                                ; preds = %83, %0
  br label %6

6:                                                ; preds = %5
  call void @tm_thread_sleep(i32 noundef 30)
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = add i64 %7, 30
  store i64 %8, ptr %2, align 8, !tbaa !5
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %9)
  %11 = load i64, ptr @tm_cooperative_thread_0_counter, align 8, !tbaa !5
  %12 = load i64, ptr @tm_cooperative_thread_1_counter, align 8, !tbaa !5
  %13 = add i64 %11, %12
  %14 = load i64, ptr @tm_cooperative_thread_2_counter, align 8, !tbaa !5
  %15 = add i64 %13, %14
  %16 = load i64, ptr @tm_cooperative_thread_3_counter, align 8, !tbaa !5
  %17 = add i64 %15, %16
  %18 = load i64, ptr @tm_cooperative_thread_4_counter, align 8, !tbaa !5
  %19 = add i64 %17, %18
  store i64 %19, ptr %1, align 8, !tbaa !5
  %20 = load i64, ptr %1, align 8, !tbaa !5
  %21 = udiv i64 %20, 5
  store i64 %21, ptr %4, align 8, !tbaa !5
  %22 = load i64, ptr @tm_cooperative_thread_0_counter, align 8, !tbaa !5
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %22)
  %24 = load i64, ptr @tm_cooperative_thread_1_counter, align 8, !tbaa !5
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %24)
  %26 = load i64, ptr @tm_cooperative_thread_2_counter, align 8, !tbaa !5
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %26)
  %28 = load i64, ptr @tm_cooperative_thread_3_counter, align 8, !tbaa !5
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %28)
  %30 = load i64, ptr @tm_cooperative_thread_4_counter, align 8, !tbaa !5
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i64 noundef %30)
  %32 = load i64, ptr @tm_cooperative_thread_0_counter, align 8, !tbaa !5
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = sub i64 %33, 1
  %35 = icmp ult i64 %32, %34
  br i1 %35, label %81, label %36

36:                                               ; preds = %6
  %37 = load i64, ptr @tm_cooperative_thread_0_counter, align 8, !tbaa !5
  %38 = load i64, ptr %4, align 8, !tbaa !5
  %39 = add i64 %38, 1
  %40 = icmp ugt i64 %37, %39
  br i1 %40, label %81, label %41

41:                                               ; preds = %36
  %42 = load i64, ptr @tm_cooperative_thread_1_counter, align 8, !tbaa !5
  %43 = load i64, ptr %4, align 8, !tbaa !5
  %44 = sub i64 %43, 1
  %45 = icmp ult i64 %42, %44
  br i1 %45, label %81, label %46

46:                                               ; preds = %41
  %47 = load i64, ptr @tm_cooperative_thread_1_counter, align 8, !tbaa !5
  %48 = load i64, ptr %4, align 8, !tbaa !5
  %49 = add i64 %48, 1
  %50 = icmp ugt i64 %47, %49
  br i1 %50, label %81, label %51

51:                                               ; preds = %46
  %52 = load i64, ptr @tm_cooperative_thread_2_counter, align 8, !tbaa !5
  %53 = load i64, ptr %4, align 8, !tbaa !5
  %54 = sub i64 %53, 1
  %55 = icmp ult i64 %52, %54
  br i1 %55, label %81, label %56

56:                                               ; preds = %51
  %57 = load i64, ptr @tm_cooperative_thread_2_counter, align 8, !tbaa !5
  %58 = load i64, ptr %4, align 8, !tbaa !5
  %59 = add i64 %58, 1
  %60 = icmp ugt i64 %57, %59
  br i1 %60, label %81, label %61

61:                                               ; preds = %56
  %62 = load i64, ptr @tm_cooperative_thread_3_counter, align 8, !tbaa !5
  %63 = load i64, ptr %4, align 8, !tbaa !5
  %64 = sub i64 %63, 1
  %65 = icmp ult i64 %62, %64
  br i1 %65, label %81, label %66

66:                                               ; preds = %61
  %67 = load i64, ptr @tm_cooperative_thread_3_counter, align 8, !tbaa !5
  %68 = load i64, ptr %4, align 8, !tbaa !5
  %69 = add i64 %68, 1
  %70 = icmp ugt i64 %67, %69
  br i1 %70, label %81, label %71

71:                                               ; preds = %66
  %72 = load i64, ptr @tm_cooperative_thread_4_counter, align 8, !tbaa !5
  %73 = load i64, ptr %4, align 8, !tbaa !5
  %74 = sub i64 %73, 1
  %75 = icmp ult i64 %72, %74
  br i1 %75, label %81, label %76

76:                                               ; preds = %71
  %77 = load i64, ptr @tm_cooperative_thread_4_counter, align 8, !tbaa !5
  %78 = load i64, ptr %4, align 8, !tbaa !5
  %79 = add i64 %78, 1
  %80 = icmp ugt i64 %77, %79
  br i1 %80, label %81, label %83

81:                                               ; preds = %76, %71, %66, %61, %56, %51, %46, %41, %36, %6
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  br label %83

83:                                               ; preds = %81, %76
  %84 = load i64, ptr %1, align 8, !tbaa !5
  %85 = load i64, ptr %3, align 8, !tbaa !5
  %86 = sub i64 %84, %85
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, i64 noundef %86)
  %88 = load i64, ptr %1, align 8, !tbaa !5
  store i64 %88, ptr %3, align 8, !tbaa !5
  br label %5
}

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

declare void @tm_thread_sleep(i32 noundef) #2

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

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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; 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_cooperative_thread_0_counter = external dso_local local_unnamed_addr global i64, align 8
@tm_cooperative_thread_1_counter = external dso_local local_unnamed_addr global i64, align 8
@tm_cooperative_thread_2_counter = external dso_local local_unnamed_addr global i64, align 8
@tm_cooperative_thread_3_counter = external dso_local local_unnamed_addr global i64, align 8
@tm_cooperative_thread_4_counter = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [72 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [109 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
define dso_local void @tm_cooperative_thread_report() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %47, %0
  %.016 = phi i64 [ 0, %0 ], [ %12, %47 ]
  %.0 = phi i64 [ 0, %0 ], [ %2, %47 ]
  tail call void @tm_thread_sleep(i32 noundef 30) #3
  %2 = add i64 %.0, 30
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %2)
  %4 = load i64, ptr @tm_cooperative_thread_0_counter, align 8, !tbaa !5
  %5 = load i64, ptr @tm_cooperative_thread_1_counter, align 8, !tbaa !5
  %6 = add i64 %5, %4
  %7 = load i64, ptr @tm_cooperative_thread_2_counter, align 8, !tbaa !5
  %8 = add i64 %6, %7
  %9 = load i64, ptr @tm_cooperative_thread_3_counter, align 8, !tbaa !5
  %10 = add i64 %8, %9
  %11 = load i64, ptr @tm_cooperative_thread_4_counter, align 8, !tbaa !5
  %12 = add i64 %10, %11
  %13 = udiv i64 %12, 5
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %4)
  %15 = load i64, ptr @tm_cooperative_thread_1_counter, align 8, !tbaa !5
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %15)
  %17 = load i64, ptr @tm_cooperative_thread_2_counter, align 8, !tbaa !5
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %17)
  %19 = load i64, ptr @tm_cooperative_thread_3_counter, align 8, !tbaa !5
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %19)
  %21 = load i64, ptr @tm_cooperative_thread_4_counter, align 8, !tbaa !5
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i64 noundef %21)
  %23 = load i64, ptr @tm_cooperative_thread_0_counter, align 8, !tbaa !5
  %24 = add nsw i64 %13, -1
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %45, label %26

26:                                               ; preds = %1
  %27 = add nuw nsw i64 %13, 1
  %28 = icmp ugt i64 %23, %27
  br i1 %28, label %45, label %29

29:                                               ; preds = %26
  %30 = load i64, ptr @tm_cooperative_thread_1_counter, align 8, !tbaa !5
  %31 = icmp ult i64 %30, %24
  %32 = icmp ugt i64 %30, %27
  %or.cond = or i1 %31, %32
  br i1 %or.cond, label %45, label %33

33:                                               ; preds = %29
  %34 = load i64, ptr @tm_cooperative_thread_2_counter, align 8, !tbaa !5
  %35 = icmp ult i64 %34, %24
  %36 = icmp ugt i64 %34, %27
  %or.cond24 = or i1 %35, %36
  br i1 %or.cond24, label %45, label %37

37:                                               ; preds = %33
  %38 = load i64, ptr @tm_cooperative_thread_3_counter, align 8, !tbaa !5
  %39 = icmp ult i64 %38, %24
  %40 = icmp ugt i64 %38, %27
  %or.cond25 = or i1 %39, %40
  br i1 %or.cond25, label %45, label %41

41:                                               ; preds = %37
  %42 = load i64, ptr @tm_cooperative_thread_4_counter, align 8, !tbaa !5
  %43 = icmp ult i64 %42, %24
  %44 = icmp ugt i64 %42, %27
  %or.cond26 = or i1 %43, %44
  br i1 %or.cond26, label %45, label %47

45:                                               ; preds = %41, %37, %33, %29, %26, %1
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  br label %47

47:                                               ; preds = %41, %45
  %48 = sub i64 %12, %.016
  %49 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, i64 noundef %48)
  br label %1
}

declare void @tm_thread_sleep(i32 noundef) local_unnamed_addr #1

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

attributes #0 = { noreturn 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 = { "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 #2 = { 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" }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass