; LLVM IR from dynexcoin/Dynex :: src/System/ContextGroup.ll (ZN6System12ContextGroup4waitEv)

; 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.System::ContextGroup" = type { ptr, %"struct.System::NativeContextGroup" }
%"struct.System::NativeContextGroup" = type { ptr, ptr, ptr, ptr }
%"struct.System::NativeContext" = type { ptr, ptr, i8, i8, ptr, ptr, ptr, ptr, %"class.std::function", %"class.std::function" }
%"class.std::function" = type { %"class.std::_Function_base", ptr }
%"class.std::_Function_base" = type { %"union.std::_Any_data", ptr }
%"union.std::_Any_data" = type { %"union.std::_Nocopy_types" }
%"union.std::_Nocopy_types" = type { { i64, i64 } }

@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [41 x i8], align 1
@__PRETTY_FUNCTION__._ZN6System12ContextGroup4waitEv = external hidden unnamed_addr constant [34 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6System12ContextGroup4waitEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %"class.System::ContextGroup", ptr %4, i32 0, i32 1
  %6 = getelementptr inbounds %"struct.System::NativeContextGroup", ptr %5, i32 0, i32 0
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %54

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %10 = getelementptr inbounds %"class.System::ContextGroup", ptr %4, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = call noundef ptr @_ZNK6System10Dispatcher17getCurrentContextEv(ptr noundef nonnull align 16 dereferenceable(440) %11)
  store ptr %12, ptr %3, align 8, !tbaa !5
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.System::NativeContext", ptr %13, i32 0, i32 4
  store ptr null, ptr %14, align 8, !tbaa !13
  %15 = getelementptr inbounds %"class.System::ContextGroup", ptr %4, i32 0, i32 1
  %16 = getelementptr inbounds %"struct.System::NativeContextGroup", ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !18
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %35

19:                                               ; preds = %9
  %20 = getelementptr inbounds %"class.System::ContextGroup", ptr %4, i32 0, i32 1
  %21 = getelementptr inbounds %"struct.System::NativeContextGroup", ptr %20, i32 0, i32 3
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %23 = getelementptr inbounds %"struct.System::NativeContext", ptr %22, i32 0, i32 4
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %19
  br label %29

27:                                               ; preds = %19
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 107, ptr noundef @__PRETTY_FUNCTION__._ZN6System12ContextGroup4waitEv) #5
  unreachable

28:                                               ; No predecessors!
  br label %29

29:                                               ; preds = %28, %26
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.System::ContextGroup", ptr %4, i32 0, i32 1
  %32 = getelementptr inbounds %"struct.System::NativeContextGroup", ptr %31, i32 0, i32 3
  %33 = load ptr, ptr %32, align 8, !tbaa !19
  %34 = getelementptr inbounds %"struct.System::NativeContext", ptr %33, i32 0, i32 4
  store ptr %30, ptr %34, align 8, !tbaa !13
  br label %39

35:                                               ; preds = %9
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %"class.System::ContextGroup", ptr %4, i32 0, i32 1
  %38 = getelementptr inbounds %"struct.System::NativeContextGroup", ptr %37, i32 0, i32 2
  store ptr %36, ptr %38, align 8, !tbaa !18
  br label %39

39:                                               ; preds = %35, %29
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %"class.System::ContextGroup", ptr %4, i32 0, i32 1
  %42 = getelementptr inbounds %"struct.System::NativeContextGroup", ptr %41, i32 0, i32 3
  store ptr %40, ptr %42, align 8, !tbaa !19
  %43 = getelementptr inbounds %"class.System::ContextGroup", ptr %4, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !12
  call void @_ZN6System10Dispatcher8dispatchEv(ptr noundef nonnull align 16 dereferenceable(440) %44)
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %"class.System::ContextGroup", ptr %4, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !12
  %48 = call noundef ptr @_ZNK6System10Dispatcher17getCurrentContextEv(ptr noundef nonnull align 16 dereferenceable(440) %47)
  %49 = icmp eq ptr %45, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %39
  br label %53

51:                                               ; preds = %39
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 115, ptr noundef @__PRETTY_FUNCTION__._ZN6System12ContextGroup4waitEv) #5
  unreachable

52:                                               ; No predecessors!
  br label %53

53:                                               ; preds = %52, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %54

54:                                               ; preds = %53, %1
  ret void
}

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

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

declare noundef ptr @_ZNK6System10Dispatcher17getCurrentContextEv(ptr noundef nonnull align 16 dereferenceable(440)) #3

declare void @_ZN6System10Dispatcher8dispatchEv(ptr noundef nonnull align 16 dereferenceable(440)) #3

attributes #0 = { noreturn 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 #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { nounwind }
attributes #5 = { noreturn 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTSN6System12ContextGroupE", !6, i64 0, !11, i64 8}
!11 = !{!"_ZTSN6System18NativeContextGroupE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!12 = !{!10, !6, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"_ZTSN6System13NativeContextE", !6, i64 0, !6, i64 8, !15, i64 16, !15, i64 17, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !16, i64 56, !16, i64 88}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTSSt8functionIFvvEE", !17, i64 0, !6, i64 24}
!17 = !{!"_ZTSSt14_Function_base", !7, i64 0, !6, i64 16}
!18 = !{!10, !6, i64 24}
!19 = !{!10, !6, i64 32}


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

@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [41 x i8], align 1
@__PRETTY_FUNCTION__._ZN6System12ContextGroup4waitEv = external hidden unnamed_addr constant [34 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6System12ContextGroup4waitEv(ptr nocapture noundef nonnull align 8 dereferenceable(40) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %24, label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !11
  %6 = tail call noundef ptr @_ZNK6System10Dispatcher17getCurrentContextEv(ptr noundef nonnull align 16 dereferenceable(440) %5)
  %7 = getelementptr inbounds i8, ptr %6, i64 24
  store ptr null, ptr %7, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !17
  %.not6 = icmp eq ptr %9, null
  br i1 %.not6, label %17, label %10

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  %12 = load ptr, ptr %11, align 8, !tbaa !18
  %13 = getelementptr inbounds i8, ptr %12, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = icmp eq ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 107, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6System12ContextGroup4waitEv) #3
  unreachable

17:                                               ; preds = %4, %10
  %.sink = phi ptr [ %13, %10 ], [ %8, %4 ]
  store ptr %6, ptr %.sink, align 8, !tbaa !19
  %18 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %6, ptr %18, align 8, !tbaa !18
  %19 = load ptr, ptr %0, align 8, !tbaa !11
  tail call void @_ZN6System10Dispatcher8dispatchEv(ptr noundef nonnull align 16 dereferenceable(440) %19)
  %20 = load ptr, ptr %0, align 8, !tbaa !11
  %21 = tail call noundef ptr @_ZNK6System10Dispatcher17getCurrentContextEv(ptr noundef nonnull align 16 dereferenceable(440) %20)
  %22 = icmp eq ptr %6, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %17
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 115, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6System12ContextGroup4waitEv) #3
  unreachable

24:                                               ; preds = %17, %1
  ret void
}

declare noundef ptr @_ZNK6System10Dispatcher17getCurrentContextEv(ptr noundef nonnull align 16 dereferenceable(440)) local_unnamed_addr #2

declare void @_ZN6System10Dispatcher8dispatchEv(ptr noundef nonnull align 16 dereferenceable(440)) local_unnamed_addr #2

attributes #0 = { noreturn 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 #1 = { 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 #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 = { noreturn 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, !7, i64 8}
!6 = !{!"_ZTSN6System12ContextGroupE", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN6System18NativeContextGroupE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !7, i64 24}
!13 = !{!"_ZTSN6System13NativeContextE", !7, i64 0, !7, i64 8, !14, i64 16, !14, i64 17, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !15, i64 56, !15, i64 88}
!14 = !{!"bool", !8, i64 0}
!15 = !{!"_ZTSSt8functionIFvvEE", !16, i64 0, !7, i64 24}
!16 = !{!"_ZTSSt14_Function_base", !8, i64 0, !7, i64 16}
!17 = !{!6, !7, i64 24}
!18 = !{!6, !7, i64 32}
!19 = !{!7, !7, i64 0}


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