; LLVM IR from kala13x/libxutils :: src/sys (mon)

; 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.XTopStats = type { i32, %struct.XSyncMutex, %struct.XCPUStats, %struct.XMemInfo, i32, %struct.XArray_, %struct.XTask, i32 }
%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.XCPUStats = type { [3 x i32], i16, %struct.XProcInfo, %struct.XCPUInfo, %struct.XArray_ }
%struct.XProcInfo = type { i32, i32, i64, i64, i64, i64, i64 }
%struct.XCPUInfo = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64 }
%struct.XMemInfo = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }
%struct.XArray_ = type { ptr, ptr, i32, ptr, i8, i8, i8, i64, i64 }
%struct.XTask = type { ptr, ptr, %struct.XThread, i32, i32, i32 }
%struct.XThread = type { ptr, ptr, i64, i32, i8, i8 }

@.str = external hidden unnamed_addr constant [9 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
declare dso_local i32 @XMon_UpdateStats(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XMon_StartMonitoring(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca [2048 x i8], align 16
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %24

12:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 2048, ptr %8) #3
  %13 = getelementptr inbounds [2048 x i8], ptr %8, i64 0, i64 0
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %13, i64 noundef 2048, ptr noundef @.str, i32 noundef %14)
  %16 = getelementptr inbounds [2048 x i8], ptr %8, i64 0, i64 0
  %17 = call zeroext i8 @XPath_Exists(ptr noundef %16)
  %18 = icmp ne i8 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %12
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %21

20:                                               ; preds = %12
  store i32 0, ptr %9, align 4
  br label %21

21:                                               ; preds = %20, %19
  call void @llvm.lifetime.end.p0(i64 2048, ptr %8) #3
  %22 = load i32, ptr %9, align 4
  switch i32 %22, label %43 [
    i32 0, label %23
    i32 1, label %41
  ]

23:                                               ; preds = %21
  br label %24

24:                                               ; preds = %23, %3
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.XTopStats, ptr %26, i32 0, i32 0
  store i32 %25, ptr %27, align 8, !tbaa !11
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.XTopStats, ptr %29, i32 0, i32 7
  store i32 %28, ptr %30, align 8, !tbaa !23
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.XTopStats, ptr %31, i32 0, i32 6
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = call i32 @XTask_Start(ptr noundef %32, ptr noundef @XMon_UpdateStats, ptr noundef %33, i32 noundef %34)
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.XTopStats, ptr %36, i32 0, i32 6
  %38 = getelementptr inbounds %struct.XTask, ptr %37, i32 0, i32 5
  %39 = atomicrmw add ptr %38, i32 0 seq_cst, align 8
  %40 = add i32 %39, 0
  store i32 %40, ptr %4, align 4
  br label %41

41:                                               ; preds = %24, %21
  %42 = load i32, ptr %4, align 4
  ret i32 %42

43:                                               ; preds = %21
  unreachable
}

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

declare zeroext i8 @XPath_Exists(ptr noundef) #2

declare i32 @XTask_Start(ptr noundef, ptr noundef, ptr noundef, i32 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"XTopStats", !10, i64 0, !13, i64 8, !14, i64 56, !20, i64 272, !10, i64 368, !19, i64 376, !21, i64 432, !10, i64 496}
!13 = !{!"XSyncMutex", !7, i64 0, !7, i64 40}
!14 = !{!"XCPUStats", !7, i64 0, !15, i64 12, !16, i64 16, !18, i64 64, !19, i64 160}
!15 = !{!"short", !7, i64 0}
!16 = !{!"XProcInfo", !10, i64 0, !10, i64 4, !17, i64 8, !17, i64 16, !17, i64 24, !17, i64 32, !17, i64 40}
!17 = !{!"long", !7, i64 0}
!18 = !{!"XCPUInfo", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !17, i64 88}
!19 = !{!"XArray_", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !7, i64 32, !7, i64 33, !7, i64 34, !17, i64 40, !17, i64 48}
!20 = !{!"XMemInfo", !17, i64 0, !17, i64 8, !17, i64 16, !17, i64 24, !17, i64 32, !17, i64 40, !17, i64 48, !17, i64 56, !17, i64 64, !17, i64 72, !17, i64 80, !17, i64 88}
!21 = !{!"XTask", !6, i64 0, !6, i64 8, !22, i64 16, !10, i64 48, !10, i64 52, !10, i64 56}
!22 = !{!"XThread", !6, i64 0, !6, i64 8, !17, i64 16, !10, i64 24, !7, i64 28, !7, i64 29}
!23 = !{!12, !10, i64 496}


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

@.str = external hidden unnamed_addr constant [9 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @XMon_UpdateStats(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XMon_StartMonitoring(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca [2048 x i8], align 16
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %4) #3
  %7 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %4, i64 noundef 2048, ptr noundef nonnull @.str, i32 noundef %2) #3
  %8 = call zeroext i8 @XPath_Exists(ptr noundef nonnull %4) #3
  %.not.not = icmp eq i8 %8, 0
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %4) #3
  br i1 %.not.not, label %15, label %9

9:                                                ; preds = %6, %3
  store i32 %1, ptr %0, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 496
  store i32 %2, ptr %10, align 8, !tbaa !21
  %11 = getelementptr inbounds i8, ptr %0, i64 432
  %12 = call i32 @XTask_Start(ptr noundef nonnull %11, ptr noundef nonnull @XMon_UpdateStats, ptr noundef nonnull %0, i32 noundef %1) #3
  %13 = getelementptr inbounds i8, ptr %0, i64 488
  %14 = atomicrmw or ptr %13, i32 0 seq_cst, align 8
  br label %15

15:                                               ; preds = %6, %9
  %.1 = phi i32 [ -1, %6 ], [ %14, %9 ]
  ret i32 %.1
}

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

declare zeroext i8 @XPath_Exists(ptr noundef) local_unnamed_addr #2

declare i32 @XTask_Start(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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, !7, i64 0}
!6 = !{!"XTopStats", !7, i64 0, !10, i64 8, !11, i64 56, !18, i64 272, !7, i64 368, !16, i64 376, !19, i64 432, !7, i64 496}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"XSyncMutex", !8, i64 0, !8, i64 40}
!11 = !{!"XCPUStats", !8, i64 0, !12, i64 12, !13, i64 16, !15, i64 64, !16, i64 160}
!12 = !{!"short", !8, i64 0}
!13 = !{!"XProcInfo", !7, i64 0, !7, i64 4, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40}
!14 = !{!"long", !8, i64 0}
!15 = !{!"XCPUInfo", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !7, i64 72, !7, i64 76, !7, i64 80, !14, i64 88}
!16 = !{!"XArray_", !17, i64 0, !17, i64 8, !7, i64 16, !17, i64 24, !8, i64 32, !8, i64 33, !8, i64 34, !14, i64 40, !14, i64 48}
!17 = !{!"any pointer", !8, i64 0}
!18 = !{!"XMemInfo", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !14, i64 88}
!19 = !{!"XTask", !17, i64 0, !17, i64 8, !20, i64 16, !7, i64 48, !7, i64 52, !7, i64 56}
!20 = !{!"XThread", !17, i64 0, !17, i64 8, !14, i64 16, !7, i64 24, !8, i64 28, !8, i64 29}
!21 = !{!6, !7, i64 496}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass