; LLVM IR from intel/qpl :: sources/isal/crc (crc_base)

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

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

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

10:                                               ; preds = %34, %3
  %11 = load i64, ptr %8, align 8, !tbaa !11
  %12 = load i64, ptr %6, align 8, !tbaa !11
  %13 = icmp ult i64 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %37

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

34:                                               ; preds = %15
  %35 = load i64, ptr %8, align 8, !tbaa !11
  %36 = add i64 %35, 1
  store i64 %36, ptr %8, align 8, !tbaa !11
  br label %10, !llvm.loop !14

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

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

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

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

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

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

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi i16 [ poison, %.lr.ph.preheader ], [ %33, %.lr.ph ]
  %.0710.unr = phi i16 [ %0, %.lr.ph.preheader ], [ %33, %.lr.ph ]
  %.089.unr = phi ptr [ %1, %.lr.ph.preheader ], [ %26, %.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
  %5 = shl i16 %.0710.unr, 8
  %6 = lshr i16 %.0710.unr, 8
  %7 = load i8, ptr %.089.unr, align 1, !tbaa !5
  %8 = zext i8 %7 to i16
  %9 = xor i16 %6, %8
  %10 = zext nneg i16 %9 to i64
  %11 = getelementptr inbounds [256 x i16], ptr @crc16tab, i64 0, i64 %10
  %12 = load i16, ptr %11, align 2, !tbaa !8
  %13 = xor i16 %12, %5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %3
  %.07.lcssa = phi i16 [ %0, %3 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %13, %.lr.ph.epil ]
  ret i16 %.07.lcssa

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.0710 = phi i16 [ %0, %.lr.ph.preheader.new ], [ %33, %.lr.ph ]
  %.089 = phi ptr [ %1, %.lr.ph.preheader.new ], [ %26, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %14 = shl i16 %.0710, 8
  %15 = lshr i16 %.0710, 8
  %16 = getelementptr inbounds i8, ptr %.089, i64 1
  %17 = load i8, ptr %.089, align 1, !tbaa !5
  %18 = zext i8 %17 to i16
  %19 = xor i16 %15, %18
  %20 = zext nneg i16 %19 to i64
  %21 = getelementptr inbounds [256 x i16], ptr @crc16tab, i64 0, i64 %20
  %22 = load i16, ptr %21, align 2, !tbaa !8
  %23 = xor i16 %22, %14
  %24 = shl i16 %22, 8
  %25 = lshr i16 %23, 8
  %26 = getelementptr inbounds i8, ptr %.089, i64 2
  %27 = load i8, ptr %16, align 1, !tbaa !5
  %28 = zext i8 %27 to i16
  %29 = xor i16 %25, %28
  %30 = zext nneg i16 %29 to i64
  %31 = getelementptr inbounds [256 x i16], ptr @crc16tab, i64 0, i64 %30
  %32 = load i16, ptr %31, align 2, !tbaa !8
  %33 = xor i16 %32, %24
  %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 = { nofree norecurse nosync nounwind 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/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