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

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

; 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 void @generate_crc_table() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %43, %0
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 256
  br i1 %7, label %8, label %46

8:                                                ; preds = %5
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  store i64 %10, ptr %4, align 8, !tbaa !9
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = call i64 @reflect(i64 noundef %11, i32 noundef 8)
  store i64 %12, ptr %4, align 8, !tbaa !9
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = shl i64 %13, 24
  store i64 %14, ptr %4, align 8, !tbaa !9
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %30, %8
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 8
  br i1 %17, label %18, label %33

18:                                               ; preds = %15
  %19 = load i64, ptr %4, align 8, !tbaa !9
  %20 = load i64, ptr @crchighbit, align 8, !tbaa !9
  %21 = and i64 %19, %20
  store i64 %21, ptr %3, align 8, !tbaa !9
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = shl i64 %22, 1
  store i64 %23, ptr %4, align 8, !tbaa !9
  %24 = load i64, ptr %3, align 8, !tbaa !9
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %18
  %27 = load i64, ptr %4, align 8, !tbaa !9
  %28 = xor i64 %27, 79764919
  store i64 %28, ptr %4, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %26, %18
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %2, align 4, !tbaa !5
  br label %15, !llvm.loop !11

33:                                               ; preds = %15
  %34 = load i64, ptr %4, align 8, !tbaa !9
  %35 = call i64 @reflect(i64 noundef %34, i32 noundef 32)
  store i64 %35, ptr %4, align 8, !tbaa !9
  %36 = load i64, ptr @crcmask, align 8, !tbaa !9
  %37 = load i64, ptr %4, align 8, !tbaa !9
  %38 = and i64 %37, %36
  store i64 %38, ptr %4, align 8, !tbaa !9
  %39 = load i64, ptr %4, align 8, !tbaa !9
  %40 = load i32, ptr %1, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [256 x i64], ptr @crctab, i64 0, i64 %41
  store i64 %39, ptr %42, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %33
  %44 = load i32, ptr %1, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !13

46:                                               ; preds = %5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

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 = !{!"int", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @generate_crc_table() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %0, %1
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %1 ]
  %2 = tail call i64 @reflect(i64 noundef %indvars.iv, i32 noundef 8)
  %3 = shl i64 %2, 24
  %4 = load i64, ptr @crchighbit, align 8, !tbaa !5
  %5 = and i64 %4, %3
  %6 = shl i64 %2, 25
  %.not = icmp eq i64 %5, 0
  %7 = xor i64 %6, 79764919
  %spec.select = select i1 %.not, i64 %6, i64 %7
  %8 = and i64 %4, %spec.select
  %9 = shl i64 %spec.select, 1
  %.not.1 = icmp eq i64 %8, 0
  %10 = xor i64 %9, 79764919
  %spec.select.1 = select i1 %.not.1, i64 %9, i64 %10
  %11 = and i64 %4, %spec.select.1
  %12 = shl i64 %spec.select.1, 1
  %.not.2 = icmp eq i64 %11, 0
  %13 = xor i64 %12, 79764919
  %spec.select.2 = select i1 %.not.2, i64 %12, i64 %13
  %14 = and i64 %4, %spec.select.2
  %15 = shl i64 %spec.select.2, 1
  %.not.3 = icmp eq i64 %14, 0
  %16 = xor i64 %15, 79764919
  %spec.select.3 = select i1 %.not.3, i64 %15, i64 %16
  %17 = and i64 %4, %spec.select.3
  %18 = shl i64 %spec.select.3, 1
  %.not.4 = icmp eq i64 %17, 0
  %19 = xor i64 %18, 79764919
  %spec.select.4 = select i1 %.not.4, i64 %18, i64 %19
  %20 = and i64 %4, %spec.select.4
  %21 = shl i64 %spec.select.4, 1
  %.not.5 = icmp eq i64 %20, 0
  %22 = xor i64 %21, 79764919
  %spec.select.5 = select i1 %.not.5, i64 %21, i64 %22
  %23 = and i64 %4, %spec.select.5
  %24 = shl i64 %spec.select.5, 1
  %.not.6 = icmp eq i64 %23, 0
  %25 = xor i64 %24, 79764919
  %spec.select.6 = select i1 %.not.6, i64 %24, i64 %25
  %26 = and i64 %4, %spec.select.6
  %27 = shl i64 %spec.select.6, 1
  %.not.7 = icmp eq i64 %26, 0
  %28 = xor i64 %27, 79764919
  %spec.select.7 = select i1 %.not.7, i64 %27, i64 %28
  %29 = tail call i64 @reflect(i64 noundef %spec.select.7, i32 noundef 32)
  %30 = load i64, ptr @crcmask, align 8, !tbaa !5
  %31 = and i64 %30, %29
  %32 = getelementptr inbounds [256 x i64], ptr @crctab, i64 0, i64 %indvars.iv
  store i64 %31, ptr %32, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 256
  br i1 %exitcond.not, label %33, label %1, !llvm.loop !9

33:                                               ; preds = %1
  ret void
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass