; LLVM IR from mitdbg/deneva :: system/abort_thread.ll (ZN11AbortThread3runEv)

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

%class.AbortQueue = type { %"class.std::priority_queue", %union.pthread_mutex_t }
%"class.std::priority_queue" = type <{ %"class.std::vector", [8 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<abort_entry *, std::allocator<abort_entry *>>::_Vector_impl" }
%"struct.std::_Vector_base<abort_entry *, std::allocator<abort_entry *>>::_Vector_impl" = type { %"struct.std::_Vector_base<abort_entry *, std::allocator<abort_entry *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<abort_entry *, std::allocator<abort_entry *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%class.Thread = type { ptr, i64, i64, ptr, %class.myrand, i64, i64, i64 }
%class.myrand = type { i64 }

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@simulation = external global ptr, align 8
@abort_queue = external global %class.AbortQueue, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11AbortThread3runEv(ptr noundef nonnull align 8 dereferenceable(64) %0) unnamed_addr #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  call void @_ZN6Thread6tsetupEv(ptr noundef nonnull align 8 dereferenceable(64) %3)
  %4 = getelementptr inbounds %class.Thread, ptr %3, i32 0, i32 1
  %5 = load i64, ptr %4, align 8, !tbaa !9
  %6 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %5)
  br label %7

7:                                                ; preds = %11, %1
  %8 = load ptr, ptr @simulation, align 8, !tbaa !5
  %9 = call noundef zeroext i1 @_ZN10SimManager7is_doneEv(ptr noundef nonnull align 8 dereferenceable(96) %8)
  %10 = xor i1 %9, true
  br i1 %10, label %11, label %13

11:                                               ; preds = %7
  call void @_ZN6Thread9heartbeatEv(ptr noundef nonnull align 8 dereferenceable(64) %3)
  %12 = call noundef i64 @_ZN6Thread10get_thd_idEv(ptr noundef nonnull align 8 dereferenceable(64) %3)
  call void @_ZN10AbortQueue7processEm(ptr noundef nonnull align 8 dereferenceable(72) @abort_queue, i64 noundef %12)
  br label %7, !llvm.loop !13

13:                                               ; preds = %7
  ret i32 6
}

declare void @_ZN6Thread6tsetupEv(ptr noundef nonnull align 8 dereferenceable(64)) #1

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

declare noundef zeroext i1 @_ZN10SimManager7is_doneEv(ptr noundef nonnull align 8 dereferenceable(96)) #1

declare void @_ZN6Thread9heartbeatEv(ptr noundef nonnull align 8 dereferenceable(64)) #1

declare void @_ZN10AbortQueue7processEm(ptr noundef nonnull align 8 dereferenceable(72), i64 noundef) #1

declare noundef i64 @_ZN6Thread10get_thd_idEv(ptr noundef nonnull align 8 dereferenceable(64)) #1

attributes #0 = { mustprogress 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" }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"_ZTS6Thread", !11, i64 8, !11, i64 16, !6, i64 24, !12, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTS6myrand", !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

%class.AbortQueue = type { %"class.std::priority_queue", %union.pthread_mutex_t }
%"class.std::priority_queue" = type <{ %"class.std::vector", [8 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<abort_entry *, std::allocator<abort_entry *>>::_Vector_impl" }
%"struct.std::_Vector_base<abort_entry *, std::allocator<abort_entry *>>::_Vector_impl" = type { %"struct.std::_Vector_base<abort_entry *, std::allocator<abort_entry *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<abort_entry *, std::allocator<abort_entry *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@simulation = external local_unnamed_addr global ptr, align 8
@abort_queue = external global %class.AbortQueue, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11AbortThread3runEv(ptr noundef nonnull align 8 dereferenceable(64) %0) unnamed_addr #0 align 2 {
  tail call void @_ZN6Thread6tsetupEv(ptr noundef nonnull align 8 dereferenceable(64) %0)
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %3)
  %5 = load ptr, ptr @simulation, align 8, !tbaa !12
  %6 = tail call noundef zeroext i1 @_ZN10SimManager7is_doneEv(ptr noundef nonnull align 8 dereferenceable(96) %5)
  br i1 %6, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  tail call void @_ZN6Thread9heartbeatEv(ptr noundef nonnull align 8 dereferenceable(64) %0)
  %7 = tail call noundef i64 @_ZN6Thread10get_thd_idEv(ptr noundef nonnull align 8 dereferenceable(64) %0)
  tail call void @_ZN10AbortQueue7processEm(ptr noundef nonnull align 8 dereferenceable(72) @abort_queue, i64 noundef %7)
  %8 = load ptr, ptr @simulation, align 8, !tbaa !12
  %9 = tail call noundef zeroext i1 @_ZN10SimManager7is_doneEv(ptr noundef nonnull align 8 dereferenceable(96) %8)
  br i1 %9, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %1
  ret i32 6
}

declare void @_ZN6Thread6tsetupEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #1

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

declare noundef zeroext i1 @_ZN10SimManager7is_doneEv(ptr noundef nonnull align 8 dereferenceable(96)) local_unnamed_addr #1

declare void @_ZN6Thread9heartbeatEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #1

declare void @_ZN10AbortQueue7processEm(ptr noundef nonnull align 8 dereferenceable(72), i64 noundef) local_unnamed_addr #1

declare noundef i64 @_ZN6Thread10get_thd_idEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #1

attributes #0 = { mustprogress 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" }

!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, !7, i64 8}
!6 = !{!"_ZTS6Thread", !7, i64 8, !7, i64 16, !10, i64 24, !11, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTS6myrand", !7, i64 0}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass