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

%struct.tagPROPVARIANT = type { i16, i16, i16, i16, %union.anon }
%union.anon = type { %struct._LARGE_INTEGER }
%struct._LARGE_INTEGER = type { i64 }
%"class.NCompress::NBcj2::CEncoder" = type <{ %struct.ICompressCoder2, %struct.ICompressSetCoderProperties, %struct.ICompressSetBufSize, %class.CMyUnknownImp, [4 x i8], %"class.NCompress::NBcj2::CBaseCoder", i32, [4 x i8] }>
%struct.ICompressCoder2 = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.ICompressSetCoderProperties = type { %struct.IUnknown }
%struct.ICompressSetBufSize = type { %struct.IUnknown }
%class.CMyUnknownImp = type { i32 }
%"class.NCompress::NBcj2::CBaseCoder" = type { [5 x ptr], [5 x i32], [5 x i32] }

; 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 nounwind uwtable
define dso_local noundef i32 @_ZN9NCompress5NBcj28CEncoder18SetCoderPropertiesEPKjPK14tagPROPVARIANTj(ptr noundef nonnull align 8 dereferenceable(116) %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) unnamed_addr #1 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  %15 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 67108864, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %58, %4
  %17 = load i32, ptr %11, align 4, !tbaa !9
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp ult i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %12, align 4
  br label %61

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %22, i64 %24
  store ptr %25, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i32, ptr %11, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %26, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !9
  store i32 %30, ptr %14, align 4, !tbaa !9
  %31 = load i32, ptr %14, align 4, !tbaa !9
  %32 = icmp uge i32 %31, 16
  br i1 %32, label %33, label %34

33:                                               ; preds = %21
  store i32 4, ptr %12, align 4
  br label %55

34:                                               ; preds = %21
  %35 = load i32, ptr %14, align 4, !tbaa !9
  switch i32 %35, label %53 [
    i32 1, label %36
    i32 13, label %51
    i32 15, label %52
  ]

36:                                               ; preds = %34
  %37 = load ptr, ptr %13, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %37, i32 0, i32 0
  %39 = load i16, ptr %38, align 8, !tbaa !11
  %40 = zext i16 %39 to i32
  %41 = icmp ne i32 %40, 19
  br i1 %41, label %42, label %43

42:                                               ; preds = %36
  store i32 -2147024809, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %55

43:                                               ; preds = %36
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %44, i32 0, i32 4
  %46 = load i32, ptr %45, align 8, !tbaa !14
  store i32 %46, ptr %10, align 4, !tbaa !9
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = icmp ugt i32 %47, -2147483648
  br i1 %48, label %49, label %50

49:                                               ; preds = %43
  store i32 -2147024809, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %55

50:                                               ; preds = %43
  br label %54

51:                                               ; preds = %34
  store i32 4, ptr %12, align 4
  br label %55

52:                                               ; preds = %34
  store i32 4, ptr %12, align 4
  br label %55

53:                                               ; preds = %34
  store i32 -2147024809, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %55

54:                                               ; preds = %50
  store i32 0, ptr %12, align 4
  br label %55

55:                                               ; preds = %54, %53, %52, %51, %49, %42, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  %56 = load i32, ptr %12, align 4
  switch i32 %56, label %61 [
    i32 0, label %57
    i32 4, label %58
  ]

57:                                               ; preds = %55
  br label %58

58:                                               ; preds = %57, %55
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = add i32 %59, 1
  store i32 %60, ptr %11, align 4, !tbaa !9
  br label %16, !llvm.loop !15

61:                                               ; preds = %55, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  %62 = load i32, ptr %12, align 4
  switch i32 %62, label %66 [
    i32 2, label %63
  ]

63:                                               ; preds = %61
  %64 = load i32, ptr %10, align 4, !tbaa !9
  %65 = getelementptr inbounds %"class.NCompress::NBcj2::CEncoder", ptr %15, i32 0, i32 6
  store i32 %64, ptr %65, align 8, !tbaa !17
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %66

66:                                               ; preds = %63, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %67 = load i32, ptr %5, align 4
  ret i32 %67
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !13, i64 0}
!12 = !{!"_ZTS14tagPROPVARIANT", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !7, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !10, i64 112}
!18 = !{!"_ZTSN9NCompress5NBcj28CEncoderE", !19, i64 0, !21, i64 8, !22, i64 16, !23, i64 24, !24, i64 32, !10, i64 112}
!19 = !{!"_ZTS15ICompressCoder2", !20, i64 0}
!20 = !{!"_ZTS8IUnknown"}
!21 = !{!"_ZTS27ICompressSetCoderProperties", !20, i64 0}
!22 = !{!"_ZTS19ICompressSetBufSize", !20, i64 0}
!23 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!24 = !{!"_ZTSN9NCompress5NBcj210CBaseCoderE", !7, i64 0, !7, i64 40, !7, i64 60}


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

%struct.tagPROPVARIANT = type { i16, i16, i16, i16, %union.anon }
%union.anon = type { %struct._LARGE_INTEGER }
%struct._LARGE_INTEGER = type { i64 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef i32 @_ZN9NCompress5NBcj28CEncoder18SetCoderPropertiesEPKjPK14tagPROPVARIANTj(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(116) %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, i32 noundef %3) unnamed_addr #0 align 2 {
  %.not2537.not = icmp eq i32 %3, 0
  br i1 %.not2537.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %wide.trip.count = zext i32 %3 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %16
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %16 ]
  %.01639 = phi i32 [ 67108864, %.lr.ph.preheader ], [ %.117.ph29, %16 ]
  %5 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %2, i64 %indvars.iv
  %6 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp ugt i32 %7, 15
  br i1 %8, label %16, label %9

9:                                                ; preds = %.lr.ph
  switch i32 %7, label %.thread34 [
    i32 1, label %10
    i32 13, label %16
    i32 15, label %16
  ]

10:                                               ; preds = %9
  %11 = load i16, ptr %5, align 8, !tbaa !9
  %.not = icmp eq i16 %11, 19
  br i1 %.not, label %12, label %.thread34

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %5, i64 8
  %14 = load i32, ptr %13, align 8, !tbaa !12
  %15 = icmp ugt i32 %14, -2147483648
  br i1 %15, label %.thread34, label %16

16:                                               ; preds = %.lr.ph, %12, %9, %9
  %.117.ph29 = phi i32 [ %.01639, %9 ], [ %.01639, %9 ], [ %14, %12 ], [ %.01639, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %16, %4
  %.016.lcssa = phi i32 [ 67108864, %4 ], [ %.117.ph29, %16 ]
  %17 = getelementptr inbounds i8, ptr %0, i64 112
  store i32 %.016.lcssa, ptr %17, align 8, !tbaa !15
  br label %.thread34

.thread34:                                        ; preds = %10, %9, %12, %._crit_edge
  %.3 = phi i32 [ 0, %._crit_edge ], [ -2147024809, %12 ], [ -2147024809, %9 ], [ -2147024809, %10 ]
  ret i32 %.3
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS14tagPROPVARIANT", !11, i64 0, !11, i64 2, !11, i64 4, !11, i64 6, !7, i64 8}
!11 = !{!"short", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 112}
!16 = !{!"_ZTSN9NCompress5NBcj28CEncoderE", !17, i64 0, !19, i64 8, !20, i64 16, !21, i64 24, !22, i64 32, !6, i64 112}
!17 = !{!"_ZTS15ICompressCoder2", !18, i64 0}
!18 = !{!"_ZTS8IUnknown"}
!19 = !{!"_ZTS27ICompressSetCoderProperties", !18, i64 0}
!20 = !{!"_ZTS19ICompressSetBufSize", !18, i64 0}
!21 = !{!"_ZTS13CMyUnknownImp", !6, i64 0}
!22 = !{!"_ZTSN9NCompress5NBcj210CBaseCoderE", !7, i64 0, !7, i64 40, !7, i64 60}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass