; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Common/InBuffer.ll (ZN13CInBufferBase9ReadBlockEv)

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

@_ZTI18CInBufferException = external dso_local constant { ptr, ptr, ptr }, align 8

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN13CInBufferBase9ReadBlockEv(ptr noundef nonnull align 8 dereferenceable(56) %0) #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 6
  %10 = load i8, ptr %9, align 8, !tbaa !9, !range !15, !noundef !16
  %11 = trunc i8 %10 to i1
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %66

13:                                               ; preds = %1
  %14 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  %16 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !18
  %18 = ptrtoint ptr %15 to i64
  %19 = ptrtoint ptr %17 to i64
  %20 = sub i64 %18, %19
  %21 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 4
  %22 = load i64, ptr %21, align 8, !tbaa !19
  %23 = add i64 %22, %20
  store i64 %23, ptr %21, align 8, !tbaa !19
  %24 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !18
  %26 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 0
  store ptr %25, ptr %26, align 8, !tbaa !17
  %27 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 1
  store ptr %28, ptr %29, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %30 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 3
  %31 = load ptr, ptr %30, align 8, !tbaa !21
  %32 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !18
  %34 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 5
  %35 = load i64, ptr %34, align 8, !tbaa !22
  %36 = trunc i64 %35 to i32
  %37 = load ptr, ptr %31, align 8, !tbaa !23
  %38 = getelementptr inbounds ptr, ptr %37, i64 5
  %39 = load ptr, ptr %38, align 8
  %40 = call noundef i32 %39(ptr noundef nonnull align 8 dereferenceable(8) %31, ptr noundef %33, i32 noundef %36, ptr noundef %4)
  store i32 %40, ptr %5, align 4, !tbaa !25
  %41 = load i32, ptr %5, align 4, !tbaa !25
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %51

43:                                               ; preds = %13
  %44 = call ptr @__cxa_allocate_exception(i64 4) #2
  %45 = load i32, ptr %5, align 4, !tbaa !25
  invoke void @_ZN18CInBufferExceptionC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %44, i32 noundef %45)
          to label %46 unwind label %47

46:                                               ; preds = %43
  call void @__cxa_throw(ptr %44, ptr @_ZTI18CInBufferException, ptr null) #3
  unreachable

47:                                               ; preds = %43
  %48 = landingpad { ptr, i32 }
          cleanup
  %49 = extractvalue { ptr, i32 } %48, 0
  store ptr %49, ptr %6, align 8
  %50 = extractvalue { ptr, i32 } %48, 1
  store i32 %50, ptr %7, align 4
  call void @__cxa_free_exception(ptr %44) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %68

51:                                               ; preds = %13
  %52 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !17
  %54 = load i32, ptr %4, align 4, !tbaa !25
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds i8, ptr %53, i64 %55
  %57 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 1
  store ptr %56, ptr %57, align 8, !tbaa !20
  %58 = load i32, ptr %4, align 4, !tbaa !25
  %59 = icmp eq i32 %58, 0
  %60 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 6
  %61 = zext i1 %59 to i8
  store i8 %61, ptr %60, align 8, !tbaa !9
  %62 = getelementptr inbounds %class.CInBufferBase, ptr %8, i32 0, i32 6
  %63 = load i8, ptr %62, align 8, !tbaa !9, !range !15, !noundef !16
  %64 = trunc i8 %63 to i1
  %65 = xor i1 %64, true
  store i1 %65, ptr %2, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %66

66:                                               ; preds = %51, %12
  %67 = load i1, ptr %2, align 1
  ret i1 %67

68:                                               ; preds = %47
  %69 = load ptr, ptr %6, align 8
  %70 = load i32, ptr %7, align 4
  %71 = insertvalue { ptr, i32 } poison, ptr %69, 0
  %72 = insertvalue { ptr, i32 } %71, i32 %70, 1
  resume { ptr, i32 } %72
}

declare ptr @__cxa_allocate_exception(i64)

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN18CInBufferExceptionC2Ei(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) unnamed_addr #1 align 2

declare void @__cxa_free_exception(ptr)

declare void @__cxa_throw(ptr, ptr, ptr)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind }
attributes #3 = { noreturn }

!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, !13, i64 48}
!10 = !{!"_ZTS13CInBufferBase", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !12, i64 40, !13, i64 48, !14, i64 52}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!10, !6, i64 0}
!18 = !{!10, !6, i64 16}
!19 = !{!10, !11, i64 32}
!20 = !{!10, !6, i64 8}
!21 = !{!10, !6, i64 24}
!22 = !{!10, !12, i64 40}
!23 = !{!24, !24, i64 0}
!24 = !{!"vtable pointer", !8, i64 0}
!25 = !{!14, !14, 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"

@_ZTI18CInBufferException = external dso_local constant { ptr, ptr, ptr }, align 8

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN13CInBufferBase9ReadBlockEv(ptr nocapture noundef nonnull align 8 dereferenceable(56) %0) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i32, align 4
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = load i8, ptr %3, align 8, !tbaa !5, !range !14, !noundef !15
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %39, label %6

6:                                                ; preds = %1
  %7 = load ptr, ptr %0, align 8, !tbaa !16
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !17
  %10 = ptrtoint ptr %7 to i64
  %11 = ptrtoint ptr %9 to i64
  %12 = sub i64 %10, %11
  %13 = getelementptr inbounds i8, ptr %0, i64 32
  %14 = load i64, ptr %13, align 8, !tbaa !18
  %15 = add i64 %12, %14
  store i64 %15, ptr %13, align 8, !tbaa !18
  store ptr %9, ptr %0, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %9, ptr %16, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #2
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = load ptr, ptr %17, align 8, !tbaa !20
  %19 = getelementptr inbounds i8, ptr %0, i64 40
  %20 = load i64, ptr %19, align 8, !tbaa !21
  %21 = trunc i64 %20 to i32
  %22 = load ptr, ptr %18, align 8, !tbaa !22
  %23 = getelementptr inbounds i8, ptr %22, i64 40
  %24 = load ptr, ptr %23, align 8
  %25 = call noundef i32 %24(ptr noundef nonnull align 8 dereferenceable(8) %18, ptr noundef %9, i32 noundef %21, ptr noundef nonnull %2)
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %31, label %26

26:                                               ; preds = %6
  %27 = call ptr @__cxa_allocate_exception(i64 4) #2
  invoke void @_ZN18CInBufferExceptionC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %27, i32 noundef %25)
          to label %28 unwind label %29

28:                                               ; preds = %26
  call void @__cxa_throw(ptr nonnull %27, ptr nonnull @_ZTI18CInBufferException, ptr null) #3
  unreachable

29:                                               ; preds = %26
  %30 = landingpad { ptr, i32 }
          cleanup
  call void @__cxa_free_exception(ptr %27) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #2
  resume { ptr, i32 } %30

31:                                               ; preds = %6
  %32 = load ptr, ptr %0, align 8, !tbaa !16
  %33 = load i32, ptr %2, align 4, !tbaa !24
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %32, i64 %34
  store ptr %35, ptr %16, align 8, !tbaa !19
  %36 = icmp eq i32 %33, 0
  %37 = zext i1 %36 to i8
  store i8 %37, ptr %3, align 8, !tbaa !5
  %38 = xor i1 %36, true
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #2
  br label %39

39:                                               ; preds = %1, %31
  %.0 = phi i1 [ %38, %31 ], [ false, %1 ]
  ret i1 %.0
}

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN18CInBufferExceptionC2Ei(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) unnamed_addr #1 align 2

declare void @__cxa_free_exception(ptr) local_unnamed_addr

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind }
attributes #3 = { noreturn }

!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, !12, i64 48}
!6 = !{!"_ZTS13CInBufferBase", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !12, i64 48, !13, i64 52}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!6, !7, i64 0}
!17 = !{!6, !7, i64 16}
!18 = !{!6, !10, i64 32}
!19 = !{!6, !7, i64 8}
!20 = !{!6, !7, i64 24}
!21 = !{!6, !11, i64 40}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !9, i64 0}
!24 = !{!13, !13, i64 0}


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