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

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [63 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @agoo_queue_multi_init(ptr noundef %0, ptr noundef %1, i64 noundef %2, i1 noundef zeroext %3, i1 noundef zeroext %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  %12 = zext i1 %3 to i8
  store i8 %12, ptr %10, align 1, !tbaa !11
  %13 = zext i1 %4 to i8
  store i8 %13, ptr %11, align 1, !tbaa !11
  %14 = load i64, ptr %9, align 8, !tbaa !9
  %15 = icmp ult i64 %14, 4
  br i1 %15, label %16, label %17

16:                                               ; preds = %5
  store i64 4, ptr %9, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %16, %5
  %18 = load i64, ptr %9, align 8, !tbaa !9
  %19 = call noalias ptr @calloc(i64 noundef %18, i64 noundef 8) #4
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._agooQueue, ptr %20, i32 0, i32 0
  store ptr %19, ptr %21, align 8, !tbaa !13
  %22 = icmp eq ptr null, %19
  br i1 %22, label %23, label %26

23:                                               ; preds = %17
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = call i32 @agoo_err_memory(ptr noundef %24, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 40)
  store i32 %25, ptr %6, align 4
  br label %65

26:                                               ; preds = %17
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._agooQueue, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = load i64, ptr %9, align 8, !tbaa !9
  %31 = getelementptr inbounds ptr, ptr %29, i64 %30
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._agooQueue, ptr %32, i32 0, i32 1
  store ptr %31, ptr %33, align 8, !tbaa !17
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._agooQueue, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._agooQueue, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !13
  call void @atomic_init(ptr noundef %35, ptr noundef %38)
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._agooQueue, ptr %39, i32 0, i32 3
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._agooQueue, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !13
  %44 = getelementptr inbounds ptr, ptr %43, i64 1
  call void @atomic_init(ptr noundef %40, ptr noundef %44)
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._agooQueue, ptr %45, i32 0, i32 6
  call void @agoo_atomic_flag_init(ptr noundef %46)
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._agooQueue, ptr %47, i32 0, i32 7
  call void @agoo_atomic_flag_init(ptr noundef %48)
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._agooQueue, ptr %49, i32 0, i32 8
  call void @atomic_init(ptr noundef %50, ptr noundef null)
  %51 = load i8, ptr %10, align 1, !tbaa !11, !range !18, !noundef !19
  %52 = trunc i8 %51 to i1
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._agooQueue, ptr %53, i32 0, i32 4
  %55 = zext i1 %52 to i8
  store i8 %55, ptr %54, align 8, !tbaa !20
  %56 = load i8, ptr %11, align 1, !tbaa !11, !range !18, !noundef !19
  %57 = trunc i8 %56 to i1
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._agooQueue, ptr %58, i32 0, i32 5
  %60 = zext i1 %57 to i8
  store i8 %60, ptr %59, align 1, !tbaa !21
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._agooQueue, ptr %61, i32 0, i32 9
  store i32 0, ptr %62, align 8, !tbaa !22
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._agooQueue, ptr %63, i32 0, i32 10
  store i32 0, ptr %64, align 4, !tbaa !23
  store i32 0, ptr %6, align 4
  br label %65

65:                                               ; preds = %26, %23
  %66 = load i32, ptr %6, align 4
  ret i32 %66
}

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #1

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @agoo_atomic_flag_init(ptr noundef) #3

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 = { nounwind allocsize(0,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 = { "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 = { 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 #4 = { nounwind allocsize(0,1) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_agooQueue", !6, i64 0, !6, i64 8, !15, i64 16, !15, i64 64, !12, i64 112, !12, i64 113, !15, i64 120, !15, i64 168, !15, i64 216, !16, i64 264, !16, i64 268}
!15 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!16 = !{!"int", !7, i64 0}
!17 = !{!14, !6, i64 8}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!14, !12, i64 112}
!21 = !{!14, !12, i64 113}
!22 = !{!14, !16, i64 264}
!23 = !{!14, !16, 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"

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [63 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @agoo_queue_multi_init(ptr noundef %0, ptr noundef %1, i64 noundef %2, i1 noundef zeroext %3, i1 noundef zeroext %4) local_unnamed_addr #0 {
  %spec.store.select = tail call i64 @llvm.umax.i64(i64 %2, i64 4)
  %6 = tail call noalias ptr @calloc(i64 noundef %spec.store.select, i64 noundef 8) #5
  store ptr %6, ptr %1, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %10

8:                                                ; preds = %5
  %9 = tail call i32 @agoo_err_memory(ptr noundef %0, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 40) #6
  br label %26

10:                                               ; preds = %5
  %11 = zext i1 %4 to i8
  %12 = zext i1 %3 to i8
  %13 = getelementptr inbounds ptr, ptr %6, i64 %spec.store.select
  %14 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %13, ptr %14, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %1, i64 16
  tail call void @atomic_init(ptr noundef nonnull %15, ptr noundef nonnull %6)
  %16 = getelementptr inbounds i8, ptr %1, i64 64
  %17 = load ptr, ptr %1, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  tail call void @atomic_init(ptr noundef nonnull %16, ptr noundef nonnull %18)
  %19 = getelementptr inbounds i8, ptr %1, i64 120
  tail call void @agoo_atomic_flag_init(ptr noundef nonnull %19)
  %20 = getelementptr inbounds i8, ptr %1, i64 168
  tail call void @agoo_atomic_flag_init(ptr noundef nonnull %20)
  %21 = getelementptr inbounds i8, ptr %1, i64 216
  tail call void @atomic_init(ptr noundef nonnull %21, ptr noundef null)
  %22 = getelementptr inbounds i8, ptr %1, i64 112
  store i8 %12, ptr %22, align 8, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %1, i64 113
  store i8 %11, ptr %23, align 1, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %1, i64 264
  store i32 0, ptr %24, align 8, !tbaa !16
  %25 = getelementptr inbounds i8, ptr %1, i64 268
  store i32 0, ptr %25, align 4, !tbaa !17
  br label %26

26:                                               ; preds = %10, %8
  %.0 = phi i32 [ %9, %8 ], [ 0, %10 ]
  ret i32 %.0
}

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @agoo_atomic_flag_init(ptr noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #4

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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 #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 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind allocsize(0,1) }
attributes #6 = { 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 = !{!"_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 = !{!6, !7, i64 8}
!14 = !{!6, !11, i64 112}
!15 = !{!6, !11, i64 113}
!16 = !{!6, !12, i64 264}
!17 = !{!6, !12, i64 268}


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