; LLVM IR from jgaeddert/liquid-dsp :: src/fec/src (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"

@liquid_reverse_byte_gentab = external constant [256 x i8], 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 i32 @crc8_generate_key(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 -1, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %11 = load i8, ptr getelementptr inbounds ([256 x i8], ptr @liquid_reverse_byte_gentab, i64 0, i64 7), align 1, !tbaa !11
  %12 = zext i8 %11 to i32
  store i32 %12, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %44, %2
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = icmp ult i32 %14, %15
  br i1 %16, label %17, label %47

17:                                               ; preds = %13
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %18, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = zext i8 %22 to i32
  store i32 %23, ptr %7, align 4, !tbaa !9
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = xor i32 %25, %24
  store i32 %26, ptr %9, align 4, !tbaa !9
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %40, %17
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp ult i32 %28, 8
  br i1 %29, label %30, label %43

30:                                               ; preds = %27
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = and i32 %31, 1
  %33 = sub i32 0, %32
  store i32 %33, ptr %8, align 4, !tbaa !9
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = lshr i32 %34, 1
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = and i32 %36, %37
  %39 = xor i32 %35, %38
  store i32 %39, ptr %9, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %30
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = add i32 %41, 1
  store i32 %42, ptr %6, align 4, !tbaa !9
  br label %27, !llvm.loop !12

43:                                               ; preds = %27
  br label %44

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

47:                                               ; preds = %13
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = xor i32 %48, -1
  %50 = and i32 %49, 255
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %50
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@liquid_reverse_byte_gentab = external local_unnamed_addr constant [256 x i8], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local range(i32 0, 256) i32 @crc8_generate_key(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i8, ptr getelementptr inbounds (i8, ptr @liquid_reverse_byte_gentab, i64 7), align 1, !tbaa !5
  %4 = zext i8 %3 to i32
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.01317 = phi i32 [ -1, %.lr.ph.preheader ], [ %48, %.lr.ph ]
  %5 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = zext i8 %6 to i32
  %8 = xor i32 %.01317, %7
  %9 = and i32 %8, 1
  %10 = lshr i32 %8, 1
  %11 = icmp eq i32 %9, 0
  %12 = select i1 %11, i32 0, i32 %4
  %13 = xor i32 %12, %10
  %14 = and i32 %13, 1
  %15 = lshr i32 %13, 1
  %16 = icmp eq i32 %14, 0
  %17 = select i1 %16, i32 0, i32 %4
  %18 = xor i32 %17, %15
  %19 = and i32 %18, 1
  %20 = lshr i32 %18, 1
  %21 = icmp eq i32 %19, 0
  %22 = select i1 %21, i32 0, i32 %4
  %23 = xor i32 %22, %20
  %24 = and i32 %23, 1
  %25 = lshr i32 %23, 1
  %26 = icmp eq i32 %24, 0
  %27 = select i1 %26, i32 0, i32 %4
  %28 = xor i32 %27, %25
  %29 = and i32 %28, 1
  %30 = lshr i32 %28, 1
  %31 = icmp eq i32 %29, 0
  %32 = select i1 %31, i32 0, i32 %4
  %33 = xor i32 %32, %30
  %34 = and i32 %33, 1
  %35 = lshr i32 %33, 1
  %36 = icmp eq i32 %34, 0
  %37 = select i1 %36, i32 0, i32 %4
  %38 = xor i32 %37, %35
  %39 = and i32 %38, 1
  %40 = lshr i32 %38, 1
  %41 = icmp eq i32 %39, 0
  %42 = select i1 %41, i32 0, i32 %4
  %43 = xor i32 %42, %40
  %44 = and i32 %43, 1
  %45 = lshr i32 %43, 1
  %46 = icmp eq i32 %44, 0
  %47 = select i1 %46, i32 0, i32 %4
  %48 = xor i32 %47, %45
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !8

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %49 = and i32 %48, 255
  %50 = xor i32 %49, 255
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.013.lcssa = phi i32 [ 0, %2 ], [ %50, %._crit_edge.loopexit ]
  ret i32 %.013.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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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