; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Bundles/LzmaSpec/LzmaSpec.ll (ZN13CRangeDecoder4InitEv)

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

%class.CRangeDecoder = type <{ i32, i32, ptr, i8, [7 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN13CRangeDecoder4InitEv(ptr noundef nonnull align 8 dereferenceable(17) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %class.CRangeDecoder, ptr %5, i32 0, i32 3
  store i8 0, ptr %6, align 8, !tbaa !9
  %7 = getelementptr inbounds %class.CRangeDecoder, ptr %5, i32 0, i32 0
  store i32 -1, ptr %7, align 8, !tbaa !13
  %8 = getelementptr inbounds %class.CRangeDecoder, ptr %5, i32 0, i32 1
  store i32 0, ptr %8, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #2
  %9 = getelementptr inbounds %class.CRangeDecoder, ptr %5, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %11 = call noundef zeroext i8 @_ZN12CInputStream8ReadByteEv(ptr noundef nonnull align 8 dereferenceable(16) %10)
  store i8 %11, ptr %3, align 1, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !17
  br label %12

12:                                               ; preds = %26, %1
  %13 = load i32, ptr %4, align 4, !tbaa !17
  %14 = icmp slt i32 %13, 4
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %29

16:                                               ; preds = %12
  %17 = getelementptr inbounds %class.CRangeDecoder, ptr %5, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = shl i32 %18, 8
  %20 = getelementptr inbounds %class.CRangeDecoder, ptr %5, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = call noundef zeroext i8 @_ZN12CInputStream8ReadByteEv(ptr noundef nonnull align 8 dereferenceable(16) %21)
  %23 = zext i8 %22 to i32
  %24 = or i32 %19, %23
  %25 = getelementptr inbounds %class.CRangeDecoder, ptr %5, i32 0, i32 1
  store i32 %24, ptr %25, align 4, !tbaa !14
  br label %26

26:                                               ; preds = %16
  %27 = load i32, ptr %4, align 4, !tbaa !17
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %4, align 4, !tbaa !17
  br label %12, !llvm.loop !18

29:                                               ; preds = %15
  %30 = load i8, ptr %3, align 1, !tbaa !16
  %31 = zext i8 %30 to i32
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %39, label %33

33:                                               ; preds = %29
  %34 = getelementptr inbounds %class.CRangeDecoder, ptr %5, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !14
  %36 = getelementptr inbounds %class.CRangeDecoder, ptr %5, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !13
  %38 = icmp eq i32 %35, %37
  br i1 %38, label %39, label %41

39:                                               ; preds = %33, %29
  %40 = getelementptr inbounds %class.CRangeDecoder, ptr %5, i32 0, i32 3
  store i8 1, ptr %40, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %39, %33
  %42 = load i8, ptr %3, align 1, !tbaa !16
  %43 = zext i8 %42 to i32
  %44 = icmp eq i32 %43, 0
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #2
  ret i1 %44
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i8 @_ZN12CInputStream8ReadByteEv(ptr noundef nonnull align 8 dereferenceable(16)) #0 align 2

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

attributes #0 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !12, i64 16}
!10 = !{!"_ZTS13CRangeDecoder", !11, i64 0, !11, i64 4, !6, i64 8, !12, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!10, !11, i64 4}
!15 = !{!10, !6, i64 8}
!16 = !{!7, !7, i64 0}
!17 = !{!11, !11, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN13CRangeDecoder4InitEv(ptr nocapture noundef nonnull align 8 dereferenceable(17) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  store i8 0, ptr %2, align 8, !tbaa !5
  store i32 -1, ptr %0, align 8, !tbaa !12
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 0, ptr %3, align 4, !tbaa !13
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !14
  %6 = tail call noundef zeroext i8 @_ZN12CInputStream8ReadByteEv(ptr noundef nonnull align 8 dereferenceable(16) %5)
  %7 = load i32, ptr %3, align 4, !tbaa !13
  %8 = shl i32 %7, 8
  %9 = load ptr, ptr %4, align 8, !tbaa !14
  %10 = tail call noundef zeroext i8 @_ZN12CInputStream8ReadByteEv(ptr noundef nonnull align 8 dereferenceable(16) %9)
  %11 = zext i8 %10 to i32
  %12 = or disjoint i32 %8, %11
  store i32 %12, ptr %3, align 4, !tbaa !13
  %13 = shl i32 %12, 8
  %14 = load ptr, ptr %4, align 8, !tbaa !14
  %15 = tail call noundef zeroext i8 @_ZN12CInputStream8ReadByteEv(ptr noundef nonnull align 8 dereferenceable(16) %14)
  %16 = zext i8 %15 to i32
  %17 = or disjoint i32 %13, %16
  store i32 %17, ptr %3, align 4, !tbaa !13
  %18 = shl i32 %17, 8
  %19 = load ptr, ptr %4, align 8, !tbaa !14
  %20 = tail call noundef zeroext i8 @_ZN12CInputStream8ReadByteEv(ptr noundef nonnull align 8 dereferenceable(16) %19)
  %21 = zext i8 %20 to i32
  %22 = or disjoint i32 %18, %21
  store i32 %22, ptr %3, align 4, !tbaa !13
  %23 = shl i32 %22, 8
  %24 = load ptr, ptr %4, align 8, !tbaa !14
  %25 = tail call noundef zeroext i8 @_ZN12CInputStream8ReadByteEv(ptr noundef nonnull align 8 dereferenceable(16) %24)
  %26 = zext i8 %25 to i32
  %27 = or disjoint i32 %23, %26
  store i32 %27, ptr %3, align 4, !tbaa !13
  %.not = icmp eq i8 %6, 0
  %28 = load i32, ptr %0, align 8
  %29 = icmp ne i32 %27, %28
  %or.cond.not = select i1 %.not, i1 %29, i1 false
  br i1 %or.cond.not, label %31, label %30

30:                                               ; preds = %1
  store i8 1, ptr %2, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %1, %30
  ret i1 %.not
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i8 @_ZN12CInputStream8ReadByteEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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, !11, i64 16}
!6 = !{!"_ZTS13CRangeDecoder", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !10, i64 8}


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