; 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._agooUpgraded = type { ptr, ptr, ptr, %struct._agooAtom, %struct._agooAtom, ptr, ptr, ptr, ptr, i8, i8, i8, i8, i8, ptr }
%struct._agooCon = type { ptr, i32, ptr, ptr, i64, [46 x i8], [8192 x i8], i64, i64, i64, double, i8, i8, i8, ptr, ptr, ptr, %union.pthread_mutex_t, ptr, ptr, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local void @agoo_server_add_upgraded(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = call i32 @pthread_mutex_lock(ptr noundef getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 19)) #2
  %4 = load ptr, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 17), align 8, !tbaa !9
  %5 = icmp eq ptr null, %4
  br i1 %5, label %6, label %9

6:                                                ; preds = %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._agooUpgraded, ptr %7, i32 0, i32 0
  store ptr null, ptr %8, align 8, !tbaa !16
  br label %13

9:                                                ; preds = %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 17), align 8, !tbaa !9
  %12 = getelementptr inbounds %struct._agooUpgraded, ptr %11, i32 0, i32 1
  store ptr %10, ptr %12, align 8, !tbaa !18
  br label %13

13:                                               ; preds = %9, %6
  %14 = load ptr, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 17), align 8, !tbaa !9
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._agooUpgraded, ptr %15, i32 0, i32 0
  store ptr %14, ptr %16, align 8, !tbaa !16
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %17, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 17), align 8, !tbaa !9
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._agooUpgraded, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !19
  %22 = getelementptr inbounds %struct._agooCon, ptr %21, i32 0, i32 18
  store ptr %18, ptr %22, align 8, !tbaa !20
  %23 = call i32 @pthread_mutex_unlock(ptr noundef getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 19)) #2
  ret void
}

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) #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 = { 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 }

!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 656}
!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 = !{!"_agooUpgraded", !6, i64 0, !6, i64 8, !6, i64 16, !15, i64 24, !15, i64 72, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !11, i64 152, !11, i64 153, !11, i64 154, !11, i64 155, !11, i64 156, !6, i64 160}
!18 = !{!17, !6, i64 8}
!19 = !{!17, !6, i64 16}
!20 = !{!21, !6, i64 8384}
!21 = !{!"_agooCon", !6, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !7, i64 40, !7, i64 86, !13, i64 8280, !13, i64 8288, !13, i64 8296, !22, i64 8304, !11, i64 8312, !11, i64 8313, !11, i64 8314, !6, i64 8320, !6, i64 8328, !6, i64 8336, !7, i64 8344, !6, i64 8384, !6, i64 8392, !6, i64 8400}
!22 = !{!"double", !7, i64 0}


; 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 uwtable
define dso_local void @agoo_server_add_upgraded(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull getelementptr inbounds (i8, ptr @agoo_server, i64 672)) #2
  %3 = load ptr, ptr getelementptr inbounds (i8, ptr @agoo_server, i64 656), align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %7, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %0, ptr %6, align 8, !tbaa !15
  br label %7

7:                                                ; preds = %1, %5
  store ptr %3, ptr %0, align 8, !tbaa !17
  store ptr %0, ptr getelementptr inbounds (i8, ptr @agoo_server, i64 656), align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !18
  %10 = getelementptr inbounds i8, ptr %9, i64 8384
  store ptr %0, ptr %10, align 8, !tbaa !19
  %11 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull getelementptr inbounds (i8, ptr @agoo_server, i64 672)) #2
  ret void
}

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(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 = { 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 }

!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, !13, i64 656}
!6 = !{!"_agooServer", !7, i64 0, !7, i64 1, !10, i64 4, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !11, i64 16, !12, i64 24, !13, i64 296, !13, i64 304, !13, i64 312, !12, i64 320, !13, i64 592, !10, i64 600, !10, i64 604, !14, i64 608, !13, i64 656, !13, i64 664, !8, i64 672, !10, i64 712, !13, i64 720, !13, i64 728, !14, i64 736}
!7 = !{!"_Bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"_agooQueue", !13, i64 0, !13, i64 8, !14, i64 16, !14, i64 64, !7, i64 112, !7, i64 113, !14, i64 120, !14, i64 168, !14, i64 216, !10, i64 264, !10, i64 268}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"_agooAtom", !13, i64 0, !8, i64 8}
!15 = !{!16, !13, i64 8}
!16 = !{!"_agooUpgraded", !13, i64 0, !13, i64 8, !13, i64 16, !14, i64 24, !14, i64 72, !13, i64 120, !13, i64 128, !13, i64 136, !13, i64 144, !7, i64 152, !7, i64 153, !7, i64 154, !7, i64 155, !7, i64 156, !13, i64 160}
!17 = !{!16, !13, i64 0}
!18 = !{!16, !13, i64 16}
!19 = !{!20, !13, i64 8384}
!20 = !{!"_agooCon", !13, i64 0, !10, i64 8, !13, i64 16, !13, i64 24, !11, i64 32, !8, i64 40, !8, i64 86, !11, i64 8280, !11, i64 8288, !11, i64 8296, !21, i64 8304, !7, i64 8312, !7, i64 8313, !7, i64 8314, !13, i64 8320, !13, i64 8328, !13, i64 8336, !8, i64 8344, !13, i64 8384, !13, i64 8392, !13, i64 8400}
!21 = !{!"double", !8, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass