; LLVM IR from AngoraFuzzer/Angora :: llvm_mode/dfsan_rt/sanitizer_common (sanitizer_thread_registry)

; 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.__sanitizer::ThreadRegistry" = type { ptr, i32, i32, i32, %"class.__sanitizer::BlockingMutex", i32, i64, i64, i64, i64, ptr, %"struct.__sanitizer::IntrusiveList", %"struct.__sanitizer::IntrusiveList" }
%"class.__sanitizer::BlockingMutex" = type { [10 x i64], i64 }
%"struct.__sanitizer::IntrusiveList" = type { i64, ptr, ptr }

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11__sanitizer14ThreadRegistry11CheckLockedEv(ptr noundef nonnull align 8 dereferenceable(208)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN11__sanitizer14ThreadRegistry23FindThreadContextLockedEPFbPNS_17ThreadContextBaseEPvES3_(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr noundef %1, ptr noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8
  call void @_ZN11__sanitizer14ThreadRegistry11CheckLockedEv(ptr noundef nonnull align 8 dereferenceable(208) %11)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %38, %3
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = getelementptr inbounds %"class.__sanitizer::ThreadRegistry", ptr %11, i32 0, i32 5
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = icmp ult i32 %13, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %12
  store i32 2, ptr %9, align 4
  br label %41

18:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %19 = getelementptr inbounds %"class.__sanitizer::ThreadRegistry", ptr %11, i32 0, i32 10
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds ptr, ptr %20, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  store ptr %24, ptr %10, align 8, !tbaa !5
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %34

27:                                               ; preds = %18
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = call noundef zeroext i1 %28(ptr noundef %29, ptr noundef %30)
  br i1 %31, label %32, label %34

32:                                               ; preds = %27
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %33, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %35

34:                                               ; preds = %27, %18
  store i32 0, ptr %9, align 4
  br label %35

35:                                               ; preds = %34, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %36 = load i32, ptr %9, align 4
  switch i32 %36, label %41 [
    i32 0, label %37
  ]

37:                                               ; preds = %35
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = add i32 %39, 1
  store i32 %40, ptr %8, align 4, !tbaa !9
  br label %12, !llvm.loop !18

41:                                               ; preds = %35, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %42 = load i32, ptr %9, align 4
  switch i32 %42, label %46 [
    i32 2, label %43
    i32 1, label %44
  ]

43:                                               ; preds = %41
  store ptr null, ptr %4, align 8
  br label %44

44:                                               ; preds = %43, %41
  %45 = load ptr, ptr %4, align 8
  ret ptr %45

46:                                               ; preds = %41
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 112}
!12 = !{!"_ZTSN11__sanitizer14ThreadRegistryE", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 24, !10, i64 112, !15, i64 120, !14, i64 128, !14, i64 136, !14, i64 144, !6, i64 152, !16, i64 160, !16, i64 184}
!13 = !{!"_ZTSN11__sanitizer13BlockingMutexE", !7, i64 0, !14, i64 80}
!14 = !{!"long", !7, i64 0}
!15 = !{!"long long", !7, i64 0}
!16 = !{!"_ZTSN11__sanitizer13IntrusiveListINS_17ThreadContextBaseEEE", !14, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!12, !6, i64 152}
!18 = distinct !{!18, !19}
!19 = !{!"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"

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11__sanitizer14ThreadRegistry11CheckLockedEv(ptr noundef nonnull align 8 dereferenceable(208)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN11__sanitizer14ThreadRegistry23FindThreadContextLockedEPFbPNS_17ThreadContextBaseEPvES3_(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 align 2 {
  tail call void @_ZN11__sanitizer14ThreadRegistry11CheckLockedEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %4 = getelementptr inbounds i8, ptr %0, i64 112
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not1819.not = icmp eq i32 %5, 0
  br i1 %.not1819.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 152
  br label %7

7:                                                ; preds = %.lr.ph, %14
  %8 = phi i32 [ %5, %.lr.ph ], [ %15, %14 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %9 = load ptr, ptr %6, align 8, !tbaa !15
  %10 = getelementptr inbounds ptr, ptr %9, i64 %indvars.iv
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %14, label %12

12:                                               ; preds = %7
  %13 = tail call noundef zeroext i1 %1(ptr noundef nonnull %11, ptr noundef %2)
  br i1 %13, label %._crit_edge, label %._crit_edge24

._crit_edge24:                                    ; preds = %12
  %.pre = load i32, ptr %4, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %._crit_edge24, %7
  %15 = phi i32 [ %.pre, %._crit_edge24 ], [ %8, %7 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = zext i32 %15 to i64
  %.not18 = icmp ult i64 %indvars.iv.next, %16
  br i1 %.not18, label %7, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %14, %12, %3
  %spec.select = phi ptr [ null, %3 ], [ %11, %12 ], [ null, %14 ]
  ret ptr %spec.select
}

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

!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, !10, i64 112}
!6 = !{!"_ZTSN11__sanitizer14ThreadRegistryE", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !11, i64 24, !10, i64 112, !13, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !7, i64 152, !14, i64 160, !14, i64 184}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTSN11__sanitizer13BlockingMutexE", !8, i64 0, !12, i64 80}
!12 = !{!"long", !8, i64 0}
!13 = !{!"long long", !8, i64 0}
!14 = !{!"_ZTSN11__sanitizer13IntrusiveListINS_17ThreadContextBaseEEE", !12, i64 0, !7, i64 8, !7, i64 16}
!15 = !{!6, !7, i64 152}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass