; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/C (Lzma2Dec)

; 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.CLzma2Dec = type { i32, i8, i8, i8, i8, i32, i32, %struct.CLzmaDec }
%struct.CLzmaDec = type { %struct._CLzmaProps, ptr, ptr, ptr, i64, i64, ptr, i32, i32, i32, i32, [4 x i32], i32, i32, i32, i32, [20 x i8] }
%struct._CLzmaProps = type { i8, i8, i8, i8, i32 }

; Function Attrs: nounwind uwtable
declare dso_local i32 @Lzma2Dec_AllocateProbs(ptr noundef, i8 noundef zeroext, ptr noundef) #0

; 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

; Function Attrs: nounwind uwtable
declare dso_local void @Lzma2Dec_Init(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @Lzma2Dec_DecodeToDic(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @Lzma2Decode(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i8 noundef zeroext %4, i32 noundef %5, ptr noundef %6, ptr noundef %7) #0 {
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i8, align 1
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca %struct.CLzma2Dec, align 8
  %19 = alloca i32, align 4
  %20 = alloca i64, align 8
  %21 = alloca i64, align 8
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store ptr %2, ptr %12, align 8, !tbaa !5
  store ptr %3, ptr %13, align 8, !tbaa !5
  store i8 %4, ptr %14, align 1, !tbaa !9
  store i32 %5, ptr %15, align 4, !tbaa !10
  store ptr %6, ptr %16, align 8, !tbaa !5
  store ptr %7, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 144, ptr %18) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = load i64, ptr %24, align 8, !tbaa !12
  store i64 %25, ptr %20, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  %26 = load ptr, ptr %13, align 8, !tbaa !5
  %27 = load i64, ptr %26, align 8, !tbaa !12
  store i64 %27, ptr %21, align 8, !tbaa !12
  %28 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 0, ptr %28, align 8, !tbaa !12
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 0, ptr %29, align 8, !tbaa !12
  %30 = load ptr, ptr %16, align 8, !tbaa !5
  store i32 0, ptr %30, align 4, !tbaa !10
  %31 = getelementptr inbounds %struct.CLzma2Dec, ptr %18, i32 0, i32 7
  %32 = getelementptr inbounds %struct.CLzmaDec, ptr %31, i32 0, i32 3
  store ptr null, ptr %32, align 8, !tbaa !14
  %33 = getelementptr inbounds %struct.CLzma2Dec, ptr %18, i32 0, i32 7
  %34 = getelementptr inbounds %struct.CLzmaDec, ptr %33, i32 0, i32 1
  store ptr null, ptr %34, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #3
  %35 = load i8, ptr %14, align 1, !tbaa !9
  %36 = load ptr, ptr %17, align 8, !tbaa !5
  %37 = call i32 @Lzma2Dec_AllocateProbs(ptr noundef %18, i8 noundef zeroext %35, ptr noundef %36)
  store i32 %37, ptr %22, align 4, !tbaa !10
  %38 = load i32, ptr %22, align 4, !tbaa !10
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %8
  %41 = load i32, ptr %22, align 4, !tbaa !10
  store i32 %41, ptr %9, align 4
  store i32 1, ptr %23, align 4
  br label %43

42:                                               ; preds = %8
  store i32 0, ptr %23, align 4
  br label %43

43:                                               ; preds = %42, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #3
  %44 = load i32, ptr %23, align 4
  switch i32 %44, label %75 [
    i32 0, label %45
  ]

45:                                               ; preds = %43
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.CLzma2Dec, ptr %18, i32 0, i32 7
  %48 = getelementptr inbounds %struct.CLzmaDec, ptr %47, i32 0, i32 3
  store ptr %46, ptr %48, align 8, !tbaa !14
  %49 = load i64, ptr %20, align 8, !tbaa !12
  %50 = getelementptr inbounds %struct.CLzma2Dec, ptr %18, i32 0, i32 7
  %51 = getelementptr inbounds %struct.CLzmaDec, ptr %50, i32 0, i32 4
  store i64 %49, ptr %51, align 8, !tbaa !19
  call void @Lzma2Dec_Init(ptr noundef %18)
  %52 = load i64, ptr %21, align 8, !tbaa !12
  %53 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 %52, ptr %53, align 8, !tbaa !12
  %54 = load i64, ptr %20, align 8, !tbaa !12
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = load i32, ptr %15, align 4, !tbaa !10
  %58 = load ptr, ptr %16, align 8, !tbaa !5
  %59 = call i32 @Lzma2Dec_DecodeToDic(ptr noundef %18, i64 noundef %54, ptr noundef %55, ptr noundef %56, i32 noundef %57, ptr noundef %58)
  store i32 %59, ptr %19, align 4, !tbaa !10
  %60 = getelementptr inbounds %struct.CLzma2Dec, ptr %18, i32 0, i32 7
  %61 = getelementptr inbounds %struct.CLzmaDec, ptr %60, i32 0, i32 5
  %62 = load i64, ptr %61, align 8, !tbaa !20
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 %62, ptr %63, align 8, !tbaa !12
  %64 = load i32, ptr %19, align 4, !tbaa !10
  %65 = icmp eq i32 %64, 0
  br i1 %65, label %66, label %71

66:                                               ; preds = %45
  %67 = load ptr, ptr %16, align 8, !tbaa !5
  %68 = load i32, ptr %67, align 4, !tbaa !10
  %69 = icmp eq i32 %68, 3
  br i1 %69, label %70, label %71

70:                                               ; preds = %66
  store i32 6, ptr %19, align 4, !tbaa !10
  br label %71

71:                                               ; preds = %70, %66, %45
  %72 = getelementptr inbounds %struct.CLzma2Dec, ptr %18, i32 0, i32 7
  %73 = load ptr, ptr %17, align 8, !tbaa !5
  call void @LzmaDec_FreeProbs(ptr noundef %72, ptr noundef %73)
  %74 = load i32, ptr %19, align 4, !tbaa !10
  store i32 %74, ptr %9, align 4
  store i32 1, ptr %23, align 4
  br label %75

75:                                               ; preds = %71, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 144, ptr %18) #3
  %76 = load i32, ptr %9, align 4
  ret i32 %76
}

