; LLVM IR from intel/cryptography-primitives :: sources/ippcp (pcpbnu32_nlz)

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

; Function Attrs: nounwind uwtable
define dso_local i32 @cpNLZ_BNU32(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 32, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = icmp ne i32 %4, 0
  br i1 %5, label %6, label %50

6:                                                ; preds = %1
  store i32 0, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = and i32 %7, -65536
  %9 = icmp eq i32 0, %8
  br i1 %9, label %10, label %15

10:                                               ; preds = %6
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = add nsw i32 %11, 16
  store i32 %12, ptr %3, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = shl i32 %13, 16
  store i32 %14, ptr %2, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %10, %6
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = and i32 %16, -16777216
  %18 = icmp eq i32 0, %17
  br i1 %18, label %19, label %24

19:                                               ; preds = %15
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = add nsw i32 %20, 8
  store i32 %21, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = shl i32 %22, 8
  store i32 %23, ptr %2, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %19, %15
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = and i32 %25, -268435456
  %27 = icmp eq i32 0, %26
  br i1 %27, label %28, label %33

28:                                               ; preds = %24
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = add nsw i32 %29, 4
  store i32 %30, ptr %3, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = shl i32 %31, 4
  store i32 %32, ptr %2, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %28, %24
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = and i32 %34, -1073741824
  %36 = icmp eq i32 0, %35
  br i1 %36, label %37, label %42

37:                                               ; preds = %33
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = add nsw i32 %38, 2
  store i32 %39, ptr %3, align 4, !tbaa !5
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = shl i32 %40, 2
  store i32 %41, ptr %2, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %37, %33
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = and i32 %43, -2147483648
  %45 = icmp eq i32 0, %44
  br i1 %45, label %46, label %49

46:                                               ; preds = %42
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %3, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %46, %42
  br label %50

50:                                               ; preds = %49, %1
  %51 = load i32, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %51
}

; 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

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 }

!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/C++ TBAA"}


; 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 nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local i32 @cpNLZ_BNU32(i32 noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %16, label %2

2:                                                ; preds = %1
  %3 = icmp ult i32 %0, 65536
  %4 = shl nuw i32 %0, 16
  %spec.select = select i1 %3, i32 %4, i32 %0
  %spec.select21 = select i1 %3, i32 16, i32 0
  %5 = icmp ult i32 %spec.select, 16777216
  %6 = or disjoint i32 %spec.select21, 8
  %7 = shl nuw i32 %spec.select, 8
  %.117 = select i1 %5, i32 %7, i32 %spec.select
  %.1 = select i1 %5, i32 %6, i32 %spec.select21
  %8 = icmp ult i32 %.117, 268435456
  %9 = or disjoint i32 %.1, 4
  %10 = shl nuw i32 %.117, 4
  %.218 = select i1 %8, i32 %10, i32 %.117
  %.2 = select i1 %8, i32 %9, i32 %.1
  %11 = icmp ult i32 %.218, 1073741824
  %12 = or disjoint i32 %.2, 2
  %13 = shl nuw i32 %.218, 2
  %.319 = select i1 %11, i32 %13, i32 %.218
  %.3 = select i1 %11, i32 %12, i32 %.2
  %14 = icmp sgt i32 %.319, -1
  %15 = zext i1 %14 to i32
  %spec.select22 = add nuw nsw i32 %.3, %15
  br label %16

16:                                               ; preds = %2, %1
  %.4 = phi i32 [ 32, %1 ], [ %spec.select22, %2 ]
  ret i32 %.4
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass