; LLVM IR from Aeternum-Veritas/Merry :: merry (merry_request_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.MerryOSRequest = type { i64, ptr, i64, i8, i8, i64 }
%struct.MerryRequestQueue = type { i64, i64, ptr, ptr }
%struct.MerryRequestNode = type { %struct.MerryOSRequest, 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: 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: nounwind uwtable
define dso_local zeroext i8 @merry_push_dbg_requests(ptr noundef %0, i64 noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3, i64 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca i64, align 8
  %11 = alloca i8, align 1
  %12 = alloca %struct.MerryOSRequest, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i8 %2, ptr %8, align 1, !tbaa !11
  store i8 %3, ptr %9, align 1, !tbaa !11
  store i64 %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #3
  store i8 1, ptr %11, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 40, ptr %12) #3
  %13 = getelementptr inbounds %struct.MerryOSRequest, ptr %12, i32 0, i32 0
  %14 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %14, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds %struct.MerryOSRequest, ptr %12, i32 0, i32 1
  store ptr null, ptr %15, align 8, !tbaa !14
  %16 = getelementptr inbounds %struct.MerryOSRequest, ptr %12, i32 0, i32 2
  store i64 0, ptr %16, align 8, !tbaa !15
  %17 = getelementptr inbounds %struct.MerryOSRequest, ptr %12, i32 0, i32 3
  %18 = load i8, ptr %8, align 1, !tbaa !11
  store i8 %18, ptr %17, align 8, !tbaa !16
  %19 = getelementptr inbounds %struct.MerryOSRequest, ptr %12, i32 0, i32 4
  %20 = load i8, ptr %9, align 1, !tbaa !11
  store i8 %20, ptr %19, align 1, !tbaa !17
  %21 = getelementptr inbounds %struct.MerryOSRequest, ptr %12, i32 0, i32 5
  %22 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %22, ptr %21, align 8, !tbaa !18
  br label %23

23:                                               ; preds = %5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.MerryRequestQueue, ptr %24, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !19
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.MerryRequestQueue, ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !21
  %30 = icmp eq i64 %26, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %23
  store i8 0, ptr %11, align 1, !tbaa !11
  br label %49

32:                                               ; preds = %23
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.MerryRequestQueue, ptr %33, i32 0, i32 3
  %35 = load ptr, ptr %34, align 8, !tbaa !22
  %36 = getelementptr inbounds %struct.MerryRequestNode, ptr %35, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %36, ptr align 8 %12, i64 40, i1 false), !tbaa.struct !23
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.MerryRequestQueue, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !19
  %40 = add i64 %39, 1
  store i64 %40, ptr %38, align 8, !tbaa !19
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.MerryRequestQueue, ptr %41, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !22
  %44 = getelementptr inbounds %struct.MerryRequestNode, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !24
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.MerryRequestQueue, ptr %46, i32 0, i32 3
  store ptr %45, ptr %47, align 8, !tbaa !22
  store i8 1, ptr %11, align 1, !tbaa !11
  br label %48

48:                                               ; preds = %32
  br label %49

49:                                               ; preds = %48, %31
  %50 = load i8, ptr %11, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 40, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  ret i8 %50
}

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

!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 = !{!"MerryOSRequest", !10, i64 0, !6, i64 8, !10, i64 16, !7, i64 24, !7, i64 25, !10, i64 32}
!14 = !{!13, !6, i64 8}
!15 = !{!13, !10, i64 16}
!16 = !{!13, !7, i64 24}
!17 = !{!13, !7, i64 25}
!18 = !{!13, !10, i64 32}
!19 = !{!20, !10, i64 8}
!20 = !{!"MerryRequestQueue", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24}
!21 = !{!20, !10, i64 0}
!22 = !{!20, !6, i64 24}
!23 = !{i64 0, i64 8, !9, i64 8, i64 8, !5, i64 16, i64 8, !9, i64 24, i64 1, !11, i64 25, i64 1, !11, i64 32, i64 8, !9}
!24 = !{!25, !6, i64 40}
!25 = !{!"MerryRequestNode", !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 @merry_push_dbg_requests(ptr nocapture noundef %0, i64 noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = load i64, ptr %0, align 8, !tbaa !11
  %9 = icmp eq i64 %7, %8
  br i1 %9, label %18, label %10

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  store i64 %1, ptr %12, align 8, !tbaa !13
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 8
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %.sroa.4.0..sroa_idx, i8 0, i64 16, i1 false)
  store i8 %2, ptr %.sroa.6.0..sroa_idx, align 8, !tbaa !14
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 25
  store i8 %3, ptr %.sroa.7.0..sroa_idx, align 1, !tbaa !14
  %.sroa.81.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 32
  store i64 %4, ptr %.sroa.81.0..sroa_idx, align 8, !tbaa !13
  %13 = load i64, ptr %6, align 8, !tbaa !5
  %14 = add i64 %13, 1
  store i64 %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %11, align 8, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %15, i64 40
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  store ptr %17, ptr %11, align 8, !tbaa !12
  br label %18

18:                                               ; preds = %5, %10
  %.0 = phi i8 [ 1, %10 ], [ 0, %5 ]
  ret i8 %.0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

!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 = !{!"MerryRequestQueue", !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 = !{!8, !8, i64 0}
!15 = !{!16, !10, i64 40}
!16 = !{!"MerryRequestNode", !17, i64 0, !10, i64 40}
!17 = !{!"MerryOSRequest", !7, i64 0, !10, i64 8, !7, i64 16, !8, i64 24, !8, i64 25, !7, i64 32}


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