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

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @atomic_fetch_sub(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @destroy(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @agoo_upgraded_release_con(ptr noundef %0) #2 {
  %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)) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct._agooUpgraded, ptr %4, i32 0, i32 2
  store ptr null, ptr %5, align 8, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct._agooUpgraded, ptr %6, i32 0, i32 4
  %8 = call i32 @atomic_fetch_sub(ptr noundef %7, i32 noundef 1)
  %9 = icmp sle i32 %8, 1
  br i1 %9, label %10, label %12

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  call void @destroy(ptr noundef %11)
  br label %12

12:                                               ; preds = %10, %1
  %13 = call i32 @pthread_mutex_unlock(ptr noundef getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 19)) #3
  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 = { inlinehint 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 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 16}
!10 = !{!"_agooUpgraded", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 72, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !12, i64 152, !12, i64 153, !12, i64 154, !12, i64 155, !12, i64 156, !6, i64 160}
!11 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!12 = !{!"_Bool", !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 global %struct._agooServer, align 8

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @atomic_fetch_sub(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @destroy(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local void @agoo_upgraded_release_con(ptr noundef %0) local_unnamed_addr #2 {
  %2 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull getelementptr inbounds (i8, ptr @agoo_server, i64 672)) #3
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr null, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 72
  %5 = tail call i32 @atomic_fetch_sub(ptr noundef nonnull %4, i32 noundef 1)
  %6 = icmp slt i32 %5, 2
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  tail call void @destroy(ptr noundef nonnull %0)
  br label %8

8:                                                ; preds = %7, %1
  %9 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull getelementptr inbounds (i8, ptr @agoo_server, i64 672)) #3
  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 = { inlinehint 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 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, !7, i64 16}
!6 = !{!"_agooUpgraded", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 72, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !11, i64 152, !11, i64 153, !11, i64 154, !11, i64 155, !11, i64 156, !7, i64 160}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_agooAtom", !7, i64 0, !8, i64 8}
!11 = !{!"_Bool", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InstCombinePass,SROAPass,TailCallElimPass