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

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

@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [37 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @agoo_con_loop(ptr noundef) #3

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

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call i32 @agoo_err_memory(ptr noundef %12, ptr noundef @.str.16, ptr noundef @.str.1, i32 noundef 1396)
  br label %56

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._agooConLoop, ptr %15, i32 0, i32 0
  store ptr null, ptr %16, align 8, !tbaa !11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._agooConLoop, ptr %18, i32 0, i32 1
  %20 = call i32 @agoo_queue_multi_init(ptr noundef %17, ptr noundef %19, i64 noundef 256, i1 noundef zeroext true, i1 noundef zeroext false)
  %21 = icmp ne i32 0, %20
  br i1 %21, label %22, label %24

22:                                               ; preds = %14
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %23) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %53

24:                                               ; preds = %14
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._agooConLoop, ptr %26, i32 0, i32 3
  store i32 %25, ptr %27, align 8, !tbaa !17
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._agooConLoop, ptr %28, i32 0, i32 4
  store ptr null, ptr %29, align 8, !tbaa !18
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._agooConLoop, ptr %30, i32 0, i32 5
  store ptr null, ptr %31, align 8, !tbaa !19
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._agooConLoop, ptr %32, i32 0, i32 6
  %34 = call i32 @pthread_mutex_init(ptr noundef %33, ptr noundef null) #5
  %35 = icmp ne i32 0, %34
  br i1 %35, label %36, label %40

36:                                               ; preds = %24
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %37) #5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = call i32 (ptr, ptr, ...) @agoo_err_no(ptr noundef %38, ptr noundef @.str.17)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %53

40:                                               ; preds = %24
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._agooConLoop, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = call i32 @pthread_create(ptr noundef %42, ptr noundef null, ptr noundef @agoo_con_loop, ptr noundef %43) #5
  store i32 %44, ptr %7, align 4, !tbaa !9
  %45 = icmp ne i32 0, %44
  br i1 %45, label %46, label %52

46:                                               ; preds = %40
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = call ptr @strerror(i32 noundef %49) #5
  %51 = call i32 (ptr, i32, ptr, ...) @agoo_err_set(ptr noundef %47, i32 noundef %48, ptr noundef @.str.18, ptr noundef %50)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %53

52:                                               ; preds = %40
  store i32 0, ptr %8, align 4
  br label %53

53:                                               ; preds = %52, %46, %36, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  %54 = load i32, ptr %8, align 4
  switch i32 %54, label %58 [
    i32 0, label %55
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55, %11
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %57, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %58

58:                                               ; preds = %56, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %59 = load ptr, ptr %3, align 8
  ret ptr %59
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

declare i32 @agoo_queue_multi_init(ptr noundef, ptr noundef, i64 noundef, i1 noundef zeroext, i1 noundef zeroext) #1

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

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

declare i32 @agoo_err_set(ptr noundef, i32 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 allocsize(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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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, !6, i64 0}
!12 = !{!"_agooConLoop", !6, i64 0, !13, i64 8, !16, i64 280, !10, i64 288, !6, i64 296, !6, i64 304, !7, i64 312}
!13 = !{!"_agooQueue", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 64, !15, i64 112, !15, i64 113, !14, i64 120, !14, i64 168, !14, i64 216, !10, i64 264, !10, i64 268}
!14 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!12, !10, i64 288}
!18 = !{!12, !6, i64 296}
!19 = !{!12, !6, i64 304}


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

@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [37 x i8], align 1

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_init(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @agoo_con_loop(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @agoo_conloop_create(ptr noundef %0, i32 noundef %1) local_unnamed_addr #3 {
  %3 = tail call noalias dereferenceable_or_null(352) ptr @malloc(i64 noundef 352) #6
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = tail call i32 @agoo_err_memory(ptr noundef %0, ptr noundef nonnull @.str.16, ptr noundef nonnull @.str.1, i32 noundef 1396) #7
  br label %.critedge

7:                                                ; preds = %2
  store ptr null, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  %9 = tail call i32 @agoo_queue_multi_init(ptr noundef %0, ptr noundef nonnull %8, i64 noundef 256, i1 noundef zeroext true, i1 noundef zeroext false) #7
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %11, label %10

10:                                               ; preds = %7
  tail call void @free(ptr noundef nonnull %3) #7
  br label %.critedge

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %3, i64 288
  store i32 %1, ptr %12, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %3, i64 296
  %14 = getelementptr inbounds i8, ptr %3, i64 312
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %13, i8 0, i64 16, i1 false)
  %15 = tail call i32 @pthread_mutex_init(ptr noundef nonnull %14, ptr noundef null) #7
  %.not22 = icmp eq i32 %15, 0
  br i1 %.not22, label %18, label %16

16:                                               ; preds = %11
  tail call void @free(ptr noundef nonnull %3) #7
  %17 = tail call i32 (ptr, ptr, ...) @agoo_err_no(ptr noundef %0, ptr noundef nonnull @.str.17) #7
  br label %.critedge

18:                                               ; preds = %11
  %19 = getelementptr inbounds i8, ptr %3, i64 280
  %20 = tail call i32 @pthread_create(ptr noundef nonnull %19, ptr noundef null, ptr noundef nonnull @agoo_con_loop, ptr noundef nonnull %3) #7
  %.not23 = icmp eq i32 %20, 0
  br i1 %.not23, label %.critedge, label %21

21:                                               ; preds = %18
  %22 = tail call ptr @strerror(i32 noundef %20) #7
  %23 = tail call i32 (ptr, i32, ptr, ...) @agoo_err_set(ptr noundef %0, i32 noundef %20, ptr noundef nonnull @.str.18, ptr noundef %22) #7
  br label %.critedge

.critedge:                                        ; preds = %10, %16, %21, %5, %18
  %.1 = phi ptr [ %3, %18 ], [ null, %5 ], [ null, %21 ], [ null, %16 ], [ null, %10 ]
  ret ptr %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

declare i32 @agoo_queue_multi_init(ptr noundef, ptr noundef, i64 noundef, i1 noundef zeroext, i1 noundef zeroext) local_unnamed_addr #0

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

; Function Attrs: nounwind
declare i32 @pthread_create(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

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 = { mustprogress nounwind willreturn allockind("free") 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 #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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { 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 = !{!"_agooConLoop", !7, i64 0, !10, i64 8, !14, i64 280, !13, i64 288, !7, i64 296, !7, i64 304, !8, i64 312}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_agooQueue", !7, i64 0, !7, 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", !7, i64 0, !8, i64 8}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!"long", !8, i64 0}
!15 = !{!6, !13, i64 288}


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