; LLVM IR from Razakhel/RaZ :: extern/fastgltf/src/fastgltf.ll (ZN8fastgltf10sse_crc32cEPKhm)

; 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: hot mustprogress nounwind willreturn memory(none) uwtable
define dso_local noundef i32 @_ZN8fastgltf10sse_crc32cEPKhm(ptr noundef %0, i64 noundef %1) #0 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i16, align 2
  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 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %9 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %9, ptr %6, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %19, %2
  %11 = load i64, ptr %6, align 8, !tbaa !9
  %12 = sub i64 %11, 4
  store i64 %12, ptr %6, align 8, !tbaa !9
  %13 = icmp sge i64 %12, 0
  br i1 %13, label %14, label %22

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 1 %15, i64 4, i1 false)
  %16 = load i32, ptr %5, align 4, !tbaa !11
  %17 = load i32, ptr %7, align 4, !tbaa !11
  %18 = invoke noundef i32 @_ZL13_mm_crc32_u32jj(i32 noundef %16, i32 noundef %17)
          to label %19 unwind label %46

19:                                               ; preds = %14
  store i32 %18, ptr %5, align 4, !tbaa !11
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 4
  store ptr %21, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %10, !llvm.loop !13

22:                                               ; preds = %10
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = and i64 %23, 2
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %34

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #5
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %8, ptr align 1 %27, i64 2, i1 false)
  %28 = load i32, ptr %5, align 4, !tbaa !11
  %29 = load i16, ptr %8, align 2, !tbaa !15
  %30 = invoke noundef i32 @_ZL13_mm_crc32_u16jt(i32 noundef %28, i16 noundef zeroext %29)
          to label %31 unwind label %46

31:                                               ; preds = %26
  store i32 %30, ptr %5, align 4, !tbaa !11
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 2
  store ptr %33, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #5
  br label %34

34:                                               ; preds = %31, %22
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = and i64 %35, 1
  %37 = icmp ne i64 %36, 0
  br i1 %37, label %38, label %44

38:                                               ; preds = %34
  %39 = load i32, ptr %5, align 4, !tbaa !11
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load i8, ptr %40, align 1, !tbaa !17
  %42 = invoke noundef i32 @_ZL12_mm_crc32_u8jh(i32 noundef %39, i8 noundef zeroext %41)
          to label %43 unwind label %46

43:                                               ; preds = %38
  store i32 %42, ptr %5, align 4, !tbaa !11
  br label %44

44:                                               ; preds = %43, %34
  %45 = load i32, ptr %5, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %45

46:                                               ; preds = %38, %26, %14
  %47 = landingpad { ptr, i32 }
          catch ptr null
  %48 = extractvalue { ptr, i32 } %47, 0
  call void @__clang_call_terminate(ptr %48) #6
  unreachable
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL13_mm_crc32_u32jj(i32 noundef, i32 noundef) #3

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #4

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL13_mm_crc32_u16jt(i32 noundef, i16 noundef zeroext) #3

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL12_mm_crc32_u8jh(i32 noundef, i8 noundef zeroext) #3

attributes #0 = { hot mustprogress nounwind willreturn memory(none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+crc32,+cx8,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { alwaysinline mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+crc32,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { noinline noreturn nounwind uwtable "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 #5 = { nounwind }
attributes #6 = { noreturn 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!7, !7, i64 0}


; 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: hot mustprogress nofree nosync nounwind willreturn memory(none) uwtable
define dso_local noundef i32 @_ZN8fastgltf10sse_crc32cEPKhm(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %3 = add i64 %1, -4
  %4 = icmp sgt i64 %3, -1
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %.lr.ph
  %5 = phi i64 [ %8, %.lr.ph ], [ %3, %2 ]
  %.022 = phi ptr [ %7, %.lr.ph ], [ %0, %2 ]
  %.01521 = phi i32 [ %6, %.lr.ph ], [ 0, %2 ]
  %.0.copyload1 = load i32, ptr %.022, align 1
  %6 = tail call noundef i32 @_ZL13_mm_crc32_u32jj(i32 noundef %.01521, i32 noundef %.0.copyload1)
  %7 = getelementptr inbounds i8, ptr %.022, i64 4
  %8 = add nsw i64 %5, -4
  %9 = icmp ugt i64 %5, 3
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.017.lcssa = phi i64 [ %1, %2 ], [ %5, %.lr.ph ]
  %.015.lcssa = phi i32 [ 0, %2 ], [ %6, %.lr.ph ]
  %.0.lcssa = phi ptr [ %0, %2 ], [ %7, %.lr.ph ]
  %10 = and i64 %.017.lcssa, 2
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %14, label %11

11:                                               ; preds = %._crit_edge
  %.0.copyload = load i16, ptr %.0.lcssa, align 1
  %12 = tail call noundef i32 @_ZL13_mm_crc32_u16jt(i32 noundef %.015.lcssa, i16 noundef zeroext %.0.copyload)
  %13 = getelementptr inbounds i8, ptr %.0.lcssa, i64 2
  br label %14

14:                                               ; preds = %11, %._crit_edge
  %.116 = phi i32 [ %12, %11 ], [ %.015.lcssa, %._crit_edge ]
  %.1 = phi ptr [ %13, %11 ], [ %.0.lcssa, %._crit_edge ]
  %15 = and i64 %.017.lcssa, 1
  %.not20 = icmp eq i64 %15, 0
  br i1 %.not20, label %19, label %16

16:                                               ; preds = %14
  %17 = load i8, ptr %.1, align 1, !tbaa !7
  %18 = tail call noundef i32 @_ZL12_mm_crc32_u8jh(i32 noundef %.116, i8 noundef zeroext %17)
  br label %19

19:                                               ; preds = %16, %14
  %.2 = phi i32 [ %18, %16 ], [ %.116, %14 ]
  ret i32 %.2
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL13_mm_crc32_u32jj(i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL13_mm_crc32_u16jt(i32 noundef, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL12_mm_crc32_u8jh(i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

attributes #0 = { hot mustprogress nofree nosync nounwind willreturn memory(none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+crc32,+cx8,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87" "tune-cpu"="generic" }
attributes #1 = { alwaysinline mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+crc32,+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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


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