; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.2/lzma465/CPP/7zip/Compress (LzmaDecoder)

; 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.ISzAlloc = type { ptr, ptr }
%"class.NCompress::NLzma::CDecoder" = type <{ %struct.ICompressCoder, %struct.ICompressSetDecoderProperties2, %struct.ICompressGetInStreamProcessedSize, %struct.ICompressSetInStream, %struct.ICompressSetOutStreamSize, %struct.ISequentialInStream, %class.CMyUnknownImp, [4 x i8], %class.CMyComPtr, ptr, i32, i32, %struct.CLzmaDec, i8, [7 x i8], i64, i64, i64, i8, [7 x i8] }>
%struct.ICompressCoder = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.ICompressSetDecoderProperties2 = type { %struct.IUnknown }
%struct.ICompressGetInStreamProcessedSize = type { %struct.IUnknown }
%struct.ICompressSetInStream = type { %struct.IUnknown }
%struct.ICompressSetOutStreamSize = type { %struct.IUnknown }
%struct.ISequentialInStream = type { %struct.IUnknown }
%class.CMyUnknownImp = type { i32 }
%class.CMyComPtr = type { ptr }
%struct.CLzmaDec = type { %struct._CLzmaProps, ptr, ptr, ptr, i32, i32, i64, i64, i32, i32, i32, [4 x i32], i32, i32, i32, i32, i32, [20 x i8] }
%struct._CLzmaProps = type { i32, i32, i32, i32 }

@_ZN9NCompress5NLzmaL7g_AllocE = external hidden global %struct.ISzAlloc, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress5NLzma8CDecoder21SetDecoderProperties2EPKhj(ptr noundef nonnull align 8 dereferenceable(249) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #0 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %10 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %11 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %10, i32 0, i32 12
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = call i32 @LzmaDec_Allocate(ptr noundef %11, ptr noundef %12, i32 noundef %13, ptr noundef @_ZN9NCompress5NLzmaL7g_AllocE)
  %15 = call noundef i32 @_ZL13SResToHRESULTi(i32 noundef %14)
  store i32 %15, ptr %8, align 4, !tbaa !9
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %20

18:                                               ; preds = %3
  %19 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %19, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %21

20:                                               ; preds = %3
  store i32 0, ptr %9, align 4
  br label %21

21:                                               ; preds = %20, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %22 = load i32, ptr %9, align 4
  switch i32 %22, label %38 [
    i32 0, label %23
    i32 1, label %36
  ]

23:                                               ; preds = %21
  %24 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %10, i32 0, i32 9
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %35

27:                                               ; preds = %23
  %28 = call ptr @MyAlloc(i64 noundef 1048576)
  %29 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %10, i32 0, i32 9
  store ptr %28, ptr %29, align 8, !tbaa !11
  %30 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %10, i32 0, i32 9
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  store i32 -2147024882, ptr %4, align 4
  br label %36

34:                                               ; preds = %27
  br label %35

35:                                               ; preds = %34, %23
  store i32 0, ptr %4, align 4
  br label %36

36:                                               ; preds = %35, %33, %21
  %37 = load i32, ptr %4, align 4
  ret i32 %37

38:                                               ; preds = %21
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL13SResToHRESULTi(i32 noundef) #2

declare i32 @LzmaDec_Allocate(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare ptr @MyAlloc(i64 noundef) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 #4 = { 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, !6, i64 64}
!12 = !{!"_ZTSN9NCompress5NLzma8CDecoderE", !13, i64 0, !15, i64 8, !16, i64 16, !17, i64 24, !18, i64 32, !19, i64 40, !20, i64 48, !21, i64 56, !6, i64 64, !10, i64 72, !10, i64 76, !22, i64 80, !25, i64 216, !26, i64 224, !26, i64 232, !26, i64 240, !25, i64 248}
!13 = !{!"_ZTS14ICompressCoder", !14, i64 0}
!14 = !{!"_ZTS8IUnknown"}
!15 = !{!"_ZTS30ICompressSetDecoderProperties2", !14, i64 0}
!16 = !{!"_ZTS33ICompressGetInStreamProcessedSize", !14, i64 0}
!17 = !{!"_ZTS20ICompressSetInStream", !14, i64 0}
!18 = !{!"_ZTS25ICompressSetOutStreamSize", !14, i64 0}
!19 = !{!"_ZTS19ISequentialInStream", !14, i64 0}
!20 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!21 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !6, i64 0}
!22 = !{!"_ZTS8CLzmaDec", !23, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !24, i64 48, !24, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !7, i64 76, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !7, i64 112}
!23 = !{!"_ZTS11_CLzmaProps", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!24 = !{!"long", !7, i64 0}
!25 = !{!"bool", !7, i64 0}
!26 = !{!"long long", !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"

%struct.ISzAlloc = type { ptr, ptr }

@_ZN9NCompress5NLzmaL7g_AllocE = external hidden global %struct.ISzAlloc, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress5NLzma8CDecoder21SetDecoderProperties2EPKhj(ptr noundef nonnull align 8 dereferenceable(249) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 80
  %5 = tail call i32 @LzmaDec_Allocate(ptr noundef nonnull %4, ptr noundef %1, i32 noundef %2, ptr noundef nonnull @_ZN9NCompress5NLzmaL7g_AllocE)
  %6 = tail call noundef i32 @_ZL13SResToHRESULTi(i32 noundef %5)
  %.not.not = icmp eq i32 %6, 0
  br i1 %.not.not, label %7, label %15

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 64
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %14

11:                                               ; preds = %7
  %12 = tail call ptr @MyAlloc(i64 noundef 1048576)
  store ptr %12, ptr %8, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %11, %7
  br label %15

15:                                               ; preds = %3, %11, %14
  %.1 = phi i32 [ %6, %3 ], [ 0, %14 ], [ -2147024882, %11 ]
  ret i32 %.1
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL13SResToHRESULTi(i32 noundef) local_unnamed_addr #1

declare i32 @LzmaDec_Allocate(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare ptr @MyAlloc(i64 noundef) local_unnamed_addr #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 = { 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 = { "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, !19, i64 64}
!6 = !{!"_ZTSN9NCompress5NLzma8CDecoderE", !7, i64 0, !9, i64 8, !10, i64 16, !11, i64 24, !12, i64 32, !13, i64 40, !14, i64 48, !18, i64 56, !19, i64 64, !15, i64 72, !15, i64 76, !20, i64 80, !23, i64 216, !24, i64 224, !24, i64 232, !24, i64 240, !23, i64 248}
!7 = !{!"_ZTS14ICompressCoder", !8, i64 0}
!8 = !{!"_ZTS8IUnknown"}
!9 = !{!"_ZTS30ICompressSetDecoderProperties2", !8, i64 0}
!10 = !{!"_ZTS33ICompressGetInStreamProcessedSize", !8, i64 0}
!11 = !{!"_ZTS20ICompressSetInStream", !8, i64 0}
!12 = !{!"_ZTS25ICompressSetOutStreamSize", !8, i64 0}
!13 = !{!"_ZTS19ISequentialInStream", !8, i64 0}
!14 = !{!"_ZTS13CMyUnknownImp", !15, i64 0}
!15 = !{!"int", !16, i64 0}
!16 = !{!"omnipotent char", !17, i64 0}
!17 = !{!"Simple C++ TBAA"}
!18 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !19, i64 0}
!19 = !{!"any pointer", !16, i64 0}
!20 = !{!"_ZTS8CLzmaDec", !21, i64 0, !19, i64 16, !19, i64 24, !19, i64 32, !15, i64 40, !15, i64 44, !22, i64 48, !22, i64 56, !15, i64 64, !15, i64 68, !15, i64 72, !16, i64 76, !15, i64 92, !15, i64 96, !15, i64 100, !15, i64 104, !15, i64 108, !16, i64 112}
!21 = !{!"_ZTS11_CLzmaProps", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12}
!22 = !{!"long", !16, i64 0}
!23 = !{!"bool", !16, i64 0}
!24 = !{!"long long", !16, i64 0}


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