; LLVM IR from intel/qpl :: tools/ref (ref_crc32)

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

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

15:                                               ; preds = %53, %4
  %16 = load i32, ptr %10, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp ult i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %56

20:                                               ; preds = %15
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = call zeroext i8 @reverse_bits_8(i8 noundef zeroext %25)
  %27 = zext i8 %26 to i32
  %28 = shl i32 %27, 24
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = xor i32 %29, %28
  store i32 %30, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %49, %20
  %32 = load i32, ptr %12, align 4, !tbaa !9
  %33 = icmp ult i32 %32, 8
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %52

35:                                               ; preds = %31
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = and i32 -2147483648, %36
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %44

39:                                               ; preds = %35
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = shl i32 %40, 1
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = xor i32 %41, %42
  br label %47

44:                                               ; preds = %35
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = shl i32 %45, 1
  br label %47

47:                                               ; preds = %44, %39
  %48 = phi i32 [ %43, %39 ], [ %46, %44 ]
  store i32 %48, ptr %9, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %47
  %50 = load i32, ptr %12, align 4, !tbaa !9
  %51 = add i32 %50, 1
  store i32 %51, ptr %12, align 4, !tbaa !9
  br label %31, !llvm.loop !12

52:                                               ; preds = %34
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = add i32 %54, 1
  store i32 %55, ptr %10, align 4, !tbaa !9
  br label %15, !llvm.loop !14

56:                                               ; preds = %19
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = call i32 @reverse_bits_32(i32 noundef %57)
  %59 = xor i32 %58, -1
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret i32 %59
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @reverse_bits_8(i8 noundef zeroext) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @reverse_bits_32(i32 noundef) #2

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 = { inlinehint 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 #3 = { 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"

; Function Attrs: nounwind uwtable
define dso_local i32 @ref_crc32(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = xor i32 %3, -1
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

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

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.014.lcssa = phi i32 [ %5, %4 ], [ %37, %.lr.ph ]
  %6 = tail call i32 @reverse_bits_32(i32 noundef %.014.lcssa)
  %7 = xor i32 %6, -1
  ret i32 %7

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.01418 = phi i32 [ %5, %.lr.ph.preheader ], [ %37, %.lr.ph ]
  %8 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = tail call zeroext i8 @reverse_bits_8(i8 noundef zeroext %9)
  %11 = zext i8 %10 to i32
  %12 = shl nuw i32 %11, 24
  %13 = xor i32 %12, %.01418
  %14 = shl i32 %13, 1
  %.not15 = icmp slt i32 %13, 0
  %15 = select i1 %.not15, i32 %2, i32 0
  %16 = xor i32 %15, %14
  %17 = shl i32 %16, 1
  %.not15.1 = icmp slt i32 %16, 0
  %18 = select i1 %.not15.1, i32 %2, i32 0
  %19 = xor i32 %18, %17
  %20 = shl i32 %19, 1
  %.not15.2 = icmp slt i32 %19, 0
  %21 = select i1 %.not15.2, i32 %2, i32 0
  %22 = xor i32 %21, %20
  %23 = shl i32 %22, 1
  %.not15.3 = icmp slt i32 %22, 0
  %24 = select i1 %.not15.3, i32 %2, i32 0
  %25 = xor i32 %24, %23
  %26 = shl i32 %25, 1
  %.not15.4 = icmp slt i32 %25, 0
  %27 = select i1 %.not15.4, i32 %2, i32 0
  %28 = xor i32 %27, %26
  %29 = shl i32 %28, 1
  %.not15.5 = icmp slt i32 %28, 0
  %30 = select i1 %.not15.5, i32 %2, i32 0
  %31 = xor i32 %30, %29
  %32 = shl i32 %31, 1
  %.not15.6 = icmp slt i32 %31, 0
  %33 = select i1 %.not15.6, i32 %2, i32 0
  %34 = xor i32 %33, %32
  %35 = shl i32 %34, 1
  %.not15.7 = icmp slt i32 %34, 0
  %36 = select i1 %.not15.7, i32 %2, i32 0
  %37 = xor i32 %36, %35
  %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, label %.lr.ph, !llvm.loop !8
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @reverse_bits_8(i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @reverse_bits_32(i32 noundef) local_unnamed_addr #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 = { inlinehint 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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