; LLVM IR from microsoft/nnfusion :: thirdparty/threadpool/util.ll (ZN11concurrency25NUMAGetThreadNodeAffinityEv)

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

%struct.hwloc_obj = type { i32, ptr, i32, ptr, i64, ptr, i32, i32, ptr, ptr, ptr, i32, ptr, ptr, i32, ptr, ptr, ptr, i32, i32, ptr, i32, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, ptr, i64 }

@_ZN11concurrencyL21hwloc_topology_handleE = external hidden global ptr, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN11concurrency17HaveHWLocTopologyEv() #0

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef ptr @_ZL26hwloc_get_next_obj_by_typeP14hwloc_topology16hwloc_obj_type_tP9hwloc_obj(ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11concurrency25NUMAGetThreadNodeAffinityEv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  store i32 -1, ptr %1, align 4, !tbaa !5
  %4 = call noundef zeroext i1 @_ZN11concurrency17HaveHWLocTopologyEv()
  br i1 %4, label %5, label %29

5:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %6 = call noalias ptr @hwloc_bitmap_alloc()
  store ptr %6, ptr %2, align 8, !tbaa !9
  %7 = load ptr, ptr @_ZN11concurrencyL21hwloc_topology_handleE, align 8, !tbaa !9
  %8 = load ptr, ptr %2, align 8, !tbaa !9
  %9 = call i32 @hwloc_get_cpubind(ptr noundef %7, ptr noundef %8, i32 noundef 2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store ptr null, ptr %3, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %26, %5
  %11 = load ptr, ptr @_ZN11concurrencyL21hwloc_topology_handleE, align 8, !tbaa !9
  %12 = load ptr, ptr %3, align 8, !tbaa !9
  %13 = call noundef ptr @_ZL26hwloc_get_next_obj_by_typeP14hwloc_topology16hwloc_obj_type_tP9hwloc_obj(ptr noundef %11, i32 noundef 13, ptr noundef %12)
  store ptr %13, ptr %3, align 8, !tbaa !9
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %27

15:                                               ; preds = %10
  %16 = load ptr, ptr %2, align 8, !tbaa !9
  %17 = load ptr, ptr %3, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.hwloc_obj, ptr %17, i32 0, i32 25
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = call i32 @hwloc_bitmap_isincluded(ptr noundef %16, ptr noundef %19) #6
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %26

22:                                               ; preds = %15
  %23 = load ptr, ptr %3, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.hwloc_obj, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 8, !tbaa !15
  store i32 %25, ptr %1, align 4, !tbaa !5
  br label %27

26:                                               ; preds = %15
  br label %10, !llvm.loop !16

27:                                               ; preds = %22, %10
  %28 = load ptr, ptr %2, align 8, !tbaa !9
  call void @hwloc_bitmap_free(ptr noundef %28)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  br label %29

29:                                               ; preds = %27, %0
  %30 = load i32, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret i32 %30
}

declare noalias ptr @hwloc_bitmap_alloc() #3

declare i32 @hwloc_get_cpubind(ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i32 @hwloc_bitmap_isincluded(ptr noundef, ptr noundef) #4

declare void @hwloc_bitmap_free(ptr noundef) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #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 willreturn memory(read) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 184}
!12 = !{!"_ZTS9hwloc_obj", !13, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !14, i64 32, !10, i64 40, !6, i64 48, !6, i64 52, !10, i64 56, !10, i64 64, !10, i64 72, !6, i64 80, !10, i64 88, !10, i64 96, !6, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !6, i64 136, !6, i64 140, !10, i64 144, !6, i64 152, !10, i64 160, !6, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !6, i64 224, !10, i64 232, !14, i64 240}
!13 = !{!"_ZTS16hwloc_obj_type_t", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !6, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@_ZN11concurrencyL21hwloc_topology_handleE = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN11concurrency17HaveHWLocTopologyEv() local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef ptr @_ZL26hwloc_get_next_obj_by_typeP14hwloc_topology16hwloc_obj_type_tP9hwloc_obj(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11concurrency25NUMAGetThreadNodeAffinityEv() local_unnamed_addr #0 {
  %1 = tail call noundef zeroext i1 @_ZN11concurrency17HaveHWLocTopologyEv()
  br i1 %1, label %2, label %16

2:                                                ; preds = %0
  %3 = tail call noalias ptr @hwloc_bitmap_alloc()
  %4 = load ptr, ptr @_ZN11concurrencyL21hwloc_topology_handleE, align 8, !tbaa !5
  %5 = tail call i32 @hwloc_get_cpubind(ptr noundef %4, ptr noundef %3, i32 noundef 2)
  br label %6

6:                                                ; preds = %9, %2
  %.0 = phi ptr [ null, %2 ], [ %8, %9 ]
  %7 = load ptr, ptr @_ZN11concurrencyL21hwloc_topology_handleE, align 8, !tbaa !5
  %8 = tail call noundef ptr @_ZL26hwloc_get_next_obj_by_typeP14hwloc_topology16hwloc_obj_type_tP9hwloc_obj(ptr noundef %7, i32 noundef 13, ptr noundef %.0)
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %.loopexit, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %8, i64 184
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = tail call i32 @hwloc_bitmap_isincluded(ptr noundef %3, ptr noundef %11) #4
  %.not8 = icmp eq i32 %12, 0
  br i1 %.not8, label %6, label %13, !llvm.loop !14

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %8, i64 16
  %15 = load i32, ptr %14, align 8, !tbaa !16
  br label %.loopexit

.loopexit:                                        ; preds = %6, %13
  %.06 = phi i32 [ %15, %13 ], [ -1, %6 ]
  tail call void @hwloc_bitmap_free(ptr noundef %3)
  br label %16

16:                                               ; preds = %.loopexit, %0
  %.1 = phi i32 [ %.06, %.loopexit ], [ -1, %0 ]
  ret i32 %.1
}

declare noalias ptr @hwloc_bitmap_alloc() local_unnamed_addr #2

declare i32 @hwloc_get_cpubind(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @hwloc_bitmap_isincluded(ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @hwloc_bitmap_free(ptr noundef) local_unnamed_addr #2

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 = { inlinehint 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 = { mustprogress nofree nounwind willreturn memory(read) "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 willreturn memory(read) }

!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 184}
!10 = !{!"_ZTS9hwloc_obj", !11, i64 0, !6, i64 8, !12, i64 16, !6, i64 24, !13, i64 32, !6, i64 40, !12, i64 48, !12, i64 52, !6, i64 56, !6, i64 64, !6, i64 72, !12, i64 80, !6, i64 88, !6, i64 96, !12, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !12, i64 136, !12, i64 140, !6, i64 144, !12, i64 152, !6, i64 160, !12, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !12, i64 224, !6, i64 232, !13, i64 240}
!11 = !{!"_ZTS16hwloc_obj_type_t", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!10, !12, i64 16}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass