; LLVM IR from stamparm/cryptospecs :: hash/sources (crc)

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

@crcmask = external dso_local global i64, align 8
@crctab = external dso_local global [256 x i64], align 16
@crcinit_direct = external dso_local global i64, align 8

; Function Attrs: nounwind uwtable
declare dso_local i64 @reflect(i64 noundef, i32 noundef) #0

; 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

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

9:                                                ; preds = %13, %2
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = add i64 %10, -1
  store i64 %11, ptr %4, align 8, !tbaa !9
  %12 = icmp ne i64 %10, 0
  br i1 %12, label %13, label %26

13:                                               ; preds = %9
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = lshr i64 %14, 8
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = and i64 %16, 255
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i32 1
  store ptr %19, ptr %3, align 8, !tbaa !5
  %20 = load i8, ptr %18, align 1, !tbaa !11
  %21 = zext i8 %20 to i64
  %22 = xor i64 %17, %21
  %23 = getelementptr inbounds [256 x i64], ptr @crctab, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = xor i64 %15, %24
  store i64 %25, ptr %5, align 8, !tbaa !9
  br label %9, !llvm.loop !12

26:                                               ; preds = %9
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = xor i64 %27, 4294967295
  store i64 %28, ptr %5, align 8, !tbaa !9
  %29 = load i64, ptr @crcmask, align 8, !tbaa !9
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = and i64 %30, %29
  store i64 %31, ptr %5, align 8, !tbaa !9
  %32 = load i64, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i64 %32
}

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

@crcmask = external dso_local local_unnamed_addr global i64, align 8
@crctab = external dso_local local_unnamed_addr global [256 x i64], align 16
@crcinit_direct = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: nounwind uwtable
declare dso_local i64 @reflect(i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @crctablefast(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = load i64, ptr @crcinit_direct, align 8, !tbaa !5
  %4 = tail call i64 @reflect(i64 noundef %3, i32 noundef 32)
  %.not9 = icmp eq i64 %1, 0
  br i1 %.not9, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %xtraiter = and i64 %1, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader
  %5 = add nsw i64 %1, -1
  %6 = lshr i64 %4, 8
  %7 = and i64 %4, 255
  %8 = getelementptr inbounds i8, ptr %0, i64 1
  %9 = load i8, ptr %0, align 1, !tbaa !9
  %10 = zext i8 %9 to i64
  %11 = xor i64 %7, %10
  %12 = getelementptr inbounds [256 x i64], ptr @crctab, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = xor i64 %13, %6
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.lcssa.unr = phi i64 [ poison, %.lr.ph.preheader ], [ %14, %.lr.ph.prol ]
  %.012.unr = phi i64 [ %4, %.lr.ph.preheader ], [ %14, %.lr.ph.prol ]
  %.0711.unr = phi i64 [ %1, %.lr.ph.preheader ], [ %5, %.lr.ph.prol ]
  %.0810.unr = phi ptr [ %0, %.lr.ph.preheader ], [ %8, %.lr.ph.prol ]
  %15 = icmp eq i64 %1, 1
  br i1 %15, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.012 = phi i64 [ %34, %.lr.ph ], [ %.012.unr, %.lr.ph.prol.loopexit ]
  %.0711 = phi i64 [ %25, %.lr.ph ], [ %.0711.unr, %.lr.ph.prol.loopexit ]
  %.0810 = phi ptr [ %28, %.lr.ph ], [ %.0810.unr, %.lr.ph.prol.loopexit ]
  %16 = lshr i64 %.012, 8
  %17 = and i64 %.012, 255
  %18 = getelementptr inbounds i8, ptr %.0810, i64 1
  %19 = load i8, ptr %.0810, align 1, !tbaa !9
  %20 = zext i8 %19 to i64
  %21 = xor i64 %17, %20
  %22 = getelementptr inbounds [256 x i64], ptr @crctab, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = xor i64 %23, %16
  %25 = add i64 %.0711, -2
  %26 = lshr i64 %24, 8
  %27 = and i64 %24, 255
  %28 = getelementptr inbounds i8, ptr %.0810, i64 2
  %29 = load i8, ptr %18, align 1, !tbaa !9
  %30 = zext i8 %29 to i64
  %31 = xor i64 %27, %30
  %32 = getelementptr inbounds [256 x i64], ptr @crctab, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = xor i64 %33, %26
  %.not.1 = icmp eq i64 %25, 0
  br i1 %.not.1, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %2
  %.0.lcssa = phi i64 [ %4, %2 ], [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %34, %.lr.ph ]
  %35 = xor i64 %.0.lcssa, 4294967295
  %36 = load i64, ptr @crcmask, align 8, !tbaa !5
  %37 = and i64 %36, %35
  ret i64 %37
}

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

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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