; 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

; Function Attrs: nounwind uwtable
declare dso_local void @LzDecodeLiteral() #1

declare zeroext i8 @RcIsBitSet(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @LzDecodeMatch(i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare dso_local void @LzDecodeRep(i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @LzDecode() #1 {
  %1 = alloca i1, align 1
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  br label %5

5:                                                ; preds = %41, %0
  %6 = call zeroext i1 @DtCanWrite(ptr noundef %2)
  br i1 %6, label %7, label %9

7:                                                ; preds = %5
  %8 = call zeroext i1 @RcCanRead()
  br label %9

9:                                                ; preds = %7, %5
  %10 = phi i1 [ false, %5 ], [ %8, %7 ]
  br i1 %10, label %11, label %42

11:                                               ; preds = %9
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = and i32 %12, 3
  %14 = trunc i32 %13 to i8
  store i8 %14, ptr %3, align 1, !tbaa !9
  %15 = load i32, ptr @Decoder, align 4, !tbaa !10
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [12 x [4 x i16]], ptr getelementptr inbounds (%struct.anon, ptr getelementptr inbounds (%struct._DECODER_STATE, ptr @Decoder, i32 0, i32 6), i32 0, i32 7), i64 0, i64 %16
  %18 = load i8, ptr %3, align 1, !tbaa !9
  %19 = zext i8 %18 to i64
  %20 = getelementptr inbounds [4 x i16], ptr %17, i64 0, i64 %19
  %21 = call zeroext i8 @RcIsBitSet(ptr noundef %20)
  %22 = icmp ne i8 %21, 0
  br i1 %22, label %23, label %40

23:                                               ; preds = %11
  %24 = load i32, ptr @Decoder, align 4, !tbaa !10
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds [12 x i16], ptr getelementptr inbounds (%struct.anon, ptr getelementptr inbounds (%struct._DECODER_STATE, ptr @Decoder, i32 0, i32 6), i32 0, i32 1), i64 0, i64 %25
  %27 = call zeroext i8 @RcIsBitSet(ptr noundef %26)
  %28 = icmp ne i8 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %23
  %30 = load i8, ptr %3, align 1, !tbaa !9
  call void @LzDecodeRep(i8 noundef zeroext %30)
  br label %33

31:                                               ; preds = %23
  %32 = load i8, ptr %3, align 1, !tbaa !9
  call void @LzDecodeMatch(i8 noundef zeroext %32)
  br label %33

33:                                               ; preds = %31, %29
  %34 = load i32, ptr getelementptr inbounds (%struct._DECODER_STATE, ptr @Decoder, i32 0, i32 5), align 4, !tbaa !12
  %35 = load i32, ptr getelementptr inbounds (%struct._DECODER_STATE, ptr @Decoder, i32 0, i32 1), align 4, !tbaa !13
  %36 = add i32 %35, 1
  %37 = call zeroext i1 @DtRepeatSymbol(i32 noundef %34, i32 noundef %36)
  br i1 %37, label %39, label %38

38:                                               ; preds = %33
  store i1 false, ptr %1, align 1
  store i32 1, ptr %4, align 4
  br label %45

39:                                               ; preds = %33
  store i32 0, ptr getelementptr inbounds (%struct._DECODER_STATE, ptr @Decoder, i32 0, i32 5), align 4, !tbaa !12
  br label %41

40:                                               ; preds = %11
  call void @LzDecodeLiteral()
  br label %41

41:                                               ; preds = %40, %39
  br label %5, !llvm.loop !14

42:                                               ; preds = %9
  call void @RcNormalize()
  %43 = load i32, ptr getelementptr inbounds (%struct._DECODER_STATE, ptr @Decoder, i32 0, i32 5), align 4, !tbaa !12
  %44 = icmp eq i32 %43, 0
  store i1 %44, ptr %1, align 1
  store i32 1, ptr %4, align 4
  br label %45

45:                                               ; preds = %42, %38
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %46 = load i1, ptr %1, align 1
  ret i1 %46
}

declare zeroext i1 @DtCanWrite(ptr noundef) #2

declare zeroext i1 @RcCanRead() #2

declare zeroext i1 @DtRepeatSymbol(i32 noundef, i32 noundef) #2

declare void @RcNormalize() #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"_DECODER_STATE", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !7, i64 24}
!12 = !{!11, !6, i64 20}
!13 = !{!11, !6, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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 global %struct._DECODER_STATE, align 4

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @LzDecodeLiteral() local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @LzDecodeMatch(i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @LzDecodeRep(i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @LzDecode() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %2 = call zeroext i1 @DtCanWrite(ptr noundef nonnull %1) #3
  br i1 %2, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %0, %27
  %3 = call zeroext i1 @RcCanRead() #3
  br i1 %3, label %4, label %.critedge

4:                                                ; preds = %.lr.ph
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = trunc i32 %5 to i8
  %7 = and i8 %6, 3
  %8 = load i32, ptr @Decoder, align 4, !tbaa !9
  %9 = zext i32 %8 to i64
  %10 = zext nneg i8 %7 to i64
  %11 = getelementptr inbounds [12 x [4 x i16]], ptr getelementptr inbounds (i8, ptr @Decoder, i64 13148), i64 0, i64 %9, i64 %10
  %12 = call zeroext i8 @RcIsBitSet(ptr noundef nonnull %11) #3
  %.not = icmp eq i8 %12, 0
  br i1 %.not, label %26, label %13

13:                                               ; preds = %4
  %14 = load i32, ptr @Decoder, align 4, !tbaa !9
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds [12 x i16], ptr getelementptr inbounds (i8, ptr @Decoder, i64 12312), i64 0, i64 %15
  %17 = call zeroext i8 @RcIsBitSet(ptr noundef nonnull %16) #3
  %.not3 = icmp eq i8 %17, 0
  br i1 %.not3, label %19, label %18

18:                                               ; preds = %13
  call void @LzDecodeRep(i8 noundef zeroext %7)
  br label %20

19:                                               ; preds = %13
  call void @LzDecodeMatch(i8 noundef zeroext %7)
  br label %20

20:                                               ; preds = %19, %18
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @Decoder, i64 20), align 4, !tbaa !11
  %22 = load i32, ptr getelementptr inbounds (i8, ptr @Decoder, i64 4), align 4, !tbaa !12
  %23 = add i32 %22, 1
  %24 = call zeroext i1 @DtRepeatSymbol(i32 noundef %21, i32 noundef %23) #3
  br i1 %24, label %25, label %.loopexit

25:                                               ; preds = %20
  store i32 0, ptr getelementptr inbounds (i8, ptr @Decoder, i64 20), align 4, !tbaa !11
  br label %27

26:                                               ; preds = %4
  call void @LzDecodeLiteral()
  br label %27

27:                                               ; preds = %26, %25
  %28 = call zeroext i1 @DtCanWrite(ptr noundef nonnull %1) #3
  br i1 %28, label %.lr.ph, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph, %27, %0
  call void @RcNormalize() #3
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @Decoder, i64 20), align 4, !tbaa !11
  %30 = icmp eq i32 %29, 0
  br label %.loopexit

.loopexit:                                        ; preds = %20, %.critedge
  %.0 = phi i1 [ %30, %.critedge ], [ false, %20 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i1 %.0
}

declare zeroext i1 @DtCanWrite(ptr noundef) local_unnamed_addr #2

declare zeroext i1 @RcCanRead() local_unnamed_addr #2

declare zeroext i1 @DtRepeatSymbol(i32 noundef, i32 noundef) local_unnamed_addr #2

declare void @RcNormalize() local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_DECODER_STATE", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !7, i64 24}
!11 = !{!10, !6, i64 20}
!12 = !{!10, !6, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass