; 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._agooHook = type { ptr, i32, ptr, i32, %union.anon.1, ptr, i8 }
%union.anon.1 = type { ptr }

@agoo_server = external dso_local global %struct._agooServer, align 8
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [64 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

; Function Attrs: nounwind uwtable
define dso_local i32 @agoo_server_add_func_hook(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i1 noundef zeroext %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  %18 = zext i1 %5 to i8
  store i8 %18, ptr %13, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store ptr null, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = load ptr, ptr %12, align 8, !tbaa !5
  %23 = call ptr @agoo_hook_func_create(i32 noundef %19, ptr noundef %20, ptr noundef %21, ptr noundef %22)
  store ptr %23, ptr %16, align 8, !tbaa !5
  %24 = load ptr, ptr %16, align 8, !tbaa !5
  %25 = icmp eq ptr null, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %6
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = call i32 @agoo_err_memory(ptr noundef %27, ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 362)
  store i32 %28, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %55

29:                                               ; preds = %6
  %30 = load i8, ptr %13, align 1, !tbaa !11, !range !13, !noundef !14
  %31 = trunc i8 %30 to i1
  %32 = load ptr, ptr %16, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._agooHook, ptr %32, i32 0, i32 6
  %34 = zext i1 %31 to i8
  store i8 %34, ptr %33, align 8, !tbaa !15
  %35 = load ptr, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 9), align 8, !tbaa !17
  store ptr %35, ptr %14, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %41, %29
  %37 = load ptr, ptr %14, align 8, !tbaa !5
  %38 = icmp ne ptr null, %37
  br i1 %38, label %39, label %45

39:                                               ; preds = %36
  %40 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %40, ptr %15, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %39
  %42 = load ptr, ptr %14, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._agooHook, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !22
  store ptr %44, ptr %14, align 8, !tbaa !5
  br label %36, !llvm.loop !23

45:                                               ; preds = %36
  %46 = load ptr, ptr %15, align 8, !tbaa !5
  %47 = icmp ne ptr null, %46
  br i1 %47, label %48, label %52

48:                                               ; preds = %45
  %49 = load ptr, ptr %16, align 8, !tbaa !5
  %50 = load ptr, ptr %15, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._agooHook, ptr %50, i32 0, i32 0
  store ptr %49, ptr %51, align 8, !tbaa !22
  br label %54

52:                                               ; preds = %45
  %53 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %53, ptr getelementptr inbounds (%struct._agooServer, ptr @agoo_server, i32 0, i32 9), align 8, !tbaa !17
  br label %54

54:                                               ; preds = %52, %48
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %55

55:                                               ; preds = %54, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %56 = load i32, ptr %7, align 4
  ret i32 %56
}

declare ptr @agoo_hook_func_create(i32 noundef, ptr noundef, ptr noundef, ptr noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !12, i64 48}
!16 = !{!"_agooHook", !6, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !7, i64 32, !6, i64 40, !12, i64 48}
!17 = !{!18, !6, i64 296}
!18 = !{!"_agooServer", !12, i64 0, !12, i64 1, !10, i64 4, !12, i64 8, !12, i64 9, !12, i64 10, !12, i64 11, !19, i64 16, !20, i64 24, !6, i64 296, !6, i64 304, !6, i64 312, !20, i64 320, !6, i64 592, !10, i64 600, !10, i64 604, !21, i64 608, !6, i64 656, !6, i64 664, !7, i64 672, !10, i64 712, !6, i64 720, !6, i64 728, !21, i64 736}
!19 = !{!"long", !7, i64 0}
!20 = !{!"_agooQueue", !6, i64 0, !6, i64 8, !21, i64 16, !21, i64 64, !12, i64 112, !12, i64 113, !21, i64 120, !21, i64 168, !21, i64 216, !10, i64 264, !10, i64 268}
!21 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!22 = !{!16, !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
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [64 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @agoo_server_add_func_hook(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i1 noundef zeroext %5) local_unnamed_addr #0 {
  %7 = tail call ptr @agoo_hook_func_create(i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %11

9:                                                ; preds = %6
  %10 = tail call i32 @agoo_err_memory(ptr noundef %0, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef 362) #2
  br label %18

11:                                               ; preds = %6
  %12 = zext i1 %5 to i8
  %13 = getelementptr inbounds i8, ptr %7, i64 48
  store i8 %12, ptr %13, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %14, %11
  %.016.in = phi ptr [ getelementptr inbounds (i8, ptr @agoo_server, i64 296), %11 ], [ %.016, %14 ]
  %.015 = phi ptr [ null, %11 ], [ %.016, %14 ]
  %.016 = load ptr, ptr %.016.in, align 8, !tbaa !12
  %.not = icmp eq ptr %.016, null
  br i1 %.not, label %15, label %14, !llvm.loop !13

15:                                               ; preds = %14
  %.not18 = icmp eq ptr %.015, null
  br i1 %.not18, label %17, label %16

16:                                               ; preds = %15
  store ptr %7, ptr %.015, align 8, !tbaa !15
  br label %18

17:                                               ; preds = %15
  store ptr %7, ptr getelementptr inbounds (i8, ptr @agoo_server, i64 296), align 8, !tbaa !16
  br label %18

18:                                               ; preds = %16, %17, %9
  %.0 = phi i32 [ %10, %9 ], [ 0, %17 ], [ 0, %16 ]
  ret i32 %.0
}

declare ptr @agoo_hook_func_create(i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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


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