; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcasecmp(ptr noundef, 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_log_cat_on(ptr noundef %0, i1 noundef zeroext %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = zext i1 %1 to i8
  store i8 %6, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = load ptr, ptr @agoo_log, align 8, !tbaa !11
  store ptr %7, ptr %5, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %28, %2
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp ne ptr null, %9
  br i1 %10, label %11, label %32

11:                                               ; preds = %8
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp eq ptr null, %12
  br i1 %13, label %21, label %14

14:                                               ; preds = %11
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._agooLogCat, ptr %16, i32 0, i32 1
  %18 = getelementptr inbounds [32 x i8], ptr %17, i64 0, i64 0
  %19 = call i32 @strcasecmp(ptr noundef %15, ptr noundef %18) #4
  %20 = icmp eq i32 0, %19
  br i1 %20, label %21, label %27

21:                                               ; preds = %14, %11
  %22 = load i8, ptr %4, align 1, !tbaa !9, !range !16, !noundef !17
  %23 = trunc i8 %22 to i1
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._agooLogCat, ptr %24, i32 0, i32 4
  %26 = zext i1 %23 to i8
  store i8 %26, ptr %25, align 4, !tbaa !18
  br label %32

27:                                               ; preds = %14
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._agooLogCat, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !20
  store ptr %31, ptr %5, align 8, !tbaa !5
  br label %8, !llvm.loop !21

32:                                               ; preds = %21, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

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

%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: mustprogress nofree nounwind willreturn memory(read)
declare i32 @strcasecmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind memory(readwrite, inaccessiblemem: read) uwtable
define dso_local void @agoo_log_cat_on(ptr noundef readonly %0, i1 noundef zeroext %1) local_unnamed_addr #1 {
  %3 = zext i1 %1 to i8
  %4 = icmp eq ptr %0, null
  br i1 %4, label %.split.us, label %.split

.split.us:                                        ; preds = %2
  %.0.us = load ptr, ptr @agoo_log, align 8, !tbaa !5
  %.not.us = icmp eq ptr %.0.us, null
  br i1 %.not.us, label %.loopexit, label %.split9.us

.split:                                           ; preds = %2, %5
  %.0.in = phi ptr [ %.0, %5 ], [ @agoo_log, %2 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.loopexit, label %5

5:                                                ; preds = %.split
  %6 = getelementptr inbounds i8, ptr %.0, i64 8
  %7 = tail call i32 @strcasecmp(ptr noundef nonnull %0, ptr noundef nonnull %6) #2
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %.split9.us, label %.split, !llvm.loop !9

.split9.us:                                       ; preds = %5, %.split.us
  %.us-phi = phi ptr [ %.0.us, %.split.us ], [ %.0, %5 ]
  %9 = getelementptr inbounds i8, ptr %.us-phi, i64 52
  store i8 %3, ptr %9, align 4, !tbaa !11
  br label %.loopexit

.loopexit:                                        ; preds = %.split, %.split.us, %.split9.us
  ret void
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(read) "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 = { nofree nounwind memory(readwrite, inaccessiblemem: read) 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 = { nounwind willreturn memory(read) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !14, i64 52}
!12 = !{!"_agooLogCat", !6, i64 0, !7, i64 8, !6, i64 40, !13, i64 48, !14, i64 52}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}


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