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

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl2ml9analytics15output_stream_tILNS1_20output_stream_type_tE0EE12perform_packEPKhjb(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %1, i32 noundef %2, i1 noundef zeroext %3) #2 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.0", ptr %13, i32 0, i32 7
  %15 = load i8, ptr %14, align 4, !tbaa !13
  %16 = icmp eq i8 %15, 0
  br i1 %16, label %22, label %17

17:                                               ; preds = %4
  %18 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t.0", ptr %13, i32 0, i32 12
  %19 = load i8, ptr %18, align 1, !tbaa !19
  %20 = zext i8 %19 to i32
  %21 = icmp ugt i32 %20, 1
  br i1 %21, label %22, label %50

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

28:                                               ; preds = %22
  store i32 225, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %71

29:                                               ; preds = %22
  %30 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t.0", ptr %13, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !21
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t.0", ptr %13, i32 0, i32 2
  %35 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t.0", ptr %13, i32 0, i32 8
  %36 = load i32, ptr %35, align 8, !tbaa !22
  %37 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t.0", ptr %13, i32 0, i32 9
  %38 = invoke noundef i32 %31(ptr noundef %32, i32 noundef %33, ptr noundef %34, i32 noundef %36, ptr noundef %37)
          to label %39 unwind label %73

39:                                               ; preds = %29
  store i32 %38, ptr %10, align 4, !tbaa !9
  %40 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t.0", ptr %13, i32 0, i32 8
  %41 = load i32, ptr %40, align 8, !tbaa !22
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t.0", ptr %13, i32 0, i32 11
  %44 = load i8, ptr %43, align 4, !tbaa !23
  %45 = zext i8 %44 to i32
  %46 = mul i32 %42, %45
  %47 = add i32 %41, %46
  %48 = and i32 %47, 7
  %49 = getelementptr inbounds %"class.qpl::ml::analytics::output_stream_t.0", ptr %13, i32 0, i32 8
  store i32 %48, ptr %49, align 8, !tbaa !22
  br label %60

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

59:                                               ; preds = %50
  store i32 %58, ptr %10, align 4, !tbaa !9
  br label %60

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

71:                                               ; preds = %60, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %72 = load i32, ptr %5, align 4
  ret i32 %72

73:                                               ; preds = %50, %29
  %74 = landingpad { ptr, i32 }
          catch ptr null
  %75 = extractvalue { ptr, i32 } %74, 0
  call void @__clang_call_terminate(ptr %75) #4
  unreachable
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 }
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, !17, i64 44}
!14 = !{!"_ZTSN3qpl2ml9analytics15output_stream_tILNS1_20output_stream_type_tE0EEE", !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, !7, i64 61}
!20 = !{!14, !18, i64 72}
!21 = !{!14, !6, i64 24}
!22 = !{!14, !10, i64 48}
!23 = !{!14, !7, i64 60}
!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"

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl2ml9analytics15output_stream_tILNS1_20output_stream_type_tE0EE12perform_packEPKhjb(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %1, i32 noundef %2, i1 noundef zeroext %3) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 44
  %6 = load i8, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i8 %6, 0
  %8 = getelementptr inbounds i8, ptr %0, i64 61
  %9 = load i8, ptr %8, align 1
  %10 = icmp ugt i8 %9, 1
  %or.cond = select i1 %7, i1 true, i1 %10
  br i1 %or.cond, label %11, label %32

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

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = getelementptr inbounds i8, ptr %0, i64 48
  %21 = load i32, ptr %20, align 8, !tbaa !18
  %22 = getelementptr inbounds i8, ptr %0, i64 52
  %23 = invoke noundef i32 %18(ptr noundef %1, i32 noundef %2, ptr noundef nonnull %19, i32 noundef %21, ptr noundef nonnull %22)
          to label %24 unwind label %47

24:                                               ; preds = %16
  %25 = load i32, ptr %20, align 8, !tbaa !18
  %26 = getelementptr inbounds i8, ptr %0, i64 60
  %27 = load i8, ptr %26, align 4, !tbaa !19
  %28 = zext i8 %27 to i32
  %29 = mul i32 %28, %2
  %30 = add i32 %29, %25
  %31 = and i32 %30, 7
  store i32 %31, ptr %20, align 8, !tbaa !18
  br label %39

32:                                               ; preds = %4
  %33 = getelementptr inbounds i8, ptr %0, i64 24
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = getelementptr inbounds i8, ptr %0, i64 32
  %36 = tail call noundef i32 @_ZNK3qpl2ml9analytics15output_stream_tILNS1_20output_stream_type_tE0EE15bytes_availableEv(ptr noundef nonnull align 8 dereferenceable(80) %0) #2
  %37 = getelementptr inbounds i8, ptr %0, i64 52
  %38 = invoke noundef i32 %34(ptr noundef %1, i32 noundef %2, ptr noundef nonnull %35, i32 noundef %36, ptr noundef nonnull %37)
          to label %._crit_edge unwind label %47

._crit_edge:                                      ; preds = %32
  %.pre = zext i32 %2 to i64
  br label %39

39:                                               ; preds = %._crit_edge, %24
  %.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %12, %24 ]
  %.0 = phi i32 [ %38, %._crit_edge ], [ %23, %24 ]
  %40 = getelementptr inbounds i8, ptr %0, i64 64
  %41 = load i32, ptr %40, align 8, !tbaa !20
  %42 = add i32 %41, %2
  store i32 %42, ptr %40, align 8, !tbaa !20
  %43 = getelementptr inbounds i8, ptr %0, i64 72
  %44 = load i64, ptr %43, align 8, !tbaa !16
  %45 = sub i64 %44, %.pre-phi
  store i64 %45, ptr %43, align 8, !tbaa !16
  br label %46

46:                                               ; preds = %11, %39
  %.010 = phi i32 [ %.0, %39 ], [ 225, %11 ]
  ret i32 %.010

47:                                               ; preds = %32, %16
  %48 = landingpad { ptr, i32 }
          catch ptr null
  %49 = extractvalue { ptr, i32 } %48, 0
  tail call void @__clang_call_terminate(ptr %49) #3
  unreachable
}

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

attributes #0 = { 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 #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 = { 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, !13, i64 44}
!6 = !{!"_ZTSN3qpl2ml9analytics15output_stream_tILNS1_20output_stream_type_tE0EEE", !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, !9, i64 60}
!20 = !{!6, !14, i64 64}


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