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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK6charls4spanIKSt4byteE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) #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_writer38write_jpegls_preset_parameters_segmentEiiNS_4spanIKSt4byteEE(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, i32 noundef %2, ptr %3, i64 %4) #2 align 2 {
  %6 = alloca %"class.charls::span.0", align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca %"class.charls::span.0", align 8
  %15 = alloca i64, align 8
  %16 = alloca %"class.charls::span.0", align 8
  %17 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 0
  store ptr %3, ptr %17, align 8
  %18 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 1
  store i64 %4, ptr %18, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  %19 = load ptr, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 65530, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %20 = call noundef ptr @_ZNK6charls4spanIKSt4byteE5beginEv(ptr noundef nonnull align 8 dereferenceable(16) %6) #4
  store ptr %20, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %21 = call noundef i64 @_ZNK6charls4spanIKSt4byteE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %6) #4
  store i64 %21, ptr %13, align 8, !tbaa !11
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %23 = load i64, ptr %22, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  store i64 %23, ptr %12, align 8, !tbaa !11
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = load i64, ptr %12, align 8, !tbaa !11
  call void @_ZN6charls4spanIKSt4byteEC2EPS2_m(ptr noundef nonnull align 8 dereferenceable(16) %14, ptr noundef %26, i64 noundef %27) #4
  %28 = getelementptr inbounds { ptr, i64 }, ptr %14, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8
  %30 = getelementptr inbounds { ptr, i64 }, ptr %14, i32 0, i32 1
  %31 = load i64, ptr %30, align 8
  call void @_ZN6charls18jpeg_stream_writer38write_jpegls_preset_parameters_segmentENS_29jpegls_preset_parameters_typeEiiNS_4spanIKSt4byteEE(ptr noundef nonnull align 8 dereferenceable(56) %19, i8 noundef zeroext 2, i32 noundef %24, i32 noundef %25, ptr %29, i64 %31)
  %32 = load i64, ptr %12, align 8, !tbaa !11
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 %32
  store ptr %34, ptr %11, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %39, %5
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = call noundef ptr @_ZNK6charls4spanIKSt4byteE3endEv(ptr noundef nonnull align 8 dereferenceable(16) %6) #4
  %38 = icmp ult ptr %36, %37
  br i1 %38, label %39, label %58

39:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %40 = call noundef ptr @_ZNK6charls4spanIKSt4byteE3endEv(ptr noundef nonnull align 8 dereferenceable(16) %6) #4
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = ptrtoint ptr %40 to i64
  %43 = ptrtoint ptr %41 to i64
  %44 = sub i64 %42, %43
  store i64 %44, ptr %15, align 8, !tbaa !11
  %45 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %15, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %46 = load i64, ptr %45, align 8, !tbaa !11
  store i64 %46, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = load i64, ptr %12, align 8, !tbaa !11
  call void @_ZN6charls4spanIKSt4byteEC2EPS2_m(ptr noundef nonnull align 8 dereferenceable(16) %16, ptr noundef %49, i64 noundef %50) #4
  %51 = getelementptr inbounds { ptr, i64 }, ptr %16, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8
  %53 = getelementptr inbounds { ptr, i64 }, ptr %16, i32 0, i32 1
  %54 = load i64, ptr %53, align 8
  call void @_ZN6charls18jpeg_stream_writer38write_jpegls_preset_parameters_segmentENS_29jpegls_preset_parameters_typeEiiNS_4spanIKSt4byteEE(ptr noundef nonnull align 8 dereferenceable(56) %19, i8 noundef zeroext 3, i32 noundef %47, i32 noundef %48, ptr %52, i64 %54)
  %55 = load i64, ptr %12, align 8, !tbaa !11
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 %55
  store ptr %57, ptr %11, align 8, !tbaa !5
  br label %35, !llvm.loop !13

58:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6charls18jpeg_stream_writer38write_jpegls_preset_parameters_segmentENS_29jpegls_preset_parameters_typeEiiNS_4spanIKSt4byteEE(ptr noundef nonnull align 8 dereferenceable(56), i8 noundef zeroext, i32 noundef, i32 noundef, ptr, i64) #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 #0 align 2

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

