; LLVM IR from eclipse-threadx/threadx :: utility/benchmarks/thread_metric (tm_interrupt_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_thread_0_counter = external dso_local global i64, align 8
@tm_interrupt_handler_counter = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [70 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_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 %2, align 8, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %5

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

6:                                                ; preds = %5
  call void @tm_thread_sleep(i32 noundef 30)
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = add i64 %7, 30
  store i64 %8, ptr %3, align 8, !tbaa !5
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %9)
  %11 = load i64, ptr @tm_interrupt_thread_0_counter, align 8, !tbaa !5
  %12 = load i64, ptr @tm_interrupt_handler_counter, align 8, !tbaa !5
  %13 = add i64 %11, %12
  store i64 %13, ptr %1, align 8, !tbaa !5
  %14 = load i64, ptr %1, align 8, !tbaa !5
  %15 = udiv i64 %14, 2
  store i64 %15, ptr %4, align 8, !tbaa !5
  %16 = load i64, ptr @tm_interrupt_thread_0_counter, align 8, !tbaa !5
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = sub i64 %17, 1
  %19 = icmp ult i64 %16, %18
  br i1 %19, label %35, label %20

20:                                               ; preds = %6
  %21 = load i64, ptr @tm_interrupt_thread_0_counter, align 8, !tbaa !5
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = add i64 %22, 1
  %24 = icmp ugt i64 %21, %23
  br i1 %24, label %35, label %25

25:                                               ; preds = %20
  %26 = load i64, ptr @tm_interrupt_handler_counter, align 8, !tbaa !5
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = sub i64 %27, 1
  %29 = icmp ult i64 %26, %28
  br i1 %29, label %35, label %30

30:                                               ; preds = %25
  %31 = load i64, ptr @tm_interrupt_handler_counter, align 8, !tbaa !5
  %32 = load i64, ptr %4, align 8, !tbaa !5
  %33 = add i64 %32, 1
  %34 = icmp ugt i64 %31, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %30, %25, %20, %6
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %37

37:                                               ; preds = %35, %30
  %38 = load i64, ptr @tm_interrupt_handler_counter, align 8, !tbaa !5
  %39 = load i64, ptr %2, align 8, !tbaa !5
  %40 = sub i64 %38, %39
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %40)
  %42 = load i64, ptr @tm_interrupt_handler_counter, align 8, !tbaa !5
  store i64 %42, ptr %2, 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_thread_0_counter = external dso_local local_unnamed_addr global i64, align 8
@tm_interrupt_handler_counter = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [70 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_thread_report() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %17, %0
  %.08 = phi i64 [ 0, %0 ], [ %2, %17 ]
  %.0 = phi i64 [ 0, %0 ], [ %21, %17 ]
  tail call void @tm_thread_sleep(i32 noundef 30) #3
  %2 = add i64 %.08, 30
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %2)
  %4 = load i64, ptr @tm_interrupt_thread_0_counter, align 8, !tbaa !5
  %5 = load i64, ptr @tm_interrupt_handler_counter, align 8, !tbaa !5
  %6 = add i64 %5, %4
  %7 = lshr i64 %6, 1
  %8 = add nsw i64 %7, -1
  %9 = icmp ult i64 %4, %8
  br i1 %9, label %15, label %10

10:                                               ; preds = %1
  %11 = add nuw i64 %7, 1
  %12 = icmp ugt i64 %4, %11
  %13 = icmp ult i64 %5, %8
  %or.cond = or i1 %12, %13
  %14 = icmp ugt i64 %5, %11
  %or.cond13 = or i1 %14, %or.cond
  br i1 %or.cond13, label %15, label %17

15:                                               ; preds = %10, %1
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %.pre = load i64, ptr @tm_interrupt_handler_counter, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %10, %15
  %18 = phi i64 [ %5, %10 ], [ %.pre, %15 ]
  %19 = sub i64 %18, %.0
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %19)
  %21 = load i64, ptr @tm_interrupt_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