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

; 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._agooLogCat = type { ptr, [32 x i8], ptr, i32, i8 }
%struct._agooErr = type { i32, [256 x i8] }
%struct._agooReady = type { ptr, i32, double, ptr, ptr }
%struct._link = type { ptr, ptr, i32, ptr, ptr, ptr }
%struct.pollfd = type { i32, i16, i16 }

@.str.1 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@agoo_error_cat = external global %struct._agooLogCat, align 8
@.str.3 = external hidden unnamed_addr constant [15 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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; 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_ready_add(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #3 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %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 i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = load ptr, ptr %11, align 8, !tbaa !5
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = call ptr @link_create(ptr noundef %16, i32 noundef %17, ptr noundef %18, ptr noundef %19)
  store ptr %20, ptr %12, align 8, !tbaa !5
  %21 = icmp eq ptr null, %20
  br i1 %21, label %22, label %26

22:                                               ; preds = %5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._agooErr, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 4, !tbaa !11
  store i32 %25, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %103

26:                                               ; preds = %5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._agooReady, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._link, ptr %30, i32 0, i32 0
  store ptr %29, ptr %31, align 8, !tbaa !16
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._agooReady, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = icmp ne ptr null, %34
  br i1 %35, label %36, label %42

36:                                               ; preds = %26
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._agooReady, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = getelementptr inbounds %struct._link, ptr %40, i32 0, i32 1
  store ptr %37, ptr %41, align 8, !tbaa !18
  br label %42

42:                                               ; preds = %36, %26
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._agooReady, ptr %44, i32 0, i32 0
  store ptr %43, ptr %45, align 8, !tbaa !13
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._agooReady, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 8, !tbaa !19
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %47, align 8, !tbaa !19
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._agooReady, ptr %50, i32 0, i32 4
  %52 = load ptr, ptr %51, align 8, !tbaa !20
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._agooReady, ptr %53, i32 0, i32 3
  %55 = load ptr, ptr %54, align 8, !tbaa !21
  %56 = ptrtoint ptr %52 to i64
  %57 = ptrtoint ptr %55 to i64
  %58 = sub i64 %56, %57
  %59 = sdiv exact i64 %58, 8
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._agooReady, ptr %60, i32 0, i32 1
  %62 = load i32, ptr %61, align 8, !tbaa !19
  %63 = sext i32 %62 to i64
  %64 = icmp sle i64 %59, %63
  br i1 %64, label %65, label %102

65:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._agooReady, ptr %66, i32 0, i32 4
  %68 = load ptr, ptr %67, align 8, !tbaa !20
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._agooReady, ptr %69, i32 0, i32 3
  %71 = load ptr, ptr %70, align 8, !tbaa !21
  %72 = ptrtoint ptr %68 to i64
  %73 = ptrtoint ptr %71 to i64
  %74 = sub i64 %72, %73
  %75 = sdiv exact i64 %74, 8
  %76 = mul nsw i64 %75, 2
  store i64 %76, ptr %14, align 8, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %77 = load i64, ptr %14, align 8, !tbaa !22
  %78 = mul i64 %77, 8
  store i64 %78, ptr %15, align 8, !tbaa !22
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._agooReady, ptr %79, i32 0, i32 3
  %81 = load ptr, ptr %80, align 8, !tbaa !21
  %82 = load i64, ptr %15, align 8, !tbaa !22
  %83 = call ptr @realloc(ptr noundef %81, i64 noundef %82) #7
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._agooReady, ptr %84, i32 0, i32 3
  store ptr %83, ptr %85, align 8, !tbaa !21
  %86 = icmp eq ptr null, %83
  br i1 %86, label %87, label %90

87:                                               ; preds = %65
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = call i32 @agoo_err_memory(ptr noundef %88, ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 160)
  call void (ptr, ptr, ...) @agoo_log_cat(ptr noundef @agoo_error_cat, ptr noundef @.str.3)
  call void (...) @agoo_log_close()
  call void @exit(i32 noundef 1) #8
  unreachable

90:                                               ; preds = %65
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct._agooReady, ptr %91, i32 0, i32 3
  %93 = load ptr, ptr %92, align 8, !tbaa !21
  %94 = load i64, ptr %14, align 8, !tbaa !22
  %95 = getelementptr inbounds %struct.pollfd, ptr %93, i64 %94
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct._agooReady, ptr %96, i32 0, i32 4
  store ptr %95, ptr %97, align 8, !tbaa !20
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct._agooReady, ptr %98, i32 0, i32 3
  %100 = load ptr, ptr %99, align 8, !tbaa !21
  %101 = load i64, ptr %15, align 8, !tbaa !22
  call void @llvm.memset.p0.i64(ptr align 4 %100, i8 0, i64 %101, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  br label %102

102:                                              ; preds = %90, %42
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %103

103:                                              ; preds = %102, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  %104 = load i32, ptr %6, align 4
  ret i32 %104
}

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

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #4

declare void @agoo_log_cat(ptr noundef, ptr noundef, ...) #1

declare void @agoo_log_close(...) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #5

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 allocsize(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 #5 = { noreturn 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(1) }
attributes #8 = { noreturn 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, !10, i64 0}
!12 = !{!"_agooErr", !10, i64 0, !7, i64 4}
!13 = !{!14, !6, i64 0}
!14 = !{!"_agooReady", !6, i64 0, !10, i64 8, !15, i64 16, !6, i64 24, !6, i64 32}
!15 = !{!"double", !7, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"_link", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!18 = !{!17, !6, i64 8}
!19 = !{!14, !10, i64 8}
!20 = !{!14, !6, i64 32}
!21 = !{!14, !6, i64 24}
!22 = !{!23, !23, i64 0}
!23 = !{!"long", !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._agooLogCat = type { ptr, [32 x i8], ptr, i32, i8 }
%struct.pollfd = type { i32, i16, i16 }

@.str.1 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@agoo_error_cat = external global %struct._agooLogCat, align 8
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @agoo_ready_add(ptr noundef %0, ptr nocapture noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = tail call ptr @link_create(ptr noundef %0, i32 noundef %2, ptr noundef %4, ptr noundef %3)
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %10

8:                                                ; preds = %5
  %9 = load i32, ptr %0, align 4, !tbaa !5
  br label %36

10:                                               ; preds = %5
  %11 = load ptr, ptr %1, align 8, !tbaa !10
  store ptr %11, ptr %6, align 8, !tbaa !14
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %14, label %12

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %11, i64 8
  store ptr %6, ptr %13, align 8, !tbaa !16
  br label %14

14:                                               ; preds = %12, %10
  store ptr %6, ptr %1, align 8, !tbaa !10
  %15 = getelementptr inbounds i8, ptr %1, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !17
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %15, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %1, i64 32
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %1, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !19
  %22 = ptrtoint ptr %19 to i64
  %23 = ptrtoint ptr %21 to i64
  %24 = sub i64 %22, %23
  %25 = ashr exact i64 %24, 3
  %26 = sext i32 %17 to i64
  %.not32 = icmp sgt i64 %25, %26
  br i1 %.not32, label %36, label %27

27:                                               ; preds = %14
  %28 = shl i64 %24, 1
  %29 = tail call ptr @realloc(ptr noundef %21, i64 noundef %28) #5
  store ptr %29, ptr %20, align 8, !tbaa !19
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %33

31:                                               ; preds = %27
  %32 = tail call i32 @agoo_err_memory(ptr noundef %0, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 160) #6
  tail call void (ptr, ptr, ...) @agoo_log_cat(ptr noundef nonnull @agoo_error_cat, ptr noundef nonnull @.str.3) #6
  tail call void (...) @agoo_log_close() #6
  tail call void @exit(i32 noundef 1) #7
  unreachable

33:                                               ; preds = %27
  %34 = ashr exact i64 %24, 2
  %35 = getelementptr inbounds %struct.pollfd, ptr %29, i64 %34
  store ptr %35, ptr %18, align 8, !tbaa !18
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %29, i8 0, i64 %28, i1 false)
  br label %36

36:                                               ; preds = %14, %33, %8
  %.0 = phi i32 [ %9, %8 ], [ 0, %33 ], [ 0, %14 ]
  ret i32 %.0
}

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

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #3

declare void @agoo_log_cat(ptr noundef, ptr noundef, ...) local_unnamed_addr #0

declare void @agoo_log_close(...) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #4

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { noreturn 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 #5 = { nounwind allocsize(1) }
attributes #6 = { nounwind }
attributes #7 = { noreturn 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 0}
!6 = !{!"_agooErr", !7, i64 0, !8, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"_agooReady", !12, i64 0, !7, i64 8, !13, i64 16, !12, i64 24, !12, i64 32}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"double", !8, i64 0}
!14 = !{!15, !12, i64 0}
!15 = !{!"_link", !12, i64 0, !12, i64 8, !7, i64 16, !12, i64 24, !12, i64 32, !12, i64 40}
!16 = !{!15, !12, i64 8}
!17 = !{!11, !7, i64 8}
!18 = !{!11, !12, i64 32}
!19 = !{!11, !12, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass