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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @agoo_log_flush(double noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca double, align 8
  store double %0, ptr %3, align 8, !tbaa !5
  %4 = call double @dtime()
  %5 = load double, ptr %3, align 8, !tbaa !5
  %6 = fadd double %5, %4
  store double %6, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %20, %1
  %8 = load volatile i8, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 8), align 8, !tbaa !9, !range !16, !noundef !17
  %9 = trunc i8 %8 to i1
  br i1 %9, label %13, label %10

10:                                               ; preds = %7
  %11 = call zeroext i1 @agoo_log_queue_empty()
  %12 = xor i1 %11, true
  br label %13

13:                                               ; preds = %10, %7
  %14 = phi i1 [ false, %7 ], [ %12, %10 ]
  br i1 %14, label %15, label %22

15:                                               ; preds = %13
  %16 = load double, ptr %3, align 8, !tbaa !5
  %17 = call double @dtime()
  %18 = fcmp olt double %16, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  store i1 false, ptr %2, align 1
  br label %29

20:                                               ; preds = %15
  %21 = call double @dsleep(double noundef 1.000000e-03)
  br label %7, !llvm.loop !18

22:                                               ; preds = %13
  %23 = load ptr, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 3), align 8, !tbaa !20
  %24 = icmp ne ptr null, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %22
  %26 = load ptr, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 3), align 8, !tbaa !20
  %27 = call i32 @fflush(ptr noundef %26)
  br label %28

28:                                               ; preds = %25, %22
  store i1 true, ptr %2, align 1
  br label %29

29:                                               ; preds = %28, %19
  %30 = load i1, ptr %2, align 1
  ret i1 %30
}

declare double @dtime() #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @agoo_log_queue_empty() #0

declare double @dsleep(double noundef) #1

declare i32 @fflush(ptr noundef) #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 = { "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" }

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


; 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 global %struct._agooLog, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @agoo_log_flush(double noundef %0) local_unnamed_addr #0 {
  %2 = tail call double @dtime() #3
  %3 = fadd double %2, %0
  %4 = load volatile i8, ptr getelementptr inbounds (i8, ptr @agoo_log, i64 1080), align 8, !tbaa !5, !range !14, !noundef !15
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %10
  %6 = tail call zeroext i1 @agoo_log_queue_empty()
  br i1 %6, label %.critedge, label %7

7:                                                ; preds = %.lr.ph
  %8 = tail call double @dtime() #3
  %9 = fcmp olt double %3, %8
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %7
  %11 = tail call double @dsleep(double noundef 1.000000e-03) #3
  %12 = load volatile i8, ptr getelementptr inbounds (i8, ptr @agoo_log, i64 1080), align 8, !tbaa !5, !range !14, !noundef !15
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %.critedge, label %.lr.ph, !llvm.loop !16

.critedge:                                        ; preds = %.lr.ph, %10, %1
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @agoo_log, i64 1048), align 8, !tbaa !18
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %.loopexit, label %15

15:                                               ; preds = %.critedge
  %16 = tail call i32 @fflush(ptr noundef nonnull %14)
  br label %.loopexit

.loopexit:                                        ; preds = %7, %.critedge, %15
  %.0 = phi i1 [ true, %15 ], [ true, %.critedge ], [ false, %7 ]
  ret i1 %.0
}

declare double @dtime() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @agoo_log_queue_empty() local_unnamed_addr #0

declare double @dsleep(double noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #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 = { "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 = { nofree 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, !12, i64 1080}
!6 = !{!"_agooLog", !7, i64 0, !8, i64 8, !8, i64 1032, !7, i64 1048, !10, i64 1056, !10, i64 1060, !11, i64 1064, !11, i64 1072, !12, i64 1080, !12, i64 1081, !12, i64 1082, !12, i64 1083, !12, i64 1084, !10, i64 1088, !11, i64 1096, !11, i64 1104, !8, i64 1112, !7, i64 1128, !7, i64 1136, !13, i64 1144, !13, i64 1192, !13, i64 1240, !13, i64 1288, !10, i64 1336, !10, i64 1340, !7, i64 1344}
!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 = !{!"_Bool", !8, i64 0}
!13 = !{!"_agooAtom", !7, i64 0, !8, i64 8}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !7, i64 1048}


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