; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/Common/CrcReg.ll (ZN10CCrcHasher12SetFunctionsEj)

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

%class.CCrcHasher = type { %struct.IHasher, %struct.ICompressSetCoderProperties, %class.CMyUnknownImp, i32, ptr, [128 x i8] }
%struct.IHasher = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.ICompressSetCoderProperties = type { %struct.IUnknown }
%class.CMyUnknownImp = type { i32 }

@g_CrcUpdate = external global ptr, align 8
@g_CrcUpdateT4 = external global ptr, align 8
@g_CrcUpdateT8 = external global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN10CCrcHasher12SetFunctionsEj(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8
  %7 = load ptr, ptr @g_CrcUpdate, align 8, !tbaa !5
  %8 = getelementptr inbounds %class.CCrcHasher, ptr %6, i32 0, i32 4
  store ptr %7, ptr %8, align 8, !tbaa !11
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %11, label %13

11:                                               ; preds = %2
  %12 = getelementptr inbounds %class.CCrcHasher, ptr %6, i32 0, i32 4
  store ptr @CrcUpdateT1, ptr %12, align 8, !tbaa !11
  br label %37

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

16:                                               ; preds = %13
  %17 = load ptr, ptr @g_CrcUpdateT4, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = load ptr, ptr @g_CrcUpdateT4, align 8, !tbaa !5
  %21 = getelementptr inbounds %class.CCrcHasher, ptr %6, i32 0, i32 4
  store ptr %20, ptr %21, align 8, !tbaa !11
  br label %23

22:                                               ; preds = %16
  store i1 false, ptr %3, align 1
  br label %38

23:                                               ; preds = %19
  br label %36

24:                                               ; preds = %13
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = icmp eq i32 %25, 8
  br i1 %26, label %27, label %35

27:                                               ; preds = %24
  %28 = load ptr, ptr @g_CrcUpdateT8, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = load ptr, ptr @g_CrcUpdateT8, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.CCrcHasher, ptr %6, i32 0, i32 4
  store ptr %31, ptr %32, align 8, !tbaa !11
  br label %34

33:                                               ; preds = %27
  store i1 false, ptr %3, align 1
  br label %38

34:                                               ; preds = %30
  br label %35

35:                                               ; preds = %34, %24
  br label %36

36:                                               ; preds = %35, %23
  br label %37

37:                                               ; preds = %36, %11
  store i1 true, ptr %3, align 1
  br label %38

38:                                               ; preds = %37, %33, %22
  %39 = load i1, ptr %3, align 1
  ret i1 %39
}

declare i32 @CrcUpdateT1(i32 noundef, ptr noundef, i64 noundef, ptr noundef) #1

attributes #0 = { mustprogress 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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"_ZTS10CCrcHasher", !13, i64 0, !15, i64 8, !16, i64 16, !10, i64 20, !6, i64 24, !7, i64 32}
!13 = !{!"_ZTS7IHasher", !14, i64 0}
!14 = !{!"_ZTS8IUnknown"}
!15 = !{!"_ZTS27ICompressSetCoderProperties", !14, i64 0}
!16 = !{!"_ZTS13CMyUnknownImp", !10, 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_CrcUpdate = external local_unnamed_addr global ptr, align 8
@g_CrcUpdateT4 = external local_unnamed_addr global ptr, align 8
@g_CrcUpdateT8 = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: write, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_ZN10CCrcHasher12SetFunctionsEj(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(160) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = load ptr, ptr @g_CrcUpdate, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %3, ptr %4, align 8, !tbaa !9
  switch i32 %1, label %9 [
    i32 1, label %.sink.split
    i32 4, label %5
    i32 8, label %7
  ]

5:                                                ; preds = %2
  %6 = load ptr, ptr @g_CrcUpdateT4, align 8, !tbaa !5
  %.not7 = icmp eq ptr %6, null
  br i1 %.not7, label %9, label %.sink.split

7:                                                ; preds = %2
  %8 = load ptr, ptr @g_CrcUpdateT8, align 8, !tbaa !5
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %9, label %.sink.split

.sink.split:                                      ; preds = %7, %5, %2
  %CrcUpdateT1.sink = phi ptr [ @CrcUpdateT1, %2 ], [ %6, %5 ], [ %8, %7 ]
  store ptr %CrcUpdateT1.sink, ptr %4, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %.sink.split, %2, %7, %5
  %.0 = phi i1 [ false, %5 ], [ false, %7 ], [ true, %2 ], [ true, %.sink.split ]
  ret i1 %.0
}

declare i32 @CrcUpdateT1(i32 noundef, ptr noundef, i64 noundef, ptr noundef) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: write, 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"_ZTS10CCrcHasher", !11, i64 0, !13, i64 8, !14, i64 16, !15, i64 20, !6, i64 24, !7, i64 32}
!11 = !{!"_ZTS7IHasher", !12, i64 0}
!12 = !{!"_ZTS8IUnknown"}
!13 = !{!"_ZTS27ICompressSetCoderProperties", !12, i64 0}
!14 = !{!"_ZTS13CMyUnknownImp", !15, i64 0}
!15 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass