; 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: nounwind uwtable
define dso_local zeroext i1 @RcInitialize(ptr noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load i16, ptr %8, align 2, !tbaa !9
  %10 = zext i16 %9 to i32
  %11 = call zeroext i1 @BfSeek(i32 noundef %10, ptr noundef %6)
  br i1 %11, label %13, label %12

12:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %46

13:                                               ; preds = %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load i16, ptr %14, align 2, !tbaa !9
  %16 = zext i16 %15 to i32
  %17 = sub nsw i32 0, %16
  %18 = call zeroext i1 @BfSeek(i32 noundef %17, ptr noundef %6)
  store i32 -1, ptr getelementptr inbounds (%struct._RANGE_DECODER_STATE, ptr @RcState, i32 0, i32 2), align 8, !tbaa !11
  store i32 0, ptr getelementptr inbounds (%struct._RANGE_DECODER_STATE, ptr @RcState, i32 0, i32 3), align 4, !tbaa !14
  store i8 0, ptr %4, align 1, !tbaa !15
  br label %19

19:                                               ; preds = %30, %13
  %20 = load i8, ptr %4, align 1, !tbaa !15
  %21 = zext i8 %20 to i32
  %22 = icmp slt i32 %21, 5
  br i1 %22, label %23, label %33

23:                                               ; preds = %19
  %24 = call zeroext i1 @BfRead(ptr noundef %5)
  %25 = load i32, ptr getelementptr inbounds (%struct._RANGE_DECODER_STATE, ptr @RcState, i32 0, i32 3), align 4, !tbaa !14
  %26 = shl i32 %25, 8
  %27 = load i8, ptr %5, align 1, !tbaa !15
  %28 = zext i8 %27 to i32
  %29 = or i32 %26, %28
  store i32 %29, ptr getelementptr inbounds (%struct._RANGE_DECODER_STATE, ptr @RcState, i32 0, i32 3), align 4, !tbaa !14
  br label %30

30:                                               ; preds = %23
  %31 = load i8, ptr %4, align 1, !tbaa !15
  %32 = add i8 %31, 1
  store i8 %32, ptr %4, align 1, !tbaa !15
  br label %19, !llvm.loop !16

33:                                               ; preds = %19
  %34 = call zeroext i1 @BfSeek(i32 noundef 0, ptr noundef @RcState)
  %35 = load ptr, ptr @RcState, align 8, !tbaa !18
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load i16, ptr %36, align 2, !tbaa !9
  %38 = zext i16 %37 to i32
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %35, i64 %39
  store ptr %40, ptr getelementptr inbounds (%struct._RANGE_DECODER_STATE, ptr @RcState, i32 0, i32 1), align 8, !tbaa !19
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i16, ptr %41, align 2, !tbaa !9
  %43 = zext i16 %42 to i32
  %44 = sub nsw i32 %43, 5
  %45 = trunc i32 %44 to i16
  store i16 %45, ptr %41, align 2, !tbaa !9
  store i1 true, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %46

46:                                               ; preds = %33, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  %47 = load i1, ptr %2, align 1
  ret i1 %47
}

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

declare zeroext i1 @BfSeek(i32 noundef, ptr noundef) #2

declare zeroext i1 @BfRead(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !13, i64 16}
!12 = !{!"_RANGE_DECODER_STATE", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 20}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 20}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!12, !6, i64 0}
!19 = !{!12, !6, i64 8}


; 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 global %struct._RANGE_DECODER_STATE, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @RcInitialize(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = load i16, ptr %0, align 2, !tbaa !5
  %5 = zext i16 %4 to i32
  %6 = call zeroext i1 @BfSeek(i32 noundef %5, ptr noundef nonnull %3) #3
  br i1 %6, label %7, label %48

7:                                                ; preds = %1
  %8 = load i16, ptr %0, align 2, !tbaa !5
  %9 = zext i16 %8 to i32
  %10 = sub nsw i32 0, %9
  %11 = call zeroext i1 @BfSeek(i32 noundef %10, ptr noundef nonnull %3) #3
  store i32 -1, ptr getelementptr inbounds (i8, ptr @RcState, i64 16), align 8, !tbaa !9
  store i32 0, ptr getelementptr inbounds (i8, ptr @RcState, i64 20), align 4, !tbaa !13
  %12 = call zeroext i1 @BfRead(ptr noundef nonnull %2) #3
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @RcState, i64 20), align 4, !tbaa !13
  %14 = shl i32 %13, 8
  %15 = load i8, ptr %2, align 1, !tbaa !14
  %16 = zext i8 %15 to i32
  %17 = or disjoint i32 %14, %16
  store i32 %17, ptr getelementptr inbounds (i8, ptr @RcState, i64 20), align 4, !tbaa !13
  %18 = call zeroext i1 @BfRead(ptr noundef nonnull %2) #3
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @RcState, i64 20), align 4, !tbaa !13
  %20 = shl i32 %19, 8
  %21 = load i8, ptr %2, align 1, !tbaa !14
  %22 = zext i8 %21 to i32
  %23 = or disjoint i32 %20, %22
  store i32 %23, ptr getelementptr inbounds (i8, ptr @RcState, i64 20), align 4, !tbaa !13
  %24 = call zeroext i1 @BfRead(ptr noundef nonnull %2) #3
  %25 = load i32, ptr getelementptr inbounds (i8, ptr @RcState, i64 20), align 4, !tbaa !13
  %26 = shl i32 %25, 8
  %27 = load i8, ptr %2, align 1, !tbaa !14
  %28 = zext i8 %27 to i32
  %29 = or disjoint i32 %26, %28
  store i32 %29, ptr getelementptr inbounds (i8, ptr @RcState, i64 20), align 4, !tbaa !13
  %30 = call zeroext i1 @BfRead(ptr noundef nonnull %2) #3
  %31 = load i32, ptr getelementptr inbounds (i8, ptr @RcState, i64 20), align 4, !tbaa !13
  %32 = shl i32 %31, 8
  %33 = load i8, ptr %2, align 1, !tbaa !14
  %34 = zext i8 %33 to i32
  %35 = or disjoint i32 %32, %34
  store i32 %35, ptr getelementptr inbounds (i8, ptr @RcState, i64 20), align 4, !tbaa !13
  %36 = call zeroext i1 @BfRead(ptr noundef nonnull %2) #3
  %37 = load i32, ptr getelementptr inbounds (i8, ptr @RcState, i64 20), align 4, !tbaa !13
  %38 = shl i32 %37, 8
  %39 = load i8, ptr %2, align 1, !tbaa !14
  %40 = zext i8 %39 to i32
  %41 = or disjoint i32 %38, %40
  store i32 %41, ptr getelementptr inbounds (i8, ptr @RcState, i64 20), align 4, !tbaa !13
  %42 = call zeroext i1 @BfSeek(i32 noundef 0, ptr noundef nonnull @RcState) #3
  %43 = load ptr, ptr @RcState, align 8, !tbaa !15
  %44 = load i16, ptr %0, align 2, !tbaa !5
  %45 = zext i16 %44 to i64
  %46 = getelementptr inbounds i8, ptr %43, i64 %45
  store ptr %46, ptr getelementptr inbounds (i8, ptr @RcState, i64 8), align 8, !tbaa !16
  %47 = add i16 %44, -5
  store i16 %47, ptr %0, align 2, !tbaa !5
  br label %48

48:                                               ; preds = %1, %7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #3
  ret i1 %6
}

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

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 16}
!10 = !{!"_RANGE_DECODER_STATE", !11, i64 0, !11, i64 8, !12, i64 16, !12, i64 20}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 20}
!14 = !{!7, !7, i64 0}
!15 = !{!10, !11, i64 0}
!16 = !{!10, !11, i64 8}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass