; LLVM IR from ionescu007/minlzma :: minlzlib (rangedec)

; 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._RANGE_DECODER_STATE = type { ptr, ptr, i32, i32 }

@RcState = external dso_local global %struct._RANGE_DECODER_STATE, align 8

; 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 @RcNormalize() #1

; Function Attrs: nounwind uwtable
declare dso_local void @RcAdapt(i1 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @RcIsBitSet(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  call void @RcNormalize()
  %5 = load i32, ptr getelementptr inbounds (%struct._RANGE_DECODER_STATE, ptr @RcState, i32 0, i32 2), align 8, !tbaa !9
  %6 = lshr i32 %5, 11
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = load i16, ptr %7, align 2, !tbaa !12
  %9 = zext i16 %8 to i32
  %10 = mul i32 %6, %9
  store i32 %10, ptr %3, align 4, !tbaa !14
  %11 = load i32, ptr getelementptr inbounds (%struct._RANGE_DECODER_STATE, ptr @RcState, i32 0, i32 3), align 4, !tbaa !15
  %12 = load i32, ptr %3, align 4, !tbaa !14
  %13 = icmp ult i32 %11, %12
  br i1 %13, label %14, label %16

14:                                               ; preds = %1
  %15 = load i32, ptr %3, align 4, !tbaa !14
  store i32 %15, ptr getelementptr inbounds (%struct._RANGE_DECODER_STATE, ptr @RcState, i32 0, i32 2), align 8, !tbaa !9
  store i8 0, ptr %4, align 1, !tbaa !16
  br label %23

16:                                               ; preds = %1
  %17 = load i32, ptr %3, align 4, !tbaa !14
  %18 = load i32, ptr getelementptr inbounds (%struct._RANGE_DECODER_STATE, ptr @RcState, i32 0, i32 2), align 8, !tbaa !9
  %19 = sub i32 %18, %17
  store i32 %19, ptr getelementptr inbounds (%struct._RANGE_DECODER_STATE, ptr @RcState, i32 0, i32 2), align 8, !tbaa !9
  %20 = load i32, ptr %3, align 4, !tbaa !14
  %21 = load i32, ptr getelementptr inbounds (%struct._RANGE_DECODER_STATE, ptr @RcState, i32 0, i32 3), align 4, !tbaa !15
  %22 = sub i32 %21, %20
  store i32 %22, ptr getelementptr inbounds (%struct._RANGE_DECODER_STATE, ptr @RcState, i32 0, i32 3), align 4, !tbaa !15
  store i8 1, ptr %4, align 1, !tbaa !16
  br label %23

23:                                               ; preds = %16, %14
  %24 = load i8, ptr %4, align 1, !tbaa !16
  %25 = icmp ne i8 %24, 0
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  call void @RcAdapt(i1 noundef zeroext %25, ptr noundef %26)
  %27 = load i8, ptr %4, align 1, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i8 %27
}

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 = { 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, !11, i64 16}
!10 = !{!"_RANGE_DECODER_STATE", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 20}
!16 = !{!7, !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._RANGE_DECODER_STATE = type { ptr, ptr, i32, i32 }

@RcState = external dso_local local_unnamed_addr global %struct._RANGE_DECODER_STATE, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @RcNormalize() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @RcAdapt(i1 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @RcIsBitSet(ptr noundef %0) local_unnamed_addr #0 {
  tail call void @RcNormalize()
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @RcState, i64 16), align 8, !tbaa !5
  %3 = lshr i32 %2, 11
  %4 = load i16, ptr %0, align 2, !tbaa !11
  %5 = zext i16 %4 to i32
  %6 = mul i32 %3, %5
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @RcState, i64 20), align 4, !tbaa !13
  %8 = icmp uge i32 %7, %6
  br i1 %8, label %9, label %12

9:                                                ; preds = %1
  %10 = sub i32 %2, %6
  %11 = sub i32 %7, %6
  store i32 %11, ptr getelementptr inbounds (i8, ptr @RcState, i64 20), align 4, !tbaa !13
  br label %12

12:                                               ; preds = %1, %9
  %.sink = phi i32 [ %10, %9 ], [ %6, %1 ]
  %.0 = phi i8 [ 1, %9 ], [ 0, %1 ]
  store i32 %.sink, ptr getelementptr inbounds (i8, ptr @RcState, i64 16), align 8
  tail call void @RcAdapt(i1 noundef zeroext %8, ptr noundef nonnull %0)
  ret i8 %.0
}

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" }

!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, !10, i64 16}
!6 = !{!"_RANGE_DECODER_STATE", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!6, !10, i64 20}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,ReassociatePass,SROAPass,TailCallElimPass