; 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] }
%struct.XLogCtx = type { ptr, i32, i8, i32, %struct.XTime }
%struct.XTime = type { i16, i8, i8, i8, i8, i8, i8 }
%struct.__va_list_tag = type { i32, i32, ptr, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local void @XLog_Display(i32 noundef %0, i8 noundef zeroext %1, ptr noundef %2, ...) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.XLogCtx, align 8
  %9 = alloca ptr, align 8
  %10 = alloca [1 x %struct.__va_list_tag], align 16
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !10
  %11 = load volatile i32, ptr @g_bInit, align 4, !tbaa !5
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %14, label %13

13:                                               ; preds = %3
  br label %54

14:                                               ; preds = %3
  call void @XSync_Lock(ptr noundef @g_xlog)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr getelementptr inbounds (%struct.XLog, ptr @g_xlog, i32 0, i32 2), ptr %7, align 8, !tbaa !10
  %15 = load i16, ptr getelementptr inbounds (%struct.XLogConfig, ptr getelementptr inbounds (%struct.XLog, ptr @g_xlog, i32 0, i32 2), i32 0, i32 12), align 8, !tbaa !12
  %16 = zext i16 %15 to i32
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = and i32 %16, %17
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp eq i32 %18, %19
  br i1 %20, label %21, label %53

21:                                               ; preds = %14
  %22 = load ptr, ptr getelementptr inbounds (%struct.XLogConfig, ptr getelementptr inbounds (%struct.XLog, ptr @g_xlog, i32 0, i32 2), i32 0, i32 2), align 8, !tbaa !18
  %23 = icmp ne ptr %22, null
  br i1 %23, label %32, label %24

24:                                               ; preds = %21
  %25 = load i8, ptr getelementptr inbounds (%struct.XLogConfig, ptr getelementptr inbounds (%struct.XLog, ptr @g_xlog, i32 0, i32 2), i32 0, i32 5), align 1, !tbaa !19
  %26 = zext i8 %25 to i32
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %32, label %28

28:                                               ; preds = %24
  %29 = load i8, ptr getelementptr inbounds (%struct.XLogConfig, ptr getelementptr inbounds (%struct.XLog, ptr @g_xlog, i32 0, i32 2), i32 0, i32 9), align 1, !tbaa !20
  %30 = zext i8 %29 to i32
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %53

32:                                               ; preds = %28, %24, %21
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #4
  %33 = getelementptr inbounds %struct.XLogCtx, ptr %8, i32 0, i32 4
  %34 = call i32 @XTime_Get(ptr noundef %33)
  %35 = getelementptr inbounds %struct.XLogCtx, ptr %8, i32 0, i32 3
  store i32 %34, ptr %35, align 8, !tbaa !21
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = getelementptr inbounds %struct.XLogCtx, ptr %8, i32 0, i32 1
  store i32 %36, ptr %37, align 8, !tbaa !24
  %38 = load ptr, ptr %6, align 8, !tbaa !10
  %39 = getelementptr inbounds %struct.XLogCtx, ptr %8, i32 0, i32 0
  store ptr %38, ptr %39, align 8, !tbaa !25
  %40 = load i8, ptr %5, align 1, !tbaa !9
  %41 = getelementptr inbounds %struct.XLogCtx, ptr %8, i32 0, i32 2
  store i8 %40, ptr %41, align 4, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %42 = load ptr, ptr %7, align 8, !tbaa !10
  %43 = getelementptr inbounds %struct.XLogConfig, ptr %42, i32 0, i32 7
  %44 = load i8, ptr %43, align 1, !tbaa !27
  %45 = zext i8 %44 to i32
  %46 = icmp ne i32 %45, 0
  %47 = zext i1 %46 to i64
  %48 = select i1 %46, ptr @XLog_DisplayHeap, ptr @XLog_DisplayStack
  store ptr %48, ptr %9, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #4
  %49 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %10, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %49)
  %50 = load ptr, ptr %9, align 8, !tbaa !10
  %51 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %10, i64 0, i64 0
  call void %50(ptr noundef %8, ptr noundef %51)
  %52 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %10, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %52)
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  br label %53

53:                                               ; preds = %32, %28, %14
  call void @XSync_Unlock(ptr noundef @g_xlog)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %54

54:                                               ; preds = %53, %13
  ret void
}

declare void @XSync_Lock(ptr noundef) #1

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

declare i32 @XTime_Get(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @XLog_DisplayHeap(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @XLog_DisplayStack(ptr noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #3

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

declare void @XSync_Unlock(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" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !17, i64 2464}
!13 = !{!"XLog", !14, i64 0, !15, i64 48, !16, i64 2432}
!14 = !{!"XSyncMutex", !7, i64 0, !7, i64 40}
!15 = !{!"XLogFile", !7, i64 0, !7, i64 2368, !11, i64 2376}
!16 = !{!"XLogConfig", !6, i64 0, !6, i64 4, !11, i64 8, !11, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !7, i64 28, !7, i64 29, !7, i64 30, !7, i64 31, !17, i64 32, !7, i64 34, !7, i64 290, !7, i64 2338}
!17 = !{!"short", !7, i64 0}
!18 = !{!13, !11, i64 2440}
!19 = !{!13, !7, i64 2457}
!20 = !{!13, !7, i64 2461}
!21 = !{!22, !6, i64 16}
!22 = !{!"XLogCtx", !11, i64 0, !6, i64 8, !7, i64 12, !6, i64 16, !23, i64 20}
!23 = !{!"XTime", !17, i64 0, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7}
!24 = !{!22, !6, i64 8}
!25 = !{!22, !11, i64 0}
!26 = !{!22, !7, i64 12}
!27 = !{!16, !7, i64 27}


; 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] }
%struct.XLogCtx = type { ptr, i32, i8, i32, %struct.XTime }
%struct.XTime = type { i16, i8, i8, i8, i8, i8, i8 }
%struct.__va_list_tag = type { i32, i32, ptr, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local void @XLog_Display(i32 noundef %0, i8 noundef zeroext %1, ptr noundef %2, ...) local_unnamed_addr #0 {
  %4 = alloca %struct.XLogCtx, align 8
  %5 = alloca [1 x %struct.__va_list_tag], align 16
  %6 = load volatile i32, ptr @g_bInit, align 4, !tbaa !5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %28, label %7

7:                                                ; preds = %3
  tail call void @XSync_Lock(ptr noundef nonnull @g_xlog) #4
  %8 = load i16, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 2464), align 8, !tbaa !9
  %9 = zext i16 %8 to i32
  %10 = and i32 %9, %0
  %11 = icmp eq i32 %10, %0
  br i1 %11, label %12, label %27

12:                                               ; preds = %7
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 2440), align 8, !tbaa !16
  %14 = icmp ne ptr %13, null
  %15 = load i8, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 2457), align 1
  %16 = icmp ne i8 %15, 0
  %or.cond = select i1 %14, i1 true, i1 %16
  %17 = load i8, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 2461), align 1
  %18 = icmp ne i8 %17, 0
  %or.cond5 = select i1 %or.cond, i1 true, i1 %18
  br i1 %or.cond5, label %19, label %27

19:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  %20 = getelementptr inbounds i8, ptr %4, i64 20
  %21 = call i32 @XTime_Get(ptr noundef nonnull %20) #4
  %22 = getelementptr inbounds i8, ptr %4, i64 16
  store i32 %21, ptr %22, align 8, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %0, ptr %23, align 8, !tbaa !20
  store ptr %2, ptr %4, align 8, !tbaa !21
  %24 = getelementptr inbounds i8, ptr %4, i64 12
  store i8 %1, ptr %24, align 4, !tbaa !22
  %25 = load i8, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 2459), align 1, !tbaa !23
  %.not11 = icmp eq i8 %25, 0
  %26 = select i1 %.not11, ptr @XLog_DisplayStack, ptr @XLog_DisplayHeap
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #4
  call void @llvm.va_start.p0(ptr nonnull %5)
  call void %26(ptr noundef nonnull %4, ptr noundef nonnull %5) #4, !callees !24
  call void @llvm.va_end.p0(ptr nonnull %5)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  br label %27

27:                                               ; preds = %12, %19, %7
  call void @XSync_Unlock(ptr noundef nonnull @g_xlog) #4
  br label %28

28:                                               ; preds = %3, %27
  ret void
}

declare void @XSync_Lock(ptr noundef) local_unnamed_addr #1

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

declare i32 @XTime_Get(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @XLog_DisplayHeap(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @XLog_DisplayStack(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #3

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

declare void @XSync_Unlock(ptr 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 = { "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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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"}
!9 = !{!10, !15, i64 2464}
!10 = !{!"XLog", !11, i64 0, !12, i64 48, !14, i64 2432}
!11 = !{!"XSyncMutex", !7, i64 0, !7, i64 40}
!12 = !{!"XLogFile", !7, i64 0, !7, i64 2368, !13, i64 2376}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"XLogConfig", !6, i64 0, !6, i64 4, !13, i64 8, !13, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !7, i64 28, !7, i64 29, !7, i64 30, !7, i64 31, !15, i64 32, !7, i64 34, !7, i64 290, !7, i64 2338}
!15 = !{!"short", !7, i64 0}
!16 = !{!10, !13, i64 2440}
!17 = !{!18, !6, i64 16}
!18 = !{!"XLogCtx", !13, i64 0, !6, i64 8, !7, i64 12, !6, i64 16, !19, i64 20}
!19 = !{!"XTime", !15, i64 0, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7}
!20 = !{!18, !6, i64 8}
!21 = !{!18, !13, i64 0}
!22 = !{!18, !7, i64 12}
!23 = !{!14, !7, i64 27}
!24 = !{ptr @XLog_DisplayHeap, ptr @XLog_DisplayStack}


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