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

; 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._agooCon = type { ptr, i32, ptr, ptr, i64, [46 x i8], [8192 x i8], i64, i64, i64, double, i8, i8, i8, ptr, ptr, ptr, %union.pthread_mutex_t, ptr, ptr, ptr }
%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._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 }
%struct._agooRes = type { ptr, ptr, ptr, %union.pthread_mutex_t, i8, i32, i8, i8, i8 }

; Function Attrs: nounwind uwtable
define dso_local ptr @agoo_res_create(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store ptr null, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct._agooCon, ptr %6, i32 0, i32 20
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct._agooConLoop, ptr %8, i32 0, i32 6
  %10 = call i32 @pthread_mutex_lock(ptr noundef %9) #4
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._agooCon, ptr %11, i32 0, i32 20
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct._agooConLoop, ptr %13, i32 0, i32 4
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  store ptr %15, ptr %4, align 8, !tbaa !5
  %16 = icmp ne ptr null, %15
  br i1 %16, label %17, label %37

17:                                               ; preds = %1
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._agooRes, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !19
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._agooCon, ptr %21, i32 0, i32 20
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct._agooConLoop, ptr %23, i32 0, i32 4
  store ptr %20, ptr %24, align 8, !tbaa !15
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._agooCon, ptr %25, i32 0, i32 20
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct._agooConLoop, ptr %27, i32 0, i32 4
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = icmp eq ptr null, %29
  br i1 %30, label %31, label %36

31:                                               ; preds = %17
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._agooCon, ptr %32, i32 0, i32 20
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct._agooConLoop, ptr %34, i32 0, i32 5
  store ptr null, ptr %35, align 8, !tbaa !21
  br label %36

36:                                               ; preds = %31, %17
  br label %37

37:                                               ; preds = %36, %1
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._agooCon, ptr %38, i32 0, i32 20
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct._agooConLoop, ptr %40, i32 0, i32 6
  %42 = call i32 @pthread_mutex_unlock(ptr noundef %41) #4
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = icmp eq ptr null, %43
  br i1 %44, label %45, label %50

45:                                               ; preds = %37
  %46 = call noalias ptr @malloc(i64 noundef 80) #5
  store ptr %46, ptr %4, align 8, !tbaa !5
  %47 = icmp eq ptr null, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %45
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %72

49:                                               ; preds = %45
  br label %50

50:                                               ; preds = %49, %37
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._agooRes, ptr %51, i32 0, i32 0
  store ptr null, ptr %52, align 8, !tbaa !19
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._agooRes, ptr %53, i32 0, i32 2
  store volatile ptr null, ptr %54, align 8, !tbaa !22
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._agooRes, ptr %55, i32 0, i32 3
  %57 = call i32 @pthread_mutex_init(ptr noundef %56, ptr noundef null) #4
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._agooRes, ptr %59, i32 0, i32 1
  store ptr %58, ptr %60, align 8, !tbaa !23
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._agooRes, ptr %61, i32 0, i32 5
  store i32 72, ptr %62, align 4, !tbaa !24
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._agooRes, ptr %63, i32 0, i32 4
  store volatile i8 0, ptr %64, align 8, !tbaa !25
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._agooRes, ptr %65, i32 0, i32 6
  store i8 0, ptr %66, align 8, !tbaa !26
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._agooRes, ptr %67, i32 0, i32 7
  store i8 0, ptr %68, align 1, !tbaa !27
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._agooRes, ptr %69, i32 0, i32 8
  store i8 0, ptr %70, align 2, !tbaa !28
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %71, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %72

72:                                               ; preds = %50, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %73 = load ptr, ptr %2, align 8
  ret ptr %73
}

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

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #4 = { nounwind }
attributes #5 = { 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, !6, i64 8400}
!10 = !{!"_agooCon", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !7, i64 40, !7, i64 86, !12, i64 8280, !12, i64 8288, !12, i64 8296, !13, i64 8304, !14, i64 8312, !14, i64 8313, !14, i64 8314, !6, i64 8320, !6, i64 8328, !6, i64 8336, !7, i64 8344, !6, i64 8384, !6, i64 8392, !6, i64 8400}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!16, !6, i64 296}
!16 = !{!"_agooConLoop", !6, i64 0, !17, i64 8, !12, i64 280, !11, i64 288, !6, i64 296, !6, i64 304, !7, i64 312}
!17 = !{!"_agooQueue", !6, i64 0, !6, i64 8, !18, i64 16, !18, i64 64, !14, i64 112, !14, i64 113, !18, i64 120, !18, i64 168, !18, i64 216, !11, i64 264, !11, i64 268}
!18 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!19 = !{!20, !6, i64 0}
!20 = !{!"_agooRes", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !14, i64 64, !11, i64 68, !14, i64 72, !14, i64 73, !14, i64 74}
!21 = !{!16, !6, i64 304}
!22 = !{!20, !6, i64 16}
!23 = !{!20, !6, i64 8}
!24 = !{!20, !11, i64 68}
!25 = !{!20, !14, i64 64}
!26 = !{!20, !14, i64 72}
!27 = !{!20, !14, i64 73}
!28 = !{!20, !14, i64 74}


; 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: nounwind uwtable
define dso_local noundef ptr @agoo_res_create(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8400
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 312
  %5 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull %4) #3
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 296
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %16, label %9

9:                                                ; preds = %1
  %10 = load ptr, ptr %8, align 8, !tbaa !18
  store ptr %10, ptr %7, align 8, !tbaa !14
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %.thread

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %6, i64 304
  store ptr null, ptr %13, align 8, !tbaa !20
  br label %.thread

.thread:                                          ; preds = %9, %12
  %14 = getelementptr inbounds i8, ptr %6, i64 312
  %15 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull %14) #3
  br label %21

16:                                               ; preds = %1
  %17 = getelementptr inbounds i8, ptr %6, i64 312
  %18 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull %17) #3
  %19 = tail call noalias dereferenceable_or_null(80) ptr @malloc(i64 noundef 80) #4
  %20 = icmp eq ptr %19, null
  br i1 %20, label %31, label %21

21:                                               ; preds = %.thread, %16
  %.0 = phi ptr [ %19, %16 ], [ %8, %.thread ]
  store ptr null, ptr %.0, align 8, !tbaa !18
  %22 = getelementptr inbounds i8, ptr %.0, i64 16
  store volatile ptr null, ptr %22, align 8, !tbaa !21
  %23 = getelementptr inbounds i8, ptr %.0, i64 24
  %24 = tail call i32 @pthread_mutex_init(ptr noundef nonnull %23, ptr noundef null) #3
  %25 = getelementptr inbounds i8, ptr %.0, i64 8
  store ptr %0, ptr %25, align 8, !tbaa !22
  %26 = getelementptr inbounds i8, ptr %.0, i64 68
  store i32 72, ptr %26, align 4, !tbaa !23
  %27 = getelementptr inbounds i8, ptr %.0, i64 64
  store volatile i8 0, ptr %27, align 8, !tbaa !24
  %28 = getelementptr inbounds i8, ptr %.0, i64 72
  store i8 0, ptr %28, align 8, !tbaa !25
  %29 = getelementptr inbounds i8, ptr %.0, i64 73
  store i8 0, ptr %29, align 1, !tbaa !26
  %30 = getelementptr inbounds i8, ptr %.0, i64 74
  store i8 0, ptr %30, align 2, !tbaa !27
  br label %31

31:                                               ; preds = %16, %21
  %.020 = phi ptr [ %.0, %21 ], [ null, %16 ]
  ret ptr %.020
}

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) local_unnamed_addr #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 #2

; Function Attrs: nounwind
declare i32 @pthread_mutex_init(ptr noundef, ptr 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 = { 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 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 #3 = { nounwind }
attributes #4 = { 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, !7, i64 8400}
!6 = !{!"_agooCon", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !8, i64 40, !8, i64 86, !11, i64 8280, !11, i64 8288, !11, i64 8296, !12, i64 8304, !13, i64 8312, !13, i64 8313, !13, i64 8314, !7, i64 8320, !7, i64 8328, !7, i64 8336, !8, i64 8344, !7, i64 8384, !7, i64 8392, !7, i64 8400}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{!15, !7, i64 296}
!15 = !{!"_agooConLoop", !7, i64 0, !16, i64 8, !11, i64 280, !10, i64 288, !7, i64 296, !7, i64 304, !8, i64 312}
!16 = !{!"_agooQueue", !7, i64 0, !7, i64 8, !17, i64 16, !17, i64 64, !13, i64 112, !13, i64 113, !17, i64 120, !17, i64 168, !17, i64 216, !10, i64 264, !10, i64 268}
!17 = !{!"_agooAtom", !7, i64 0, !8, i64 8}
!18 = !{!19, !7, i64 0}
!19 = !{!"_agooRes", !7, i64 0, !7, i64 8, !7, i64 16, !8, i64 24, !13, i64 64, !10, i64 68, !13, i64 72, !13, i64 73, !13, i64 74}
!20 = !{!15, !7, i64 304}
!21 = !{!19, !7, i64 16}
!22 = !{!19, !7, i64 8}
!23 = !{!19, !10, i64 68}
!24 = !{!19, !13, i64 64}
!25 = !{!19, !13, i64 72}
!26 = !{!19, !13, i64 73}
!27 = !{!19, !13, i64 74}


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