; LLVM IR from kala13x/libxutils :: src/net (api)

; 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.xapi_ = type { ptr, %struct.XEvents, i64, ptr, i8, i8, i8 }
%struct.XEvents = type { ptr, i32, ptr, ptr, i32, i32, i8, %struct.XHash }
%struct.XHash = type { ptr, ptr, i64, [32 x %struct.xlist] }
%struct.xlist = type { ptr, ptr, %struct.xlist_data, i8 }
%struct.xlist_data = type { ptr, ptr, ptr, i64 }

; Function Attrs: nounwind uwtable
define dso_local i32 @XAPI_Init(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %4
  store i32 -2, ptr %5, align 4
  br label %35

13:                                               ; preds = %4
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.xapi_, ptr %14, i32 0, i32 4
  store i8 0, ptr %15, align 8, !tbaa !11
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.xapi_, ptr %16, i32 0, i32 5
  store i8 0, ptr %17, align 1, !tbaa !16
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.xapi_, ptr %18, i32 0, i32 6
  store i8 1, ptr %19, align 2, !tbaa !17
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.xapi_, ptr %21, i32 0, i32 0
  store ptr %20, ptr %22, align 8, !tbaa !18
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.xapi_, ptr %24, i32 0, i32 3
  store ptr %23, ptr %25, align 8, !tbaa !19
  %26 = load i64, ptr %9, align 8, !tbaa !9
  %27 = icmp ne i64 %26, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %13
  %29 = load i64, ptr %9, align 8, !tbaa !9
  br label %31

30:                                               ; preds = %13
  br label %31

31:                                               ; preds = %30, %28
  %32 = phi i64 [ %29, %28 ], [ 5120000, %30 ]
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.xapi_, ptr %33, i32 0, i32 2
  store i64 %32, ptr %34, align 8, !tbaa !20
  store i32 1, ptr %5, align 4
  br label %35

35:                                               ; preds = %31, %12
  %36 = load i32, ptr %5, align 4
  ret i32 %36
}

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

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !7, i64 1888}
!12 = !{!"xapi_", !6, i64 0, !13, i64 8, !10, i64 1872, !6, i64 1880, !7, i64 1888, !7, i64 1889, !7, i64 1890}
!13 = !{!"XEvents", !6, i64 0, !14, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !14, i64 36, !7, i64 40, !15, i64 48}
!14 = !{!"int", !7, i64 0}
!15 = !{!"XHash", !6, i64 0, !6, i64 8, !10, i64 16, !7, i64 24}
!16 = !{!12, !7, i64 1889}
!17 = !{!12, !7, i64 1890}
!18 = !{!12, !6, i64 0}
!19 = !{!12, !6, i64 1880}
!20 = !{!12, !10, i64 1872}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local range(i32 -2, 2) i32 @XAPI_Init(ptr noundef writeonly %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %12, label %5

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 1888
  store i8 0, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 1889
  store i8 0, ptr %7, align 1, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %0, i64 1890
  store i8 1, ptr %8, align 2, !tbaa !15
  store ptr %1, ptr %0, align 8, !tbaa !16
  %9 = getelementptr inbounds i8, ptr %0, i64 1880
  store ptr %2, ptr %9, align 8, !tbaa !17
  %.not12 = icmp eq i64 %3, 0
  %10 = select i1 %.not12, i64 5120000, i64 %3
  %11 = getelementptr inbounds i8, ptr %0, i64 1872
  store i64 %10, ptr %11, align 8, !tbaa !18
  br label %12

12:                                               ; preds = %4, %5
  %.0 = phi i32 [ 1, %5 ], [ -2, %4 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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" }

!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, !8, i64 1888}
!6 = !{!"xapi_", !7, i64 0, !10, i64 8, !13, i64 1872, !7, i64 1880, !8, i64 1888, !8, i64 1889, !8, i64 1890}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"XEvents", !7, i64 0, !11, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !11, i64 36, !8, i64 40, !12, i64 48}
!11 = !{!"int", !8, i64 0}
!12 = !{!"XHash", !7, i64 0, !7, i64 8, !13, i64 16, !8, i64 24}
!13 = !{!"long", !8, i64 0}
!14 = !{!6, !8, i64 1889}
!15 = !{!6, !8, i64 1890}
!16 = !{!6, !7, i64 0}
!17 = !{!6, !7, i64 1880}
!18 = !{!6, !13, i64 1872}


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