; LLVM IR from intel/qpl :: sources/isal/crc (crc64_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"

@crc64_ecma_norm_table = external hidden constant [256 x i64], align 16

; 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: nounwind uwtable
define dso_local i64 @qpl_crc64_ecma_norm_base(i64 noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %11 = xor i64 %10, -1
  store i64 %11, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %33, %3
  %13 = load i64, ptr %8, align 8, !tbaa !5
  %14 = load i64, ptr %6, align 8, !tbaa !5
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %36

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = load i64, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %18, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !11
  store i8 %21, ptr %9, align 1, !tbaa !11
  %22 = load i64, ptr %7, align 8, !tbaa !5
  %23 = lshr i64 %22, 56
  %24 = load i8, ptr %9, align 1, !tbaa !11
  %25 = zext i8 %24 to i64
  %26 = xor i64 %23, %25
  %27 = and i64 %26, 255
  %28 = getelementptr inbounds [256 x i64], ptr @crc64_ecma_norm_table, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = load i64, ptr %7, align 8, !tbaa !5
  %31 = shl i64 %30, 8
  %32 = xor i64 %29, %31
  store i64 %32, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  br label %33

33:                                               ; preds = %17
  %34 = load i64, ptr %8, align 8, !tbaa !5
  %35 = add i64 %34, 1
  store i64 %35, ptr %8, align 8, !tbaa !5
  br label %12, !llvm.loop !12

36:                                               ; preds = %16
  %37 = load i64, ptr %7, align 8, !tbaa !5
  %38 = xor i64 %37, -1
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i64 %38
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@crc64_ecma_norm_table = external hidden local_unnamed_addr constant [256 x i64], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local i64 @qpl_crc64_ecma_norm_base(i64 noundef %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
  %4 = xor i64 %0, -1
  %xtraiter = and i64 %2, 1
  %5 = icmp eq i64 %2, 1
  br i1 %5, 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 i64 [ poison, %.lr.ph.preheader ], [ %34, %.lr.ph ]
  %.011.unr = phi i64 [ %4, %.lr.ph.preheader ], [ %34, %.lr.ph ]
  %.0910.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %35, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %6 = getelementptr inbounds i8, ptr %1, i64 %.0910.unr
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = lshr i64 %.011.unr, 56
  %9 = zext i8 %7 to i64
  %10 = xor i64 %8, %9
  %11 = getelementptr inbounds [256 x i64], ptr @crc64_ecma_norm_table, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !8
  %13 = shl i64 %.011.unr, 8
  %14 = xor i64 %12, %13
  br label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.lcssa = phi i64 [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %14, %.lr.ph.epil ]
  %15 = xor i64 %.lcssa, -1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %3
  %.0.lcssa = phi i64 [ %0, %3 ], [ %15, %._crit_edge.loopexit ]
  ret i64 %.0.lcssa

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.011 = phi i64 [ %4, %.lr.ph.preheader.new ], [ %34, %.lr.ph ]
  %.0910 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %35, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %16 = getelementptr inbounds i8, ptr %1, i64 %.0910
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %18 = lshr i64 %.011, 56
  %19 = zext i8 %17 to i64
  %20 = xor i64 %18, %19
  %21 = getelementptr inbounds [256 x i64], ptr @crc64_ecma_norm_table, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !8
  %23 = shl i64 %.011, 8
  %24 = xor i64 %22, %23
  %25 = or disjoint i64 %.0910, 1
  %26 = getelementptr inbounds i8, ptr %1, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = lshr i64 %24, 56
  %29 = zext i8 %27 to i64
  %30 = xor i64 %28, %29
  %31 = getelementptr inbounds [256 x i64], ptr @crc64_ecma_norm_table, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !8
  %33 = shl i64 %24, 8
  %34 = xor i64 %32, %33
  %35 = add nuw i64 %.0910, 2
  %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(argmem: read) 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 = !{!"long", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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