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

; 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.CInFileStream = type <{ %struct.IInStream, %struct.IStreamGetSize, %class.CMyUnknownImp, %"class.NC::NFile::NIO::CInFile", i8, [7 x i8], ptr, i32, [4 x i8] }>
%struct.IInStream = type { %struct.ISequentialInStream }
%struct.ISequentialInStream = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.IStreamGetSize = type { %struct.IUnknown }
%class.CMyUnknownImp = type { i32 }
%"class.NC::NFile::NIO::CInFile" = type { %"class.NC::NFile::NIO::CFileBase" }
%"class.NC::NFile::NIO::CFileBase" = type { i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN13CInFileStream4ReadEPvjPj(ptr noundef nonnull align 8 dereferenceable(44) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %17

15:                                               ; preds = %4
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %15, %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %18 = getelementptr inbounds %class.CInFileStream, ptr %12, i32 0, i32 3
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  %22 = call noundef i64 @_ZN2NC5NFile3NIO7CInFile4ReadEPvm(ptr noundef nonnull align 4 dereferenceable(4) %18, ptr noundef %19, i64 noundef %21)
  store i64 %22, ptr %10, align 8, !tbaa !11
  %23 = load i64, ptr %10, align 8, !tbaa !11
  %24 = icmp eq i64 %23, -1
  br i1 %24, label %25, label %39

25:                                               ; preds = %17
  %26 = getelementptr inbounds %class.CInFileStream, ptr %12, i32 0, i32 6
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %38

29:                                               ; preds = %25
  %30 = getelementptr inbounds %class.CInFileStream, ptr %12, i32 0, i32 6
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = getelementptr inbounds %class.CInFileStream, ptr %12, i32 0, i32 7
  %33 = load i32, ptr %32, align 8, !tbaa !23
  %34 = load ptr, ptr %31, align 8, !tbaa !24
  %35 = getelementptr inbounds ptr, ptr %34, i64 0
  %36 = load ptr, ptr %35, align 8
  %37 = call noundef i32 %36(ptr noundef nonnull align 8 dereferenceable(8) %31, i32 noundef %33, i32 noundef -2147467259)
  store i32 %37, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %47

38:                                               ; preds = %25
  store i32 -2147467259, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %47

39:                                               ; preds = %17
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %46

42:                                               ; preds = %39
  %43 = load i64, ptr %10, align 8, !tbaa !11
  %44 = trunc i64 %43 to i32
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %44, ptr %45, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %42, %39
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %47

47:                                               ; preds = %46, %38, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %48 = load i32, ptr %5, align 4
  ret i32 %48
}

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

declare noundef i64 @_ZN2NC5NFile3NIO7CInFile4ReadEPvm(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef, i64 noundef) #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 = { "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 }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 32}
!14 = !{!"_ZTS13CInFileStream", !15, i64 0, !18, i64 8, !19, i64 16, !20, i64 20, !22, i64 24, !6, i64 32, !10, i64 40}
!15 = !{!"_ZTS9IInStream", !16, i64 0}
!16 = !{!"_ZTS19ISequentialInStream", !17, i64 0}
!17 = !{!"_ZTS8IUnknown"}
!18 = !{!"_ZTS14IStreamGetSize", !17, i64 0}
!19 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!20 = !{!"_ZTSN2NC5NFile3NIO7CInFileE", !21, i64 0}
!21 = !{!"_ZTSN2NC5NFile3NIO9CFileBaseE", !10, i64 0}
!22 = !{!"bool", !7, i64 0}
!23 = !{!14, !10, i64 40}
!24 = !{!25, !25, i64 0}
!25 = !{!"vtable pointer", !8, 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 uwtable
define dso_local noundef i32 @_ZN13CInFileStream4ReadEPvjPj(ptr noundef nonnull align 8 dereferenceable(44) %0, ptr noundef %1, i32 noundef %2, ptr noundef writeonly %3) unnamed_addr #0 align 2 {
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %5, label %.thread

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 20
  %7 = zext i32 %2 to i64
  %8 = tail call noundef i64 @_ZN2NC5NFile3NIO7CInFile4ReadEPvm(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef %1, i64 noundef %7)
  %9 = icmp eq i64 %8, -1
  br i1 %9, label %14, label %25

.thread:                                          ; preds = %4
  store i32 0, ptr %3, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 20
  %11 = zext i32 %2 to i64
  %12 = tail call noundef i64 @_ZN2NC5NFile3NIO7CInFile4ReadEPvm(ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef %1, i64 noundef %11)
  %13 = icmp eq i64 %12, -1
  br i1 %13, label %14, label %23

14:                                               ; preds = %.thread, %5
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %.not12 = icmp eq ptr %16, null
  br i1 %.not12, label %25, label %17

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %0, i64 40
  %19 = load i32, ptr %18, align 8, !tbaa !20
  %20 = load ptr, ptr %16, align 8, !tbaa !21
  %21 = load ptr, ptr %20, align 8
  %22 = tail call noundef i32 %21(ptr noundef nonnull align 8 dereferenceable(8) %16, i32 noundef %19, i32 noundef -2147467259)
  br label %25

23:                                               ; preds = %.thread
  %24 = trunc i64 %12 to i32
  store i32 %24, ptr %3, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %5, %23, %14, %17
  %.0 = phi i32 [ %22, %17 ], [ -2147467259, %14 ], [ 0, %23 ], [ 0, %5 ]
  ret i32 %.0
}

declare noundef i64 @_ZN2NC5NFile3NIO7CInFile4ReadEPvm(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef, i64 noundef) local_unnamed_addr #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 = { "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++ TBAA"}
!9 = !{!10, !19, i64 32}
!10 = !{!"_ZTS13CInFileStream", !11, i64 0, !14, i64 8, !15, i64 16, !16, i64 20, !18, i64 24, !19, i64 32, !6, i64 40}
!11 = !{!"_ZTS9IInStream", !12, i64 0}
!12 = !{!"_ZTS19ISequentialInStream", !13, i64 0}
!13 = !{!"_ZTS8IUnknown"}
!14 = !{!"_ZTS14IStreamGetSize", !13, i64 0}
!15 = !{!"_ZTS13CMyUnknownImp", !6, i64 0}
!16 = !{!"_ZTSN2NC5NFile3NIO7CInFileE", !17, i64 0}
!17 = !{!"_ZTSN2NC5NFile3NIO9CFileBaseE", !6, i64 0}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"any pointer", !7, i64 0}
!20 = !{!10, !6, i64 40}
!21 = !{!22, !22, i64 0}
!22 = !{!"vtable pointer", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass