; LLVM IR from ionescu007/minlzma :: minlzlib (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._DECODER_STATE = type { i32, i32, i32, i32, i32, i32, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { [8 x [768 x i16]], [12 x i16], [12 x i16], [12 x [4 x i16]], [12 x i16], [12 x i16], %struct._LENGTH_DECODER_STATE, [12 x [4 x i16]], [4 x [64 x i16]], [114 x i16], [16 x i16], %struct._LENGTH_DECODER_STATE }
%struct._LENGTH_DECODER_STATE = type { i16, i16, [4 x [8 x i16]], [4 x [8 x i16]], [256 x i16] }

@Decoder = external dso_local global %struct._DECODER_STATE, align 4

; 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

declare zeroext i8 @RcGetBitTree(ptr noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local void @LzDecodeLen(ptr noundef %0, i8 noundef zeroext %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #3
  store i32 2, ptr getelementptr inbounds (%struct._DECODER_STATE, ptr @Decoder, i32 0, i32 5), align 4, !tbaa !10
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._LENGTH_DECODER_STATE, ptr %7, i32 0, i32 0
  %9 = call zeroext i8 @RcIsBitSet(ptr noundef %8)
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %11, label %32

11:                                               ; preds = %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._LENGTH_DECODER_STATE, ptr %12, i32 0, i32 1
  %14 = call zeroext i8 @RcIsBitSet(ptr noundef %13)
  %15 = icmp ne i8 %14, 0
  br i1 %15, label %16, label %22

16:                                               ; preds = %11
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._LENGTH_DECODER_STATE, ptr %17, i32 0, i32 4
  %19 = getelementptr inbounds [256 x i16], ptr %18, i64 0, i64 0
  store ptr %19, ptr %5, align 8, !tbaa !5
  store i16 256, ptr %6, align 2, !tbaa !13
  %20 = load i32, ptr getelementptr inbounds (%struct._DECODER_STATE, ptr @Decoder, i32 0, i32 5), align 4, !tbaa !10
  %21 = add i32 %20, 16
  store i32 %21, ptr getelementptr inbounds (%struct._DECODER_STATE, ptr @Decoder, i32 0, i32 5), align 4, !tbaa !10
  br label %31

22:                                               ; preds = %11
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._LENGTH_DECODER_STATE, ptr %23, i32 0, i32 3
  %25 = load i8, ptr %4, align 1, !tbaa !9
  %26 = zext i8 %25 to i64
  %27 = getelementptr inbounds [4 x [8 x i16]], ptr %24, i64 0, i64 %26
  %28 = getelementptr inbounds [8 x i16], ptr %27, i64 0, i64 0
  store ptr %28, ptr %5, align 8, !tbaa !5
  store i16 8, ptr %6, align 2, !tbaa !13
  %29 = load i32, ptr getelementptr inbounds (%struct._DECODER_STATE, ptr @Decoder, i32 0, i32 5), align 4, !tbaa !10
  %30 = add i32 %29, 8
  store i32 %30, ptr getelementptr inbounds (%struct._DECODER_STATE, ptr @Decoder, i32 0, i32 5), align 4, !tbaa !10
  br label %31

31:                                               ; preds = %22, %16
  br label %39

32:                                               ; preds = %2
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._LENGTH_DECODER_STATE, ptr %33, i32 0, i32 2
  %35 = load i8, ptr %4, align 1, !tbaa !9
  %36 = zext i8 %35 to i64
  %37 = getelementptr inbounds [4 x [8 x i16]], ptr %34, i64 0, i64 %36
  %38 = getelementptr inbounds [8 x i16], ptr %37, i64 0, i64 0
  store ptr %38, ptr %5, align 8, !tbaa !5
  store i16 8, ptr %6, align 2, !tbaa !13
  br label %39

39:                                               ; preds = %32, %31
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i16, ptr %6, align 2, !tbaa !13
  %42 = call zeroext i8 @RcGetBitTree(ptr noundef %40, i16 noundef zeroext %41)
  %43 = zext i8 %42 to i32
  %44 = load i32, ptr getelementptr inbounds (%struct._DECODER_STATE, ptr @Decoder, i32 0, i32 5), align 4, !tbaa !10
  %45 = add i32 %44, %43
  store i32 %45, ptr getelementptr inbounds (%struct._DECODER_STATE, ptr @Decoder, i32 0, i32 5), align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

declare zeroext i8 @RcIsBitSet(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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, !12, i64 20}
!11 = !{!"_DECODER_STATE", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !7, i64 24}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !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._DECODER_STATE = type { i32, i32, i32, i32, i32, i32, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { [8 x [768 x i16]], [12 x i16], [12 x i16], [12 x [4 x i16]], [12 x i16], [12 x i16], %struct._LENGTH_DECODER_STATE, [12 x [4 x i16]], [4 x [64 x i16]], [114 x i16], [16 x i16], %struct._LENGTH_DECODER_STATE }
%struct._LENGTH_DECODER_STATE = type { i16, i16, [4 x [8 x i16]], [4 x [8 x i16]], [256 x i16] }

@Decoder = external dso_local local_unnamed_addr global %struct._DECODER_STATE, align 4

declare zeroext i8 @RcGetBitTree(ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @LzDecodeLen(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #1 {
  store i32 2, ptr getelementptr inbounds (i8, ptr @Decoder, i64 20), align 4, !tbaa !5
  %3 = tail call zeroext i8 @RcIsBitSet(ptr noundef %0) #2
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %17, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 2
  %6 = tail call zeroext i8 @RcIsBitSet(ptr noundef nonnull %5) #2
  %.not9 = icmp eq i8 %6, 0
  br i1 %.not9, label %11, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 132
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @Decoder, i64 20), align 4, !tbaa !5
  %10 = add i32 %9, 16
  store i32 %10, ptr getelementptr inbounds (i8, ptr @Decoder, i64 20), align 4, !tbaa !5
  br label %21

11:                                               ; preds = %4
  %12 = getelementptr inbounds i8, ptr %0, i64 68
  %13 = zext i8 %1 to i64
  %14 = getelementptr inbounds [4 x [8 x i16]], ptr %12, i64 0, i64 %13
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @Decoder, i64 20), align 4, !tbaa !5
  %16 = add i32 %15, 8
  store i32 %16, ptr getelementptr inbounds (i8, ptr @Decoder, i64 20), align 4, !tbaa !5
  br label %21

17:                                               ; preds = %2
  %18 = getelementptr inbounds i8, ptr %0, i64 4
  %19 = zext i8 %1 to i64
  %20 = getelementptr inbounds [4 x [8 x i16]], ptr %18, i64 0, i64 %19
  br label %21

21:                                               ; preds = %7, %11, %17
  %.08 = phi ptr [ %8, %7 ], [ %14, %11 ], [ %20, %17 ]
  %.0 = phi i16 [ 256, %7 ], [ 8, %11 ], [ 8, %17 ]
  %22 = tail call zeroext i8 @RcGetBitTree(ptr noundef nonnull %.08, i16 noundef zeroext %.0) #2
  %23 = zext i8 %22 to i32
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @Decoder, i64 20), align 4, !tbaa !5
  %25 = add i32 %24, %23
  store i32 %25, ptr getelementptr inbounds (i8, ptr @Decoder, i64 20), align 4, !tbaa !5
  ret void
}

declare zeroext i8 @RcIsBitSet(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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, !7, i64 20}
!6 = !{!"_DECODER_STATE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !8, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}


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