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

; Function Attrs: nounwind uwtable
define dso_local void @RcAdapt(i1 noundef zeroext %0, ptr noundef %1) #0 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = zext i1 %0 to i8
  store i8 %5, ptr %3, align 1, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %6 = load i8, ptr %3, align 1, !tbaa !5, !range !11, !noundef !12
  %7 = trunc i8 %6 to i1
  br i1 %7, label %8, label %18

8:                                                ; preds = %2
  %9 = load ptr, ptr %4, align 8, !tbaa !9
  %10 = load i16, ptr %9, align 2, !tbaa !13
  %11 = zext i16 %10 to i32
  %12 = ashr i32 %11, 5
  %13 = load ptr, ptr %4, align 8, !tbaa !9
  %14 = load i16, ptr %13, align 2, !tbaa !13
  %15 = zext i16 %14 to i32
  %16 = sub nsw i32 %15, %12
  %17 = trunc i32 %16 to i16
  store i16 %17, ptr %13, align 2, !tbaa !13
  br label %29

18:                                               ; preds = %2
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  %20 = load i16, ptr %19, align 2, !tbaa !13
  %21 = zext i16 %20 to i32
  %22 = sub nsw i32 2048, %21
  %23 = ashr i32 %22, 5
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = load i16, ptr %24, align 2, !tbaa !13
  %26 = zext i16 %25 to i32
  %27 = add nsw i32 %26, %23
  %28 = trunc i32 %27 to i16
  store i16 %28, ptr %24, align 2, !tbaa !13
  br label %29

29:                                               ; preds = %18, %8
  ret void
}

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, !6, i64 0}
!6 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @RcAdapt(i1 noundef zeroext %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = load i16, ptr %1, align 2, !tbaa !5
  br i1 %0, label %4, label %7

4:                                                ; preds = %2
  %5 = lshr i16 %3, 5
  %6 = sub i16 %3, %5
  br label %13

7:                                                ; preds = %2
  %8 = zext i16 %3 to i32
  %9 = sub nsw i32 2048, %8
  %10 = lshr i32 %9, 5
  %11 = trunc i32 %10 to i16
  %12 = add i16 %3, %11
  br label %13

13:                                               ; preds = %7, %4
  %storemerge = phi i16 [ %12, %7 ], [ %6, %4 ]
  store i16 %storemerge, ptr %1, align 2, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !6, i64 0}
!6 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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