; LLVM IR from team-charls/charls :: src/jpeg_stream_reader.ll (ZN6charls18jpeg_stream_reader17read_segment_sizeEv)

; 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.charls::span" = type { ptr, i64 }
%"class.charls::jpeg_stream_reader" = type { ptr, ptr, %"class.charls::span", %struct.charls_frame_info, %"struct.charls::coding_parameters", %struct.charls_jpegls_pc_parameters, %"class.std::vector", %"class.std::vector.0", i32, i32, i32, i32, i8, i32, %"struct.charls::callback_function", %"struct.charls::callback_function.5" }
%struct.charls_frame_info = type { i32, i32, i32, i32 }
%"struct.charls::coding_parameters" = type { i32, i32, i32, i32 }
%struct.charls_jpegls_pc_parameters = type { i32, i32, i32, i32, i32 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<charls::jpeg_stream_reader::component_info, std::allocator<charls::jpeg_stream_reader::component_info>>::_Vector_impl" }
%"struct.std::_Vector_base<charls::jpeg_stream_reader::component_info, std::allocator<charls::jpeg_stream_reader::component_info>>::_Vector_impl" = type { %"struct.std::_Vector_base<charls::jpeg_stream_reader::component_info, std::allocator<charls::jpeg_stream_reader::component_info>>::_Vector_impl_data" }
%"struct.std::_Vector_base<charls::jpeg_stream_reader::component_info, std::allocator<charls::jpeg_stream_reader::component_info>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<charls::jpeg_stream_reader::mapping_table_entry, std::allocator<charls::jpeg_stream_reader::mapping_table_entry>>::_Vector_impl" }
%"struct.std::_Vector_base<charls::jpeg_stream_reader::mapping_table_entry, std::allocator<charls::jpeg_stream_reader::mapping_table_entry>>::_Vector_impl" = type { %"struct.std::_Vector_base<charls::jpeg_stream_reader::mapping_table_entry, std::allocator<charls::jpeg_stream_reader::mapping_table_entry>>::_Vector_impl_data" }
%"struct.std::_Vector_base<charls::jpeg_stream_reader::mapping_table_entry, std::allocator<charls::jpeg_stream_reader::mapping_table_entry>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.charls::callback_function" = type { ptr, ptr }
%"struct.charls::callback_function.5" = type { ptr, ptr }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #0

; Function Attrs: mustprogress noinline noreturn uwtable
declare dso_local void @_ZN6charls4impl18throw_jpegls_errorENS_11jpegls_errcE(i32 noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6charls18jpeg_stream_reader17read_segment_sizeEv(ptr noundef nonnull align 8 dereferenceable(192) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca %"class.charls::span", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  store i64 2, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %7 = call noundef zeroext i16 @_ZN6charls18jpeg_stream_reader19read_uint16_checkedEv(ptr noundef nonnull align 8 dereferenceable(192) %6)
  %8 = zext i16 %7 to i64
  store i64 %8, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #6
  %9 = getelementptr inbounds %"class.charls::jpeg_stream_reader", ptr %6, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = sub i64 %11, 2
  call void @_ZN6charls4spanIKSt4byteEC2EPS2_m(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef %10, i64 noundef %12) #6
  %13 = getelementptr inbounds %"class.charls::jpeg_stream_reader", ptr %6, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %13, ptr align 8 %5, i64 16, i1 false), !tbaa.struct !33
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #6
  %14 = load i64, ptr %4, align 8, !tbaa !9
  %15 = icmp ult i64 %14, 2
  br i1 %15, label %25, label %16

16:                                               ; preds = %1
  %17 = getelementptr inbounds %"class.charls::jpeg_stream_reader", ptr %6, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds %"class.charls::jpeg_stream_reader", ptr %6, i32 0, i32 2
  %20 = call noundef i64 @_ZNK6charls4spanIKSt4byteE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %19) #6
  %21 = getelementptr inbounds i8, ptr %18, i64 %20
  %22 = getelementptr inbounds %"class.charls::jpeg_stream_reader", ptr %6, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !34
  %24 = icmp ugt ptr %21, %23
  br label %25

25:                                               ; preds = %16, %1
  %26 = phi i1 [ true, %1 ], [ %24, %16 ]
  %27 = xor i1 %26, true
  %28 = xor i1 %27, true
  %29 = zext i1 %28 to i64
  %30 = call i64 @llvm.expect.i64(i64 %29, i64 0)
  %31 = icmp ne i64 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %25
  call void @_ZN6charls4impl18throw_jpegls_errorENS_11jpegls_errcE(i32 noundef 15) #7
  unreachable

33:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i16 @_ZN6charls18jpeg_stream_reader19read_uint16_checkedEv(ptr noundef nonnull align 8 dereferenceable(192)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6charls4spanIKSt4byteEC2EPS2_m(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i64 noundef) unnamed_addr #5 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #1 = { mustprogress noinline noreturn 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 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { nounwind }
attributes #7 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSN6charls18jpeg_stream_readerE", !6, i64 0, !6, i64 8, !13, i64 16, !14, i64 32, !16, i64 48, !19, i64 64, !20, i64 88, !24, i64 112, !28, i64 136, !15, i64 140, !15, i64 144, !17, i64 148, !29, i64 152, !30, i64 156, !31, i64 160, !32, i64 176}
!13 = !{!"_ZTSN6charls4spanIKSt4byteEE", !6, i64 0, !10, i64 8}
!14 = !{!"_ZTS17charls_frame_info", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTSN6charls17coding_parametersE", !15, i64 0, !15, i64 4, !17, i64 8, !18, i64 12}
!17 = !{!"_ZTSN6charls15interleave_modeE", !7, i64 0}
!18 = !{!"_ZTSN6charls20color_transformationE", !7, i64 0}
!19 = !{!"_ZTS27charls_jpegls_pc_parameters", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12, !15, i64 16}
!20 = !{!"_ZTSSt6vectorIN6charls18jpeg_stream_reader14component_infoESaIS2_EE", !21, i64 0}
!21 = !{!"_ZTSSt12_Vector_baseIN6charls18jpeg_stream_reader14component_infoESaIS2_EE", !22, i64 0}
!22 = !{!"_ZTSNSt12_Vector_baseIN6charls18jpeg_stream_reader14component_infoESaIS2_EE12_Vector_implE", !23, i64 0}
!23 = !{!"_ZTSNSt12_Vector_baseIN6charls18jpeg_stream_reader14component_infoESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!24 = !{!"_ZTSSt6vectorIN6charls18jpeg_stream_reader19mapping_table_entryESaIS2_EE", !25, i64 0}
!25 = !{!"_ZTSSt12_Vector_baseIN6charls18jpeg_stream_reader19mapping_table_entryESaIS2_EE", !26, i64 0}
!26 = !{!"_ZTSNSt12_Vector_baseIN6charls18jpeg_stream_reader19mapping_table_entryESaIS2_EE12_Vector_implE", !27, i64 0}
!27 = !{!"_ZTSNSt12_Vector_baseIN6charls18jpeg_stream_reader19mapping_table_entryESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!28 = !{!"_ZTSN6charls18jpeg_stream_reader5stateE", !7, i64 0}
!29 = !{!"bool", !7, i64 0}
!30 = !{!"_ZTSN6charls22compressed_data_formatE", !7, i64 0}
!31 = !{!"_ZTSN6charls17callback_functionIPFiPKvmPvEEE", !6, i64 0, !6, i64 8}
!32 = !{!"_ZTSN6charls17callback_functionIPFiiPKvmPvEEE", !6, i64 0, !6, i64 8}
!33 = !{i64 0, i64 8, !5, i64 8, i64 8, !9}
!34 = !{!12, !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"

%"class.charls::span" = type { ptr, i64 }

; Function Attrs: mustprogress noinline noreturn uwtable
declare dso_local void @_ZN6charls4impl18throw_jpegls_errorENS_11jpegls_errcE(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6charls18jpeg_stream_reader17read_segment_sizeEv(ptr noundef nonnull align 8 dereferenceable(192) %0) local_unnamed_addr #2 align 2 {
  %2 = alloca %"class.charls::span", align 8
  %3 = tail call noundef zeroext i16 @_ZN6charls18jpeg_stream_reader19read_uint16_checkedEv(ptr noundef nonnull align 8 dereferenceable(192) %0)
  %4 = zext i16 %3 to i64
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #5
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = add nsw i64 %4, -2
  call void @_ZN6charls4spanIKSt4byteEC2EPS2_m(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef %5, i64 noundef %6) #5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 8 dereferenceable(16) %2, i64 16, i1 false), !tbaa.struct !31
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #5
  %8 = icmp ult i16 %3, 2
  br i1 %8, label %.critedge, label %9, !prof !34

9:                                                ; preds = %1
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %11 = call noundef i64 @_ZNK6charls4spanIKSt4byteE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %7) #5
  %12 = getelementptr inbounds i8, ptr %10, i64 %11
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !35
  %15 = icmp ugt ptr %12, %14
  br i1 %15, label %.critedge, label %16, !prof !34

.critedge:                                        ; preds = %1, %9
  call void @_ZN6charls4impl18throw_jpegls_errorENS_11jpegls_errcE(i32 noundef 15) #6
  unreachable

16:                                               ; preds = %9
  ret void
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i16 @_ZN6charls18jpeg_stream_reader19read_uint16_checkedEv(ptr noundef nonnull align 8 dereferenceable(192)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6charls4spanIKSt4byteEC2EPS2_m(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i64 noundef) unnamed_addr #4 align 2

attributes #0 = { mustprogress noinline noreturn 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nounwind }
attributes #6 = { 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, !7, i64 0}
!6 = !{!"_ZTSN6charls18jpeg_stream_readerE", !7, i64 0, !7, i64 8, !10, i64 16, !12, i64 32, !14, i64 48, !17, i64 64, !18, i64 88, !22, i64 112, !26, i64 136, !13, i64 140, !13, i64 144, !15, i64 148, !27, i64 152, !28, i64 156, !29, i64 160, !30, i64 176}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN6charls4spanIKSt4byteEE", !7, i64 0, !11, i64 8}
!11 = !{!"long", !8, i64 0}
!12 = !{!"_ZTS17charls_frame_info", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12}
!13 = !{!"int", !8, i64 0}
!14 = !{!"_ZTSN6charls17coding_parametersE", !13, i64 0, !13, i64 4, !15, i64 8, !16, i64 12}
!15 = !{!"_ZTSN6charls15interleave_modeE", !8, i64 0}
!16 = !{!"_ZTSN6charls20color_transformationE", !8, i64 0}
!17 = !{!"_ZTS27charls_jpegls_pc_parameters", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16}
!18 = !{!"_ZTSSt6vectorIN6charls18jpeg_stream_reader14component_infoESaIS2_EE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseIN6charls18jpeg_stream_reader14component_infoESaIS2_EE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIN6charls18jpeg_stream_reader14component_infoESaIS2_EE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIN6charls18jpeg_stream_reader14component_infoESaIS2_EE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!22 = !{!"_ZTSSt6vectorIN6charls18jpeg_stream_reader19mapping_table_entryESaIS2_EE", !23, i64 0}
!23 = !{!"_ZTSSt12_Vector_baseIN6charls18jpeg_stream_reader19mapping_table_entryESaIS2_EE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseIN6charls18jpeg_stream_reader19mapping_table_entryESaIS2_EE12_Vector_implE", !25, i64 0}
!25 = !{!"_ZTSNSt12_Vector_baseIN6charls18jpeg_stream_reader19mapping_table_entryESaIS2_EE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!26 = !{!"_ZTSN6charls18jpeg_stream_reader5stateE", !8, i64 0}
!27 = !{!"bool", !8, i64 0}
!28 = !{!"_ZTSN6charls22compressed_data_formatE", !8, i64 0}
!29 = !{!"_ZTSN6charls17callback_functionIPFiPKvmPvEEE", !7, i64 0, !7, i64 8}
!30 = !{!"_ZTSN6charls17callback_functionIPFiiPKvmPvEEE", !7, i64 0, !7, i64 8}
!31 = !{i64 0, i64 8, !32, i64 8, i64 8, !33}
!32 = !{!7, !7, i64 0}
!33 = !{!11, !11, i64 0}
!34 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!35 = !{!6, !7, i64 8}


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