; LLVM IR from intel/qpl :: sources/middle-layer/analytics (output_stream)

; 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.qpl::ml::analytics::output_stream_t" = type { %"class.qpl::ml::buffer_t", ptr, ptr, i8, i8, i8, i8, i8, i32, i32, i32, i8, i8, i32, i64 }
%"class.qpl::ml::buffer_t" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl2ml9analytics15output_stream_tILNS1_20output_stream_type_tE1EE12perform_packEPKhjb(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %1, i32 noundef %2, i1 noundef zeroext %3) #0 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  %12 = zext i1 %3 to i8
  store i8 %12, ptr %9, align 1, !tbaa !11
  %13 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  %14 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t", ptr %13, i32 0, i32 11
  %15 = load i8, ptr %14, align 4, !tbaa !13
  %16 = zext i8 %15 to i32
  %17 = icmp eq i32 1, %16
  br i1 %17, label %18, label %48

18:                                               ; preds = %4
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t", ptr %13, i32 0, i32 14
  %22 = load i64, ptr %21, align 8, !tbaa !19
  %23 = icmp ugt i64 %20, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %18
  store i32 225, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %69

25:                                               ; preds = %18
  %26 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t", ptr %13, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !20
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t", ptr %13, i32 0, i32 2
  %31 = load i8, ptr %9, align 1, !tbaa !11, !range !21, !noundef !22
  %32 = trunc i8 %31 to i1
  br i1 %32, label %33, label %36

33:                                               ; preds = %25
  %34 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t", ptr %13, i32 0, i32 8
  %35 = load i32, ptr %34, align 8, !tbaa !23
  br label %37

36:                                               ; preds = %25
  br label %37

37:                                               ; preds = %36, %33
  %38 = phi i32 [ %35, %33 ], [ 0, %36 ]
  %39 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t", ptr %13, i32 0, i32 9
  %40 = invoke noundef i32 %27(ptr noundef %28, i32 noundef %29, ptr noundef %30, i32 noundef %38, ptr noundef %39)
          to label %41 unwind label %71

41:                                               ; preds = %37
  store i32 %40, ptr %10, align 4, !tbaa !9
  %42 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t", ptr %13, i32 0, i32 8
  %43 = load i32, ptr %42, align 8, !tbaa !23
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = add i32 %43, %44
  %46 = and i32 %45, 7
  %47 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t", ptr %13, i32 0, i32 8
  store i32 %46, ptr %47, align 8, !tbaa !23
  br label %58

48:                                               ; preds = %4
  %49 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t", ptr %13, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !20
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t", ptr %13, i32 0, i32 2
  %54 = call noundef i32 @_ZNK3qpl2ml9analytics15output_stream_tILNS1_20output_stream_type_tE1EE15bytes_availableEv(ptr noundef nonnull align 8 dereferenceable(80) %13) #3
  %55 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t", ptr %13, i32 0, i32 9
  %56 = invoke noundef i32 %50(ptr noundef %51, i32 noundef %52, ptr noundef %53, i32 noundef %54, ptr noundef %55)
          to label %57 unwind label %71

57:                                               ; preds = %48
  store i32 %56, ptr %10, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %57, %41
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t", ptr %13, i32 0, i32 13
  %61 = load i32, ptr %60, align 8, !tbaa !24
  %62 = add i32 %61, %59
  store i32 %62, ptr %60, align 8, !tbaa !24
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t", ptr %13, i32 0, i32 14
  %66 = load i64, ptr %65, align 8, !tbaa !19
  %67 = sub i64 %66, %64
  store i64 %67, ptr %65, align 8, !tbaa !19
  %68 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %68, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %69

69:                                               ; preds = %58, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %70 = load i32, ptr %5, align 4
  ret i32 %70

71:                                               ; preds = %48, %37
  %72 = landingpad { ptr, i32 }
          catch ptr null
  %73 = extractvalue { ptr, i32 } %72, 0
  call void @__clang_call_terminate(ptr %73) #4
  unreachable
}

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

declare i32 @__gxx_personality_v0(...)

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

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

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

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 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !7, i64 60}
!14 = !{!"_ZTSN3qpl2ml9analytics15output_stream_tILNS1_20output_stream_type_tE1EEE", !15, i64 0, !6, i64 24, !6, i64 32, !12, i64 40, !12, i64 41, !12, i64 42, !16, i64 43, !17, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !7, i64 60, !7, i64 61, !10, i64 64, !18, i64 72}
!15 = !{!"_ZTSN3qpl2ml8buffer_tE", !6, i64 8, !6, i64 16}
!16 = !{!"_ZTSN3qpl2ml9analytics15stream_format_tE", !7, i64 0}
!17 = !{!"_ZTSN3qpl2ml9analytics25output_bit_width_format_tE", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!14, !18, i64 72}
!20 = !{!14, !6, i64 24}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!14, !10, i64 48}
!24 = !{!14, !10, i64 64}


; 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 nounwind uwtable
define dso_local noundef i32 @_ZN3qpl2ml9analytics15output_stream_tILNS1_20output_stream_type_tE1EE12perform_packEPKhjb(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %1, i32 noundef %2, i1 noundef zeroext %3) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 60
  %6 = load i8, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i8 %6, 1
  br i1 %7, label %8, label %26

8:                                                ; preds = %4
  %9 = zext i32 %2 to i64
  %10 = getelementptr inbounds i8, ptr %0, i64 72
  %11 = load i64, ptr %10, align 8, !tbaa !16
  %12 = icmp ult i64 %11, %9
  br i1 %12, label %40, label %13

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  %17 = getelementptr inbounds i8, ptr %0, i64 48
  %18 = load i32, ptr %17, align 8
  %19 = select i1 %3, i32 %18, i32 0
  %20 = getelementptr inbounds i8, ptr %0, i64 52
  %21 = invoke noundef i32 %15(ptr noundef %1, i32 noundef %2, ptr noundef nonnull %16, i32 noundef %19, ptr noundef nonnull %20)
          to label %22 unwind label %41

22:                                               ; preds = %13
  %23 = load i32, ptr %17, align 8, !tbaa !18
  %24 = add i32 %23, %2
  %25 = and i32 %24, 7
  store i32 %25, ptr %17, align 8, !tbaa !18
  br label %33

26:                                               ; preds = %4
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = getelementptr inbounds i8, ptr %0, i64 32
  %30 = tail call noundef i32 @_ZNK3qpl2ml9analytics15output_stream_tILNS1_20output_stream_type_tE1EE15bytes_availableEv(ptr noundef nonnull align 8 dereferenceable(80) %0) #2
  %31 = getelementptr inbounds i8, ptr %0, i64 52
  %32 = invoke noundef i32 %28(ptr noundef %1, i32 noundef %2, ptr noundef nonnull %29, i32 noundef %30, ptr noundef nonnull %31)
          to label %._crit_edge unwind label %41

._crit_edge:                                      ; preds = %26
  %.pre = zext i32 %2 to i64
  br label %33

33:                                               ; preds = %._crit_edge, %22
  %.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %9, %22 ]
  %.0 = phi i32 [ %32, %._crit_edge ], [ %21, %22 ]
  %34 = getelementptr inbounds i8, ptr %0, i64 64
  %35 = load i32, ptr %34, align 8, !tbaa !19
  %36 = add i32 %35, %2
  store i32 %36, ptr %34, align 8, !tbaa !19
  %37 = getelementptr inbounds i8, ptr %0, i64 72
  %38 = load i64, ptr %37, align 8, !tbaa !16
  %39 = sub i64 %38, %.pre-phi
  store i64 %39, ptr %37, align 8, !tbaa !16
  br label %40

40:                                               ; preds = %8, %33
  %.011 = phi i32 [ %.0, %33 ], [ 225, %8 ]
  ret i32 %.011

41:                                               ; preds = %26, %13
  %42 = landingpad { ptr, i32 }
          catch ptr null
  %43 = extractvalue { ptr, i32 } %42, 0
  tail call void @__clang_call_terminate(ptr %43) #3
  unreachable
}

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3qpl2ml9analytics15output_stream_tILNS1_20output_stream_type_tE1EE15bytes_availableEv(ptr noundef nonnull align 8 dereferenceable(80)) 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 = { 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 #2 = { nounwind }
attributes #3 = { 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, !9, i64 60}
!6 = !{!"_ZTSN3qpl2ml9analytics15output_stream_tILNS1_20output_stream_type_tE1EEE", !7, i64 0, !8, i64 24, !8, i64 32, !11, i64 40, !11, i64 41, !11, i64 42, !12, i64 43, !13, i64 44, !14, i64 48, !14, i64 52, !14, i64 56, !9, i64 60, !9, i64 61, !14, i64 64, !15, i64 72}
!7 = !{!"_ZTSN3qpl2ml8buffer_tE", !8, i64 8, !8, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"bool", !9, i64 0}
!12 = !{!"_ZTSN3qpl2ml9analytics15stream_format_tE", !9, i64 0}
!13 = !{!"_ZTSN3qpl2ml9analytics25output_bit_width_format_tE", !9, i64 0}
!14 = !{!"int", !9, i64 0}
!15 = !{!"long", !9, i64 0}
!16 = !{!6, !15, i64 72}
!17 = !{!6, !8, i64 24}
!18 = !{!6, !14, i64 48}
!19 = !{!6, !14, i64 64}


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