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

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

@In = external dso_local global %struct._BUFFER_STATE, align 8

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @BfSeek(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %6 = load i32, ptr getelementptr inbounds (%struct._BUFFER_STATE, ptr @In, i32 0, i32 1), align 8, !tbaa !11
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = add i32 %6, %7
  %9 = load i32, ptr getelementptr inbounds (%struct._BUFFER_STATE, ptr @In, i32 0, i32 2), align 4, !tbaa !13
  %10 = icmp ugt i32 %8, %9
  br i1 %10, label %11, label %13

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr null, ptr %12, align 8, !tbaa !9
  store i1 false, ptr %3, align 1
  br label %22

13:                                               ; preds = %2
  %14 = load ptr, ptr @In, align 8, !tbaa !14
  %15 = load i32, ptr getelementptr inbounds (%struct._BUFFER_STATE, ptr @In, i32 0, i32 1), align 8, !tbaa !11
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %14, i64 %16
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %17, ptr %18, align 8, !tbaa !9
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = load i32, ptr getelementptr inbounds (%struct._BUFFER_STATE, ptr @In, i32 0, i32 1), align 8, !tbaa !11
  %21 = add i32 %20, %19
  store i32 %21, ptr getelementptr inbounds (%struct._BUFFER_STATE, ptr @In, i32 0, i32 1), align 8, !tbaa !11
  store i1 true, ptr %3, align 1
  br label %22

22:                                               ; preds = %13, %11
  %23 = load i1, ptr %3, align 1
  ret i1 %23
}

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

@In = external dso_local local_unnamed_addr global %struct._BUFFER_STATE, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @BfSeek(i32 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @In, i64 8), align 8, !tbaa !5
  %4 = add i32 %3, %0
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @In, i64 12), align 4, !tbaa !11
  %6 = icmp ule i32 %4, %5
  br i1 %6, label %7, label %11

7:                                                ; preds = %2
  %8 = load ptr, ptr @In, align 8, !tbaa !12
  %9 = zext i32 %3 to i64
  %10 = getelementptr inbounds i8, ptr %8, i64 %9
  store i32 %4, ptr getelementptr inbounds (i8, ptr @In, i64 8), align 8, !tbaa !5
  br label %11

11:                                               ; preds = %2, %7
  %.sink = phi ptr [ %10, %7 ], [ null, %2 ]
  store ptr %.sink, ptr %1, align 8
  ret i1 %6
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none) 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 8}
!6 = !{!"_BUFFER_STATE", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass