; LLVM IR from mncoppola/rpef :: utilities_src/squashfs2.1/lzma/C/7zip/Archive/7z_C (7zCrc)

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

@g_CrcTable = external dso_local global [256 x i32], 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 void @CrcUpdate(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load i32, ptr %9, align 4, !tbaa !11
  store i32 %10, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %11, ptr %8, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %29, %3
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = icmp ugt i64 %13, 0
  br i1 %14, label %15, label %34

15:                                               ; preds = %12
  %16 = load i32, ptr %7, align 4, !tbaa !11
  %17 = trunc i32 %16 to i8
  %18 = zext i8 %17 to i32
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !13
  %21 = zext i8 %20 to i32
  %22 = xor i32 %18, %21
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [256 x i32], ptr @g_CrcTable, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = load i32, ptr %7, align 4, !tbaa !11
  %27 = lshr i32 %26, 8
  %28 = xor i32 %25, %27
  store i32 %28, ptr %7, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %15
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = add i64 %30, -1
  store i64 %31, ptr %6, align 8, !tbaa !9
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i32 1
  store ptr %33, ptr %8, align 8, !tbaa !5
  br label %12, !llvm.loop !14

34:                                               ; preds = %12
  %35 = load i32, ptr %7, align 4, !tbaa !11
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 %35, ptr %36, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@g_CrcTable = external dso_local local_unnamed_addr global [256 x i32], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @CrcUpdate(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %0, align 4, !tbaa !5
  %.not11 = icmp eq i64 %2, 0
  br i1 %.not11, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %xtraiter = and i64 %2, 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 = and i32 %4, 255
  %6 = load i8, ptr %1, align 1, !tbaa !9
  %7 = zext i8 %6 to i32
  %8 = xor i32 %5, %7
  %9 = zext nneg i32 %8 to i64
  %10 = getelementptr inbounds [256 x i32], ptr @g_CrcTable, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = lshr i32 %4, 8
  %13 = xor i32 %11, %12
  %14 = add nsw i64 %2, -1
  %15 = getelementptr inbounds i8, ptr %1, i64 1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.lcssa.unr = phi i32 [ poison, %.lr.ph.preheader ], [ %13, %.lr.ph.prol ]
  %.014.unr = phi ptr [ %1, %.lr.ph.preheader ], [ %15, %.lr.ph.prol ]
  %.0913.unr = phi i32 [ %4, %.lr.ph.preheader ], [ %13, %.lr.ph.prol ]
  %.01012.unr = phi i64 [ %2, %.lr.ph.preheader ], [ %14, %.lr.ph.prol ]
  %16 = icmp eq i64 %2, 1
  br i1 %16, label %._crit_edge, label %.lr.ph

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

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %3
  %.09.lcssa = phi i32 [ %4, %3 ], [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %35, %.lr.ph ]
  store i32 %.09.lcssa, ptr %0, align 4, !tbaa !5
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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 = !{!"int", !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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass