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

; 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._agooLog = type { ptr, [1024 x i8], [16 x i8], ptr, i32, i32, i64, i64, i8, i8, i8, i8, i8, i32, i64, i64, [16 x i8], ptr, ptr, %struct._agooAtom, %struct._agooAtom, %struct._agooAtom, %struct._agooAtom, i32, i32, ptr }
%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 }
%struct._agooLogCat = type { ptr, [32 x i8], ptr, i32, i8 }

@agoo_log = external dso_local global %struct._agooLog, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @find_color(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @agoo_log_cat_reg(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i1 noundef zeroext %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %12 = zext i1 %4 to i8
  store i8 %12, ptr %10, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = call ptr @agoo_log_cat_find(ptr noundef %13)
  store ptr %14, ptr %11, align 8, !tbaa !5
  %15 = load ptr, ptr %11, align 8, !tbaa !5
  %16 = icmp ne ptr null, %15
  br i1 %16, label %17, label %19

17:                                               ; preds = %5
  %18 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %18, ptr %6, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %17, %5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._agooLogCat, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds [32 x i8], ptr %21, i64 0, i64 0
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = call ptr @strncpy(ptr noundef %22, ptr noundef %23, i64 noundef 32) #3
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._agooLogCat, ptr %25, i32 0, i32 1
  %27 = getelementptr inbounds [32 x i8], ptr %26, i64 0, i64 31
  store i8 0, ptr %27, align 1, !tbaa !13
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._agooLogCat, ptr %29, i32 0, i32 3
  store i32 %28, ptr %30, align 8, !tbaa !14
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = call ptr @find_color(ptr noundef %31)
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._agooLogCat, ptr %33, i32 0, i32 2
  store ptr %32, ptr %34, align 8, !tbaa !16
  %35 = load i8, ptr %10, align 1, !tbaa !11, !range !17, !noundef !18
  %36 = trunc i8 %35 to i1
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._agooLogCat, ptr %37, i32 0, i32 4
  %39 = zext i1 %36 to i8
  store i8 %39, ptr %38, align 4, !tbaa !19
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = icmp eq ptr null, %40
  br i1 %41, label %42, label %47

42:                                               ; preds = %19
  %43 = load ptr, ptr @agoo_log, align 8, !tbaa !20
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._agooLogCat, ptr %44, i32 0, i32 0
  store ptr %43, ptr %45, align 8, !tbaa !24
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %46, ptr @agoo_log, align 8, !tbaa !20
  br label %47

47:                                               ; preds = %42, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @agoo_log_cat_find(ptr noundef) #0

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #2

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 }

!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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 48}
!15 = !{!"_agooLogCat", !6, i64 0, !7, i64 8, !6, i64 40, !10, i64 48, !12, i64 52}
!16 = !{!15, !6, i64 40}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!15, !12, i64 52}
!20 = !{!21, !6, i64 0}
!21 = !{!"_agooLog", !6, i64 0, !7, i64 8, !7, i64 1032, !6, i64 1048, !10, i64 1056, !10, i64 1060, !22, i64 1064, !22, i64 1072, !12, i64 1080, !12, i64 1081, !12, i64 1082, !12, i64 1083, !12, i64 1084, !10, i64 1088, !22, i64 1096, !22, i64 1104, !7, i64 1112, !6, i64 1128, !6, i64 1136, !23, i64 1144, !23, i64 1192, !23, i64 1240, !23, i64 1288, !10, i64 1336, !10, i64 1340, !6, i64 1344}
!22 = !{!"long", !7, i64 0}
!23 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!24 = !{!15, !6, i64 0}


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

%struct._agooLog = type { ptr, [1024 x i8], [16 x i8], ptr, i32, i32, i64, i64, i8, i8, i8, i8, i8, i32, i64, i64, [16 x i8], ptr, ptr, %struct._agooAtom, %struct._agooAtom, %struct._agooAtom, %struct._agooAtom, i32, i32, ptr }
%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 }

@agoo_log = external dso_local local_unnamed_addr global %struct._agooLog, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @find_color(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @agoo_log_cat_reg(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i1 noundef zeroext %4) local_unnamed_addr #0 {
  %6 = zext i1 %4 to i8
  %7 = tail call ptr @agoo_log_cat_find(ptr noundef %1)
  %.not = icmp eq ptr %7, null
  %spec.select = select i1 %.not, ptr %0, ptr %7
  %8 = getelementptr inbounds i8, ptr %spec.select, i64 8
  %9 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %8, ptr noundef nonnull dereferenceable(1) %1, i64 noundef 32) #2
  %10 = getelementptr inbounds i8, ptr %spec.select, i64 39
  store i8 0, ptr %10, align 1, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %spec.select, i64 48
  store i32 %2, ptr %11, align 8, !tbaa !8
  %12 = tail call ptr @find_color(ptr noundef %3)
  %13 = getelementptr inbounds i8, ptr %spec.select, i64 40
  store ptr %12, ptr %13, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %spec.select, i64 52
  store i8 %6, ptr %14, align 4, !tbaa !14
  br i1 %.not, label %15, label %17

15:                                               ; preds = %5
  %16 = load ptr, ptr @agoo_log, align 8, !tbaa !15
  store ptr %16, ptr %0, align 8, !tbaa !19
  store ptr %0, ptr @agoo_log, align 8, !tbaa !15
  br label %17

17:                                               ; preds = %15, %5
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @agoo_log_cat_find(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !11, i64 48}
!9 = !{!"_agooLogCat", !10, i64 0, !6, i64 8, !10, i64 40, !11, i64 48, !12, i64 52}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"_Bool", !6, i64 0}
!13 = !{!9, !10, i64 40}
!14 = !{!9, !12, i64 52}
!15 = !{!16, !10, i64 0}
!16 = !{!"_agooLog", !10, i64 0, !6, i64 8, !6, i64 1032, !10, i64 1048, !11, i64 1056, !11, i64 1060, !17, i64 1064, !17, i64 1072, !12, i64 1080, !12, i64 1081, !12, i64 1082, !12, i64 1083, !12, i64 1084, !11, i64 1088, !17, i64 1096, !17, i64 1104, !6, i64 1112, !10, i64 1128, !10, i64 1136, !18, i64 1144, !18, i64 1192, !18, i64 1240, !18, i64 1288, !11, i64 1336, !11, i64 1340, !10, i64 1344}
!17 = !{!"long", !6, i64 0}
!18 = !{!"_agooAtom", !10, i64 0, !6, i64 8}
!19 = !{!9, !10, i64 0}


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