; LLVM IR from eclipse-threadx/threadx :: utility/benchmarks/thread_metric (tm_interrupt_preemption_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_interrupt_preemption_thread_0_counter = external dso_local global i64, align 8
@tm_interrupt_preemption_thread_1_counter = external dso_local global i64, align 8
@tm_interrupt_preemption_handler_counter = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [81 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @tm_interrupt_preemption_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 = %49, %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_interrupt_preemption_thread_0_counter, align 8, !tbaa !5
  %12 = load i64, ptr @tm_interrupt_preemption_thread_1_counter, align 8, !tbaa !5
  %13 = add i64 %11, %12
  %14 = load i64, ptr @tm_interrupt_preemption_handler_counter, align 8, !tbaa !5
  %15 = add i64 %13, %14
  store i64 %15, ptr %1, align 8, !tbaa !5
  %16 = load i64, ptr %1, align 8, !tbaa !5
  %17 = udiv i64 %16, 3
  store i64 %17, ptr %4, align 8, !tbaa !5
  %18 = load i64, ptr @tm_interrupt_preemption_thread_0_counter, align 8, !tbaa !5
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = sub i64 %19, 1
  %21 = icmp ult i64 %18, %20
  br i1 %21, label %47, label %22

22:                                               ; preds = %6
  %23 = load i64, ptr @tm_interrupt_preemption_thread_0_counter, align 8, !tbaa !5
  %24 = load i64, ptr %4, align 8, !tbaa !5
  %25 = add i64 %24, 1
  %26 = icmp ugt i64 %23, %25
  br i1 %26, label %47, label %27

27:                                               ; preds = %22
  %28 = load i64, ptr @tm_interrupt_preemption_thread_1_counter, align 8, !tbaa !5
  %29 = load i64, ptr %4, align 8, !tbaa !5
  %30 = sub i64 %29, 1
  %31 = icmp ult i64 %28, %30
  br i1 %31, label %47, label %32

32:                                               ; preds = %27
  %33 = load i64, ptr @tm_interrupt_preemption_thread_1_counter, align 8, !tbaa !5
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = add i64 %34, 1
  %36 = icmp ugt i64 %33, %35
  br i1 %36, label %47, label %37

37:                                               ; preds = %32
  %38 = load i64, ptr @tm_interrupt_preemption_handler_counter, align 8, !tbaa !5
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = sub i64 %39, 1
  %41 = icmp ult i64 %38, %40
  br i1 %41, label %47, label %42

42:                                               ; preds = %37
  %43 = load i64, ptr @tm_interrupt_preemption_handler_counter, align 8, !tbaa !5
  %44 = load i64, ptr %4, align 8, !tbaa !5
  %45 = add i64 %44, 1
  %46 = icmp ugt i64 %43, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %42, %37, %32, %27, %22, %6
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %49

49:                                               ; preds = %47, %42
  %50 = load i64, ptr @tm_interrupt_preemption_handler_counter, align 8, !tbaa !5
  %51 = load i64, ptr %3, align 8, !tbaa !5
  %52 = sub i64 %50, %51
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %52)
  %54 = load i64, ptr @tm_interrupt_preemption_handler_counter, align 8, !tbaa !5
  store i64 %54, 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_interrupt_preemption_thread_0_counter = external dso_local local_unnamed_addr global i64, align 8
@tm_interrupt_preemption_thread_1_counter = external dso_local local_unnamed_addr global i64, align 8
@tm_interrupt_preemption_handler_counter = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [81 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1

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

1:                                                ; preds = %21, %0
  %.010 = phi i64 [ 0, %0 ], [ %25, %21 ]
  %.0 = phi i64 [ 0, %0 ], [ %2, %21 ]
  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_interrupt_preemption_thread_0_counter, align 8, !tbaa !5
  %5 = load i64, ptr @tm_interrupt_preemption_thread_1_counter, align 8, !tbaa !5
  %6 = add i64 %5, %4
  %7 = load i64, ptr @tm_interrupt_preemption_handler_counter, align 8, !tbaa !5
  %8 = add i64 %6, %7
  %9 = udiv i64 %8, 3
  %10 = add nsw i64 %9, -1
  %11 = icmp ult i64 %4, %10
  br i1 %11, label %19, label %12

12:                                               ; preds = %1
  %13 = add nuw nsw i64 %9, 1
  %14 = icmp ugt i64 %4, %13
  %15 = icmp ult i64 %5, %10
  %or.cond = or i1 %14, %15
  %16 = icmp ugt i64 %5, %13
  %or.cond16 = or i1 %16, %or.cond
  %17 = icmp ult i64 %7, %10
  %or.cond17 = or i1 %17, %or.cond16
  %18 = icmp ugt i64 %7, %13
  %or.cond18 = or i1 %18, %or.cond17
  br i1 %or.cond18, label %19, label %21

19:                                               ; preds = %12, %1
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %.pre = load i64, ptr @tm_interrupt_preemption_handler_counter, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %12, %19
  %22 = phi i64 [ %7, %12 ], [ %.pre, %19 ]
  %23 = sub i64 %22, %.010
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %23)
  %25 = load i64, ptr @tm_interrupt_preemption_handler_counter, align 8, !tbaa !5
  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,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass