; 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 }
%struct._agooRes = type { ptr, ptr, ptr, %union.pthread_mutex_t, i8, i32, i8, i8, i8 }
%struct._agooErr = type { i32, [256 x i8] }

@agoo_server = external dso_local global %struct._agooServer, align 8
@.str.4 = external hidden unnamed_addr constant [64 x i8], align 1
@gql_type_func = external global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [9 x i8], align 1

; 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

declare i32 @agoo_err_set(ptr noundef, i32 noundef, ptr noundef, ...) #1

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

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

declare i32 @agoo_err_memory(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @agoo_server_gpublish(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %13 = load ptr, ptr @gql_type_func, align 8, !tbaa !5
  %14 = icmp eq ptr null, %13
  br i1 %14, label %20, label %15

15:                                               ; preds = %3
  %16 = load ptr, ptr @gql_type_func, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call ptr %16(ptr noundef %17)
  store ptr %18, ptr %9, align 8, !tbaa !5
  %19 = icmp eq ptr null, %18
  br i1 %19, label %20, label %23

20:                                               ; preds = %15, %3
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call i32 (ptr, i32, ptr, ...) @agoo_err_set(ptr noundef %21, i32 noundef 312, ptr noundef @.str.5)
  store i32 %22, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %75

23:                                               ; preds = %15
  %24 = call i32 @pthread_mutex_lock(ptr noundef getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 19)) #4
  %25 = load ptr, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 18), align 8, !tbaa !9
  store ptr %25, ptr %8, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %66, %23
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = icmp ne ptr null, %27
  br i1 %28, label %29, label %70

29:                                               ; preds = %26
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._gqlSub, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = call zeroext i1 @subject_check(ptr noundef %32, ptr noundef %33)
  br i1 %34, label %35, label %65

35:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._gqlSub, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !18
  %39 = call ptr @agoo_res_create(ptr noundef %38)
  store ptr %39, ptr %11, align 8, !tbaa !5
  %40 = icmp eq ptr null, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %35
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = call i32 @agoo_err_memory(ptr noundef %42, ptr noundef @.str.6, ptr noundef @.str.4, i32 noundef 482)
  store i32 2, ptr %10, align 4
  br label %62

44:                                               ; preds = %35
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._gqlSub, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !19
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = call ptr @gpub_eval(ptr noundef %45, ptr noundef %48, ptr noundef %49)
  store ptr %50, ptr %12, align 8, !tbaa !5
  %51 = icmp eq ptr null, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %44
  store i32 2, ptr %10, align 4
  br label %62

53:                                               ; preds = %44
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._agooRes, ptr %54, i32 0, i32 5
  store i32 0, ptr %55, align 4, !tbaa !20
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  call void @agoo_res_message_push(ptr noundef %56, ptr noundef %57)
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._gqlSub, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !18
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  call void @agoo_con_res_append(ptr noundef %60, ptr noundef %61)
  store i32 0, ptr %10, align 4
  br label %62

62:                                               ; preds = %53, %52, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %63 = load i32, ptr %10, align 4
  switch i32 %63, label %77 [
    i32 0, label %64
    i32 2, label %70
  ]

64:                                               ; preds = %62
  br label %65

65:                                               ; preds = %64, %29
  br label %66

66:                                               ; preds = %65
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._gqlSub, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !22
  store ptr %69, ptr %8, align 8, !tbaa !5
  br label %26, !llvm.loop !23

70:                                               ; preds = %62, %26
  %71 = call i32 @pthread_mutex_unlock(ptr noundef getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 19)) #4
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._agooErr, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 4, !tbaa !25
  store i32 %74, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %75

75:                                               ; preds = %70, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %76 = load i32, ptr %4, align 4
  ret i32 %76

77:                                               ; preds = %62
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @subject_check(ptr noundef, ptr noundef) #3

declare ptr @agoo_res_create(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden ptr @gpub_eval(ptr noundef, ptr noundef, ptr noundef) #3

declare void @agoo_res_message_push(ptr noundef, ptr noundef) #1

declare void @agoo_con_res_append(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 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 #4 = { 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 16}
!17 = !{!"_gqlSub", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!18 = !{!17, !6, i64 8}
!19 = !{!17, !6, i64 24}
!20 = !{!21, !12, i64 68}
!21 = !{!"_agooRes", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !11, i64 64, !12, i64 68, !11, i64 72, !11, i64 73, !11, i64 74}
!22 = !{!17, !6, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!26, !12, i64 0}
!26 = !{!"_agooErr", !12, i64 0, !7, i64 4}


; 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
@.str.4 = external hidden unnamed_addr constant [64 x i8], align 1
@gql_type_func = external local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [9 x i8], align 1

declare i32 @agoo_err_set(ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; 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

declare i32 @agoo_err_memory(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @agoo_server_gpublish(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = load ptr, ptr @gql_type_func, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %9, label %6

6:                                                ; preds = %3
  %7 = tail call ptr %4(ptr noundef %2) #3
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %11

9:                                                ; preds = %6, %3
  %10 = tail call i32 (ptr, i32, ptr, ...) @agoo_err_set(ptr noundef %0, i32 noundef 312, ptr noundef nonnull @.str.5) #3
  br label %34

11:                                               ; preds = %6
  %12 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull getelementptr inbounds (i8, ptr @agoo_server, i64 672)) #3
  %.01825 = load ptr, ptr getelementptr inbounds (i8, ptr @agoo_server, i64 664), align 8, !tbaa !5
  %.not26 = icmp eq ptr %.01825, null
  br i1 %.not26, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %11, %31
  %.01827 = phi ptr [ %.018, %31 ], [ %.01825, %11 ]
  %13 = getelementptr inbounds i8, ptr %.01827, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = tail call zeroext i1 @subject_check(ptr noundef %14, ptr noundef %1)
  br i1 %15, label %16, label %31

16:                                               ; preds = %.lr.ph
  %17 = getelementptr inbounds i8, ptr %.01827, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = tail call ptr @agoo_res_create(ptr noundef %18) #3
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %23

21:                                               ; preds = %16
  %22 = tail call i32 @agoo_err_memory(ptr noundef %0, ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.4, i32 noundef 482) #3
  br label %.thread

23:                                               ; preds = %16
  %24 = getelementptr inbounds i8, ptr %.01827, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = tail call ptr @gpub_eval(ptr noundef %0, ptr noundef %25, ptr noundef %2)
  %27 = icmp eq ptr %26, null
  br i1 %27, label %.thread, label %28

28:                                               ; preds = %23
  %29 = getelementptr inbounds i8, ptr %19, i64 68
  store i32 0, ptr %29, align 4, !tbaa !13
  tail call void @agoo_res_message_push(ptr noundef nonnull %19, ptr noundef nonnull %26) #3
  %30 = load ptr, ptr %17, align 8, !tbaa !11
  tail call void @agoo_con_res_append(ptr noundef %30, ptr noundef nonnull %19) #3
  br label %31

31:                                               ; preds = %28, %.lr.ph
  %.018 = load ptr, ptr %.01827, align 8, !tbaa !5
  %.not = icmp eq ptr %.018, null
  br i1 %.not, label %.thread, label %.lr.ph, !llvm.loop !17

.thread:                                          ; preds = %31, %23, %11, %21
  %32 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull getelementptr inbounds (i8, ptr @agoo_server, i64 672)) #3
  %33 = load i32, ptr %0, align 4, !tbaa !19
  br label %34

34:                                               ; preds = %.thread, %9
  %.0 = phi i32 [ %10, %9 ], [ %33, %.thread ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @subject_check(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @agoo_res_create(ptr noundef) local_unnamed_addr #0

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

declare void @agoo_res_message_push(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @agoo_con_res_append(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #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 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 = !{!"_gqlSub", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 24}
!13 = !{!14, !16, i64 68}
!14 = !{!"_agooRes", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !15, i64 64, !16, i64 68, !15, i64 72, !15, i64 73, !15, i64 74}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !16, i64 0}
!20 = !{!"_agooErr", !16, i64 0, !7, i64 4}


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