; LLVM IR from mitdbg/deneva :: transport/message.ll (ZN18ClientQueryMessage11copy_to_bufEPc)

; 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.ClientQueryMessage = type { %class.Message, i64, i64, i64, i64, %class.Array.0 }
%class.Message = type { ptr, i32, i64, i64, i64, i64, i64, i64, double, double, double, double, double, double, double }
%class.Array.0 = type { ptr, i64, i64 }

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

; 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) #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
declare dso_local noundef i64 @_ZN7Message9mget_sizeEv(ptr noundef nonnull align 8 dereferenceable(120)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7Message12mcopy_to_bufEPc(ptr noundef nonnull align 8 dereferenceable(120), ptr noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN18ClientQueryMessage11copy_to_bufEPc(ptr noundef nonnull align 8 dereferenceable(176) %0, ptr noundef %1) unnamed_addr #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN7Message12mcopy_to_bufEPc(ptr noundef nonnull align 8 dereferenceable(120) %9, ptr noundef %10)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %11 = call noundef i64 @_ZN7Message9mget_sizeEv(ptr noundef nonnull align 8 dereferenceable(120) %9)
  store i64 %11, ptr %5, align 8, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %12, i64 %13
  %15 = getelementptr inbounds %class.ClientQueryMessage, ptr %9, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %14, ptr align 8 %15, i64 8, i1 false)
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = add i64 %16, 8
  store i64 %17, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %18 = getelementptr inbounds %class.ClientQueryMessage, ptr %9, i32 0, i32 5
  %19 = call noundef i64 @_ZN5ArrayImE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %18)
  store i64 %19, ptr %6, align 8, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %20, i64 %21
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %22, ptr align 8 %6, i64 8, i1 false)
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = add i64 %23, 8
  store i64 %24, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %39, %2
  %26 = load i64, ptr %7, align 8, !tbaa !9
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %42

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %31 = getelementptr inbounds %class.ClientQueryMessage, ptr %9, i32 0, i32 5
  %32 = load i64, ptr %7, align 8, !tbaa !9
  %33 = call noundef i64 @_ZN5ArrayImEixEm(ptr noundef nonnull align 8 dereferenceable(24) %31, i64 noundef %32)
  store i64 %33, ptr %8, align 8, !tbaa !9
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i64, ptr %5, align 8, !tbaa !9
  %36 = getelementptr inbounds i8, ptr %34, i64 %35
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %36, ptr align 8 %8, i64 8, i1 false)
  %37 = load i64, ptr %5, align 8, !tbaa !9
  %38 = add i64 %37, 8
  store i64 %38, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %39

39:                                               ; preds = %30
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = add i64 %40, 1
  store i64 %41, ptr %7, align 8, !tbaa !9
  br label %25, !llvm.loop !11

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN5ArrayImEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = { 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 = { 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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7Message12mcopy_to_bufEPc(ptr noundef nonnull align 8 dereferenceable(120), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN18ClientQueryMessage11copy_to_bufEPc(ptr noundef nonnull align 8 dereferenceable(176) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  tail call void @_ZN7Message12mcopy_to_bufEPc(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr noundef %1)
  %3 = tail call noundef i64 @_ZN7Message9mget_sizeEv(ptr noundef nonnull align 8 dereferenceable(120) %0)
  %4 = getelementptr inbounds i8, ptr %1, i64 %3
  %5 = getelementptr inbounds i8, ptr %0, i64 136
  %6 = load i64, ptr %5, align 8
  store i64 %6, ptr %4, align 1
  %7 = getelementptr inbounds i8, ptr %0, i64 152
  %8 = tail call noundef i64 @_ZN5ArrayImE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7)
  %9 = getelementptr i8, ptr %4, i64 8
  store i64 %8, ptr %9, align 1
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %10 = add i64 %3, 16
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %2
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.017 = phi i64 [ %13, %.lr.ph ], [ %10, %.lr.ph.preheader ]
  %.01516 = phi i64 [ %14, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %11 = tail call noundef i64 @_ZN5ArrayImEixEm(ptr noundef nonnull align 8 dereferenceable(24) %7, i64 noundef %.01516)
  %12 = getelementptr inbounds i8, ptr %1, i64 %.017
  store i64 %11, ptr %12, align 1
  %13 = add i64 %.017, 8
  %14 = add nuw i64 %.01516, 1
  %exitcond.not = icmp eq i64 %14, %8
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN5ArrayImEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) 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 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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