; LLVM IR from kala13x/libxutils :: examples (async-client)

; 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.xasync_client_args_t = type { [128 x i8], i16, i8, 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 }

@g_nInterrupted = external hidden global i32, align 4
@__const.main.nSignals = external hidden unnamed_addr constant [2 x i32], align 4

; Function Attrs: nounwind uwtable
declare dso_local void @signal_callback(i32 noundef) #0

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %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.xasync_client_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) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 @__const.main.nSignals, i64 8, i1 false)
  %12 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 0
  %13 = call i32 @XSig_Register(ptr noundef %12, i64 noundef 2, ptr noundef @signal_callback)
  call void @llvm.lifetime.start.p0(i64 132, ptr %7) #4
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = call zeroext i8 @parse_args(ptr noundef %7, i32 noundef %14, ptr noundef %15)
  %17 = icmp ne i8 %16, 0
  br i1 %17, label %22, label %18

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

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

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

40:                                               ; preds = %22
  br label %41

41:                                               ; preds = %57, %40
  %42 = load i32, ptr @g_nInterrupted, align 4, !tbaa !5
  %43 = icmp ne i32 %42, 0
  %44 = xor i1 %43, true
  br i1 %44, label %45, label %58

45:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %46 = call i32 @XAPI_Service(ptr noundef %9, i32 noundef 100)
  store i32 %46, ptr %11, align 4, !tbaa !5
  %47 = load i32, ptr %11, align 4, !tbaa !5
  %48 = icmp ne i32 %47, 11
  br i1 %48, label %49, label %50

49:                                               ; preds = %45
  store i32 3, ptr %8, align 4
  br label %55

50:                                               ; preds = %45
  %51 = call i64 @XAPI_GetEventCount(ptr noundef %9)
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %54, label %53

53:                                               ; preds = %50
  store i32 3, ptr %8, align 4
  br label %55

54:                                               ; preds = %50
  store i32 0, ptr %8, align 4
  br label %55

55:                                               ; preds = %54, %53, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %56 = load i32, ptr %8, align 4
  switch i32 %56, label %62 [
    i32 0, label %57
    i32 3, label %58
  ]

57:                                               ; preds = %55
  br label %41, !llvm.loop !23

58:                                               ; preds = %55, %41
  call void @XAPI_Destroy(ptr noundef %9)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %59

59:                                               ; preds = %58, %39
  call void @llvm.lifetime.end.p0(i64 96, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 1896, ptr %9) #4
  br label %60

60:                                               ; preds = %59, %18
  call void @llvm.lifetime.end.p0(i64 132, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %61 = load i32, ptr %3, align 4
  ret i32 %61

62:                                               ; preds = %55
  unreachable
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

declare i64 @XAPI_GetEventCount(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !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 128}
!17 = !{!"", !7, i64 0, !14, i64 128, !7, i64 130, !7, i64 131}
!18 = !{!12, !14, i64 84}
!19 = !{!17, !7, i64 130}
!20 = !{!12, !7, i64 93}
!21 = !{!17, !7, i64 131}
!22 = !{!12, !7, i64 94}
!23 = distinct !{!23, !24}
!24 = !{!"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.xasync_client_args_t = type { [128 x i8], i16, i8, 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 }

@g_nInterrupted = external hidden local_unnamed_addr global i32, align 4
@__const.main.nSignals = external hidden unnamed_addr constant [2 x i32], align 4

; Function Attrs: nounwind uwtable
declare dso_local void @signal_callback(i32 noundef) #0

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca [2 x i32], align 8
  %4 = alloca %struct.xasync_client_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
  %7 = load i64, ptr @__const.main.nSignals, align 4
  store i64 %7, ptr %3, align 8
  %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 132, 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 !5
  call void @display_usage(ptr noundef %11)
  br label %31

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 %4, 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 4, ptr %6, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %6, i64 64
  store ptr %4, ptr %14, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %4, i64 128
  %16 = load i16, ptr %15, align 2, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %6, i64 84
  store i16 %16, ptr %17, align 4, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %4, i64 130
  %19 = load i8, ptr %18, align 2, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %6, i64 93
  store i8 %19, ptr %20, align 1, !tbaa !19
  %21 = getelementptr inbounds i8, ptr %4, i64 131
  %22 = load i8, ptr %21, align 1, !tbaa !20
  %23 = getelementptr inbounds i8, ptr %6, i64 94
  store i8 %22, ptr %23, align 2, !tbaa !21
  %24 = call i32 @XAPI_AddEndpoint(ptr noundef nonnull %5, ptr noundef nonnull %6, i32 noundef 3) #3
  %25 = icmp slt i32 %24, 0
  br i1 %25, label %.thread, label %26

26:                                               ; preds = %12
  %.old = load i32, ptr @g_nInterrupted, align 4, !tbaa !22
  %.not6.old = icmp eq i32 %.old, 0
  br i1 %.not6.old, label %.preheader, label %.thread

.preheader:                                       ; preds = %26, %28
  %27 = call i32 @XAPI_Service(ptr noundef nonnull %5, i32 noundef 100) #3
  %.not7 = icmp eq i32 %27, 11
  br i1 %.not7, label %28, label %.thread

28:                                               ; preds = %.preheader
  %29 = call i64 @XAPI_GetEventCount(ptr noundef nonnull %5) #3
  %.not8 = icmp ne i64 %29, 0
  %30 = load i32, ptr @g_nInterrupted, align 4
  %.not6 = icmp eq i32 %30, 0
  %or.cond = select i1 %.not8, i1 %.not6, i1 false
  br i1 %or.cond, label %.preheader, label %.thread

.thread:                                          ; preds = %28, %.preheader, %26, %12
  %.0 = phi i32 [ -1, %12 ], [ 0, %26 ], [ 0, %.preheader ], [ 0, %28 ]
  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 %31

31:                                               ; preds = %.thread, %10
  %.1 = phi i32 [ %.0, %.thread ], [ -1, %10 ]
  call void @llvm.lifetime.end.p0(i64 132, 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

declare i64 @XAPI_GetEventCount(ptr noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 0}
!10 = !{!"xapi_endpoint_", !11, i64 0, !12, i64 8, !6, i64 56, !6, i64 64, !6, i64 72, !11, i64 80, !13, i64 84, !11, i64 88, !7, i64 92, !7, i64 93, !7, i64 94}
!11 = !{!"int", !7, i64 0}
!12 = !{!"XSocketCert", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !6, i64 64}
!15 = !{!16, !13, i64 128}
!16 = !{!"", !7, i64 0, !13, i64 128, !7, i64 130, !7, i64 131}
!17 = !{!10, !13, i64 84}
!18 = !{!16, !7, i64 130}
!19 = !{!10, !7, i64 93}
!20 = !{!16, !7, i64 131}
!21 = !{!10, !7, i64 94}
!22 = !{!11, !11, i64 0}


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