; LLVM IR from philanc/luazen :: src/lzma (LzmaDec)

; 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.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 void @LzmaDec_Init(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @LzmaDec_DecodeToDic(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef, 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 @LzmaDec_FreeProbs(ptr noundef, ptr noundef) #0

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

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

35:                                               ; preds = %9
  store i32 6, ptr %10, align 4
  store i32 1, ptr %24, align 4
  br label %76

36:                                               ; preds = %9
  %37 = getelementptr inbounds %struct.CLzmaDec, ptr %20, i32 0, i32 3
  store ptr null, ptr %37, align 8, !tbaa !13
  %38 = getelementptr inbounds %struct.CLzmaDec, ptr %20, i32 0, i32 1
  store ptr null, ptr %38, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #2
  %39 = load ptr, ptr %15, align 8, !tbaa !5
  %40 = load i32, ptr %16, align 4, !tbaa !9
  %41 = load ptr, ptr %19, align 8, !tbaa !5
  %42 = call i32 @LzmaDec_AllocateProbs(ptr noundef %20, ptr noundef %39, i32 noundef %40, ptr noundef %41)
  store i32 %42, ptr %25, align 4, !tbaa !9
  %43 = load i32, ptr %25, align 4, !tbaa !9
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %36
  %46 = load i32, ptr %25, align 4, !tbaa !9
  store i32 %46, ptr %10, align 4
  store i32 1, ptr %24, align 4
  br label %48

47:                                               ; preds = %36
  store i32 0, ptr %24, align 4
  br label %48

48:                                               ; preds = %47, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #2
  %49 = load i32, ptr %24, align 4
  switch i32 %49, label %76 [
    i32 0, label %50
  ]

50:                                               ; preds = %48
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.CLzmaDec, ptr %20, i32 0, i32 3
  store ptr %51, ptr %52, align 8, !tbaa !13
  %53 = load i64, ptr %22, align 8, !tbaa !11
  %54 = getelementptr inbounds %struct.CLzmaDec, ptr %20, i32 0, i32 4
  store i64 %53, ptr %54, align 8, !tbaa !17
  call void @LzmaDec_Init(ptr noundef %20)
  %55 = load i64, ptr %23, align 8, !tbaa !11
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  store i64 %55, ptr %56, align 8, !tbaa !11
  %57 = load i64, ptr %22, align 8, !tbaa !11
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load ptr, ptr %14, align 8, !tbaa !5
  %60 = load i32, ptr %17, align 4, !tbaa !9
  %61 = load ptr, ptr %18, align 8, !tbaa !5
  %62 = call i32 @LzmaDec_DecodeToDic(ptr noundef %20, i64 noundef %57, ptr noundef %58, ptr noundef %59, i32 noundef %60, ptr noundef %61)
  store i32 %62, ptr %21, align 4, !tbaa !9
  %63 = getelementptr inbounds %struct.CLzmaDec, ptr %20, i32 0, i32 5
  %64 = load i64, ptr %63, align 8, !tbaa !18
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  store i64 %64, ptr %65, align 8, !tbaa !11
  %66 = load i32, ptr %21, align 4, !tbaa !9
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %68, label %73

68:                                               ; preds = %50
  %69 = load ptr, ptr %18, align 8, !tbaa !5
  %70 = load i32, ptr %69, align 4, !tbaa !9
  %71 = icmp eq i32 %70, 3
  br i1 %71, label %72, label %73

72:                                               ; preds = %68
  store i32 6, ptr %21, align 4, !tbaa !9
  br label %73

73:                                               ; preds = %72, %68, %50
  %74 = load ptr, ptr %19, align 8, !tbaa !5
  call void @LzmaDec_FreeProbs(ptr noundef %20, ptr noundef %74)
  %75 = load i32, ptr %21, align 4, !tbaa !9
  store i32 %75, ptr %10, align 4
  store i32 1, ptr %24, align 4
  br label %76

76:                                               ; preds = %73, %48, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #2
  call void @llvm.lifetime.end.p0(i64 128, ptr %20) #2
  %77 = load i32, ptr %10, align 4
  ret i32 %77
}

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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"", !15, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 40, !6, 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}
!15 = !{!"_CLzmaProps", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !10, i64 4}
!16 = !{!14, !6, i64 8}
!17 = !{!14, !12, i64 32}
!18 = !{!14, !12, i64 40}


; 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.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 void @LzmaDec_Init(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @LzmaDec_DecodeToDic(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef, 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 @LzmaDec_FreeProbs(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @LzmaDecode(ptr noundef %0, ptr nocapture noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6, ptr noundef %7, ptr noundef %8) local_unnamed_addr #0 {
  %10 = alloca %struct.CLzmaDec, align 8
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %10) #2
  %11 = load i64, ptr %1, align 8, !tbaa !5
  %12 = 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 %7, align 4, !tbaa !9
  %13 = icmp ult i64 %12, 5
  br i1 %13, label %28, label %14

14:                                               ; preds = %9
  %15 = getelementptr inbounds i8, ptr %10, i64 24
  store ptr null, ptr %15, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %10, i64 8
  store ptr null, ptr %16, align 8, !tbaa !15
  %17 = call i32 @LzmaDec_AllocateProbs(ptr noundef nonnull %10, ptr noundef %4, i32 noundef %5, ptr noundef %8)
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %18, label %28

18:                                               ; preds = %14
  store ptr %0, ptr %15, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %10, i64 32
  store i64 %11, ptr %19, align 8, !tbaa !16
  call void @LzmaDec_Init(ptr noundef nonnull %10)
  store i64 %12, ptr %3, align 8, !tbaa !5
  %20 = call i32 @LzmaDec_DecodeToDic(ptr noundef nonnull %10, i64 noundef %11, ptr noundef %2, ptr noundef nonnull %3, i32 noundef %6, ptr noundef nonnull %7)
  %21 = getelementptr inbounds i8, ptr %10, i64 40
  %22 = load i64, ptr %21, align 8, !tbaa !17
  store i64 %22, ptr %1, align 8, !tbaa !5
  %23 = icmp eq i32 %20, 0
  br i1 %23, label %24, label %27

24:                                               ; preds = %18
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = icmp eq i32 %25, 3
  %spec.select = select i1 %26, i32 6, i32 0
  br label %27

27:                                               ; preds = %24, %18
  %.027 = phi i32 [ %20, %18 ], [ %spec.select, %24 ]
  call void @LzmaDec_FreeProbs(ptr noundef nonnull %10, ptr noundef %8)
  br label %28

28:                                               ; preds = %9, %14, %27
  %.1 = phi i32 [ %.027, %27 ], [ %17, %14 ], [ 6, %9 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %10) #2
  ret i32 %.1
}

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 = { 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, !14, i64 24}
!12 = !{!"", !13, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !6, i64 32, !6, i64 40, !14, 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}
!13 = !{!"_CLzmaProps", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !10, i64 4}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!12, !14, i64 8}
!16 = !{!12, !6, i64 32}
!17 = !{!12, !6, i64 40}


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