declare void @LzmaDec_FreeProbs(ptr noundef, ptr noundef) #2

attributes #0 = { 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 = { "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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !6, i64 40}
!15 = !{!"", !11, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !11, i64 8, !11, i64 12, !16, i64 16}
!16 = !{!"", !17, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !13, i64 40, !6, i64 48, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !7, i64 72, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !7, i64 104}
!17 = !{!"_CLzmaProps", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !11, i64 4}
!18 = !{!15, !6, i64 24}
!19 = !{!15, !13, i64 48}
!20 = !{!15, !13, i64 56}


; 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.CLzma2Dec = type { i32, i8, i8, i8, i8, i32, i32, %struct.CLzmaDec }
%struct.CLzmaDec = type { %struct._CLzmaProps, ptr, ptr, ptr, i64, i64, ptr, i32, i32, i32, i32, [4 x i32], i32, i32, i32, i32, [20 x i8] }
%struct._CLzmaProps = type { i8, i8, i8, i8, i32 }

; Function Attrs: nounwind uwtable
declare dso_local i32 @Lzma2Dec_AllocateProbs(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @Lzma2Dec_Init(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @Lzma2Dec_DecodeToDic(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @Lzma2Decode(ptr noundef %0, ptr nocapture noundef %1, ptr noundef %2, ptr noundef %3, i8 noundef zeroext %4, i32 noundef %5, ptr noundef %6, ptr noundef %7) local_unnamed_addr #0 {
  %9 = alloca %struct.CLzma2Dec, align 8
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %9) #3
  %10 = load i64, ptr %1, align 8, !tbaa !5
  %11 = load i64, ptr %3, align 8, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !5
  store i64 0, ptr %1, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %9, i64 16
  %13 = getelementptr inbounds i8, ptr %9, i64 40
  store ptr null, ptr %13, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %9, i64 24
  store ptr null, ptr %14, align 8, !tbaa !16
  %15 = call i32 @Lzma2Dec_AllocateProbs(ptr noundef nonnull %9, i8 noundef zeroext %4, ptr noundef %7)
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %16, label %26

16:                                               ; preds = %8
  store ptr %0, ptr %13, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %9, i64 48
  store i64 %10, ptr %17, align 8, !tbaa !17
  call void @Lzma2Dec_Init(ptr noundef nonnull %9)
  store i64 %11, ptr %3, align 8, !tbaa !5
  %18 = call i32 @Lzma2Dec_DecodeToDic(ptr noundef nonnull %9, i64 noundef %10, ptr noundef %2, ptr noundef nonnull %3, i32 noundef %5, ptr noundef nonnull %6)
  %19 = getelementptr inbounds i8, ptr %9, i64 56
  %20 = load i64, ptr %19, align 8, !tbaa !18
  store i64 %20, ptr %1, align 8, !tbaa !5
  %21 = icmp eq i32 %18, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %16
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 3
  %spec.select = select i1 %24, i32 6, i32 0
  br label %25

25:                                               ; preds = %22, %16
  %.025 = phi i32 [ %18, %16 ], [ %spec.select, %22 ]
  call void @LzmaDec_FreeProbs(ptr noundef nonnull %12, ptr noundef %7) #3
  br label %26

26:                                               ; preds = %8, %25
  %.1 = phi i32 [ %.025, %25 ], [ %15, %8 ]
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %9) #3
  ret i32 %.1
}

declare void @LzmaDec_FreeProbs(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !15, i64 40}
!12 = !{!"", !10, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !10, i64 8, !10, i64 12, !13, i64 16}
!13 = !{!"", !14, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !6, i64 32, !6, i64 40, !15, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !7, i64 72, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !7, i64 104}
!14 = !{!"_CLzmaProps", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !10, i64 4}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!12, !15, i64 24}
!17 = !{!12, !6, i64 48}
!18 = !{!12, !6, i64 56}


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