; 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: nounwind uwtable
define dso_local zeroext i8 @merry_push_request(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  %10 = alloca %struct.MerryOSRequest, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  store i8 1, ptr %9, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 40, ptr %10) #3
  %11 = getelementptr inbounds %struct.MerryOSRequest, ptr %10, i32 0, i32 0
  %12 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %12, ptr %11, align 8, !tbaa !12
  %13 = getelementptr inbounds %struct.MerryOSRequest, ptr %10, i32 0, i32 1
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %14, ptr %13, align 8, !tbaa !14
  %15 = getelementptr inbounds %struct.MerryOSRequest, ptr %10, i32 0, i32 2
  %16 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %16, ptr %15, align 8, !tbaa !15
  %17 = getelementptr inbounds %struct.MerryOSRequest, ptr %10, i32 0, i32 3
  store i8 0, ptr %17, align 8, !tbaa !16
  %18 = getelementptr inbounds %struct.MerryOSRequest, ptr %10, i32 0, i32 4
  store i8 0, ptr %18, align 1, !tbaa !17
  %19 = getelementptr inbounds %struct.MerryOSRequest, ptr %10, i32 0, i32 5
  store i64 0, ptr %19, align 8, !tbaa !18
  br label %20

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

28:                                               ; preds = %20
  store i8 0, ptr %9, align 1, !tbaa !11
  br label %46

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

45:                                               ; preds = %29
  br label %46

46:                                               ; preds = %45, %28
  %47 = load i8, ptr %9, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 40, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  ret i8 %47
}

; 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 = !{!"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_request(ptr nocapture noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = load i64, ptr %0, align 8, !tbaa !11
  %8 = icmp eq i64 %6, %7
  br i1 %8, label %17, label %9

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

17:                                               ; preds = %4, %9
  %.0 = phi i8 [ 1, %9 ], [ 0, %4 ]
  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 = !{!"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 = !{!10, !10, i64 0}
!15 = !{!8, !8, i64 0}
!16 = !{!17, !10, i64 40}
!17 = !{!"MerryRequestNode", !18, i64 0, !10, i64 40}
!18 = !{!"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