; 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

declare i32 @fclose(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @agoo_log_close() #1 {
  store volatile i8 1, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 8), align 8, !tbaa !5
  call void @agoo_log_cat_on(ptr noundef null, i1 noundef zeroext false)
  %1 = load i64, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 7), align 8, !tbaa !14
  %2 = icmp ne i64 0, %1
  br i1 %2, label %3, label %6

3:                                                ; preds = %0
  %4 = load i64, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 7), align 8, !tbaa !14
  %5 = call i32 @pthread_join(i64 noundef %4, ptr noundef null)
  store i64 0, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 7), align 8, !tbaa !14
  br label %6

6:                                                ; preds = %3, %0
  %7 = load ptr, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 3), align 8, !tbaa !15
  %8 = icmp ne ptr null, %7
  br i1 %8, label %9, label %12

9:                                                ; preds = %6
  %10 = load ptr, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 3), align 8, !tbaa !15
  %11 = call i32 @fclose(ptr noundef %10)
  store ptr null, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 3), align 8, !tbaa !15
  br label %12

12:                                               ; preds = %9, %6
  %13 = load ptr, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 17), align 8, !tbaa !16
  %14 = icmp ne ptr null, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %12
  %16 = load ptr, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 17), align 8, !tbaa !16
  call void @free(ptr noundef %16) #3
  store ptr null, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 17), align 8, !tbaa !16
  store ptr null, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 18), align 8, !tbaa !17
  br label %17

17:                                               ; preds = %15, %12
  %18 = load i32, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 24), align 4, !tbaa !18
  %19 = icmp slt i32 0, %18
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  %21 = load i32, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 24), align 4, !tbaa !18
  %22 = call i32 @close(i32 noundef %21)
  store i32 0, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 24), align 4, !tbaa !18
  br label %23

23:                                               ; preds = %20, %17
  %24 = load i32, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 23), align 8, !tbaa !19
  %25 = icmp slt i32 0, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %23
  %27 = load i32, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 23), align 8, !tbaa !19
  %28 = call i32 @close(i32 noundef %27)
  store i32 0, ptr getelementptr inbounds (%struct._agooLog, ptr @agoo_log, i32 0, i32 23), align 8, !tbaa !19
  br label %29

29:                                               ; preds = %26, %23
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @agoo_log_cat_on(ptr noundef, i1 noundef zeroext) #1

declare i32 @pthread_join(i64 noundef, ptr noundef) #0

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

declare i32 @close(i32 noundef) #0

attributes #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 = { 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 = { 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 = !{!6, !11, i64 1072}
!15 = !{!6, !7, i64 1048}
!16 = !{!6, !7, i64 1128}
!17 = !{!6, !7, i64 1136}
!18 = !{!6, !10, i64 1340}
!19 = !{!6, !10, i64 1336}


; 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: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @agoo_log_close() local_unnamed_addr #1 {
  store volatile i8 1, ptr getelementptr inbounds (i8, ptr @agoo_log, i64 1080), align 8, !tbaa !5
  tail call void @agoo_log_cat_on(ptr noundef null, i1 noundef zeroext false)
  %1 = load i64, ptr getelementptr inbounds (i8, ptr @agoo_log, i64 1072), align 8, !tbaa !14
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %4, label %2

2:                                                ; preds = %0
  %3 = tail call i32 @pthread_join(i64 noundef %1, ptr noundef null) #5
  store i64 0, ptr getelementptr inbounds (i8, ptr @agoo_log, i64 1072), align 8, !tbaa !14
  br label %4

4:                                                ; preds = %2, %0
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @agoo_log, i64 1048), align 8, !tbaa !15
  %.not5 = icmp eq ptr %5, null
  br i1 %.not5, label %8, label %6

6:                                                ; preds = %4
  %7 = tail call i32 @fclose(ptr noundef nonnull %5)
  store ptr null, ptr getelementptr inbounds (i8, ptr @agoo_log, i64 1048), align 8, !tbaa !15
  br label %8

8:                                                ; preds = %6, %4
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @agoo_log, i64 1128), align 8, !tbaa !16
  %.not6 = icmp eq ptr %9, null
  br i1 %.not6, label %11, label %10

10:                                               ; preds = %8
  tail call void @free(ptr noundef nonnull %9) #5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) getelementptr inbounds (i8, ptr @agoo_log, i64 1128), i8 0, i64 16, i1 false)
  br label %11

11:                                               ; preds = %10, %8
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @agoo_log, i64 1340), align 4, !tbaa !17
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  %15 = tail call i32 @close(i32 noundef %12) #5
  store i32 0, ptr getelementptr inbounds (i8, ptr @agoo_log, i64 1340), align 4, !tbaa !17
  br label %16

16:                                               ; preds = %14, %11
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @agoo_log, i64 1336), align 8, !tbaa !18
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %16
  %20 = tail call i32 @close(i32 noundef %17) #5
  store i32 0, ptr getelementptr inbounds (i8, ptr @agoo_log, i64 1336), align 8, !tbaa !18
  br label %21

21:                                               ; preds = %19, %16
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @agoo_log_cat_on(ptr noundef, i1 noundef zeroext) local_unnamed_addr #1

declare i32 @pthread_join(i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

declare i32 @close(i32 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { 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 #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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = !{!6, !11, i64 1072}
!15 = !{!6, !7, i64 1048}
!16 = !{!6, !7, i64 1128}
!17 = !{!6, !10, i64 1340}
!18 = !{!6, !10, i64 1336}


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