; LLVM IR from tevador/RandomX :: src/tests/affinity.ll (Z15cpuid_from_maskmRKj)

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

@_ZZ15cpuid_from_maskmRKjE6lookup = external hidden global [64 x i32], align 16
@_ZZ15cpuid_from_maskmRKjE4init = external hidden global i8, align 1

; 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 nounwind uwtable
define dso_local noundef i32 @_Z15cpuid_from_maskmRKj(i64 noundef %0, ptr noundef nonnull align 4 dereferenceable(4) %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %8 = load i8, ptr @_ZZ15cpuid_from_maskmRKjE4init, align 1, !tbaa !11, !range !13, !noundef !14
  %9 = trunc i8 %8 to i1
  br i1 %9, label %10, label %16

10:                                               ; preds = %2
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  %12 = load i32, ptr %11, align 4, !tbaa !15
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds [64 x i32], ptr @_ZZ15cpuid_from_maskmRKjE6lookup, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !15
  store i32 %15, ptr %3, align 4
  br label %44

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !15
  br label %17

17:                                               ; preds = %35, %16
  %18 = load i32, ptr %7, align 4, !tbaa !15
  %19 = icmp ult i32 %18, 64
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %38

21:                                               ; preds = %17
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = and i64 1, %22
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %32

25:                                               ; preds = %21
  %26 = load i32, ptr %7, align 4, !tbaa !15
  %27 = load i32, ptr %6, align 4, !tbaa !15
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds [64 x i32], ptr @_ZZ15cpuid_from_maskmRKjE6lookup, i64 0, i64 %28
  store i32 %26, ptr %29, align 4, !tbaa !15
  %30 = load i32, ptr %6, align 4, !tbaa !15
  %31 = add i32 %30, 1
  store i32 %31, ptr %6, align 4, !tbaa !15
  br label %32

32:                                               ; preds = %25, %21
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = lshr i64 %33, 1
  store i64 %34, ptr %4, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %32
  %36 = load i32, ptr %7, align 4, !tbaa !15
  %37 = add i32 %36, 1
  store i32 %37, ptr %7, align 4, !tbaa !15
  br label %17, !llvm.loop !17

38:                                               ; preds = %20
  store i8 1, ptr @_ZZ15cpuid_from_maskmRKjE4init, align 1, !tbaa !11
  %39 = load ptr, ptr %5, align 8, !tbaa !9
  %40 = load i32, ptr %39, align 4, !tbaa !15
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds [64 x i32], ptr @_ZZ15cpuid_from_maskmRKjE6lookup, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !15
  store i32 %43, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %44

44:                                               ; preds = %38, %10
  %45 = load i32, ptr %3, align 4
  ret i32 %45
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #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 = !{!"long", !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, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@_ZZ15cpuid_from_maskmRKjE6lookup = external hidden local_unnamed_addr global [64 x i32], align 16
@_ZZ15cpuid_from_maskmRKjE4init = external hidden local_unnamed_addr global i8, align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z15cpuid_from_maskmRKj(i64 noundef %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(4) %1) local_unnamed_addr #0 {
  %3 = load i8, ptr @_ZZ15cpuid_from_maskmRKjE4init, align 1, !tbaa !5, !range !9, !noundef !10
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %20, label %.preheader

5:                                                ; preds = %18
  store i8 1, ptr @_ZZ15cpuid_from_maskmRKjE4init, align 1, !tbaa !5
  br label %20

.preheader:                                       ; preds = %2, %18
  %.014 = phi i32 [ %19, %18 ], [ 0, %2 ]
  %.0913 = phi i32 [ %.1.1, %18 ], [ 0, %2 ]
  %.01112 = phi i64 [ %11, %18 ], [ %0, %2 ]
  %6 = and i64 %.01112, 1
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %.preheader.1, label %7

7:                                                ; preds = %.preheader
  %8 = zext i32 %.0913 to i64
  %9 = getelementptr inbounds [64 x i32], ptr @_ZZ15cpuid_from_maskmRKjE6lookup, i64 0, i64 %8
  store i32 %.014, ptr %9, align 4, !tbaa !11
  %10 = add i32 %.0913, 1
  br label %.preheader.1

.preheader.1:                                     ; preds = %7, %.preheader
  %.1 = phi i32 [ %10, %7 ], [ %.0913, %.preheader ]
  %11 = lshr i64 %.01112, 2
  %12 = and i64 %.01112, 2
  %.not.1 = icmp eq i64 %12, 0
  br i1 %.not.1, label %18, label %13

13:                                               ; preds = %.preheader.1
  %14 = or disjoint i32 %.014, 1
  %15 = zext i32 %.1 to i64
  %16 = getelementptr inbounds [64 x i32], ptr @_ZZ15cpuid_from_maskmRKjE6lookup, i64 0, i64 %15
  store i32 %14, ptr %16, align 4, !tbaa !11
  %17 = add i32 %.1, 1
  br label %18

18:                                               ; preds = %13, %.preheader.1
  %.1.1 = phi i32 [ %17, %13 ], [ %.1, %.preheader.1 ]
  %19 = add nuw nsw i32 %.014, 2
  %exitcond.not.1 = icmp eq i32 %19, 64
  br i1 %exitcond.not.1, label %5, label %.preheader, !llvm.loop !13

20:                                               ; preds = %2, %5
  %.pn.in = load i32, ptr %1, align 4, !tbaa !11
  %.pn = zext i32 %.pn.in to i64
  %.010.in = getelementptr inbounds [64 x i32], ptr @_ZZ15cpuid_from_maskmRKjE6lookup, i64 0, i64 %.pn
  %.010 = load i32, ptr %.010.in, align 4, !tbaa !11
  ret i32 %.010
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass