; 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
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1

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

; 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 @XLog_Init(ptr noundef %0, i16 noundef zeroext %1, i8 noundef zeroext %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !11
  %10 = load volatile i32, ptr @g_bInit, align 4, !tbaa !12
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  br label %77

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr getelementptr inbounds (%struct.XLog, ptr @g_xlog, i32 0, i32 1), ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr getelementptr inbounds (%struct.XLog, ptr @g_xlog, i32 0, i32 2), ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.XLogConfig, ptr %14, i32 0, i32 0
  store i32 1, ptr %15, align 8, !tbaa !14
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.XLogConfig, ptr %16, i32 0, i32 1
  store i32 0, ptr %17, align 4, !tbaa !16
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.XLogConfig, ptr %18, i32 0, i32 3
  store ptr null, ptr %19, align 8, !tbaa !17
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.XLogConfig, ptr %20, i32 0, i32 2
  store ptr null, ptr %21, align 8, !tbaa !18
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.XLogConfig, ptr %22, i32 0, i32 15
  %24 = getelementptr inbounds [256 x i8], ptr %23, i64 0, i64 0
  store i8 32, ptr %24, align 2, !tbaa !11
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.XLogConfig, ptr %25, i32 0, i32 15
  %27 = getelementptr inbounds [256 x i8], ptr %26, i64 0, i64 1
  store i8 0, ptr %27, align 1, !tbaa !11
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.XLogConfig, ptr %28, i32 0, i32 14
  %30 = getelementptr inbounds [2048 x i8], ptr %29, i64 0, i64 0
  store i8 46, ptr %30, align 2, !tbaa !11
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.XLogConfig, ptr %31, i32 0, i32 14
  %33 = getelementptr inbounds [2048 x i8], ptr %32, i64 0, i64 1
  store i8 0, ptr %33, align 1, !tbaa !11
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.XLogConfig, ptr %34, i32 0, i32 4
  store i8 0, ptr %35, align 8, !tbaa !19
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.XLogConfig, ptr %36, i32 0, i32 5
  store i8 1, ptr %37, align 1, !tbaa !20
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.XLogConfig, ptr %38, i32 0, i32 6
  store i8 1, ptr %39, align 2, !tbaa !21
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.XLogConfig, ptr %40, i32 0, i32 7
  store i8 0, ptr %41, align 1, !tbaa !22
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.XLogConfig, ptr %42, i32 0, i32 9
  store i8 0, ptr %43, align 1, !tbaa !23
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.XLogConfig, ptr %44, i32 0, i32 10
  store i8 0, ptr %45, align 2, !tbaa !24
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.XLogConfig, ptr %46, i32 0, i32 8
  store i8 1, ptr %47, align 4, !tbaa !25
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.XLogConfig, ptr %48, i32 0, i32 11
  store i8 0, ptr %49, align 1, !tbaa !26
  %50 = load i16, ptr %5, align 2, !tbaa !9
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.XLogConfig, ptr %51, i32 0, i32 12
  store i16 %50, ptr %52, align 8, !tbaa !27
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %57

55:                                               ; preds = %13
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  br label %58

57:                                               ; preds = %13
  br label %58

58:                                               ; preds = %57, %55
  %59 = phi ptr [ %56, %55 ], [ @.str.3, %57 ]
  store ptr %59, ptr %9, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.XLogConfig, ptr %60, i32 0, i32 13
  %62 = getelementptr inbounds [256 x i8], ptr %61, i64 0, i64 0
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %62, i64 noundef 256, ptr noundef @.str, ptr noundef %63)
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.XLogFile, ptr %65, i32 0, i32 0
  %67 = getelementptr inbounds [2368 x i8], ptr %66, i64 0, i64 0
  store i8 0, ptr %67, align 8, !tbaa !11
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.XLogFile, ptr %68, i32 0, i32 2
  store ptr null, ptr %69, align 8, !tbaa !28
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.XLogFile, ptr %70, i32 0, i32 1
  store i8 0, ptr %71, align 8, !tbaa !30
  %72 = load i8, ptr %6, align 1, !tbaa !11
  %73 = icmp ne i8 %72, 0
  br i1 %73, label %74, label %75

74:                                               ; preds = %58
  call void @XSync_Init(ptr noundef @g_xlog)
  br label %76

75:                                               ; preds = %58
  store i8 0, ptr getelementptr inbounds (%struct.XSyncMutex, ptr @g_xlog, i32 0, i32 1), align 8, !tbaa !31
  br label %76

76:                                               ; preds = %75, %74
  store volatile i32 1, ptr @g_bInit, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %77

77:                                               ; preds = %76, %12
  ret void
}

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) #2

declare void @XSync_Init(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"XLogConfig", !13, i64 0, !13, i64 4, !6, i64 8, !6, 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, !10, i64 32, !7, i64 34, !7, i64 290, !7, i64 2338}
!16 = !{!15, !13, i64 4}
!17 = !{!15, !6, i64 16}
!18 = !{!15, !6, i64 8}
!19 = !{!15, !7, i64 24}
!20 = !{!15, !7, i64 25}
!21 = !{!15, !7, i64 26}
!22 = !{!15, !7, i64 27}
!23 = !{!15, !7, i64 29}
!24 = !{!15, !7, i64 30}
!25 = !{!15, !7, i64 28}
!26 = !{!15, !7, i64 31}
!27 = !{!15, !10, i64 32}
!28 = !{!29, !6, i64 2376}
!29 = !{!"XLogFile", !7, i64 0, !7, i64 2368, !6, i64 2376}
!30 = !{!29, !7, i64 2368}
!31 = !{!32, !7, i64 40}
!32 = !{!"XLog", !33, i64 0, !29, i64 48, !15, i64 2432}
!33 = !{!"XSyncMutex", !7, i64 0, !7, i64 40}


; 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
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @XLog_Init(ptr noundef %0, i16 noundef zeroext %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = load volatile i32, ptr @g_bInit, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %11

5:                                                ; preds = %3
  store i32 1, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 2432), align 8, !tbaa !9
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(20) getelementptr inbounds (i8, ptr @g_xlog, i64 2436), i8 0, i64 20, i1 false)
  store i8 32, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 4770), align 2, !tbaa !13
  store i8 0, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 4771), align 1, !tbaa !13
  store i8 46, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 2722), align 2, !tbaa !13
  store i8 0, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 2723), align 1, !tbaa !13
  store <8 x i8> <i8 0, i8 1, i8 1, i8 0, i8 1, i8 0, i8 0, i8 0>, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 2456), align 8, !tbaa !13
  store i16 %1, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 2464), align 8, !tbaa !14
  %.not25 = icmp eq ptr %0, null
  %6 = select i1 %.not25, ptr @.str.3, ptr %0
  %7 = tail call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull getelementptr inbounds (i8, ptr @g_xlog, i64 2466), i64 noundef 256, ptr noundef nonnull @.str, ptr noundef nonnull %6) #3
  store i8 0, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 48), align 8, !tbaa !13
  store ptr null, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 2424), align 8, !tbaa !15
  store i8 0, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 2416), align 8, !tbaa !17
  %.not26 = icmp eq i8 %2, 0
  br i1 %.not26, label %9, label %8

8:                                                ; preds = %5
  tail call void @XSync_Init(ptr noundef nonnull @g_xlog) #3
  br label %10

9:                                                ; preds = %5
  store i8 0, ptr getelementptr inbounds (i8, ptr @g_xlog, i64 40), align 8, !tbaa !18
  br label %10

10:                                               ; preds = %9, %8
  store volatile i32 1, ptr @g_bInit, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %3, %10
  ret void
}

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #1

declare void @XSync_Init(ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { 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"}
!9 = !{!10, !6, i64 0}
!10 = !{!"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, !12, i64 32, !7, i64 34, !7, i64 290, !7, i64 2338}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!10, !12, i64 32}
!15 = !{!16, !11, i64 2376}
!16 = !{!"XLogFile", !7, i64 0, !7, i64 2368, !11, i64 2376}
!17 = !{!16, !7, i64 2368}
!18 = !{!19, !7, i64 40}
!19 = !{!"XLog", !20, i64 0, !16, i64 48, !10, i64 2432}
!20 = !{!"XSyncMutex", !7, i64 0, !7, i64 40}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass