; LLVM IR from team-charls/charls :: src (jpeg_stream_writer)

; 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.std::array.1" = type { [5 x i8] }
%"class.charls::span.0" = type { ptr, i64 }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6charls18jpeg_stream_writer13write_segmentENS_16jpeg_marker_codeENS_4spanIKSt4byteEE(ptr noundef nonnull align 8 dereferenceable(56), i8 noundef zeroext, ptr, i64) #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6charls18jpeg_stream_writer29write_color_transform_segmentENS_20color_transformationE(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %"struct.std::array.1", align 1
  %6 = alloca %"class.charls::span.0", align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 5, ptr %5) #3
  %8 = getelementptr inbounds %"struct.std::array.1", ptr %5, i32 0, i32 0
  store i8 109, ptr %8, align 1, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %8, i64 1
  store i8 114, ptr %9, align 1, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %8, i64 2
  store i8 102, ptr %10, align 1, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %8, i64 3
  store i8 120, ptr %11, align 1, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %8, i64 4
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = trunc i32 %13 to i8
  store i8 %14, ptr %12, align 1, !tbaa !11
  call void @_ZN6charls4spanIKSt4byteEC2IS1_Lm5EEERKSt5arrayIT_XT0_EE(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 1 dereferenceable(5) %5) #3
  %15 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8
  %17 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 1
  %18 = load i64, ptr %17, align 8
  call void @_ZN6charls18jpeg_stream_writer13write_segmentENS_16jpeg_marker_codeENS_4spanIKSt4byteEE(ptr noundef nonnull align 8 dereferenceable(56) %7, i8 noundef zeroext -24, ptr %16, i64 %18)
  call void @llvm.lifetime.end.p0(i64 5, ptr %5) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6charls4spanIKSt4byteEC2IS1_Lm5EEERKSt5arrayIT_XT0_EE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 1 dereferenceable(5)) unnamed_addr #2 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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 = !{!"_ZTSN6charls20color_transformationE", !7, i64 0}
!11 = !{!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"

%"struct.std::array.1" = type { [5 x i8] }
%"class.charls::span.0" = type { ptr, i64 }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6charls18jpeg_stream_writer13write_segmentENS_16jpeg_marker_codeENS_4spanIKSt4byteEE(ptr noundef nonnull align 8 dereferenceable(56), i8 noundef zeroext, ptr, i64) local_unnamed_addr #0 align 2

; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6charls18jpeg_stream_writer29write_color_transform_segmentENS_20color_transformationE(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = alloca %"struct.std::array.1", align 4
  %4 = alloca %"class.charls::span.0", align 8
  call void @llvm.lifetime.start.p0(i64 5, ptr nonnull %3) #3
  store <4 x i8> <i8 109, i8 114, i8 102, i8 120>, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %3, i64 4
  %6 = trunc i32 %1 to i8
  store i8 %6, ptr %5, align 4, !tbaa !5
  call void @_ZN6charls4spanIKSt4byteEC2IS1_Lm5EEERKSt5arrayIT_XT0_EE(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 1 dereferenceable(5) %3) #3
  %7 = load ptr, ptr %4, align 8
  %8 = getelementptr inbounds i8, ptr %4, i64 8
  %9 = load i64, ptr %8, align 8
  call void @_ZN6charls18jpeg_stream_writer13write_segmentENS_16jpeg_marker_codeENS_4spanIKSt4byteEE(ptr noundef nonnull align 8 dereferenceable(56) %0, i8 noundef zeroext -24, ptr %7, i64 %9)
  call void @llvm.lifetime.end.p0(i64 5, ptr nonnull %3) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6charls4spanIKSt4byteEC2IS1_Lm5EEERKSt5arrayIT_XT0_EE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 1 dereferenceable(5)) unnamed_addr #2 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass