; LLVM IR from mncoppola/rpef :: utilities_src/squashfs2.1/lzma/C/7zip/Common/InBuffer.ll (ZN9CInBuffer9ReadBlockEv)

; 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.CInBuffer = type <{ ptr, ptr, ptr, %class.CMyComPtr, i64, i32, i8, [3 x i8] }>
%class.CMyComPtr = type { ptr }

@_ZTI18CInBufferException = external dso_local constant { 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

; 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 @_ZN9CInBuffer9ReadBlockEv(ptr noundef nonnull align 8 dereferenceable(45) %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.CInBuffer, ptr %8, i32 0, i32 6
  %10 = load i8, ptr %9, align 4, !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 %62

13:                                               ; preds = %1
  %14 = getelementptr inbounds %class.CInBuffer, ptr %8, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  %16 = getelementptr inbounds %class.CInBuffer, 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.CInBuffer, 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %24 = getelementptr inbounds %class.CInBuffer, ptr %8, i32 0, i32 3
  %25 = call noundef ptr @_ZNK9CMyComPtrI19ISequentialInStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8) %24)
  %26 = getelementptr inbounds %class.CInBuffer, ptr %8, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !18
  %28 = getelementptr inbounds %class.CInBuffer, ptr %8, i32 0, i32 5
  %29 = load i32, ptr %28, align 8, !tbaa !20
  %30 = load ptr, ptr %25, align 8, !tbaa !21
  %31 = getelementptr inbounds ptr, ptr %30, i64 3
  %32 = load ptr, ptr %31, align 8
  %33 = call noundef i32 %32(ptr noundef nonnull align 8 dereferenceable(8) %25, ptr noundef %27, i32 noundef %29, ptr noundef %4)
  store i32 %33, ptr %5, align 4, !tbaa !23
  %34 = load i32, ptr %5, align 4, !tbaa !23
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %44

36:                                               ; preds = %13
  %37 = call ptr @__cxa_allocate_exception(i64 4) #3
  %38 = load i32, ptr %5, align 4, !tbaa !23
  invoke void @_ZN18CInBufferExceptionC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %37, i32 noundef %38)
          to label %39 unwind label %40

39:                                               ; preds = %36
  call void @__cxa_throw(ptr %37, ptr @_ZTI18CInBufferException, ptr null) #4
  unreachable

40:                                               ; preds = %36
  %41 = landingpad { ptr, i32 }
          cleanup
  %42 = extractvalue { ptr, i32 } %41, 0
  store ptr %42, ptr %6, align 8
  %43 = extractvalue { ptr, i32 } %41, 1
  store i32 %43, ptr %7, align 4
  call void @__cxa_free_exception(ptr %37) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %64

44:                                               ; preds = %13
  %45 = getelementptr inbounds %class.CInBuffer, ptr %8, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = getelementptr inbounds %class.CInBuffer, ptr %8, i32 0, i32 0
  store ptr %46, ptr %47, align 8, !tbaa !17
  %48 = getelementptr inbounds %class.CInBuffer, ptr %8, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = load i32, ptr %4, align 4, !tbaa !23
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %49, i64 %51
  %53 = getelementptr inbounds %class.CInBuffer, ptr %8, i32 0, i32 1
  store ptr %52, ptr %53, align 8, !tbaa !24
  %54 = load i32, ptr %4, align 4, !tbaa !23
  %55 = icmp eq i32 %54, 0
  %56 = getelementptr inbounds %class.CInBuffer, ptr %8, i32 0, i32 6
  %57 = zext i1 %55 to i8
  store i8 %57, ptr %56, align 4, !tbaa !9
  %58 = getelementptr inbounds %class.CInBuffer, ptr %8, i32 0, i32 6
  %59 = load i8, ptr %58, align 4, !tbaa !9, !range !15, !noundef !16
  %60 = trunc i8 %59 to i1
  %61 = xor i1 %60, true
  store i1 %61, ptr %2, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %62

62:                                               ; preds = %44, %12
  %63 = load i1, ptr %2, align 1
  ret i1 %63

64:                                               ; preds = %40
  %65 = load ptr, ptr %6, align 8
  %66 = load i32, ptr %7, align 4
  %67 = insertvalue { ptr, i32 } poison, ptr %65, 0
  %68 = insertvalue { ptr, i32 } %67, i32 %66, 1
  resume { ptr, i32 } %68
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK9CMyComPtrI19ISequentialInStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

declare ptr @__cxa_allocate_exception(i64)

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

declare i32 @__gxx_personality_v0(...)

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 = { mustprogress 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 #3 = { nounwind }
attributes #4 = { 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, !14, i64 44}
!10 = !{!"_ZTS9CInBuffer", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !12, i64 32, !13, i64 40, !14, i64 44}
!11 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !6, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!10, !6, i64 0}
!18 = !{!10, !6, i64 16}
!19 = !{!10, !12, i64 32}
!20 = !{!10, !13, i64 40}
!21 = !{!22, !22, i64 0}
!22 = !{!"vtable pointer", !8, i64 0}
!23 = !{!13, !13, i64 0}
!24 = !{!10, !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"

@_ZTI18CInBufferException = external dso_local constant { 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

; 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 @_ZN9CInBuffer9ReadBlockEv(ptr noundef nonnull align 8 dereferenceable(45) %0) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i32, align 4
  %3 = getelementptr inbounds i8, ptr %0, i64 44
  %4 = load i8, ptr %3, align 4, !tbaa !5, !range !14, !noundef !15
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %36, 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
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  %17 = tail call noundef ptr @_ZNK9CMyComPtrI19ISequentialInStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8) %16)
  %18 = load ptr, ptr %8, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %0, i64 40
  %20 = load i32, ptr %19, align 8, !tbaa !19
  %21 = load ptr, ptr %17, align 8, !tbaa !20
  %22 = getelementptr inbounds i8, ptr %21, i64 24
  %23 = load ptr, ptr %22, align 8
  %24 = call noundef i32 %23(ptr noundef nonnull align 8 dereferenceable(8) %17, ptr noundef %18, i32 noundef %20, ptr noundef nonnull %2)
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %27, label %25

25:                                               ; preds = %6
  %26 = call ptr @__cxa_allocate_exception(i64 4) #3
  call void @_ZN18CInBufferExceptionC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %26, i32 noundef %24)
  call void @__cxa_throw(ptr nonnull %26, ptr nonnull @_ZTI18CInBufferException, ptr null) #4
  unreachable

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

36:                                               ; preds = %1, %27
  %.0 = phi i1 [ %35, %27 ], [ false, %1 ]
  ret i1 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK9CMyComPtrI19ISequentialInStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

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

declare i32 @__gxx_personality_v0(...)

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


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