; LLVM IR from ponylang/ponyc :: src/libponyrt/platform (threads)

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

@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@_numa_available = external hidden global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@_numa_num_task_cpus = external hidden global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1
@_numa_set_localalloc = external hidden global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@_numa_node_of_cpu = external hidden global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1
@_numa_alloc_onnode = external hidden global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [11 x i8], align 1
@_numa_alloc = external hidden global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [10 x i8], align 1
@_numa_free = external hidden global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [19 x i8], align 1
@_numa_all_nodes_ptr = external hidden global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [22 x i8], align 1
@_numa_allocate_cpumask = external hidden global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [18 x i8], align 1
@_numa_bitmask_free = external hidden global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [18 x i8], align 1
@_numa_node_to_cpus = external hidden global ptr, align 8
@.str.12 = external hidden unnamed_addr constant [20 x i8], align 1
@_numa_bitmask_weight = external hidden global ptr, align 8
@.str.13 = external hidden unnamed_addr constant [22 x i8], align 1
@_numa_bitmask_isbitset = external hidden global ptr, align 8
@use_numa = external hidden global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @ponyint_numa_init() #0 {
  %1 = alloca i1, align 1
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %5 = call ptr @dlopen(ptr noundef @.str, i32 noundef 1) #3
  store ptr %5, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %0
  store i1 false, ptr %1, align 1
  store i32 1, ptr %4, align 4
  br label %111

9:                                                ; preds = %0
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call ptr @dlsym(ptr noundef %10, ptr noundef @.str.1) #3
  store ptr %11, ptr @_numa_available, align 8, !tbaa !5
  %12 = load ptr, ptr @_numa_available, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  %14 = zext i1 %13 to i32
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = add nsw i32 %15, %14
  store i32 %16, ptr %3, align 4, !tbaa !9
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = call ptr @dlsym(ptr noundef %17, ptr noundef @.str.2) #3
  store ptr %18, ptr @_numa_num_task_cpus, align 8, !tbaa !5
  %19 = load ptr, ptr @_numa_num_task_cpus, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  %21 = zext i1 %20 to i32
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = add nsw i32 %22, %21
  store i32 %23, ptr %3, align 4, !tbaa !9
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call ptr @dlsym(ptr noundef %24, ptr noundef @.str.3) #3
  store ptr %25, ptr @_numa_set_localalloc, align 8, !tbaa !5
  %26 = load ptr, ptr @_numa_set_localalloc, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  %28 = zext i1 %27 to i32
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = add nsw i32 %29, %28
  store i32 %30, ptr %3, align 4, !tbaa !9
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = call ptr @dlsym(ptr noundef %31, ptr noundef @.str.4) #3
  store ptr %32, ptr @_numa_node_of_cpu, align 8, !tbaa !5
  %33 = load ptr, ptr @_numa_node_of_cpu, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  %35 = zext i1 %34 to i32
  %36 = load i32, ptr %3, align 4, !tbaa !9
  %37 = add nsw i32 %36, %35
  store i32 %37, ptr %3, align 4, !tbaa !9
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = call ptr @dlsym(ptr noundef %38, ptr noundef @.str.5) #3
  store ptr %39, ptr @_numa_alloc_onnode, align 8, !tbaa !5
  %40 = load ptr, ptr @_numa_alloc_onnode, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  %42 = zext i1 %41 to i32
  %43 = load i32, ptr %3, align 4, !tbaa !9
  %44 = add nsw i32 %43, %42
  store i32 %44, ptr %3, align 4, !tbaa !9
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = call ptr @dlsym(ptr noundef %45, ptr noundef @.str.6) #3
  store ptr %46, ptr @_numa_alloc, align 8, !tbaa !5
  %47 = load ptr, ptr @_numa_alloc, align 8, !tbaa !5
  %48 = icmp eq ptr %47, null
  %49 = zext i1 %48 to i32
  %50 = load i32, ptr %3, align 4, !tbaa !9
  %51 = add nsw i32 %50, %49
  store i32 %51, ptr %3, align 4, !tbaa !9
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = call ptr @dlsym(ptr noundef %52, ptr noundef @.str.7) #3
  store ptr %53, ptr @_numa_free, align 8, !tbaa !5
  %54 = load ptr, ptr @_numa_free, align 8, !tbaa !5
  %55 = icmp eq ptr %54, null
  %56 = zext i1 %55 to i32
  %57 = load i32, ptr %3, align 4, !tbaa !9
  %58 = add nsw i32 %57, %56
  store i32 %58, ptr %3, align 4, !tbaa !9
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = call ptr @dlsym(ptr noundef %59, ptr noundef @.str.8) #3
  store ptr %60, ptr @_numa_all_nodes_ptr, align 8, !tbaa !5
  %61 = load ptr, ptr @_numa_all_nodes_ptr, align 8, !tbaa !5
  %62 = icmp eq ptr %61, null
  %63 = zext i1 %62 to i32
  %64 = load i32, ptr %3, align 4, !tbaa !9
  %65 = add nsw i32 %64, %63
  store i32 %65, ptr %3, align 4, !tbaa !9
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = call ptr @dlsym(ptr noundef %66, ptr noundef @.str.9) #3
  store ptr %67, ptr @_numa_allocate_cpumask, align 8, !tbaa !5
  %68 = load ptr, ptr @_numa_allocate_cpumask, align 8, !tbaa !5
  %69 = icmp eq ptr %68, null
  %70 = zext i1 %69 to i32
  %71 = load i32, ptr %3, align 4, !tbaa !9
  %72 = add nsw i32 %71, %70
  store i32 %72, ptr %3, align 4, !tbaa !9
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = call ptr @dlsym(ptr noundef %73, ptr noundef @.str.10) #3
  store ptr %74, ptr @_numa_bitmask_free, align 8, !tbaa !5
  %75 = load ptr, ptr @_numa_bitmask_free, align 8, !tbaa !5
  %76 = icmp eq ptr %75, null
  %77 = zext i1 %76 to i32
  %78 = load i32, ptr %3, align 4, !tbaa !9
  %79 = add nsw i32 %78, %77
  store i32 %79, ptr %3, align 4, !tbaa !9
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = call ptr @dlsym(ptr noundef %80, ptr noundef @.str.11) #3
  store ptr %81, ptr @_numa_node_to_cpus, align 8, !tbaa !5
  %82 = load ptr, ptr @_numa_node_to_cpus, align 8, !tbaa !5
  %83 = icmp eq ptr %82, null
  %84 = zext i1 %83 to i32
  %85 = load i32, ptr %3, align 4, !tbaa !9
  %86 = add nsw i32 %85, %84
  store i32 %86, ptr %3, align 4, !tbaa !9
  %87 = load ptr, ptr %2, align 8, !tbaa !5
  %88 = call ptr @dlsym(ptr noundef %87, ptr noundef @.str.12) #3
  store ptr %88, ptr @_numa_bitmask_weight, align 8, !tbaa !5
  %89 = load ptr, ptr @_numa_bitmask_weight, align 8, !tbaa !5
  %90 = icmp eq ptr %89, null
  %91 = zext i1 %90 to i32
  %92 = load i32, ptr %3, align 4, !tbaa !9
  %93 = add nsw i32 %92, %91
  store i32 %93, ptr %3, align 4, !tbaa !9
  %94 = load ptr, ptr %2, align 8, !tbaa !5
  %95 = call ptr @dlsym(ptr noundef %94, ptr noundef @.str.13) #3
  store ptr %95, ptr @_numa_bitmask_isbitset, align 8, !tbaa !5
  %96 = load ptr, ptr @_numa_bitmask_isbitset, align 8, !tbaa !5
  %97 = icmp eq ptr %96, null
  %98 = zext i1 %97 to i32
  %99 = load i32, ptr %3, align 4, !tbaa !9
  %100 = add nsw i32 %99, %98
  store i32 %100, ptr %3, align 4, !tbaa !9
  %101 = load i32, ptr %3, align 4, !tbaa !9
  %102 = icmp ne i32 %101, 0
  br i1 %102, label %103, label %104

103:                                              ; preds = %9
  store i1 false, ptr %1, align 1
  store i32 1, ptr %4, align 4
  br label %111

104:                                              ; preds = %9
  %105 = load ptr, ptr @_numa_available, align 8, !tbaa !5
  %106 = call i32 (...) %105()
  %107 = icmp eq i32 %106, -1
  br i1 %107, label %108, label %109

108:                                              ; preds = %104
  store i1 false, ptr %1, align 1
  store i32 1, ptr %4, align 4
  br label %111

109:                                              ; preds = %104
  store i8 1, ptr @use_numa, align 1, !tbaa !11
  %110 = load ptr, ptr @_numa_set_localalloc, align 8, !tbaa !5
  call void (...) %110()
  store i1 true, ptr %1, align 1
  store i32 1, ptr %4, align 4
  br label %111

111:                                              ; preds = %109, %108, %103, %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %112 = load i1, ptr %1, align 1
  ret i1 %112
}

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

; Function Attrs: nounwind
declare ptr @dlopen(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind
declare ptr @dlsym(ptr noundef, ptr noundef) #2

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

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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}


; 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 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@_numa_available = external hidden local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@_numa_num_task_cpus = external hidden local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1
@_numa_set_localalloc = external hidden local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@_numa_node_of_cpu = external hidden local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1
@_numa_alloc_onnode = external hidden local_unnamed_addr global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [11 x i8], align 1
@_numa_alloc = external hidden local_unnamed_addr global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [10 x i8], align 1
@_numa_free = external hidden local_unnamed_addr global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [19 x i8], align 1
@_numa_all_nodes_ptr = external hidden local_unnamed_addr global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [22 x i8], align 1
@_numa_allocate_cpumask = external hidden local_unnamed_addr global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [18 x i8], align 1
@_numa_bitmask_free = external hidden local_unnamed_addr global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [18 x i8], align 1
@_numa_node_to_cpus = external hidden local_unnamed_addr global ptr, align 8
@.str.12 = external hidden unnamed_addr constant [20 x i8], align 1
@_numa_bitmask_weight = external hidden local_unnamed_addr global ptr, align 8
@.str.13 = external hidden unnamed_addr constant [22 x i8], align 1
@_numa_bitmask_isbitset = external hidden local_unnamed_addr global ptr, align 8
@use_numa = external hidden local_unnamed_addr global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @ponyint_numa_init() local_unnamed_addr #0 {
  %1 = tail call ptr @dlopen(ptr noundef nonnull @.str, i32 noundef 1) #3
  %2 = icmp eq ptr %1, null
  br i1 %2, label %46, label %3

