; LLVM IR from buzz-lang/Buzz :: src/buzz (buzzoutmsg)

; 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.dict_to_array_s = type { i64, i64, ptr }
%struct.buzzvm_s = type { ptr, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i16, ptr, ptr, ptr, ptr, i32, i32, ptr, i16, ptr, i32 }
%struct.buzzoutmsg_queue_s = type { [6 x ptr], ptr }
%struct.buzzoutmsg_swarm_s = type { i32, ptr, i16 }
%struct.buzzdarray_s = type { ptr, i64, i32, i32, ptr }

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

declare void @buzzdarray_insert(ptr noundef, i32 noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @dict_to_array(ptr noundef, ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @buzzoutmsg_queue_append_swarm_list(ptr noundef %0, ptr noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.dict_to_array_s, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.buzzvm_s, ptr %7, i32 0, i32 17
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.buzzoutmsg_queue_s, ptr %9, i32 0, i32 0
  %11 = getelementptr inbounds [6 x ptr], ptr %10, i64 0, i64 1
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  call void @buzzdarray_clear(ptr noundef %12, i32 noundef 1)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.buzzvm_s, ptr %13, i32 0, i32 17
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.buzzoutmsg_queue_s, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds [6 x ptr], ptr %16, i64 0, i64 4
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  call void @buzzdarray_clear(ptr noundef %18, i32 noundef 1)
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.buzzvm_s, ptr %19, i32 0, i32 17
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.buzzoutmsg_queue_s, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds [6 x ptr], ptr %22, i64 0, i64 5
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  call void @buzzdarray_clear(ptr noundef %24, i32 noundef 1)
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #6
  %25 = getelementptr inbounds %struct.dict_to_array_s, ptr %5, i32 0, i32 0
  store i64 0, ptr %25, align 8, !tbaa !13
  %26 = getelementptr inbounds %struct.dict_to_array_s, ptr %5, i32 0, i32 1
  store i64 1, ptr %26, align 8, !tbaa !16
  %27 = getelementptr inbounds %struct.dict_to_array_s, ptr %5, i32 0, i32 2
  %28 = call noalias ptr @malloc(i64 noundef 2) #7
  store ptr %28, ptr %27, align 8, !tbaa !17
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  call void @buzzdict_foreach(ptr noundef %29, ptr noundef @dict_to_array, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %30 = call noalias ptr @malloc(i64 noundef 24) #7
  store ptr %30, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.buzzoutmsg_swarm_s, ptr %31, i32 0, i32 0
  store i32 1, ptr %32, align 8, !tbaa !18
  %33 = getelementptr inbounds %struct.dict_to_array_s, ptr %5, i32 0, i32 0
  %34 = load i64, ptr %33, align 8, !tbaa !13
  %35 = trunc i64 %34 to i16
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.buzzoutmsg_swarm_s, ptr %36, i32 0, i32 2
  store i16 %35, ptr %37, align 8, !tbaa !18
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.buzzoutmsg_swarm_s, ptr %38, i32 0, i32 2
  %40 = load i16, ptr %39, align 8, !tbaa !18
  %41 = zext i16 %40 to i64
  %42 = mul i64 %41, 2
  %43 = call noalias ptr @malloc(i64 noundef %42) #7
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.buzzoutmsg_swarm_s, ptr %44, i32 0, i32 1
  store ptr %43, ptr %45, align 8, !tbaa !18
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.buzzoutmsg_swarm_s, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !18
  %49 = getelementptr inbounds %struct.dict_to_array_s, ptr %5, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !17
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.buzzoutmsg_swarm_s, ptr %51, i32 0, i32 2
  %53 = load i16, ptr %52, align 8, !tbaa !18
  %54 = zext i16 %53 to i64
  %55 = mul i64 %54, 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %48, ptr align 2 %50, i64 %55, i1 false)
  %56 = getelementptr inbounds %struct.dict_to_array_s, ptr %5, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  call void @free(ptr noundef %57) #6
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.buzzvm_s, ptr %58, i32 0, i32 17
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.buzzoutmsg_queue_s, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds [6 x ptr], ptr %61, i64 0, i64 1
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.buzzvm_s, ptr %64, i32 0, i32 17
  %66 = load ptr, ptr %65, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.buzzoutmsg_queue_s, ptr %66, i32 0, i32 0
  %68 = getelementptr inbounds [6 x ptr], ptr %67, i64 0, i64 1
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.buzzdarray_s, ptr %69, i32 0, i32 1
  %71 = load i64, ptr %70, align 8, !tbaa !19
  %72 = trunc i64 %71 to i32
  call void @buzzdarray_insert(ptr noundef %63, i32 noundef %72, ptr noundef %6)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #6
  ret void
}

declare void @buzzdarray_clear(ptr noundef, i32 noundef) #3

declare void @buzzdict_foreach(ptr noundef, ptr noundef, ptr noundef) #3

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

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

!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, !6, i64 128}
!10 = !{!"buzzvm_s", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !12, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !11, i64 152, !11, i64 156, !6, i64 160, !12, i64 168, !6, i64 176, !11, i64 184}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"dict_to_array_s", !15, i64 0, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !15, i64 8}
!17 = !{!14, !6, i64 16}
!18 = !{!7, !7, i64 0}
!19 = !{!20, !15, i64 8}
!20 = !{!"buzzdarray_s", !6, i64 0, !15, i64 8, !11, i64 16, !11, i64 20, !6, i64 24}


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

%struct.dict_to_array_s = type { i64, i64, ptr }

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

declare void @buzzdarray_insert(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @dict_to_array(ptr noundef, ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @buzzoutmsg_queue_append_swarm_list(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #4 {
  %3 = alloca %struct.dict_to_array_s, align 8
  %4 = alloca ptr, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 128
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  tail call void @buzzdarray_clear(ptr noundef %8, i32 noundef 1) #6
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 32
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  tail call void @buzzdarray_clear(ptr noundef %11, i32 noundef 1) #6
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 40
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  tail call void @buzzdarray_clear(ptr noundef %14, i32 noundef 1) #6
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #6
  store i64 0, ptr %3, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %3, i64 8
  store i64 1, ptr %15, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %3, i64 16
  %17 = tail call noalias dereferenceable_or_null(2) ptr @malloc(i64 noundef 2) #7
  store ptr %17, ptr %16, align 8, !tbaa !17
  call void @buzzdict_foreach(ptr noundef %1, ptr noundef nonnull @dict_to_array, ptr noundef nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  %18 = call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #7
  store ptr %18, ptr %4, align 8, !tbaa !12
  store i32 1, ptr %18, align 8, !tbaa !18
  %19 = load i64, ptr %3, align 8, !tbaa !13
  %20 = trunc i64 %19 to i16
  %21 = getelementptr inbounds i8, ptr %18, i64 16
  store i16 %20, ptr %21, align 8, !tbaa !18
  %22 = shl i64 %19, 1
  %23 = and i64 %22, 131070
  %24 = call noalias ptr @malloc(i64 noundef %23) #7
  %25 = getelementptr inbounds i8, ptr %18, i64 8
  store ptr %24, ptr %25, align 8, !tbaa !18
  %26 = load ptr, ptr %16, align 8, !tbaa !17
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %24, ptr align 2 %26, i64 %23, i1 false)
  call void @free(ptr noundef %26) #6
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  %31 = load i64, ptr %30, align 8, !tbaa !19
  %32 = trunc i64 %31 to i32
  call void @buzzdarray_insert(ptr noundef %29, i32 noundef %32, ptr noundef nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #6
  ret void
}

declare void @buzzdarray_clear(ptr noundef, i32 noundef) local_unnamed_addr #3

declare void @buzzdict_foreach(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 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 #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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 128}
!6 = !{!"buzzvm_s", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !11, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !10, i64 152, !10, i64 156, !7, i64 160, !11, i64 168, !7, i64 176, !10, i64 184}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"dict_to_array_s", !15, i64 0, !15, i64 8, !7, i64 16}
!15 = !{!"long", !8, i64 0}
!16 = !{!14, !15, i64 8}
!17 = !{!14, !7, i64 16}
!18 = !{!8, !8, i64 0}
!19 = !{!20, !15, i64 8}
!20 = !{!"buzzdarray_s", !7, i64 0, !15, i64 8, !10, i64 16, !10, i64 20, !7, i64 24}


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