; LLVM IR from ohler55/agoo :: ext/agoo (server)

; 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._agooServer = type { i8, i8, i32, i8, i8, i8, i8, i64, %struct._agooQueue, ptr, ptr, ptr, %struct._agooQueue, ptr, i32, i32, %struct._agooAtom, ptr, ptr, %union.pthread_mutex_t, i32, ptr, ptr, %struct._agooAtom }
%struct._agooQueue = type { ptr, ptr, %struct._agooAtom, %struct._agooAtom, i8, i8, %struct._agooAtom, %struct._agooAtom, %struct._agooAtom, i32, i32 }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%struct._agooAtom = type { ptr, %union.pthread_mutex_t }
%struct._agooConLoop = type { ptr, %struct._agooQueue, i64, i32, ptr, ptr, %union.pthread_mutex_t }

@agoo_server = external dso_local global %struct._agooServer, align 8

; 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 void @agoo_server_publish(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 13), align 8, !tbaa !9
  store ptr %4, ptr %3, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %23, %1
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp ne ptr null, %6
  br i1 %7, label %8, label %27

8:                                                ; preds = %5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._agooConLoop, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  %12 = icmp eq ptr null, %11
  br i1 %12, label %13, label %17

13:                                               ; preds = %8
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._agooConLoop, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  call void @agoo_queue_push(ptr noundef %15, ptr noundef %16)
  br label %22

17:                                               ; preds = %8
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._agooConLoop, ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = call ptr @agoo_pub_dup(ptr noundef %20)
  call void @agoo_queue_push(ptr noundef %19, ptr noundef %21)
  br label %22

22:                                               ; preds = %17, %13
  br label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._agooConLoop, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  store ptr %26, ptr %3, align 8, !tbaa !5
  br label %5, !llvm.loop !18

27:                                               ; preds = %5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare void @agoo_queue_push(ptr noundef, ptr noundef) #2

declare ptr @agoo_pub_dup(ptr noundef) #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 = { "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, !6, i64 592}
!10 = !{!"_agooServer", !11, i64 0, !11, i64 1, !12, i64 4, !11, i64 8, !11, i64 9, !11, i64 10, !11, i64 11, !13, i64 16, !14, i64 24, !6, i64 296, !6, i64 304, !6, i64 312, !14, i64 320, !6, i64 592, !12, i64 600, !12, i64 604, !15, i64 608, !6, i64 656, !6, i64 664, !7, i64 672, !12, i64 712, !6, i64 720, !6, i64 728, !15, i64 736}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_agooQueue", !6, i64 0, !6, i64 8, !15, i64 16, !15, i64 64, !11, i64 112, !11, i64 113, !15, i64 120, !15, i64 168, !15, i64 216, !12, i64 264, !12, i64 268}
!15 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!16 = !{!17, !6, i64 0}
!17 = !{!"_agooConLoop", !6, i64 0, !14, i64 8, !13, i64 280, !12, i64 288, !6, i64 296, !6, i64 304, !7, i64 312}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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._agooServer = type { i8, i8, i32, i8, i8, i8, i8, i64, %struct._agooQueue, ptr, ptr, ptr, %struct._agooQueue, ptr, i32, i32, %struct._agooAtom, ptr, ptr, %union.pthread_mutex_t, i32, ptr, ptr, %struct._agooAtom }
%struct._agooQueue = type { ptr, ptr, %struct._agooAtom, %struct._agooAtom, i8, i8, %struct._agooAtom, %struct._agooAtom, %struct._agooAtom, i32, i32 }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%struct._agooAtom = type { ptr, %union.pthread_mutex_t }

@agoo_server = external dso_local local_unnamed_addr global %struct._agooServer, align 8

; Function Attrs: nounwind uwtable
define dso_local void @agoo_server_publish(ptr noundef %0) local_unnamed_addr #0 {
  %.07 = load ptr, ptr getelementptr inbounds (i8, ptr @agoo_server, i64 592), align 8, !tbaa !5
  %.not8 = icmp eq ptr %.07, null
  br i1 %.not8, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %7
  %.09 = phi ptr [ %.0, %7 ], [ %.07, %1 ]
  %2 = load ptr, ptr %.09, align 8, !tbaa !9
  %3 = icmp eq ptr %2, null
  %4 = getelementptr inbounds i8, ptr %.09, i64 8
  br i1 %3, label %7, label %5

5:                                                ; preds = %.lr.ph
  %6 = tail call ptr @agoo_pub_dup(ptr noundef %0) #2
  br label %7

7:                                                ; preds = %.lr.ph, %5
  %.sink = phi ptr [ %6, %5 ], [ %0, %.lr.ph ]
  tail call void @agoo_queue_push(ptr noundef nonnull %4, ptr noundef %.sink) #2
  %.0 = load ptr, ptr %.09, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %7, %1
  ret void
}

declare void @agoo_queue_push(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @agoo_pub_dup(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { "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 }

!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 0}
!10 = !{!"_agooConLoop", !6, i64 0, !11, i64 8, !15, i64 280, !14, i64 288, !6, i64 296, !6, i64 304, !7, i64 312}
!11 = !{!"_agooQueue", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 64, !13, i64 112, !13, i64 113, !12, i64 120, !12, i64 168, !12, i64 216, !14, i64 264, !14, i64 268}
!12 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass