; 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._agooEarly = type { ptr, i8, ptr }
%struct._agooRes = type { ptr, ptr, ptr, %union.pthread_mutex_t, i8, i32, i8, i8, i8 }
%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._agooText = type { ptr, i64, i64, %struct._agooAtom, i8, [8 x i8] }
%struct._agooAtom = type { ptr, %union.pthread_mutex_t }

@early_103 = external hidden constant [27 x i8], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(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 void @agoo_res_add_early(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = call ptr @agoo_text_allocate(i32 noundef 1024)
  store ptr %7, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = call ptr @agoo_text_append(ptr noundef %8, ptr noundef @early_103, i32 noundef 26)
  store ptr %9, ptr %5, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %23, %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr null, %11
  br i1 %12, label %13, label %27

13:                                               ; preds = %10
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call ptr @agoo_text_append(ptr noundef %14, ptr noundef @.str, i32 noundef 6)
  store ptr %15, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._agooEarly, ptr %17, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = call ptr @agoo_text_append(ptr noundef %16, ptr noundef %19, i32 noundef -1)
  store ptr %20, ptr %5, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call ptr @agoo_text_append(ptr noundef %21, ptr noundef @.str.1, i32 noundef 2)
  store ptr %22, ptr %5, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %13
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._agooEarly, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  store ptr %26, ptr %4, align 8, !tbaa !5
  br label %10, !llvm.loop !13

27:                                               ; preds = %10
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call ptr @agoo_text_append(ptr noundef %28, ptr noundef @.str.1, i32 noundef 2)
  store ptr %29, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._agooRes, ptr %30, i32 0, i32 3
  %32 = call i32 @pthread_mutex_lock(ptr noundef %31) #4
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._agooRes, ptr %33, i32 0, i32 4
  %35 = load volatile i8, ptr %34, align 8, !tbaa !15, !range !18, !noundef !19
  %36 = trunc i8 %35 to i1
  br i1 %36, label %67, label %37

37:                                               ; preds = %27
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._agooRes, ptr %38, i32 0, i32 2
  %40 = load volatile ptr, ptr %39, align 8, !tbaa !20
  %41 = icmp eq ptr null, %40
  br i1 %41, label %42, label %46

42:                                               ; preds = %37
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._agooRes, ptr %44, i32 0, i32 2
  store volatile ptr %43, ptr %45, align 8, !tbaa !20
  br label %64

46:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._agooRes, ptr %47, i32 0, i32 2
  %49 = load volatile ptr, ptr %48, align 8, !tbaa !20
  store ptr %49, ptr %6, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %56, %46
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._agooText, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !21
  %54 = icmp ne ptr null, %53
  br i1 %54, label %55, label %60

55:                                               ; preds = %50
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._agooText, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !21
  store ptr %59, ptr %6, align 8, !tbaa !5
  br label %50, !llvm.loop !25

60:                                               ; preds = %50
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._agooText, ptr %62, i32 0, i32 0
  store ptr %61, ptr %63, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %64

64:                                               ; preds = %60, %42
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._agooRes, ptr %65, i32 0, i32 4
  store volatile i8 0, ptr %66, align 8, !tbaa !15
  br label %67

67:                                               ; preds = %64, %27
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._agooRes, ptr %68, i32 0, i32 3
  %70 = call i32 @pthread_mutex_unlock(ptr noundef %69) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

declare ptr @agoo_text_allocate(i32 noundef) #3

declare ptr @agoo_text_append(ptr noundef, ptr noundef, i32 noundef) #3

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

!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 16}
!10 = !{!"_agooEarly", !6, i64 0, !11, i64 8, !6, i64 16}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !11, i64 64}
!16 = !{!"_agooRes", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !11, i64 64, !17, i64 68, !11, i64 72, !11, i64 73, !11, i64 74}
!17 = !{!"int", !7, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!16, !6, i64 16}
!21 = !{!22, !6, i64 0}
!22 = !{!"_agooText", !6, i64 0, !23, i64 8, !23, i64 16, !24, i64 24, !11, i64 72, !7, i64 73}
!23 = !{!"long", !7, i64 0}
!24 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!25 = distinct !{!25, !14}


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

@early_103 = external hidden constant [27 x i8], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @agoo_res_add_early(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #1 {
  %3 = tail call ptr @agoo_text_allocate(i32 noundef 1024) #3
  %4 = tail call ptr @agoo_text_append(ptr noundef %3, ptr noundef nonnull @early_103, i32 noundef 26) #3
  %.not24 = icmp eq ptr %1, null
  br i1 %.not24, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.02026 = phi ptr [ %9, %.lr.ph ], [ %4, %2 ]
  %.02125 = phi ptr [ %10, %.lr.ph ], [ %1, %2 ]
  %5 = tail call ptr @agoo_text_append(ptr noundef %.02026, ptr noundef nonnull @.str, i32 noundef 6) #3
  %6 = getelementptr inbounds i8, ptr %.02125, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = tail call ptr @agoo_text_append(ptr noundef %5, ptr noundef %7, i32 noundef -1) #3
  %9 = tail call ptr @agoo_text_append(ptr noundef %8, ptr noundef nonnull @.str.1, i32 noundef 2) #3
  %10 = load ptr, ptr %.02125, align 8, !tbaa !11
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.020.lcssa = phi ptr [ %4, %2 ], [ %9, %.lr.ph ]
  %11 = tail call ptr @agoo_text_append(ptr noundef %.020.lcssa, ptr noundef nonnull @.str.1, i32 noundef 2) #3
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull %12) #3
  %14 = getelementptr inbounds i8, ptr %0, i64 64
  %15 = load volatile i8, ptr %14, align 8, !tbaa !14, !range !17, !noundef !18
  %16 = trunc nuw i8 %15 to i1
  br i1 %16, label %28, label %17

17:                                               ; preds = %._crit_edge
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  %19 = load volatile ptr, ptr %18, align 8, !tbaa !19
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  store volatile ptr %11, ptr %18, align 8, !tbaa !19
  br label %27

22:                                               ; preds = %17
  %23 = load volatile ptr, ptr %18, align 8, !tbaa !19
  br label %24

24:                                               ; preds = %24, %22
  %.0 = phi ptr [ %23, %22 ], [ %25, %24 ]
  %25 = load ptr, ptr %.0, align 8, !tbaa !20
  %.not23 = icmp eq ptr %25, null
  br i1 %.not23, label %26, label %24, !llvm.loop !24

26:                                               ; preds = %24
  store ptr %11, ptr %.0, align 8, !tbaa !20
  br label %27

27:                                               ; preds = %26, %21
  store volatile i8 0, ptr %14, align 8, !tbaa !14
  br label %28

28:                                               ; preds = %27, %._crit_edge
  %29 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull %12) #3
  ret void
}

declare ptr @agoo_text_allocate(i32 noundef) local_unnamed_addr #2

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

attributes #0 = { 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 #1 = { 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 = { "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 }

!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 16}
!6 = !{!"_agooEarly", !7, i64 0, !10, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !10, i64 64}
!15 = !{!"_agooRes", !7, i64 0, !7, i64 8, !7, i64 16, !8, i64 24, !10, i64 64, !16, i64 68, !10, i64 72, !10, i64 73, !10, i64 74}
!16 = !{!"int", !8, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!15, !7, i64 16}
!20 = !{!21, !7, i64 0}
!21 = !{!"_agooText", !7, i64 0, !22, i64 8, !22, i64 16, !23, i64 24, !10, i64 72, !8, i64 73}
!22 = !{!"long", !8, i64 0}
!23 = !{!"_agooAtom", !7, i64 0, !8, i64 8}
!24 = distinct !{!24, !13}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass