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

; 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._agooQueue = type { ptr, ptr, %struct._agooAtom, %struct._agooAtom, i8, i8, %struct._agooAtom, %struct._agooAtom, %struct._agooAtom, i32, i32 }
%struct._agooAtom = type { ptr, %union.pthread_mutex_t }
%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 }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; 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_queue_listen(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca [2 x i32], align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct._agooQueue, ptr %4, i32 0, i32 9
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp eq i32 0, %6
  br i1 %7, label %8, label %28

8:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %9 = getelementptr inbounds [2 x i32], ptr %3, i64 0, i64 0
  %10 = call i32 @pipe(ptr noundef %9) #5
  %11 = icmp eq i32 0, %10
  br i1 %11, label %12, label %27

12:                                               ; preds = %8
  %13 = getelementptr inbounds [2 x i32], ptr %3, i64 0, i64 0
  %14 = load i32, ptr %13, align 4, !tbaa !14
  %15 = call i32 (i32, i32, ...) @fcntl(i32 noundef %14, i32 noundef 4, i32 noundef 2048)
  %16 = getelementptr inbounds [2 x i32], ptr %3, i64 0, i64 1
  %17 = load i32, ptr %16, align 4, !tbaa !14
  %18 = call i32 (i32, i32, ...) @fcntl(i32 noundef %17, i32 noundef 4, i32 noundef 2048)
  %19 = getelementptr inbounds [2 x i32], ptr %3, i64 0, i64 0
  %20 = load i32, ptr %19, align 4, !tbaa !14
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._agooQueue, ptr %21, i32 0, i32 9
  store i32 %20, ptr %22, align 8, !tbaa !9
  %23 = getelementptr inbounds [2 x i32], ptr %3, i64 0, i64 1
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._agooQueue, ptr %25, i32 0, i32 10
  store i32 %24, ptr %26, align 4, !tbaa !15
  br label %27

27:                                               ; preds = %12, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %28

28:                                               ; preds = %27, %1
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._agooQueue, ptr %29, i32 0, i32 8
  call void @_atomic_store(ptr noundef %30, ptr noundef inttoptr (i64 1 to ptr))
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._agooQueue, ptr %31, i32 0, i32 9
  %33 = load i32, ptr %32, align 8, !tbaa !9
  ret i32 %33
}

; Function Attrs: nounwind
declare i32 @pipe(ptr noundef) #3

declare i32 @fcntl(i32 noundef, i32 noundef, ...) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = { "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 }

!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, !13, i64 264}
!10 = !{!"_agooQueue", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 64, !12, i64 112, !12, i64 113, !11, i64 120, !11, i64 168, !11, i64 216, !13, i64 264, !13, i64 268}
!11 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!10, !13, i64 268}


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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress 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_queue_listen(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca [2 x i32], align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 264
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %6, label %17

6:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %7 = call i32 @pipe(ptr noundef nonnull %2) #5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %16

9:                                                ; preds = %6
  %10 = load i32, ptr %2, align 8, !tbaa !13
  %11 = call i32 (i32, i32, ...) @fcntl(i32 noundef %10, i32 noundef 4, i32 noundef 2048) #5
  %12 = getelementptr inbounds i8, ptr %2, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = call i32 (i32, i32, ...) @fcntl(i32 noundef %13, i32 noundef 4, i32 noundef 2048) #5
  %15 = load <2 x i32>, ptr %2, align 8, !tbaa !13
  store <2 x i32> %15, ptr %3, align 8, !tbaa !13
  br label %16

16:                                               ; preds = %9, %6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  br label %17

17:                                               ; preds = %16, %1
  %18 = getelementptr inbounds i8, ptr %0, i64 216
  call void @_atomic_store(ptr noundef nonnull %18, ptr noundef nonnull inttoptr (i64 1 to ptr))
  %19 = load i32, ptr %3, align 8, !tbaa !5
  ret i32 %19
}

; Function Attrs: nounwind
declare i32 @pipe(ptr noundef) local_unnamed_addr #3

declare i32 @fcntl(i32 noundef, i32 noundef, ...) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = { "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 }

!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, !12, i64 264}
!6 = !{!"_agooQueue", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 64, !11, i64 112, !11, i64 113, !10, i64 120, !10, i64 168, !10, i64 216, !12, i64 264, !12, i64 268}
!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}
!12 = !{!"int", !8, i64 0}
!13 = !{!12, !12, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass