; LLVM IR from Aeternum-Veritas/Merry :: subsyshelpers/src (queue)

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

%struct.QueueItem = type { i64, [4 x i64] }
%struct.Queue = type { i64, i64, ptr, ptr }
%struct.QueueNode = type { %struct.QueueItem, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @push_to_queue(ptr noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca %struct.QueueItem, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  store i8 1, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 40, ptr %8) #3
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.QueueItem, ptr %8, i32 0, i32 0
  store i64 %9, ptr %10, align 8, !tbaa !12
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds i64, ptr %11, i64 0
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.QueueItem, ptr %8, i32 0, i32 1
  %15 = getelementptr inbounds [4 x i64], ptr %14, i64 0, i64 0
  store i64 %13, ptr %15, align 8, !tbaa !9
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds i64, ptr %16, i64 1
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.QueueItem, ptr %8, i32 0, i32 1
  %20 = getelementptr inbounds [4 x i64], ptr %19, i64 0, i64 1
  store i64 %18, ptr %20, align 8, !tbaa !9
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds i64, ptr %21, i64 2
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.QueueItem, ptr %8, i32 0, i32 1
  %25 = getelementptr inbounds [4 x i64], ptr %24, i64 0, i64 2
  store i64 %23, ptr %25, align 8, !tbaa !9
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds i64, ptr %26, i64 3
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.QueueItem, ptr %8, i32 0, i32 1
  %30 = getelementptr inbounds [4 x i64], ptr %29, i64 0, i64 3
  store i64 %28, ptr %30, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %3
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Queue, ptr %32, i32 0, i32 1
  %34 = load i64, ptr %33, align 8, !tbaa !14
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Queue, ptr %35, i32 0, i32 0
  %37 = load i64, ptr %36, align 8, !tbaa !16
  %38 = icmp eq i64 %34, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %31
  store i8 0, ptr %7, align 1, !tbaa !11
  br label %57

40:                                               ; preds = %31
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Queue, ptr %41, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  %44 = getelementptr inbounds %struct.QueueNode, ptr %43, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %44, ptr align 8 %8, i64 40, i1 false), !tbaa.struct !18
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Queue, ptr %45, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !14
  %48 = add i64 %47, 1
  store i64 %48, ptr %46, align 8, !tbaa !14
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Queue, ptr %49, i32 0, i32 3
  %51 = load ptr, ptr %50, align 8, !tbaa !17
  %52 = getelementptr inbounds %struct.QueueNode, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !19
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Queue, ptr %54, i32 0, i32 3
  store ptr %53, ptr %55, align 8, !tbaa !17
  store i8 1, ptr %7, align 1, !tbaa !11
  br label %56

56:                                               ; preds = %40
  br label %57

57:                                               ; preds = %56, %39
  %58 = load i8, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 40, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  ret i8 %58
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"QueueItem", !10, i64 0, !7, i64 8}
!14 = !{!15, !10, i64 8}
!15 = !{!"Queue", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!15, !10, i64 0}
!17 = !{!15, !6, i64 24}
!18 = !{i64 0, i64 8, !9, i64 8, i64 32, !11}
!19 = !{!20, !6, i64 40}
!20 = !{!"QueueNode", !13, i64 0, !6, 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 nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local zeroext range(i8 0, 2) i8 @push_to_queue(ptr nocapture noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = load i64, ptr %0, align 8, !tbaa !11
  %7 = icmp eq i64 %5, %6
  br i1 %7, label %19, label %8

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %2, i64 16
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 8
  %12 = load <2 x i64>, ptr %2, align 8, !tbaa !13
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 24
  %13 = load <2 x i64>, ptr %9, align 8, !tbaa !13
  store i64 %1, ptr %11, align 8, !tbaa !13
  store <2 x i64> %12, ptr %.sroa.4.0..sroa_idx, align 8
  store <2 x i64> %13, ptr %.sroa.6.0..sroa_idx, align 8
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = add i64 %14, 1
  store i64 %15, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %10, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %16, i64 40
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  store ptr %18, ptr %10, align 8, !tbaa !12
  br label %19

19:                                               ; preds = %3, %8
  %.0 = phi i8 [ 1, %8 ], [ 0, %3 ]
  ret i8 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) 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, !7, i64 8}
!6 = !{!"Queue", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 24}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 40}
!15 = !{!"QueueNode", !16, i64 0, !10, i64 40}
!16 = !{!"QueueItem", !7, i64 0, !8, i64 8}


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