; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/C (XzCrc64)

; 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_Crc64Update = external hidden global ptr, align 8
@g_Crc64Table = external dso_local global [1024 x i64], align 16

; Function Attrs: nounwind uwtable
define dso_local void @Crc64GenerateTable() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %5

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

8:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = zext i32 %9 to i64
  store i64 %10, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %22, %8
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = icmp ult i32 %12, 8
  br i1 %13, label %14, label %25

14:                                               ; preds = %11
  %15 = load i64, ptr %2, align 8, !tbaa !9
  %16 = lshr i64 %15, 1
  %17 = load i64, ptr %2, align 8, !tbaa !9
  %18 = and i64 %17, 1
  %19 = sub i64 0, %18
  %20 = and i64 -3932672073523589310, %19
  %21 = xor i64 %16, %20
  store i64 %21, ptr %2, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %14
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = add i32 %23, 1
  store i32 %24, ptr %3, align 4, !tbaa !5
  br label %11, !llvm.loop !11

25:                                               ; preds = %11
  %26 = load i64, ptr %2, align 8, !tbaa !9
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds [1024 x i64], ptr @g_Crc64Table, i64 0, i64 %28
  store i64 %26, ptr %29, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %30

30:                                               ; preds = %25
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = add i32 %31, 1
  store i32 %32, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !13

33:                                               ; preds = %5
  store i32 256, ptr %1, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %53, %33
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = icmp ult i32 %35, 1024
  br i1 %36, label %37, label %56

37:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %38 = load i32, ptr %1, align 4, !tbaa !5
  %39 = zext i32 %38 to i64
  %40 = sub i64 %39, 256
  %41 = getelementptr inbounds [1024 x i64], ptr @g_Crc64Table, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !9
  store i64 %42, ptr %4, align 8, !tbaa !9
  %43 = load i64, ptr %4, align 8, !tbaa !9
  %44 = and i64 %43, 255
  %45 = getelementptr inbounds [1024 x i64], ptr @g_Crc64Table, i64 0, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !9
  %47 = load i64, ptr %4, align 8, !tbaa !9
  %48 = lshr i64 %47, 8
  %49 = xor i64 %46, %48
  %50 = load i32, ptr %1, align 4, !tbaa !5
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds [1024 x i64], ptr @g_Crc64Table, i64 0, i64 %51
  store i64 %49, ptr %52, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %53

53:                                               ; preds = %37
  %54 = load i32, ptr %1, align 4, !tbaa !5
  %55 = add i32 %54, 1
  store i32 %55, ptr %1, align 4, !tbaa !5
  br label %34, !llvm.loop !14

56:                                               ; preds = %34
  store ptr @XzCrc64UpdateT4, ptr @g_Crc64Update, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

; 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

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

@g_Crc64Update = external hidden local_unnamed_addr global ptr, align 8
@g_Crc64Table = external dso_local local_unnamed_addr global [1024 x i64], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @Crc64GenerateTable() local_unnamed_addr #0 {
vector.ph:
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i64> [ <i64 0, i64 1>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %0 = lshr <2 x i64> %vec.ind, <i64 1, i64 1>
  %1 = and <2 x i64> %vec.ind, <i64 1, i64 1>
  %2 = icmp eq <2 x i64> %1, zeroinitializer
  %3 = select <2 x i1> %2, <2 x i64> zeroinitializer, <2 x i64> <i64 -3932672073523589310, i64 -3932672073523589310>
  %4 = xor <2 x i64> %3, %0
  %5 = lshr <2 x i64> %4, <i64 1, i64 1>
  %6 = and <2 x i64> %vec.ind, <i64 2, i64 2>
  %7 = icmp eq <2 x i64> %6, zeroinitializer
  %8 = select <2 x i1> %7, <2 x i64> zeroinitializer, <2 x i64> <i64 -3932672073523589310, i64 -3932672073523589310>
  %9 = xor <2 x i64> %8, %5
  %10 = lshr <2 x i64> %9, <i64 1, i64 1>
  %11 = and <2 x i64> %4, <i64 2, i64 2>
  %12 = icmp eq <2 x i64> %11, zeroinitializer
  %13 = select <2 x i1> %12, <2 x i64> zeroinitializer, <2 x i64> <i64 -3932672073523589310, i64 -3932672073523589310>
  %14 = xor <2 x i64> %13, %10
  %15 = lshr <2 x i64> %14, <i64 1, i64 1>
  %16 = and <2 x i64> %9, <i64 2, i64 2>
  %17 = icmp eq <2 x i64> %16, zeroinitializer
  %18 = select <2 x i1> %17, <2 x i64> zeroinitializer, <2 x i64> <i64 -3932672073523589310, i64 -3932672073523589310>
  %19 = xor <2 x i64> %18, %15
  %20 = lshr <2 x i64> %19, <i64 1, i64 1>
  %21 = and <2 x i64> %14, <i64 2, i64 2>
  %22 = icmp eq <2 x i64> %21, zeroinitializer
  %23 = select <2 x i1> %22, <2 x i64> zeroinitializer, <2 x i64> <i64 -3932672073523589310, i64 -3932672073523589310>
  %24 = xor <2 x i64> %23, %20
  %25 = lshr <2 x i64> %24, <i64 1, i64 1>
  %26 = and <2 x i64> %19, <i64 2, i64 2>
  %27 = icmp eq <2 x i64> %26, zeroinitializer
  %28 = select <2 x i1> %27, <2 x i64> zeroinitializer, <2 x i64> <i64 -3932672073523589310, i64 -3932672073523589310>
  %29 = xor <2 x i64> %28, %25
  %30 = lshr <2 x i64> %29, <i64 2, i64 2>
  %31 = and <2 x i64> %24, <i64 2, i64 2>
  %32 = icmp eq <2 x i64> %31, zeroinitializer
  %33 = select <2 x i1> %32, <2 x i64> zeroinitializer, <2 x i64> <i64 7257036000092981153, i64 7257036000092981153>
  %34 = xor <2 x i64> %33, %30
  %35 = and <2 x i64> %29, <i64 2, i64 2>
  %36 = icmp eq <2 x i64> %35, zeroinitializer
  %37 = select <2 x i1> %36, <2 x i64> zeroinitializer, <2 x i64> <i64 -3932672073523589310, i64 -3932672073523589310>
  %38 = xor <2 x i64> %37, %34
  %39 = getelementptr inbounds [1024 x i64], ptr @g_Crc64Table, i64 0, i64 %index
  store <2 x i64> %38, ptr %39, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 2
  %vec.ind.next = add <2 x i64> %vec.ind, <i64 2, i64 2>
  %40 = icmp eq i64 %index.next, 256
  br i1 %40, label %.preheader, label %vector.body, !llvm.loop !9

.preheader:                                       ; preds = %vector.body, %.preheader
  %indvars.iv22 = phi i64 [ %indvars.iv.next23.1, %.preheader ], [ 256, %vector.body ]
  %41 = add nsw i64 %indvars.iv22, -256
  %42 = getelementptr inbounds [1024 x i64], ptr @g_Crc64Table, i64 0, i64 %41
  %43 = load i64, ptr %42, align 16, !tbaa !5
  %44 = and i64 %43, 255
  %45 = getelementptr inbounds [1024 x i64], ptr @g_Crc64Table, i64 0, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !5
  %47 = lshr i64 %43, 8
  %48 = xor i64 %46, %47
  %49 = getelementptr inbounds [1024 x i64], ptr @g_Crc64Table, i64 0, i64 %indvars.iv22
  store i64 %48, ptr %49, align 16, !tbaa !5
  %indvars.iv.next23 = or disjoint i64 %indvars.iv22, 1
  %50 = add nsw i64 %indvars.iv22, -255
  %51 = getelementptr inbounds [1024 x i64], ptr @g_Crc64Table, i64 0, i64 %50
  %52 = load i64, ptr %51, align 8, !tbaa !5
  %53 = and i64 %52, 255
  %54 = getelementptr inbounds [1024 x i64], ptr @g_Crc64Table, i64 0, i64 %53
  %55 = load i64, ptr %54, align 8, !tbaa !5
  %56 = lshr i64 %52, 8
  %57 = xor i64 %55, %56
  %58 = getelementptr inbounds [1024 x i64], ptr @g_Crc64Table, i64 0, i64 %indvars.iv.next23
  store i64 %57, ptr %58, align 8, !tbaa !5
  %indvars.iv.next23.1 = add nuw nsw i64 %indvars.iv22, 2
  %exitcond25.not.1 = icmp eq i64 %indvars.iv.next23.1, 1024
  br i1 %exitcond25.not.1, label %59, label %.preheader, !llvm.loop !13

59:                                               ; preds = %.preheader
  store ptr @XzCrc64UpdateT4, ptr @g_Crc64Update, align 8, !tbaa !14
  ret void
}

declare i64 @XzCrc64UpdateT4(i64 noundef, ptr noundef, i64 noundef, ptr noundef) #1

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: none, 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" }
attributes #1 = { "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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !7, i64 0}


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