attributes #0 = { 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 #1 = { 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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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.0" = type { ptr, i64 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK6charls4spanIKSt4byteE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) 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_writer38write_jpegls_preset_parameters_segmentEiiNS_4spanIKSt4byteEE(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, i32 noundef %2, ptr %3, i64 %4) local_unnamed_addr #2 align 2 {
  %6 = alloca %"class.charls::span.0", align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca %"class.charls::span.0", align 8
  %10 = alloca i64, align 8
  %11 = alloca %"class.charls::span.0", align 8
  store ptr %3, ptr %6, align 8
  %12 = getelementptr inbounds i8, ptr %6, i64 8
  store i64 %4, ptr %12, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  store i64 65530, ptr %7, align 8, !tbaa !5
  %13 = call noundef ptr @_ZNK6charls4spanIKSt4byteE5beginEv(ptr noundef nonnull align 8 dereferenceable(16) %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  %14 = call noundef i64 @_ZNK6charls4spanIKSt4byteE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %6) #4
  store i64 %14, ptr %8, align 8, !tbaa !5
  %15 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %16 = load i64, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  call void @_ZN6charls4spanIKSt4byteEC2EPS2_m(ptr noundef nonnull align 8 dereferenceable(16) %9, ptr noundef %13, i64 noundef %16) #4
  %17 = load ptr, ptr %9, align 8
  %18 = getelementptr inbounds i8, ptr %9, i64 8
  %19 = load i64, ptr %18, align 8
  call void @_ZN6charls18jpeg_stream_writer38write_jpegls_preset_parameters_segmentENS_29jpegls_preset_parameters_typeEiiNS_4spanIKSt4byteEE(ptr noundef nonnull align 8 dereferenceable(56) %0, i8 noundef zeroext 2, i32 noundef %1, i32 noundef %2, ptr %17, i64 %19)
  %20 = getelementptr inbounds i8, ptr %13, i64 %16
  %21 = call noundef ptr @_ZNK6charls4spanIKSt4byteE3endEv(ptr noundef nonnull align 8 dereferenceable(16) %6) #4
  %22 = icmp ult ptr %20, %21
  br i1 %22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %23 = getelementptr inbounds i8, ptr %11, i64 8
  br label %24

24:                                               ; preds = %.lr.ph, %24
  %.014 = phi ptr [ %20, %.lr.ph ], [ %33, %24 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #4
  %25 = call noundef ptr @_ZNK6charls4spanIKSt4byteE3endEv(ptr noundef nonnull align 8 dereferenceable(16) %6) #4
  %26 = ptrtoint ptr %25 to i64
  %27 = ptrtoint ptr %.014 to i64
  %28 = sub i64 %26, %27
  store i64 %28, ptr %10, align 8, !tbaa !5
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %10, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %30 = load i64, ptr %29, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #4
  call void @_ZN6charls4spanIKSt4byteEC2EPS2_m(ptr noundef nonnull align 8 dereferenceable(16) %11, ptr noundef %.014, i64 noundef %30) #4
  %31 = load ptr, ptr %11, align 8
  %32 = load i64, ptr %23, align 8
  call void @_ZN6charls18jpeg_stream_writer38write_jpegls_preset_parameters_segmentENS_29jpegls_preset_parameters_typeEiiNS_4spanIKSt4byteEE(ptr noundef nonnull align 8 dereferenceable(56) %0, i8 noundef zeroext 3, i32 noundef %1, i32 noundef %2, ptr %31, i64 %32)
  %33 = getelementptr inbounds i8, ptr %.014, i64 %30
  %34 = call noundef ptr @_ZNK6charls4spanIKSt4byteE3endEv(ptr noundef nonnull align 8 dereferenceable(16) %6) #4
  %35 = icmp ult ptr %33, %34
  br i1 %35, label %24, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %24, %5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6charls18jpeg_stream_writer38write_jpegls_preset_parameters_segmentENS_29jpegls_preset_parameters_typeEiiNS_4spanIKSt4byteEE(ptr noundef nonnull align 8 dereferenceable(56), i8 noundef zeroext, i32 noundef, i32 noundef, ptr, i64) 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 #0 align 2

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

attributes #0 = { 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 #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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass