; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Compress (XzEncoder)

; 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.NCompress::NXz::CEncoder" = type { %struct.ICompressCoder, %struct.ICompressSetCoderProperties, %struct.ICompressSetCoderPropertiesOpt, %class.CMyUnknownImp, ptr, %struct.CXzProps }
%struct.ICompressCoder = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.ICompressSetCoderProperties = type { %struct.IUnknown }
%struct.ICompressSetCoderPropertiesOpt = type { %struct.IUnknown }
%class.CMyUnknownImp = type { i32 }
%struct.CXzProps = type { %struct.CLzma2EncProps, %struct.CXzFilterProps, i32, i64, i32, i32, i32, i32, i64 }
%struct.CLzma2EncProps = type { %struct._CLzmaEncProps, i64, i32, i32, i32 }
%struct._CLzmaEncProps = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64 }
%struct.CXzFilterProps = type { i32, i32, i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN9NCompress3NXz8CEncoder12SetCheckSizeEj(ptr noundef nonnull align 8 dereferenceable(176) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %9, label %14 [
    i32 0, label %10
    i32 4, label %11
    i32 8, label %12
    i32 32, label %13
  ]

10:                                               ; preds = %2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %15

11:                                               ; preds = %2
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %15

12:                                               ; preds = %2
  store i32 4, ptr %6, align 4, !tbaa !9
  br label %15

13:                                               ; preds = %2
  store i32 10, ptr %6, align 4, !tbaa !9
  br label %15

14:                                               ; preds = %2
  store i32 -2147024809, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %19

15:                                               ; preds = %13, %12, %11, %10
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = getelementptr inbounds %"class.NCompress::NXz::CEncoder", ptr %8, i32 0, i32 5
  %18 = getelementptr inbounds %struct.CXzProps, ptr %17, i32 0, i32 2
  store i32 %16, ptr %18, align 8, !tbaa !11
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %19

19:                                               ; preds = %15, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %20 = load i32, ptr %3, align 4
  ret i32 %20
}

; 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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 136}
!12 = !{!"_ZTSN9NCompress3NXz8CEncoderE", !13, i64 0, !15, i64 8, !16, i64 16, !17, i64 24, !6, i64 32, !18, i64 40}
!13 = !{!"_ZTS14ICompressCoder", !14, i64 0}
!14 = !{!"_ZTS8IUnknown"}
!15 = !{!"_ZTS27ICompressSetCoderProperties", !14, i64 0}
!16 = !{!"_ZTS30ICompressSetCoderPropertiesOpt", !14, i64 0}
!17 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!18 = !{!"_ZTS8CXzProps", !19, i64 0, !22, i64 80, !10, i64 96, !21, i64 104, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !21, i64 128}
!19 = !{!"_ZTS14CLzma2EncProps", !20, i64 0, !21, i64 56, !10, i64 64, !10, i64 68, !10, i64 72}
!20 = !{!"_ZTS14_CLzmaEncProps", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !21, i64 48}
!21 = !{!"long long", !7, i64 0}
!22 = !{!"_ZTS14CXzFilterProps", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}


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

@switch.table._ZN9NCompress3NXz8CEncoder12SetCheckSizeEj = private unnamed_addr constant [9 x i32] [i32 0, i32 1, i32 4, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10], align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local noundef range(i32 -2147024809, 1) i32 @_ZN9NCompress3NXz8CEncoder12SetCheckSizeEj(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(176) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = tail call i32 @llvm.fshl.i32(i32 %1, i32 %1, i32 30)
  %4 = icmp ult i32 %3, 9
  br i1 %4, label %switch.hole_check, label %7

switch.hole_check:                                ; preds = %2
  %switch.maskindex = trunc nuw i32 %3 to i16
  %switch.shifted = lshr i16 263, %switch.maskindex
  %switch.lobit = trunc i16 %switch.shifted to i1
  br i1 %switch.lobit, label %switch.lookup, label %7

switch.lookup:                                    ; preds = %switch.hole_check
  %5 = zext nneg i32 %3 to i64
  %switch.gep = getelementptr inbounds [9 x i32], ptr @switch.table._ZN9NCompress3NXz8CEncoder12SetCheckSizeEj, i64 0, i64 %5
  %switch.load = load i32, ptr %switch.gep, align 4
  %6 = getelementptr inbounds i8, ptr %0, i64 136
  store i32 %switch.load, ptr %6, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %switch.hole_check, %2, %switch.lookup
  %.03 = phi i32 [ 0, %switch.lookup ], [ -2147024809, %2 ], [ -2147024809, %switch.hole_check ]
  ret i32 %.03
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.fshl.i32(i32, i32, i32) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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 speculatable willreturn memory(none) }

!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, !12, i64 136}
!6 = !{!"_ZTSN9NCompress3NXz8CEncoderE", !7, i64 0, !9, i64 8, !10, i64 16, !11, i64 24, !15, i64 32, !16, i64 40}
!7 = !{!"_ZTS14ICompressCoder", !8, i64 0}
!8 = !{!"_ZTS8IUnknown"}
!9 = !{!"_ZTS27ICompressSetCoderProperties", !8, i64 0}
!10 = !{!"_ZTS30ICompressSetCoderPropertiesOpt", !8, i64 0}
!11 = !{!"_ZTS13CMyUnknownImp", !12, i64 0}
!12 = !{!"int", !13, i64 0}
!13 = !{!"omnipotent char", !14, i64 0}
!14 = !{!"Simple C++ TBAA"}
!15 = !{!"any pointer", !13, i64 0}
!16 = !{!"_ZTS8CXzProps", !17, i64 0, !20, i64 80, !12, i64 96, !19, i64 104, !12, i64 112, !12, i64 116, !12, i64 120, !12, i64 124, !19, i64 128}
!17 = !{!"_ZTS14CLzma2EncProps", !18, i64 0, !19, i64 56, !12, i64 64, !12, i64 68, !12, i64 72}
!18 = !{!"_ZTS14_CLzmaEncProps", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !19, i64 48}
!19 = !{!"long long", !13, i64 0}
!20 = !{!"_ZTS14CXzFilterProps", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12}


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