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

; 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::NBcj2::CBaseCoder" = type { [5 x ptr], [5 x i32], [5 x i32] }
%"class.NCompress::NBcj2::CDecoder" = type { %struct.ICompressCoder2, %struct.ICompressSetFinishMode, %struct.ICompressGetInStreamProcessedSize2, %struct.ICompressSetInStream2, %struct.ISequentialInStream, %struct.ICompressSetOutStreamSize, %struct.ICompressSetBufSize, %class.CMyUnknownImp, %"class.NCompress::NBcj2::CBaseCoder", [4 x i32], [4 x i64], [4 x i32], [4 x %class.CMyComPtr.0], i8, i8, i64, i64, %struct.CBcj2Dec }
%struct.ICompressCoder2 = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.ICompressSetFinishMode = type { %struct.IUnknown }
%struct.ICompressGetInStreamProcessedSize2 = type { %struct.IUnknown }
%struct.ICompressSetInStream2 = type { %struct.IUnknown }
%struct.ISequentialInStream = type { %struct.IUnknown }
%struct.ICompressSetOutStreamSize = type { %struct.IUnknown }
%struct.ICompressSetBufSize = type { %struct.IUnknown }
%class.CMyUnknownImp = type { i32 }
%class.CMyComPtr.0 = type { ptr }
%struct.CBcj2Dec = type { [4 x ptr], [4 x ptr], ptr, ptr, i32, i32, [4 x i8], i32, i32, [258 x i16] }

; 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: mustprogress uwtable
define dso_local void @_ZN9NCompress5NBcj28CDecoder10InitCommonEv(ptr noundef nonnull align 8 dereferenceable(880) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %27, %1
  %7 = load i32, ptr %3, align 4, !tbaa !9
  %8 = icmp slt i32 %7, 4
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %30

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %5, i64 64
  %12 = getelementptr inbounds %"class.NCompress::NBcj2::CBaseCoder", ptr %11, i32 0, i32 0
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [5 x ptr], ptr %12, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %5, i32 0, i32 17
  %18 = getelementptr inbounds %struct.CBcj2Dec, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [4 x ptr], ptr %18, i64 0, i64 %20
  store ptr %16, ptr %21, align 8, !tbaa !5
  %22 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %5, i32 0, i32 17
  %23 = getelementptr inbounds %struct.CBcj2Dec, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [4 x ptr], ptr %23, i64 0, i64 %25
  store ptr %16, ptr %26, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %10
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %3, align 4, !tbaa !9
  br label %6, !llvm.loop !11

30:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %48, %30
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = icmp slt i32 %32, 4
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %51

35:                                               ; preds = %31
  %36 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %5, i32 0, i32 9
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [4 x i32], ptr %36, i64 0, i64 %38
  store i32 0, ptr %39, align 4, !tbaa !9
  %40 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %5, i32 0, i32 10
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [4 x i64], ptr %40, i64 0, i64 %42
  store i64 0, ptr %43, align 8, !tbaa !13
  %44 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %5, i32 0, i32 11
  %45 = load i32, ptr %4, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [4 x i32], ptr %44, i64 0, i64 %46
  store i32 0, ptr %47, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %35
  %49 = load i32, ptr %4, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %4, align 4, !tbaa !9
  br label %31, !llvm.loop !15

51:                                               ; preds = %34
  %52 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %5, i32 0, i32 17
  call void @Bcj2Dec_Init(ptr noundef %52)
  ret void
}

declare void @Bcj2Dec_Init(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !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"

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9NCompress5NBcj28CDecoder10InitCommonEv(ptr noundef nonnull align 8 dereferenceable(880) %0) local_unnamed_addr #0 align 2 {
.preheader:
  %1 = getelementptr inbounds i8, ptr %0, i64 64
  %2 = getelementptr inbounds i8, ptr %0, i64 264
  %3 = getelementptr inbounds i8, ptr %0, i64 296
  %4 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %4, ptr %2, align 8, !tbaa !5
  store ptr %4, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 72
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 272
  store ptr %6, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 304
  store ptr %6, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 80
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 280
  store ptr %10, ptr %11, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 312
  store ptr %10, ptr %12, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 88
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 288
  store ptr %14, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 320
  store ptr %14, ptr %16, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 144
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(64) %17, i8 0, i64 64, i1 false)
  tail call void @Bcj2Dec_Init(ptr noundef nonnull %2)
  ret void
}

declare void @Bcj2Dec_Init(ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { mustprogress 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" }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass