; 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._gqlSub = type { ptr, ptr, ptr, ptr }

@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
declare i32 @pthread_mutex_lock(ptr noundef) #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @agoo_server_del_gsub(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr null, ptr %4, align 8, !tbaa !5
  %5 = call i32 @pthread_mutex_lock(ptr noundef getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 19)) #3
  %6 = load ptr, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 18), align 8, !tbaa !9
  store ptr %6, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %30, %1
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr null, %8
  br i1 %9, label %10, label %34

10:                                               ; preds = %7
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = icmp eq ptr %11, %12
  br i1 %13, label %14, label %28

14:                                               ; preds = %10
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = icmp eq ptr null, %15
  br i1 %16, label %17, label %21

17:                                               ; preds = %14
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._gqlSub, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  store ptr %20, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 18), align 8, !tbaa !9
  br label %27

21:                                               ; preds = %14
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._gqlSub, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._gqlSub, ptr %25, i32 0, i32 0
  store ptr %24, ptr %26, align 8, !tbaa !16
  br label %27

27:                                               ; preds = %21, %17
  br label %28

28:                                               ; preds = %27, %10
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %29, ptr %4, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %28
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._gqlSub, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  store ptr %33, ptr %3, align 8, !tbaa !5
  br label %7, !llvm.loop !18

34:                                               ; preds = %7
  %35 = call i32 @pthread_mutex_unlock(ptr noundef getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 19)) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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 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, !6, i64 664}
!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 = !{!"_gqlSub", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!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 global %struct._agooServer, align 8

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @agoo_server_del_gsub(ptr noundef readnone %0) local_unnamed_addr #1 {
  %2 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull getelementptr inbounds (i8, ptr @agoo_server, i64 672)) #2
  %.0910 = load ptr, ptr getelementptr inbounds (i8, ptr @agoo_server, i64 664), align 8, !tbaa !5
  %.not11 = icmp eq ptr %.0910, null
  br i1 %.not11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %9
  %.0913 = phi ptr [ %.09, %9 ], [ %.0910, %1 ]
  %.012 = phi ptr [ %.0913, %9 ], [ null, %1 ]
  %3 = icmp eq ptr %.0913, %0
  br i1 %3, label %4, label %.lr.ph._crit_edge

.lr.ph._crit_edge:                                ; preds = %.lr.ph
  %.09.pre = load ptr, ptr %.0913, align 8, !tbaa !5
  br label %9

4:                                                ; preds = %.lr.ph
  %5 = icmp eq ptr %.012, null
  %6 = load ptr, ptr %.0913, align 8, !tbaa !5
  br i1 %5, label %7, label %8

7:                                                ; preds = %4
  store ptr %6, ptr getelementptr inbounds (i8, ptr @agoo_server, i64 664), align 8, !tbaa !9
  br label %9

8:                                                ; preds = %4
  store ptr %6, ptr %.012, align 8, !tbaa !16
  br label %9

9:                                                ; preds = %.lr.ph._crit_edge, %7, %8
  %.09 = phi ptr [ %.09.pre, %.lr.ph._crit_edge ], [ %6, %7 ], [ %6, %8 ]
  %.not = icmp eq ptr %.09, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %9, %1
  %10 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull getelementptr inbounds (i8, ptr @agoo_server, i64 672)) #2
  ret void
}

attributes #0 = { 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 #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 = { 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 664}
!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 = !{!"_gqlSub", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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