3:                                                ; preds = %0
  %4 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.1) #3
  store ptr %4, ptr @_numa_available, align 8, !tbaa !5
  %5 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.2) #3
  store ptr %5, ptr @_numa_num_task_cpus, align 8, !tbaa !5
  %6 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.3) #3
  store ptr %6, ptr @_numa_set_localalloc, align 8, !tbaa !5
  %7 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.4) #3
  store ptr %7, ptr @_numa_node_of_cpu, align 8, !tbaa !5
  %8 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.5) #3
  store ptr %8, ptr @_numa_alloc_onnode, align 8, !tbaa !5
  %9 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.6) #3
  store ptr %9, ptr @_numa_alloc, align 8, !tbaa !5
  %10 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.7) #3
  store ptr %10, ptr @_numa_free, align 8, !tbaa !5
  %11 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.8) #3
  store ptr %11, ptr @_numa_all_nodes_ptr, align 8, !tbaa !5
  %12 = insertelement <8 x ptr> poison, ptr %5, i64 0
  %13 = insertelement <8 x ptr> %12, ptr %4, i64 1
  %14 = insertelement <8 x ptr> %13, ptr %6, i64 2
  %15 = insertelement <8 x ptr> %14, ptr %7, i64 3
  %16 = insertelement <8 x ptr> %15, ptr %8, i64 4
  %17 = insertelement <8 x ptr> %16, ptr %9, i64 5
  %18 = insertelement <8 x ptr> %17, ptr %10, i64 6
  %19 = insertelement <8 x ptr> %18, ptr %11, i64 7
  %20 = icmp eq <8 x ptr> %19, zeroinitializer
  %21 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.9) #3
  store ptr %21, ptr @_numa_allocate_cpumask, align 8, !tbaa !5
  %22 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.10) #3
  store ptr %22, ptr @_numa_bitmask_free, align 8, !tbaa !5
  %23 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.11) #3
  store ptr %23, ptr @_numa_node_to_cpus, align 8, !tbaa !5
  %24 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.12) #3
  store ptr %24, ptr @_numa_bitmask_weight, align 8, !tbaa !5
  %25 = insertelement <4 x ptr> poison, ptr %21, i64 0
  %26 = insertelement <4 x ptr> %25, ptr %22, i64 1
  %27 = insertelement <4 x ptr> %26, ptr %23, i64 2
  %28 = insertelement <4 x ptr> %27, ptr %24, i64 3
  %29 = icmp eq <4 x ptr> %28, zeroinitializer
  %30 = bitcast <8 x i1> %20 to i8
  %31 = tail call range(i8 0, 9) i8 @llvm.ctpop.i8(i8 %30)
  %32 = zext nneg i8 %31 to i32
  %33 = bitcast <4 x i1> %29 to i4
  %34 = tail call range(i4 0, 5) i4 @llvm.ctpop.i4(i4 %33)
  %35 = zext nneg i4 %34 to i32
  %op.rdx = add nuw nsw i32 %32, %35
  %36 = tail call ptr @dlsym(ptr noundef nonnull %1, ptr noundef nonnull @.str.13) #3
  store ptr %36, ptr @_numa_bitmask_isbitset, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  %38 = zext i1 %37 to i32
  %39 = or i32 %op.rdx, %38
  %.not = icmp eq i32 %39, 0
  br i1 %.not, label %40, label %46

40:                                               ; preds = %3
  %41 = load ptr, ptr @_numa_available, align 8, !tbaa !5
  %42 = tail call i32 (...) %41() #3
  %43 = icmp eq i32 %42, -1
  br i1 %43, label %46, label %44

44:                                               ; preds = %40
  store i8 1, ptr @use_numa, align 1, !tbaa !9
  %45 = load ptr, ptr @_numa_set_localalloc, align 8, !tbaa !5
  tail call void (...) %45() #3
  br label %46

46:                                               ; preds = %40, %3, %0, %44
  %.0 = phi i1 [ true, %44 ], [ false, %0 ], [ false, %3 ], [ false, %40 ]
  ret i1 %.0
}

; Function Attrs: nounwind
declare ptr @dlopen(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare ptr @dlsym(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.ctpop.i8(i8) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i4 @llvm.ctpop.i4(i4) #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 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass