; LLVM IR from junhyeokahn/PyPnC :: external_source/yaml/src/stream.ll (ZNK4YAML6Stream11GetNextByteEv)

; 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.YAML::Stream" = type { ptr, %"struct.YAML::Mark", i32, %"class.std::deque", ptr, i64, i64 }
%"struct.YAML::Mark" = type { i32, i32, i32 }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<char, std::allocator<char>>::_Deque_impl" }
%"struct.std::_Deque_base<char, std::allocator<char>>::_Deque_impl" = type { %"struct.std::_Deque_base<char, std::allocator<char>>::_Deque_impl_data" }
%"struct.std::_Deque_base<char, std::allocator<char>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, ptr }

; 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 i8 @_ZNK4YAML6Stream11GetNextByteEv(ptr noundef nonnull align 8 dereferenceable(128) %0) #1 align 2 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %"class.YAML::Stream", ptr %6, i32 0, i32 6
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds %"class.YAML::Stream", ptr %6, i32 0, i32 5
  %10 = load i64, ptr %9, align 8, !tbaa !20
  %11 = icmp uge i64 %8, %10
  br i1 %11, label %12, label %46

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %13 = getelementptr inbounds %"class.YAML::Stream", ptr %6, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !21
  %15 = load ptr, ptr %14, align 8, !tbaa !22
  %16 = getelementptr i8, ptr %15, i64 -24
  %17 = load i64, ptr %16, align 8
  %18 = getelementptr inbounds i8, ptr %14, i64 %17
  %19 = call noundef ptr @_ZNKSt9basic_iosIcSt11char_traitsIcEE5rdbufEv(ptr noundef nonnull align 8 dereferenceable(264) %18)
  store ptr %19, ptr %4, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.YAML::Stream", ptr %6, i32 0, i32 4
  %22 = load ptr, ptr %21, align 8, !tbaa !24
  %23 = call noundef ptr @_ZN4YAML10ReadBufferEPh(ptr noundef %22)
  %24 = call noundef i64 @_ZNSt15basic_streambufIcSt11char_traitsIcEE5sgetnEPcl(ptr noundef nonnull align 8 dereferenceable(64) %20, ptr noundef %23, i64 noundef 2048)
  %25 = getelementptr inbounds %"class.YAML::Stream", ptr %6, i32 0, i32 5
  store i64 %24, ptr %25, align 8, !tbaa !20
  %26 = getelementptr inbounds %"class.YAML::Stream", ptr %6, i32 0, i32 6
  store i64 0, ptr %26, align 8, !tbaa !9
  %27 = getelementptr inbounds %"class.YAML::Stream", ptr %6, i32 0, i32 5
  %28 = load i64, ptr %27, align 8, !tbaa !20
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %37, label %30

30:                                               ; preds = %12
  %31 = getelementptr inbounds %"class.YAML::Stream", ptr %6, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !21
  %33 = load ptr, ptr %32, align 8, !tbaa !22
  %34 = getelementptr i8, ptr %33, i64 -24
  %35 = load i64, ptr %34, align 8
  %36 = getelementptr inbounds i8, ptr %32, i64 %35
  call void @_ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate(ptr noundef nonnull align 8 dereferenceable(264) %36, i32 noundef 2)
  br label %37

37:                                               ; preds = %30, %12
  %38 = getelementptr inbounds %"class.YAML::Stream", ptr %6, i32 0, i32 5
  %39 = load i64, ptr %38, align 8, !tbaa !20
  %40 = icmp eq i64 0, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %37
  store i8 0, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %43

42:                                               ; preds = %37
  store i32 0, ptr %5, align 4
  br label %43

43:                                               ; preds = %42, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %44 = load i32, ptr %5, align 4
  switch i32 %44, label %56 [
    i32 0, label %45
    i32 1, label %54
  ]

45:                                               ; preds = %43
  br label %46

46:                                               ; preds = %45, %1
  %47 = getelementptr inbounds %"class.YAML::Stream", ptr %6, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !24
  %49 = getelementptr inbounds %"class.YAML::Stream", ptr %6, i32 0, i32 6
  %50 = load i64, ptr %49, align 8, !tbaa !9
  %51 = add i64 %50, 1
  store i64 %51, ptr %49, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %48, i64 %50
  %53 = load i8, ptr %52, align 1, !tbaa !25
  store i8 %53, ptr %2, align 1
  br label %54

54:                                               ; preds = %46, %43
  %55 = load i8, ptr %2, align 1
  ret i8 %55

56:                                               ; preds = %43
  unreachable
}

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

; Function Attrs: mustprogress uwtable
declare noundef i64 @_ZNSt15basic_streambufIcSt11char_traitsIcEE5sgetnEPcl(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef, i64 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4YAML10ReadBufferEPh(ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare void @_ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate(ptr noundef nonnull align 8 dereferenceable(264), i32 noundef) #1 align 2

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 = { inlinehint 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 #4 = { 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, !18, i64 120}
!10 = !{!"_ZTSN4YAML6StreamE", !6, i64 0, !11, i64 8, !13, i64 20, !14, i64 24, !6, i64 104, !18, i64 112, !18, i64 120}
!11 = !{!"_ZTSN4YAML4MarkE", !12, i64 0, !12, i64 4, !12, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTSN4YAML6Stream12CharacterSetE", !7, i64 0}
!14 = !{!"_ZTSSt5dequeIcSaIcEE", !15, i64 0}
!15 = !{!"_ZTSSt11_Deque_baseIcSaIcEE", !16, i64 0}
!16 = !{!"_ZTSNSt11_Deque_baseIcSaIcEE11_Deque_implE", !17, i64 0}
!17 = !{!"_ZTSNSt11_Deque_baseIcSaIcEE16_Deque_impl_dataE", !6, i64 0, !18, i64 8, !19, i64 16, !19, i64 48}
!18 = !{!"long", !7, i64 0}
!19 = !{!"_ZTSSt15_Deque_iteratorIcRcPcE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!20 = !{!10, !18, i64 112}
!21 = !{!10, !6, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !8, i64 0}
!24 = !{!10, !6, i64 104}
!25 = !{!7, !7, 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 zeroext i8 @_ZNK4YAML6Stream11GetNextByteEv(ptr nocapture noundef nonnull align 8 dereferenceable(128) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 120
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 112
  %5 = load i64, ptr %4, align 8, !tbaa !19
  %.not = icmp ult i64 %3, %5
  br i1 %.not, label %24, label %6

6:                                                ; preds = %1
  %7 = load ptr, ptr %0, align 8, !tbaa !20
  %8 = load ptr, ptr %7, align 8, !tbaa !21
  %9 = getelementptr i8, ptr %8, i64 -24
  %10 = load i64, ptr %9, align 8
  %11 = getelementptr inbounds i8, ptr %7, i64 %10
  %12 = tail call noundef ptr @_ZNKSt9basic_iosIcSt11char_traitsIcEE5rdbufEv(ptr noundef nonnull align 8 dereferenceable(264) %11)
  %13 = getelementptr inbounds i8, ptr %0, i64 104
  %14 = load ptr, ptr %13, align 8, !tbaa !23
  %15 = tail call noundef ptr @_ZN4YAML10ReadBufferEPh(ptr noundef %14)
  %16 = tail call noundef i64 @_ZNSt15basic_streambufIcSt11char_traitsIcEE5sgetnEPcl(ptr noundef nonnull align 8 dereferenceable(64) %12, ptr noundef %15, i64 noundef 2048)
  store i64 %16, ptr %4, align 8, !tbaa !19
  store i64 0, ptr %2, align 8, !tbaa !5
  %.not4 = icmp eq i64 %16, 0
  br i1 %.not4, label %17, label %._crit_edge

17:                                               ; preds = %6
  %18 = load ptr, ptr %0, align 8, !tbaa !20
  %19 = load ptr, ptr %18, align 8, !tbaa !21
  %20 = getelementptr i8, ptr %19, i64 -24
  %21 = load i64, ptr %20, align 8
  %22 = getelementptr inbounds i8, ptr %18, i64 %21
  tail call void @_ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate(ptr noundef nonnull align 8 dereferenceable(264) %22, i32 noundef 2)
  %.pre = load i64, ptr %4, align 8, !tbaa !19
  %23 = icmp eq i64 %.pre, 0
  br i1 %23, label %31, label %._crit_edge

._crit_edge:                                      ; preds = %6, %17
  %.pre6 = load i64, ptr %2, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %._crit_edge, %1
  %25 = phi i64 [ %.pre6, %._crit_edge ], [ %3, %1 ]
  %26 = getelementptr inbounds i8, ptr %0, i64 104
  %27 = load ptr, ptr %26, align 8, !tbaa !23
  %28 = add i64 %25, 1
  store i64 %28, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %27, i64 %25
  %30 = load i8, ptr %29, align 1, !tbaa !24
  br label %31

31:                                               ; preds = %17, %24
  %.1 = phi i8 [ 0, %17 ], [ %30, %24 ]
  ret i8 %.1
}

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

; Function Attrs: mustprogress uwtable
declare noundef i64 @_ZNSt15basic_streambufIcSt11char_traitsIcEE5sgetnEPcl(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4YAML10ReadBufferEPh(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare void @_ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate(ptr noundef nonnull align 8 dereferenceable(264), i32 noundef) 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" }
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 = { inlinehint 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" }

!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, !17, i64 120}
!6 = !{!"_ZTSN4YAML6StreamE", !7, i64 0, !10, i64 8, !12, i64 20, !13, i64 24, !7, i64 104, !17, i64 112, !17, i64 120}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN4YAML4MarkE", !11, i64 0, !11, i64 4, !11, i64 8}
!11 = !{!"int", !8, i64 0}
!12 = !{!"_ZTSN4YAML6Stream12CharacterSetE", !8, i64 0}
!13 = !{!"_ZTSSt5dequeIcSaIcEE", !14, i64 0}
!14 = !{!"_ZTSSt11_Deque_baseIcSaIcEE", !15, i64 0}
!15 = !{!"_ZTSNSt11_Deque_baseIcSaIcEE11_Deque_implE", !16, i64 0}
!16 = !{!"_ZTSNSt11_Deque_baseIcSaIcEE16_Deque_impl_dataE", !7, i64 0, !17, i64 8, !18, i64 16, !18, i64 48}
!17 = !{!"long", !8, i64 0}
!18 = !{!"_ZTSSt15_Deque_iteratorIcRcPcE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!19 = !{!6, !17, i64 112}
!20 = !{!6, !7, i64 0}
!21 = !{!22, !22, i64 0}
!22 = !{!"vtable pointer", !9, i64 0}
!23 = !{!6, !7, i64 104}
!24 = !{!8, !8, i64 0}


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