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

; 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_message_push(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp ne ptr null, %6
  br i1 %7, label %8, label %10

8:                                                ; preds = %2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  call void @agoo_text_ref(ptr noundef %9)
  br label %10

10:                                               ; preds = %8, %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._agooRes, ptr %11, i32 0, i32 3
  %13 = call i32 @pthread_mutex_lock(ptr noundef %12) #4
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._agooRes, ptr %14, i32 0, i32 4
  %16 = load volatile i8, ptr %15, align 8, !tbaa !9, !range !13, !noundef !14
  %17 = trunc i8 %16 to i1
  br i1 %17, label %48, label %18

18:                                               ; preds = %10
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._agooRes, ptr %19, i32 0, i32 2
  %21 = load volatile ptr, ptr %20, align 8, !tbaa !15
  %22 = icmp eq ptr null, %21
  br i1 %22, label %23, label %27

23:                                               ; preds = %18
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._agooRes, ptr %25, i32 0, i32 2
  store volatile ptr %24, ptr %26, align 8, !tbaa !15
  br label %45

27:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._agooRes, ptr %28, i32 0, i32 2
  %30 = load volatile ptr, ptr %29, align 8, !tbaa !15
  store ptr %30, ptr %5, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %37, %27
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._agooText, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = icmp ne ptr null, %34
  br i1 %35, label %36, label %41

36:                                               ; preds = %31
  br label %37

37:                                               ; preds = %36
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._agooText, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  store ptr %40, ptr %5, align 8, !tbaa !5
  br label %31, !llvm.loop !20

41:                                               ; preds = %31
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._agooText, ptr %43, i32 0, i32 0
  store ptr %42, ptr %44, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %45

45:                                               ; preds = %41, %23
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._agooRes, ptr %46, i32 0, i32 4
  store volatile i8 1, ptr %47, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %45, %10
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._agooRes, ptr %49, i32 0, i32 3
  %51 = call i32 @pthread_mutex_unlock(ptr noundef %50) #4
  ret void
}

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


; 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
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_message_push(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %4, label %3

3:                                                ; preds = %2
  tail call void @agoo_text_ref(ptr noundef nonnull %1) #3
  br label %4

4:                                                ; preds = %3, %2
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull %5) #3
  %7 = getelementptr inbounds i8, ptr %0, i64 64
  %8 = load volatile i8, ptr %7, align 8, !tbaa !5, !range !12, !noundef !13
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %21, label %10

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load volatile ptr, ptr %11, align 8, !tbaa !14
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  store volatile ptr %1, ptr %11, align 8, !tbaa !14
  br label %20

15:                                               ; preds = %10
  %16 = load volatile ptr, ptr %11, align 8, !tbaa !14
  br label %17

17:                                               ; preds = %17, %15
  %.0 = phi ptr [ %16, %15 ], [ %18, %17 ]
  %18 = load ptr, ptr %.0, align 8, !tbaa !15
  %.not16 = icmp eq ptr %18, null
  br i1 %.not16, label %19, label %17, !llvm.loop !19

19:                                               ; preds = %17
  store ptr %1, ptr %.0, align 8, !tbaa !15
  br label %20

20:                                               ; preds = %19, %14
  store volatile i8 1, ptr %7, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %20, %4
  %22 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull %5) #3
  ret void
}

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


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