; LLVM IR from seppo0010/rlite :: src (crc64)

; 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_tab = external hidden constant [256 x i64], align 16

; Function Attrs: nounwind uwtable
define dso_local i64 @rl_crc64(i64 noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = 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
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %30, %3
  %10 = load i64, ptr %7, align 8, !tbaa !5
  %11 = load i64, ptr %6, align 8, !tbaa !5
  %12 = icmp ult i64 %10, %11
  br i1 %12, label %13, label %33

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  %15 = load i64, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %14, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !11
  store i8 %17, ptr %8, align 1, !tbaa !11
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = trunc i64 %18 to i8
  %20 = zext i8 %19 to i32
  %21 = load i8, ptr %8, align 1, !tbaa !11
  %22 = zext i8 %21 to i32
  %23 = xor i32 %20, %22
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [256 x i64], ptr @crc64_tab, i64 0, i64 %24
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = lshr i64 %27, 8
  %29 = xor i64 %26, %28
  store i64 %29, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  br label %30

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

33:                                               ; preds = %9
  %34 = load i64, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i64 %34
}

; 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", !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_tab = 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 @rl_crc64(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
  %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

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.010 = phi i64 [ %0, %.lr.ph.preheader.new ], [ %23, %.lr.ph ]
  %.089 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %24, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %5 = getelementptr inbounds i8, ptr %1, i64 %.089
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = and i64 %.010, 255
  %8 = zext i8 %6 to i64
  %9 = xor i64 %7, %8
  %10 = getelementptr inbounds [256 x i64], ptr @crc64_tab, i64 0, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !8
  %12 = lshr i64 %.010, 8
  %13 = xor i64 %11, %12
  %14 = or disjoint i64 %.089, 1
  %15 = getelementptr inbounds i8, ptr %1, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = and i64 %13, 255
  %18 = zext i8 %16 to i64
  %19 = xor i64 %17, %18
  %20 = getelementptr inbounds [256 x i64], ptr @crc64_tab, i64 0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !8
  %22 = lshr i64 %13, 8
  %23 = xor i64 %21, %22
  %24 = add nuw i64 %.089, 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

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %23, %.lr.ph ]
  %.010.unr = phi i64 [ %0, %.lr.ph.preheader ], [ %23, %.lr.ph ]
  %.089.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %24, %.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
  %25 = getelementptr inbounds i8, ptr %1, i64 %.089.unr
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = and i64 %.010.unr, 255
  %28 = zext i8 %26 to i64
  %29 = xor i64 %27, %28
  %30 = getelementptr inbounds [256 x i64], ptr @crc64_tab, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !8
  %32 = lshr i64 %.010.unr, 8
  %33 = xor i64 %31, %32
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %3
  %.0.lcssa = phi i64 [ %0, %3 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %33, %.lr.ph.epil ]
  ret i64 %.0.lcssa
}

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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass