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

; 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 @cpNTZ_BNU(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 64, ptr %3, align 4, !tbaa !9
  %4 = load i64, ptr %2, align 8, !tbaa !5
  %5 = icmp ne i64 %4, 0
  br i1 %5, label %6, label %59

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

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

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

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

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

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

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

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

42:                                               ; preds = %37, %33
  %43 = load i64, ptr %2, align 8, !tbaa !5
  %44 = and i64 %43, 3
  %45 = icmp eq i64 0, %44
  br i1 %45, label %46, label %51

46:                                               ; preds = %42
  %47 = load i32, ptr %3, align 4, !tbaa !9
  %48 = add nsw i32 %47, 2
  store i32 %48, ptr %3, align 4, !tbaa !9
  %49 = load i64, ptr %2, align 8, !tbaa !5
  %50 = lshr i64 %49, 2
  store i64 %50, ptr %2, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %46, %42
  %52 = load i64, ptr %2, align 8, !tbaa !5
  %53 = and i64 %52, 1
  %54 = icmp eq i64 0, %53
  br i1 %54, label %55, label %58

55:                                               ; preds = %51
  %56 = load i32, ptr %3, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %3, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %55, %51
  br label %59

59:                                               ; preds = %58, %1
  %60 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %60
}

; 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local i32 @cpNTZ_BNU(i64 noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %25, label %2

2:                                                ; preds = %1
  %3 = and i64 %0, 4294967295
  %4 = icmp eq i64 %3, 0
  %5 = lshr exact i64 %0, 32
  %spec.select = select i1 %4, i64 %5, i64 %0
  %spec.select25 = select i1 %4, i32 32, i32 0
  %6 = and i64 %spec.select, 65535
  %7 = icmp eq i64 %6, 0
  %8 = or disjoint i32 %spec.select25, 16
  %9 = lshr exact i64 %spec.select, 16
  %.120 = select i1 %7, i64 %9, i64 %spec.select
  %.1 = select i1 %7, i32 %8, i32 %spec.select25
  %10 = and i64 %.120, 255
  %11 = icmp eq i64 %10, 0
  %12 = or disjoint i32 %.1, 8
  %13 = lshr exact i64 %.120, 8
  %.221 = select i1 %11, i64 %13, i64 %.120
  %.2 = select i1 %11, i32 %12, i32 %.1
  %14 = and i64 %.221, 15
  %15 = icmp eq i64 %14, 0
  %16 = or disjoint i32 %.2, 4
  %17 = lshr exact i64 %.221, 4
  %.322 = select i1 %15, i64 %17, i64 %.221
  %.3 = select i1 %15, i32 %16, i32 %.2
  %18 = and i64 %.322, 3
  %19 = icmp eq i64 %18, 0
  %20 = add nuw nsw i32 %.3, 2
  %21 = lshr exact i64 %.322, 2
  %.423 = select i1 %19, i64 %21, i64 %.322
  %.4 = select i1 %19, i32 %20, i32 %.3
  %22 = trunc i64 %.423 to i32
  %23 = and i32 %22, 1
  %24 = xor i32 %23, 1
  %spec.select26 = add nuw nsw i32 %24, %.4
  br label %25

25:                                               ; preds = %2, %1
  %.5 = phi i32 [ 64, %1 ], [ %spec.select26, %2 ]
  ret i32 %.5
}

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,SCCPPass,SROAPass,SimplifyCFGPass