; LLVM IR from kala13x/libxutils :: examples (ws-server)

; 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.xws_args_t = type { [2048 x i8], [2048 x i8], [2048 x i8], [128 x i8], i16, i8 }
%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 }
%struct.xapi_endpoint_ = type { i32, %struct.XSocketCert, ptr, ptr, ptr, i32, i16, i32, i8, i8, i8 }
%struct.XSocketCert = type { ptr, ptr, ptr, ptr, ptr, i32 }

; 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 void @signal_callback(i32 noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @display_usage(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @parse_args(ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [2 x i32], align 4
  %7 = alloca %struct.xws_args_t, align 2
  %8 = alloca i32, align 4
  %9 = alloca %struct.xapi_, align 8
  %10 = alloca %struct.xapi_endpoint_, align 8
  %11 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @XLog_Init(ptr noundef null, i16 noundef zeroext 203, i8 noundef zeroext 0)
  call void @XLog_TimeFormatSet(i32 noundef 1)
  call void @XLog_FlagsSet(i16 noundef zeroext 255)
  call void @XLog_IndentSet(i8 noundef zeroext 1)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %12 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 0
  store i32 15, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 1
  store i32 2, ptr %13, align 4, !tbaa !5
  %14 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 0
  %15 = call i32 @XSig_Register(ptr noundef %14, i64 noundef 2, ptr noundef @signal_callback)
  call void @llvm.lifetime.start.p0(i64 6276, ptr %7) #3
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = call zeroext i8 @parse_args(ptr noundef %7, i32 noundef %16, ptr noundef %17)
  %19 = icmp ne i8 %18, 0
  br i1 %19, label %24, label %20

20:                                               ; preds = %2
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = getelementptr inbounds ptr, ptr %21, i64 0
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  call void @display_usage(ptr noundef %23)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %64

24:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1896, ptr %9) #3
  %25 = call i32 @XAPI_Init(ptr noundef %9, ptr noundef @service_callback, ptr noundef %9, i64 noundef 0)
  call void @llvm.lifetime.start.p0(i64 96, ptr %10) #3
  call void @XAPI_InitEndpoint(ptr noundef %10)
  %26 = getelementptr inbounds %struct.xapi_endpoint_, ptr %10, i32 0, i32 0
  store i32 5, ptr %26, align 8, !tbaa !11
  %27 = getelementptr inbounds %struct.xws_args_t, ptr %7, i32 0, i32 3
  %28 = getelementptr inbounds [128 x i8], ptr %27, i64 0, i64 0
  %29 = getelementptr inbounds %struct.xapi_endpoint_, ptr %10, i32 0, i32 3
  store ptr %28, ptr %29, align 8, !tbaa !15
  %30 = getelementptr inbounds %struct.xws_args_t, ptr %7, i32 0, i32 4
  %31 = load i16, ptr %30, align 2, !tbaa !16
  %32 = getelementptr inbounds %struct.xapi_endpoint_, ptr %10, i32 0, i32 6
  store i16 %31, ptr %32, align 4, !tbaa !18
  %33 = getelementptr inbounds %struct.xws_args_t, ptr %7, i32 0, i32 5
  %34 = load i8, ptr %33, align 2, !tbaa !19
  %35 = getelementptr inbounds %struct.xapi_endpoint_, ptr %10, i32 0, i32 10
  store i8 %34, ptr %35, align 2, !tbaa !20
  %36 = getelementptr inbounds %struct.xapi_endpoint_, ptr %10, i32 0, i32 10
  %37 = load i8, ptr %36, align 2, !tbaa !20
  %38 = icmp ne i8 %37, 0
  br i1 %38, label %39, label %52

39:                                               ; preds = %24
  %40 = getelementptr inbounds %struct.xws_args_t, ptr %7, i32 0, i32 0
  %41 = getelementptr inbounds [2048 x i8], ptr %40, i64 0, i64 0
  %42 = getelementptr inbounds %struct.xapi_endpoint_, ptr %10, i32 0, i32 1
  %43 = getelementptr inbounds %struct.XSocketCert, ptr %42, i32 0, i32 2
  store ptr %41, ptr %43, align 8, !tbaa !21
  %44 = getelementptr inbounds %struct.xws_args_t, ptr %7, i32 0, i32 2
  %45 = getelementptr inbounds [2048 x i8], ptr %44, i64 0, i64 0
  %46 = getelementptr inbounds %struct.xapi_endpoint_, ptr %10, i32 0, i32 1
  %47 = getelementptr inbounds %struct.XSocketCert, ptr %46, i32 0, i32 1
  store ptr %45, ptr %47, align 8, !tbaa !22
  %48 = getelementptr inbounds %struct.xws_args_t, ptr %7, i32 0, i32 1
  %49 = getelementptr inbounds [2048 x i8], ptr %48, i64 0, i64 0
  %50 = getelementptr inbounds %struct.xapi_endpoint_, ptr %10, i32 0, i32 1
  %51 = getelementptr inbounds %struct.XSocketCert, ptr %50, i32 0, i32 0
  store ptr %49, ptr %51, align 8, !tbaa !23
  br label %52

52:                                               ; preds = %39, %24
  %53 = call i32 @XAPI_AddEndpoint(ptr noundef %9, ptr noundef %10, i32 noundef 2)
  %54 = icmp slt i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %52
  call void @XAPI_Destroy(ptr noundef %9)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %63

56:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  br label %57

57:                                               ; preds = %59, %56
  %58 = call i32 @XAPI_Service(ptr noundef %9, i32 noundef 100)
  store i32 %58, ptr %11, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %57
  %60 = load i32, ptr %11, align 4, !tbaa !5
  %61 = icmp eq i32 %60, 11
  br i1 %61, label %57, label %62, !llvm.loop !24

62:                                               ; preds = %59
  call void @XAPI_Destroy(ptr noundef %9)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %63

63:                                               ; preds = %62, %55
  call void @llvm.lifetime.end.p0(i64 96, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1896, ptr %9) #3
  br label %64

64:                                               ; preds = %63, %20
  call void @llvm.lifetime.end.p0(i64 6276, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %65 = load i32, ptr %3, align 4
  ret i32 %65
}

declare void @XLog_Init(ptr noundef, i16 noundef zeroext, i8 noundef zeroext) #2

declare void @XLog_TimeFormatSet(i32 noundef) #2

declare void @XLog_FlagsSet(i16 noundef zeroext) #2

declare void @XLog_IndentSet(i8 noundef zeroext) #2

declare i32 @XSig_Register(ptr noundef, i64 noundef, ptr noundef) #2

declare i32 @XAPI_Init(ptr noundef, ptr noundef, ptr noundef, i64 noundef) #2

declare void @XAPI_InitEndpoint(ptr noundef) #2

declare i32 @XAPI_AddEndpoint(ptr noundef, ptr noundef, i32 noundef) #2

declare void @XAPI_Destroy(ptr noundef) #2

declare i32 @XAPI_Service(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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"xapi_endpoint_", !6, i64 0, !13, i64 8, !10, i64 56, !10, i64 64, !10, i64 72, !6, i64 80, !14, i64 84, !6, i64 88, !7, i64 92, !7, i64 93, !7, i64 94}
!13 = !{!"XSocketCert", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !10, i64 64}
!16 = !{!17, !14, i64 6272}
!17 = !{!"", !7, i64 0, !7, i64 2048, !7, i64 4096, !7, i64 6144, !14, i64 6272, !7, i64 6274}
!18 = !{!12, !14, i64 84}
!19 = !{!17, !7, i64 6274}
!20 = !{!12, !7, i64 94}
!21 = !{!12, !10, i64 24}
!22 = !{!12, !10, i64 16}
!23 = !{!12, !10, i64 8}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


; 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.xws_args_t = type { [2048 x i8], [2048 x i8], [2048 x i8], [128 x i8], i16, i8 }
%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 }
%struct.xapi_endpoint_ = type { i32, %struct.XSocketCert, ptr, ptr, ptr, i32, i16, i32, i8, i8, i8 }
%struct.XSocketCert = type { ptr, ptr, ptr, ptr, ptr, i32 }

; 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 void @signal_callback(i32 noundef) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @parse_args(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca [2 x i32], align 4
  %4 = alloca %struct.xws_args_t, align 2
  %5 = alloca %struct.xapi_, align 8
  %6 = alloca %struct.xapi_endpoint_, align 8
  tail call void @XLog_Init(ptr noundef null, i16 noundef zeroext 203, i8 noundef zeroext 0) #3
  tail call void @XLog_TimeFormatSet(i32 noundef 1) #3
  tail call void @XLog_FlagsSet(i16 noundef zeroext 255) #3
  tail call void @XLog_IndentSet(i8 noundef zeroext 1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store i32 15, ptr %3, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 2, ptr %7, align 4, !tbaa !5
  %8 = call i32 @XSig_Register(ptr noundef nonnull %3, i64 noundef 2, ptr noundef nonnull @signal_callback) #3
  call void @llvm.lifetime.start.p0(i64 6276, ptr nonnull %4) #3
  %9 = call zeroext i8 @parse_args(ptr noundef nonnull %4, i32 noundef %0, ptr noundef %1)
  %.not = icmp eq i8 %9, 0
  br i1 %.not, label %10, label %12

10:                                               ; preds = %2
  %11 = load ptr, ptr %1, align 8, !tbaa !9
  call void @display_usage(ptr noundef %11)
  br label %33

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1896, ptr nonnull %5) #3
  %13 = call i32 @XAPI_Init(ptr noundef nonnull %5, ptr noundef nonnull @service_callback, ptr noundef nonnull %5, i64 noundef 0) #3
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %6) #3
  call void @XAPI_InitEndpoint(ptr noundef nonnull %6) #3
  store i32 5, ptr %6, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %4, i64 6144
  %15 = getelementptr inbounds i8, ptr %6, i64 64
  store ptr %14, ptr %15, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %4, i64 6272
  %17 = load i16, ptr %16, align 2, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %6, i64 84
  store i16 %17, ptr %18, align 4, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %4, i64 6274
  %20 = load i8, ptr %19, align 2, !tbaa !19
  %21 = getelementptr inbounds i8, ptr %6, i64 94
  store i8 %20, ptr %21, align 2, !tbaa !20
  %.not4 = icmp eq i8 %20, 0
  br i1 %.not4, label %28, label %22

22:                                               ; preds = %12
  %23 = getelementptr inbounds i8, ptr %6, i64 8
  %24 = getelementptr inbounds i8, ptr %6, i64 24
  store ptr %4, ptr %24, align 8, !tbaa !21
  %25 = getelementptr inbounds i8, ptr %4, i64 4096
  %26 = getelementptr inbounds i8, ptr %6, i64 16
  store ptr %25, ptr %26, align 8, !tbaa !22
  %27 = getelementptr inbounds i8, ptr %4, i64 2048
  store ptr %27, ptr %23, align 8, !tbaa !23
  br label %28

28:                                               ; preds = %22, %12
  %29 = call i32 @XAPI_AddEndpoint(ptr noundef nonnull %5, ptr noundef nonnull %6, i32 noundef 2) #3
  %30 = icmp slt i32 %29, 0
  br i1 %30, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %28, %.preheader
  %31 = call i32 @XAPI_Service(ptr noundef nonnull %5, i32 noundef 100) #3
  %32 = icmp eq i32 %31, 11
  br i1 %32, label %.preheader, label %.loopexit, !llvm.loop !24

.loopexit:                                        ; preds = %.preheader, %28
  %.0 = phi i32 [ -1, %28 ], [ 0, %.preheader ]
  call void @XAPI_Destroy(ptr noundef nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 1896, ptr nonnull %5) #3
  br label %33

33:                                               ; preds = %.loopexit, %10
  %.1 = phi i32 [ %.0, %.loopexit ], [ -1, %10 ]
  call void @llvm.lifetime.end.p0(i64 6276, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i32 %.1
}

declare void @XLog_Init(ptr noundef, i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #2

declare void @XLog_TimeFormatSet(i32 noundef) local_unnamed_addr #2

declare void @XLog_FlagsSet(i16 noundef zeroext) local_unnamed_addr #2

declare void @XLog_IndentSet(i8 noundef zeroext) local_unnamed_addr #2

declare i32 @XSig_Register(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

declare i32 @XAPI_Init(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @XAPI_InitEndpoint(ptr noundef) local_unnamed_addr #2

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

declare void @XAPI_Destroy(ptr noundef) local_unnamed_addr #2

declare i32 @XAPI_Service(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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"xapi_endpoint_", !6, i64 0, !13, i64 8, !10, i64 56, !10, i64 64, !10, i64 72, !6, i64 80, !14, i64 84, !6, i64 88, !7, i64 92, !7, i64 93, !7, i64 94}
!13 = !{!"XSocketCert", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !10, i64 64}
!16 = !{!17, !14, i64 6272}
!17 = !{!"", !7, i64 0, !7, i64 2048, !7, i64 4096, !7, i64 6144, !14, i64 6272, !7, i64 6274}
!18 = !{!12, !14, i64 84}
!19 = !{!17, !7, i64 6274}
!20 = !{!12, !7, i64 94}
!21 = !{!12, !10, i64 24}
!22 = !{!12, !10, i64 16}
!23 = !{!12, !10, i64 8}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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