; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Common (CWrappers)

; 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.CByteInBufWrap = type { %struct.IByteIn, ptr, ptr, ptr, i32, ptr, i64, i8, i32 }
%struct.IByteIn = type { ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i8 @_ZN14CByteInBufWrap20ReadByteFromNewBlockEv(ptr noundef nonnull align 8 dereferenceable(64) %0) #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 8
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %53

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %11 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 3
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %15 = ptrtoint ptr %12 to i64
  %16 = ptrtoint ptr %14 to i64
  %17 = sub i64 %15, %16
  %18 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 6
  %19 = load i64, ptr %18, align 8, !tbaa !17
  %20 = add i64 %19, %17
  store i64 %20, ptr %18, align 8, !tbaa !17
  %21 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 4
  %26 = load i32, ptr %25, align 8, !tbaa !19
  %27 = load ptr, ptr %22, align 8, !tbaa !20
  %28 = getelementptr inbounds ptr, ptr %27, i64 5
  %29 = load ptr, ptr %28, align 8
  %30 = invoke noundef i32 %29(ptr noundef nonnull align 8 dereferenceable(8) %22, ptr noundef %24, i32 noundef %26, ptr noundef %4)
          to label %31 unwind label %57

31:                                               ; preds = %10
  %32 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 8
  store i32 %30, ptr %32, align 4, !tbaa !9
  %33 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 1
  store ptr %34, ptr %35, align 8, !tbaa !15
  %36 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 3
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = load i32, ptr %4, align 4, !tbaa !22
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %37, i64 %39
  %41 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 2
  store ptr %40, ptr %41, align 8, !tbaa !23
  %42 = load i32, ptr %4, align 4, !tbaa !22
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %49

44:                                               ; preds = %31
  %45 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr %45, align 8, !tbaa !15
  %48 = load i8, ptr %46, align 1, !tbaa !24
  store i8 %48, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %50

49:                                               ; preds = %31
  store i32 0, ptr %5, align 4
  br label %50

50:                                               ; preds = %49, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %51 = load i32, ptr %5, align 4
  switch i32 %51, label %60 [
    i32 0, label %52
    i32 1, label %55
  ]

52:                                               ; preds = %50
  br label %53

53:                                               ; preds = %52, %1
  %54 = getelementptr inbounds %struct.CByteInBufWrap, ptr %6, i32 0, i32 7
  store i8 1, ptr %54, align 8, !tbaa !25
  store i8 0, ptr %2, align 1
  br label %55

55:                                               ; preds = %53, %50
  %56 = load i8, ptr %2, align 1
  ret i8 %56

57:                                               ; preds = %10
  %58 = landingpad { ptr, i32 }
          catch ptr null
  %59 = extractvalue { ptr, i32 } %58, 0
  call void @__clang_call_terminate(ptr %59) #4
  unreachable

60:                                               ; preds = %50
  unreachable
}

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

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

attributes #0 = { noinline noreturn nounwind uwtable "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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind }
attributes #4 = { noreturn 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 60}
!10 = !{!"_ZTS14CByteInBufWrap", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !6, i64 40, !13, i64 48, !14, i64 56, !12, i64 60}
!11 = !{!"_ZTS7IByteIn", !6, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!10, !6, i64 8}
!16 = !{!10, !6, i64 24}
!17 = !{!10, !13, i64 48}
!18 = !{!10, !6, i64 40}
!19 = !{!10, !12, i64 32}
!20 = !{!21, !21, i64 0}
!21 = !{!"vtable pointer", !8, i64 0}
!22 = !{!12, !12, i64 0}
!23 = !{!10, !6, i64 16}
!24 = !{!7, !7, i64 0}
!25 = !{!10, !14, i64 56}


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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i8 @_ZN14CByteInBufWrap20ReadByteFromNewBlockEv(ptr nocapture noundef nonnull align 8 dereferenceable(64) %0) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i32, align 4
  %3 = getelementptr inbounds i8, ptr %0, i64 60
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %6, label %34

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

25:                                               ; preds = %6
  store i32 %24, ptr %3, align 4, !tbaa !5
  %26 = load ptr, ptr %9, align 8, !tbaa !15
  store ptr %26, ptr %7, align 8, !tbaa !14
  %27 = load i32, ptr %2, align 4, !tbaa !21
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %26, i64 %28
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %29, ptr %30, align 8, !tbaa !22
  %.not.not = icmp eq i32 %27, 0
  br i1 %.not.not, label %.thread, label %31

.thread:                                          ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  br label %34

31:                                               ; preds = %25
  %32 = getelementptr inbounds i8, ptr %26, i64 1
  store ptr %32, ptr %7, align 8, !tbaa !14
  %33 = load i8, ptr %26, align 1, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  br label %36

34:                                               ; preds = %.thread, %1
  %35 = getelementptr inbounds i8, ptr %0, i64 56
  store i8 1, ptr %35, align 8, !tbaa !24
  br label %36

36:                                               ; preds = %31, %34
  %.1 = phi i8 [ %33, %31 ], [ 0, %34 ]
  ret i8 %.1

37:                                               ; preds = %6
  %38 = landingpad { ptr, i32 }
          catch ptr null
  %39 = extractvalue { ptr, i32 } %38, 0
  call void @__clang_call_terminate(ptr %39) #4
  unreachable
}

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

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

attributes #0 = { noinline noreturn nounwind uwtable "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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind }
attributes #4 = { noreturn 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, !11, i64 60}
!6 = !{!"_ZTS14CByteInBufWrap", !7, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !11, i64 32, !8, i64 40, !12, i64 48, !13, i64 56, !11, i64 60}
!7 = !{!"_ZTS7IByteIn", !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"long long", !9, i64 0}
!13 = !{!"bool", !9, i64 0}
!14 = !{!6, !8, i64 8}
!15 = !{!6, !8, i64 24}
!16 = !{!6, !12, i64 48}
!17 = !{!6, !8, i64 40}
!18 = !{!6, !11, i64 32}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !10, i64 0}
!21 = !{!11, !11, i64 0}
!22 = !{!6, !8, i64 16}
!23 = !{!9, !9, i64 0}
!24 = !{!6, !13, i64 56}


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