; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/queue.ll (ZN3qOS5queue15copyDataToQueueEPKvNS_13queueSendModeE)

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

; 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) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS5queue15copyDataToQueueEPKvNS_13queueSendModeE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8
  %8 = load i32, ptr %6, align 4, !tbaa !9
  %9 = icmp eq i32 0, %8
  br i1 %9, label %10, label %31

10:                                               ; preds = %3
  %11 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 3
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 7
  %15 = load i64, ptr %14, align 8, !tbaa !14
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %12, ptr align 1 %13, i64 %15, i1 false)
  %16 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 7
  %17 = load i64, ptr %16, align 8, !tbaa !14
  %18 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %19, i64 %17
  store ptr %20, ptr %18, align 8, !tbaa !11
  %21 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 3
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  %25 = icmp uge ptr %22, %24
  br i1 %25, label %26, label %30

26:                                               ; preds = %10
  %27 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !16
  %29 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 3
  store ptr %28, ptr %29, align 8, !tbaa !11
  br label %30

30:                                               ; preds = %26, %10
  br label %57

31:                                               ; preds = %3
  %32 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 4
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 7
  %36 = load i64, ptr %35, align 8, !tbaa !14
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %33, ptr align 1 %34, i64 %36, i1 false)
  %37 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 7
  %38 = load i64, ptr %37, align 8, !tbaa !14
  %39 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 4
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = sub i64 0, %38
  %42 = getelementptr inbounds i8, ptr %40, i64 %41
  store ptr %42, ptr %39, align 8, !tbaa !17
  %43 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 4
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  %45 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  %47 = icmp ult ptr %44, %46
  br i1 %47, label %48, label %56

48:                                               ; preds = %31
  %49 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 7
  %52 = load i64, ptr %51, align 8, !tbaa !14
  %53 = sub i64 0, %52
  %54 = getelementptr inbounds i8, ptr %50, i64 %53
  %55 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 4
  store ptr %54, ptr %55, align 8, !tbaa !17
  br label %56

56:                                               ; preds = %48, %31
  br label %57

57:                                               ; preds = %56, %30
  %58 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 5
  %59 = load volatile i64, ptr %58, align 8, !tbaa !18
  %60 = add i64 %59, 1
  %61 = getelementptr inbounds %"class.qOS::queue", ptr %7, i32 0, i32 5
  store volatile i64 %60, ptr %61, align 8, !tbaa !18
  ret void
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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" }

!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 = !{!"_ZTSN3qOS13queueSendModeE", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"_ZTSN3qOS5queueE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !13, i64 48, !13, i64 56}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 56}
!15 = !{!12, !6, i64 16}
!16 = !{!12, !6, i64 8}
!17 = !{!12, !6, i64 32}
!18 = !{!12, !13, i64 40}


; 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 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) #0

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local void @_ZN3qOS5queue15copyDataToQueueEPKvNS_13queueSendModeE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = icmp eq i32 %2, 0
  %5 = getelementptr inbounds i8, ptr %0, i64 56
  %6 = load i64, ptr %5, align 8, !tbaa !5
  br i1 %4, label %7, label %18

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %9, ptr align 1 %1, i64 %6, i1 false)
  %10 = load i64, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %8, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %11, i64 %10
  store ptr %12, ptr %8, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %.not = icmp ult ptr %12, %14
  br i1 %.not, label %32, label %15

15:                                               ; preds = %7
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  store ptr %17, ptr %8, align 8, !tbaa !11
  br label %32

18:                                               ; preds = %3
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %20, ptr align 1 %1, i64 %6, i1 false)
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %19, align 8, !tbaa !14
  %23 = sub i64 0, %21
  %24 = getelementptr inbounds i8, ptr %22, i64 %23
  store ptr %24, ptr %19, align 8, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = icmp ult ptr %24, %26
  br i1 %27, label %28, label %32

28:                                               ; preds = %18
  %29 = getelementptr inbounds i8, ptr %0, i64 16
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = getelementptr inbounds i8, ptr %30, i64 %23
  store ptr %31, ptr %19, align 8, !tbaa !14
  br label %32

32:                                               ; preds = %18, %28, %7, %15
  %33 = getelementptr inbounds i8, ptr %0, i64 40
  %34 = load volatile i64, ptr %33, align 8, !tbaa !15
  %35 = add i64 %34, 1
  store volatile i64 %35, ptr %33, align 8, !tbaa !15
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree norecurse 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" }

!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, !10, i64 56}
!6 = !{!"_ZTSN3qOS5queueE", !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 48, !10, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 24}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 32}
!15 = !{!6, !10, i64 40}


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