; 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._agooBind = type { ptr, i32, i32, i16, %union.anon, ptr, ptr, ptr, ptr, ptr, i32 }
%union.anon = type { %struct.in6_addr }
%struct.in6_addr = type { %union.anon.0 }
%union.anon.0 = type { [4 x i32] }

@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

declare void @agoo_bind_destroy(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @agoo_server_bind(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr null, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct._agooBind, ptr %6, i32 0, i32 5
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp eq ptr null, %8
  br i1 %9, label %10, label %13

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._agooBind, ptr %11, i32 0, i32 5
  store ptr @agoo_con_http_read, ptr %12, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %10, %1
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._agooBind, ptr %14, i32 0, i32 6
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = icmp eq ptr null, %16
  br i1 %17, label %18, label %21

18:                                               ; preds = %13
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._agooBind, ptr %19, i32 0, i32 6
  store ptr @agoo_con_http_write, ptr %20, align 8, !tbaa !13
  br label %21

21:                                               ; preds = %18, %13
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._agooBind, ptr %22, i32 0, i32 7
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = icmp eq ptr null, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %21
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._agooBind, ptr %27, i32 0, i32 7
  store ptr @agoo_con_http_events, ptr %28, align 8, !tbaa !14
  br label %29

29:                                               ; preds = %26, %21
  %30 = load ptr, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 11), align 8, !tbaa !15
  store ptr %30, ptr %4, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %60, %29
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = icmp ne ptr null, %32
  br i1 %33, label %34, label %64

34:                                               ; preds = %31
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._agooBind, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 4, !tbaa !21
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._agooBind, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 4, !tbaa !21
  %41 = icmp eq i32 %37, %40
  br i1 %41, label %42, label %58

42:                                               ; preds = %34
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._agooBind, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !22
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._agooBind, ptr %46, i32 0, i32 0
  store ptr %45, ptr %47, align 8, !tbaa !22
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = icmp eq ptr null, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %42
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %51, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 11), align 8, !tbaa !15
  br label %56

52:                                               ; preds = %42
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._agooBind, ptr %54, i32 0, i32 0
  store ptr %53, ptr %55, align 8, !tbaa !22
  br label %56

56:                                               ; preds = %52, %50
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  call void @agoo_bind_destroy(ptr noundef %57)
  store i32 1, ptr %5, align 4
  br label %69

58:                                               ; preds = %34
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %59, ptr %3, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %58
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._agooBind, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !22
  store ptr %63, ptr %4, align 8, !tbaa !5
  br label %31, !llvm.loop !23

64:                                               ; preds = %31
  %65 = load ptr, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 11), align 8, !tbaa !15
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._agooBind, ptr %66, i32 0, i32 0
  store ptr %65, ptr %67, align 8, !tbaa !22
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %68, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 11), align 8, !tbaa !15
  store i32 0, ptr %5, align 4
  br label %69

69:                                               ; preds = %64, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %70 = load i32, ptr %5, align 4
  switch i32 %70, label %72 [
    i32 0, label %71
    i32 1, label %71
  ]

71:                                               ; preds = %69, %69
  ret void

72:                                               ; preds = %69
  unreachable
}

declare zeroext i1 @agoo_con_http_read(ptr noundef) #1

declare zeroext i1 @agoo_con_http_write(ptr noundef) #1

declare signext i16 @agoo_con_http_events(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 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 40}
!10 = !{!"_agooBind", !6, i64 0, !11, i64 8, !11, i64 12, !12, i64 16, !7, i64 20, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !11, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!10, !6, i64 48}
!14 = !{!10, !6, i64 56}
!15 = !{!16, !6, i64 312}
!16 = !{!"_agooServer", !17, i64 0, !17, i64 1, !11, i64 4, !17, i64 8, !17, i64 9, !17, i64 10, !17, i64 11, !18, i64 16, !19, i64 24, !6, i64 296, !6, i64 304, !6, i64 312, !19, i64 320, !6, i64 592, !11, i64 600, !11, i64 604, !20, i64 608, !6, i64 656, !6, i64 664, !7, i64 672, !11, i64 712, !6, i64 720, !6, i64 728, !20, i64 736}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!"_agooQueue", !6, i64 0, !6, i64 8, !20, i64 16, !20, i64 64, !17, i64 112, !17, i64 113, !20, i64 120, !20, i64 168, !20, i64 216, !11, i64 264, !11, i64 268}
!20 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!21 = !{!10, !11, i64 12}
!22 = !{!10, !6, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"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

declare void @agoo_bind_destroy(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @agoo_server_bind(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %6

5:                                                ; preds = %1
  store ptr @agoo_con_http_read, ptr %2, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %5, %1
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %6
  store ptr @agoo_con_http_write, ptr %7, align 8, !tbaa !12
  br label %11

11:                                               ; preds = %10, %6
  %12 = getelementptr inbounds i8, ptr %0, i64 56
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  store ptr @agoo_con_http_events, ptr %12, align 8, !tbaa !13
  br label %16

16:                                               ; preds = %15, %11
  %17 = getelementptr inbounds i8, ptr %0, i64 12
  br label %18

18:                                               ; preds = %19, %16
  %.020 = phi ptr [ null, %16 ], [ %.0, %19 ]
  %.0.in = phi ptr [ getelementptr inbounds (i8, ptr @agoo_server, i64 312), %16 ], [ %.0, %19 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !14
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %27, label %19

19:                                               ; preds = %18
  %20 = getelementptr inbounds i8, ptr %.0, i64 12
  %21 = load i32, ptr %20, align 4, !tbaa !15
  %22 = load i32, ptr %17, align 4, !tbaa !15
  %23 = icmp eq i32 %21, %22
  br i1 %23, label %24, label %18, !llvm.loop !16

24:                                               ; preds = %19
  %25 = load ptr, ptr %.0, align 8, !tbaa !18
  store ptr %25, ptr %0, align 8, !tbaa !18
  %26 = icmp eq ptr %.020, null
  %..020.lcssa26 = select i1 %26, ptr getelementptr inbounds (i8, ptr @agoo_server, i64 312), ptr %.020
  store ptr %0, ptr %..020.lcssa26, align 8, !tbaa !14
  tail call void @agoo_bind_destroy(ptr noundef nonnull %.0) #2
  br label %29

27:                                               ; preds = %18
  %28 = load ptr, ptr getelementptr inbounds (i8, ptr @agoo_server, i64 312), align 8, !tbaa !19
  store ptr %28, ptr %0, align 8, !tbaa !18
  store ptr %0, ptr getelementptr inbounds (i8, ptr @agoo_server, i64 312), align 8, !tbaa !19
  br label %29

29:                                               ; preds = %27, %24
  ret void
}

declare zeroext i1 @agoo_con_http_read(ptr noundef) #0

declare zeroext i1 @agoo_con_http_write(ptr noundef) #0

declare signext i16 @agoo_con_http_events(ptr noundef) #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 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, !7, i64 40}
!6 = !{!"_agooBind", !7, i64 0, !10, i64 8, !10, i64 12, !11, i64 16, !8, i64 20, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !10, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!6, !7, i64 48}
!13 = !{!6, !7, i64 56}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !10, i64 12}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !7, i64 0}
!19 = !{!20, !7, i64 312}
!20 = !{!"_agooServer", !21, i64 0, !21, i64 1, !10, i64 4, !21, i64 8, !21, i64 9, !21, i64 10, !21, i64 11, !22, i64 16, !23, i64 24, !7, i64 296, !7, i64 304, !7, i64 312, !23, i64 320, !7, i64 592, !10, i64 600, !10, i64 604, !24, i64 608, !7, i64 656, !7, i64 664, !8, i64 672, !10, i64 712, !7, i64 720, !7, i64 728, !24, i64 736}
!21 = !{!"_Bool", !8, i64 0}
!22 = !{!"long", !8, i64 0}
!23 = !{!"_agooQueue", !7, i64 0, !7, i64 8, !24, i64 16, !24, i64 64, !21, i64 112, !21, i64 113, !24, i64 120, !24, i64 168, !24, i64 216, !10, i64 264, !10, i64 268}
!24 = !{!"_agooAtom", !7, i64 0, !8, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass