; LLVM IR from kala13x/libxutils :: src/sys (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.XLog = type { %struct.XSyncMutex, %struct.XLogFile, %struct.XLogConfig }
%struct.XSyncMutex = type { %union.pthread_mutex_t, 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.XLogFile = type { [2368 x i8], i8, ptr }
%struct.XLogConfig = type { i32, i32, ptr, ptr, i8, i8, i8, i8, i8, i8, i8, i8, i16, [256 x i8], [2048 x i8], [256 x i8] }

@g_bInit = external hidden global i32, align 4
@g_xlog = external hidden global %struct.XLog, align 8

declare void @XSync_Lock(ptr noundef) #0

declare void @XSync_Unlock(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @XLog_CloseFile(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @XLog_Destroy() #1 {
  call void @XSync_Lock(ptr noundef @g_xlog)
  call void @XLog_CloseFile(ptr noundef getelementptr inbounds (%struct.XLog, ptr @g_xlog, i32 0, i32 1))
  call void @llvm.memset.p0.i64(ptr align 8 getelementptr inbounds (%struct.XLog, ptr @g_xlog, i32 0, i32 2), i8 0, i64 2600, i1 false)
  store ptr null, ptr getelementptr inbounds (%struct.XLogConfig, ptr getelementptr inbounds (%struct.XLog, ptr @g_xlog, i32 0, i32 2), i32 0, i32 2), align 8, !tbaa !5
  store ptr null, ptr getelementptr inbounds (%struct.XLogConfig, ptr getelementptr inbounds (%struct.XLog, ptr @g_xlog, i32 0, i32 2), i32 0, i32 3), align 8, !tbaa !15
  call void @XSync_Unlock(ptr noundef @g_xlog)
  call void @XSync_Destroy(ptr noundef @g_xlog)
  store volatile i32 0, ptr @g_bInit, align 4, !tbaa !16
  ret void
}

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

declare void @XSync_Destroy(ptr 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !11, i64 2440}
!6 = !{!"XLog", !7, i64 0, !10, i64 48, !12, i64 2432}
!7 = !{!"XSyncMutex", !8, i64 0, !8, i64 40}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"XLogFile", !8, i64 0, !8, i64 2368, !11, i64 2376}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"XLogConfig", !13, i64 0, !13, i64 4, !11, i64 8, !11, i64 16, !8, i64 24, !8, i64 25, !8, i64 26, !8, i64 27, !8, i64 28, !8, i64 29, !8, i64 30, !8, i64 31, !14, i64 32, !8, i64 34, !8, i64 290, !8, i64 2338}
!13 = !{!"int", !8, i64 0}
!14 = !{!"short", !8, i64 0}
!15 = !{!6, !11, i64 2448}
!16 = !{!13, !13, 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.XLog = type { %struct.XSyncMutex, %struct.XLogFile, %struct.XLogConfig }
%struct.XSyncMutex = type { %union.pthread_mutex_t, 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.XLogFile = type { [2368 x i8], i8, ptr }
%struct.XLogConfig = type { i32, i32, ptr, ptr, i8, i8, i8, i8, i8, i8, i8, i8, i16, [256 x i8], [2048 x i8], [256 x i8] }

@g_bInit = external hidden global i32, align 4
@g_xlog = external hidden global %struct.XLog, align 8

declare void @XSync_Lock(ptr noundef) local_unnamed_addr #0

declare void @XSync_Unlock(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @XLog_CloseFile(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @XLog_Destroy() local_unnamed_addr #1 {
  tail call void @XSync_Lock(ptr noundef nonnull @g_xlog) #3
  tail call void @XLog_CloseFile(ptr noundef nonnull getelementptr inbounds (i8, ptr @g_xlog, i64 48))
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(2600) getelementptr inbounds (i8, ptr @g_xlog, i64 2432), i8 0, i64 2600, i1 false)
  tail call void @XSync_Unlock(ptr noundef nonnull @g_xlog) #3
  tail call void @XSync_Destroy(ptr noundef nonnull @g_xlog) #3
  store volatile i32 0, ptr @g_bInit, align 4, !tbaa !5
  ret void
}

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

declare void @XSync_Destroy(ptr noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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