; 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_counter = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [80 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [64 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_basic_processing_thread_report() #0 {
  %1 = alloca i64, align 8
  %2 = 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
  store i64 0, ptr %1, align 8, !tbaa !5
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %14, %0
  br label %4

4:                                                ; preds = %3
  call void @tm_thread_sleep(i32 noundef 30)
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = add i64 %5, 30
  store i64 %6, ptr %2, align 8, !tbaa !5
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %7)
  %9 = load i64, ptr @tm_basic_processing_counter, align 8, !tbaa !5
  %10 = load i64, ptr %1, align 8, !tbaa !5
  %11 = icmp eq i64 %9, %10
  br i1 %11, label %12, label %14

12:                                               ; preds = %4
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %14

14:                                               ; preds = %12, %4
  %15 = load i64, ptr @tm_basic_processing_counter, align 8, !tbaa !5
  %16 = load i64, ptr %1, align 8, !tbaa !5
  %17 = sub i64 %15, %16
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %17)
  %19 = load i64, ptr @tm_basic_processing_counter, align 8, !tbaa !5
  store i64 %19, ptr %1, align 8, !tbaa !5
  br label %3
}

; 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_basic_processing_counter = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [80 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [64 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_basic_processing_thread_report() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %8, %0
  %.04 = phi i64 [ 0, %0 ], [ %12, %8 ]
  %.0 = phi i64 [ 0, %0 ], [ %2, %8 ]
  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_basic_processing_counter, align 8, !tbaa !5
  %5 = icmp eq i64 %4, %.04
  br i1 %5, label %6, label %8

6:                                                ; preds = %1
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %.pre = load i64, ptr @tm_basic_processing_counter, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %6, %1
  %9 = phi i64 [ %.pre, %6 ], [ %4, %1 ]
  %10 = sub i64 %9, %.04
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %10)
  %12 = load i64, ptr @tm_basic_processing_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: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass