; LLVM IR from apache/kvrocks :: src/cluster/redis_slot.ll (Z5Crc16PKcm)

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

@_ZL8crc16tab = external hidden constant [256 x i16], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i16 @_Z5Crc16PKcm(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i16, align 2
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  store i16 0, ptr %5, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %31, %2
  %8 = load i64, ptr %6, align 8, !tbaa !9
  %9 = load i64, ptr %4, align 8, !tbaa !9
  %10 = icmp ult i64 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %34

12:                                               ; preds = %7
  %13 = load i16, ptr %5, align 2, !tbaa !11
  %14 = zext i16 %13 to i32
  %15 = shl i32 %14, 8
  %16 = load i16, ptr %5, align 2, !tbaa !11
  %17 = zext i16 %16 to i32
  %18 = ashr i32 %17, 8
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i32 1
  store ptr %20, ptr %3, align 8, !tbaa !5
  %21 = load i8, ptr %19, align 1, !tbaa !13
  %22 = sext i8 %21 to i32
  %23 = xor i32 %18, %22
  %24 = and i32 %23, 255
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [256 x i16], ptr @_ZL8crc16tab, i64 0, i64 %25
  %27 = load i16, ptr %26, align 2, !tbaa !11
  %28 = zext i16 %27 to i32
  %29 = xor i32 %15, %28
  %30 = trunc i32 %29 to i16
  store i16 %30, ptr %5, align 2, !tbaa !11
  br label %31

31:                                               ; preds = %12
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = add i64 %32, 1
  store i64 %33, ptr %6, align 8, !tbaa !9
  br label %7, !llvm.loop !14

34:                                               ; preds = %11
  %35 = load i16, ptr %5, align 2, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  ret i16 %35
}

; 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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@_ZL8crc16tab = external hidden local_unnamed_addr constant [256 x i16], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i16 @_Z5Crc16PKcm(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %xtraiter = and i64 %1, 1
  %3 = icmp eq i64 %1, 1
  br i1 %3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %1, -2
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi i16 [ poison, %.lr.ph.preheader ], [ %32, %.lr.ph ]
  %.069.unr = phi i16 [ 0, %.lr.ph.preheader ], [ %32, %.lr.ph ]
  %.078.unr = phi ptr [ %0, %.lr.ph.preheader ], [ %25, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %4 = shl i16 %.069.unr, 8
  %5 = lshr i16 %.069.unr, 8
  %6 = load i8, ptr %.078.unr, align 1, !tbaa !5
  %7 = zext i8 %6 to i16
  %8 = xor i16 %5, %7
  %9 = zext nneg i16 %8 to i64
  %10 = getelementptr inbounds [256 x i16], ptr @_ZL8crc16tab, i64 0, i64 %9
  %11 = load i16, ptr %10, align 2, !tbaa !8
  %12 = xor i16 %11, %4
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %2
  %.06.lcssa = phi i16 [ 0, %2 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %12, %.lr.ph.epil ]
  ret i16 %.06.lcssa

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.069 = phi i16 [ 0, %.lr.ph.preheader.new ], [ %32, %.lr.ph ]
  %.078 = phi ptr [ %0, %.lr.ph.preheader.new ], [ %25, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %13 = shl i16 %.069, 8
  %14 = lshr i16 %.069, 8
  %15 = getelementptr inbounds i8, ptr %.078, i64 1
  %16 = load i8, ptr %.078, align 1, !tbaa !5
  %17 = zext i8 %16 to i16
  %18 = xor i16 %14, %17
  %19 = zext nneg i16 %18 to i64
  %20 = getelementptr inbounds [256 x i16], ptr @_ZL8crc16tab, i64 0, i64 %19
  %21 = load i16, ptr %20, align 2, !tbaa !8
  %22 = xor i16 %21, %13
  %23 = shl i16 %21, 8
  %24 = lshr i16 %22, 8
  %25 = getelementptr inbounds i8, ptr %.078, i64 2
  %26 = load i8, ptr %15, align 1, !tbaa !5
  %27 = zext i8 %26 to i16
  %28 = xor i16 %24, %27
  %29 = zext nneg i16 %28 to i64
  %30 = getelementptr inbounds [256 x i16], ptr @_ZL8crc16tab, i64 0, i64 %29
  %31 = load i16, ptr %30, align 2, !tbaa !8
  %32 = xor i16 %31, %23
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !10
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass