; LLVM IR from kala13x/libxutils :: examples (events)

; 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.XSocket = type { i32, %union.xsock_addr_t, i32, i32, i16, i32, i32, i32, i32, ptr }
%union.xsock_addr_t = type { %struct.sockaddr_in, [96 x i8] }
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%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.XEventData = type { ptr, i32, i8, i32, i32, i32 }
%struct.xhttp_ = type { ptr, i16, ptr, i32, %struct.XByteBuffer, i32, %struct.XMap, i16, i16, i64, i64, i64, i64, i64, i8, i8, i8, [256 x i8], [128 x i8], [2048 x i8] }
%struct.XByteBuffer = type { ptr, i64, i64, i16, i16, i32 }
%struct.XMap = type { ptr, ptr, ptr, i64, i64, i32 }

@.str.12 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [31 x i8], align 1

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

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

declare void @XLog_Display(i32 noundef, i8 noundef zeroext, ptr noundef, ...) #2

; 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
define dso_local i32 @read_event(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.XSocket, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca %struct.XSocket, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %21, label %18

18:                                               ; preds = %2
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %18, %2
  store i32 -1, ptr %3, align 4
  br label %146

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.XEvents, ptr %23, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  store ptr %25, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.XSocket, ptr %26, i32 0, i32 5
  %28 = load i32, ptr %27, align 8, !tbaa !14
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.XEventData, ptr %29, i32 0, i32 3
  %31 = load i32, ptr %30, align 8, !tbaa !17
  %32 = icmp eq i32 %28, %31
  br i1 %32, label %33, label %66

33:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 152, ptr %7) #5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call i32 @XSock_Accept(ptr noundef %34, ptr noundef %7)
  %36 = icmp eq i32 %35, -1
  br i1 %36, label %40, label %37

37:                                               ; preds = %33
  %38 = call i32 @XSock_NonBlock(ptr noundef %7, i8 noundef zeroext 1)
  %39 = icmp eq i32 %38, -1
  br i1 %39, label %40, label %42

40:                                               ; preds = %37, %33
  %41 = call ptr @XSock_ErrStr(ptr noundef %7)
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 8, i8 noundef zeroext 1, ptr noundef @.str.12, ptr noundef %41)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %65

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %43 = call ptr @XHTTP_Alloc(i32 noundef 0, i64 noundef 0)
  store ptr %43, ptr %9, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = icmp eq ptr %44, null
  br i1 %45, label %46, label %49

46:                                               ; preds = %42
  %47 = call ptr @__errno_location() #6
  %48 = load i32, ptr %47, align 4, !tbaa !19
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.13, i32 noundef %48)
  call void @XSock_Close(ptr noundef %7)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %64

49:                                               ; preds = %42
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.XSocket, ptr %7, i32 0, i32 5
  %53 = load i32, ptr %52, align 8, !tbaa !14
  %54 = call ptr @XEvents_RegisterEvent(ptr noundef %50, ptr noundef %51, i32 noundef %53, i32 noundef 1, i32 noundef 0)
  %55 = icmp eq ptr %54, null
  br i1 %55, label %56, label %61

56:                                               ; preds = %49
  %57 = getelementptr inbounds %struct.XSocket, ptr %7, i32 0, i32 5
  %58 = load i32, ptr %57, align 8, !tbaa !14
  %59 = call ptr @XSTR_Error()
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.14, i32 noundef %58, ptr noundef %59)
  call void @XSock_Close(ptr noundef %7)
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  call void @XHTTP_Clear(ptr noundef %60)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %64

61:                                               ; preds = %49
  %62 = getelementptr inbounds %struct.XSocket, ptr %7, i32 0, i32 5
  %63 = load i32, ptr %62, align 8, !tbaa !14
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef @.str.15, i32 noundef %63)
  store i32 2, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %64

64:                                               ; preds = %61, %56, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %65

65:                                               ; preds = %64, %40
  call void @llvm.lifetime.end.p0(i64 152, ptr %7) #5
  br label %145

66:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 152, ptr %10) #5
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.XEventData, ptr %67, i32 0, i32 3
  %69 = load i32, ptr %68, align 8, !tbaa !17
  %70 = call i32 @XSock_Init(ptr noundef %10, i32 noundef 16641, i32 noundef %69)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.XEventData, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !20
  store ptr %73, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = call i32 @XHTTP_Receive(ptr noundef %74, ptr noundef %10)
  store i32 %75, ptr %12, align 4, !tbaa !19
  %76 = load i32, ptr %12, align 4, !tbaa !19
  %77 = icmp eq i32 %76, 20
  br i1 %77, label %78, label %98

78:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = call i32 @handle_request(ptr noundef %79)
  store i32 %80, ptr %13, align 4, !tbaa !19
  %81 = load i32, ptr %13, align 4, !tbaa !19
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %85

83:                                               ; preds = %78
  %84 = load i32, ptr %13, align 4, !tbaa !19
  store i32 %84, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %97

85:                                               ; preds = %78
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = call i32 @XEvents_Modify(ptr noundef %86, ptr noundef %87, i32 noundef 4)
  store i32 %88, ptr %14, align 4, !tbaa !19
  %89 = load i32, ptr %14, align 4, !tbaa !19
  %90 = icmp ne i32 %89, 11
  br i1 %90, label %91, label %95

91:                                               ; preds = %85
  %92 = load i32, ptr %14, align 4, !tbaa !19
  %93 = call ptr @XEvents_GetStatusStr(i32 noundef %92)
  %94 = call ptr @XSTR_Error()
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.16, ptr noundef %93, ptr noundef %94)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %96

95:                                               ; preds = %85
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %96

96:                                               ; preds = %95, %91
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %97

97:                                               ; preds = %96, %83
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %141

98:                                               ; preds = %66
  %99 = load i32, ptr %12, align 4, !tbaa !19
  %100 = icmp eq i32 %99, 5
  br i1 %100, label %101, label %122

101:                                              ; preds = %98
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %102 = call ptr @XSock_ErrStr(ptr noundef %10)
  store ptr %102, ptr %15, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.XSocket, ptr %10, i32 0, i32 0
  %104 = load i32, ptr %103, align 8, !tbaa !21
  %105 = icmp eq i32 %104, 38
  br i1 %105, label %106, label %111

106:                                              ; preds = %101
  %107 = load ptr, ptr %15, align 8, !tbaa !5
  %108 = load ptr, ptr %5, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.XEventData, ptr %108, i32 0, i32 3
  %110 = load i32, ptr %109, align 8, !tbaa !17
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef @.str.17, ptr noundef %107, i32 noundef %110)
  br label %119

111:                                              ; preds = %101
  %112 = getelementptr inbounds %struct.XSocket, ptr %10, i32 0, i32 0
  %113 = load i32, ptr %112, align 8, !tbaa !21
  %114 = icmp ne i32 %113, 0
  br i1 %114, label %115, label %118

115:                                              ; preds = %111
  %116 = load ptr, ptr %15, align 8, !tbaa !5
  %117 = call ptr @XSTR_Error()
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.18, ptr noundef %116, ptr noundef %117)
  br label %118

118:                                              ; preds = %115, %111
  br label %119

119:                                              ; preds = %118, %106
  %120 = load ptr, ptr %5, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.XEventData, ptr %120, i32 0, i32 2
  store i8 0, ptr %121, align 4, !tbaa !22
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  br label %141

122:                                              ; preds = %98
  %123 = load i32, ptr %12, align 4, !tbaa !19
  %124 = icmp ne i32 %123, 23
  br i1 %124, label %125, label %131

125:                                              ; preds = %122
  %126 = load i32, ptr %12, align 4, !tbaa !19
  %127 = icmp ne i32 %126, 17
  br i1 %127, label %128, label %131

128:                                              ; preds = %125
  %129 = load i32, ptr %12, align 4, !tbaa !19
  %130 = call ptr @XHTTP_GetStatusStr(i32 noundef %129)
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.12, ptr noundef %130)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %141

131:                                              ; preds = %125, %122
  br label %132

132:                                              ; preds = %131
  br label %133

133:                                              ; preds = %132
  %134 = load ptr, ptr %5, align 8, !tbaa !5
  %135 = getelementptr inbounds %struct.XEventData, ptr %134, i32 0, i32 3
  %136 = load i32, ptr %135, align 8, !tbaa !17
  %137 = load ptr, ptr %11, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.xhttp_, ptr %137, i32 0, i32 4
  %139 = getelementptr inbounds %struct.XByteBuffer, ptr %138, i32 0, i32 2
  %140 = load i64, ptr %139, align 8, !tbaa !23
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 16, i8 noundef zeroext 1, ptr noundef @.str.19, i32 noundef %136, i64 noundef %140)
  store i32 0, ptr %8, align 4
  br label %141

141:                                              ; preds = %133, %128, %119, %97
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 152, ptr %10) #5
  %142 = load i32, ptr %8, align 4
  switch i32 %142, label %145 [
    i32 0, label %143
  ]

143:                                              ; preds = %141
  br label %144

144:                                              ; preds = %143
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %145

145:                                              ; preds = %144, %141, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %146

146:                                              ; preds = %145, %21
  %147 = load i32, ptr %3, align 4
  ret i32 %147
}

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

declare i32 @XSock_NonBlock(ptr noundef, i8 noundef zeroext) #2

declare ptr @XSock_ErrStr(ptr noundef) #2

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

declare void @XSock_Close(ptr noundef) #2

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

declare void @XHTTP_Clear(ptr noundef) #2

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

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

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

declare ptr @XEvents_GetStatusStr(i32 noundef) #2

declare ptr @XHTTP_GetStatusStr(i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @XSTR_Error() #4

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 = { nounwind willreturn memory(none) "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 #4 = { inlinehint 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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, !6, i64 24}
!10 = !{!"XEvents", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !11, i64 36, !7, i64 40, !12, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"XHash", !6, i64 0, !6, i64 8, !13, i64 16, !7, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !11, i64 128}
!15 = !{!"XSocket", !11, i64 0, !7, i64 4, !11, i64 116, !11, i64 120, !16, i64 124, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !6, i64 144}
!16 = !{!"short", !7, i64 0}
!17 = !{!18, !11, i64 16}
!18 = !{!"XEventData", !6, i64 0, !11, i64 8, !7, i64 12, !11, i64 16, !11, i64 20, !11, i64 24}
!19 = !{!11, !11, i64 0}
!20 = !{!18, !6, i64 0}
!21 = !{!15, !11, i64 0}
!22 = !{!18, !7, i64 12}
!23 = !{!24, !13, i64 48}
!24 = !{!"xhttp_", !6, i64 0, !16, i64 8, !6, i64 16, !11, i64 24, !25, i64 32, !11, i64 64, !26, i64 72, !16, i64 120, !16, i64 122, !13, i64 128, !13, i64 136, !13, i64 144, !13, i64 152, !13, i64 160, !7, i64 168, !7, i64 169, !7, i64 170, !7, i64 171, !7, i64 427, !7, i64 555}
!25 = !{!"XByteBuffer", !6, i64 0, !13, i64 8, !13, i64 16, !16, i64 24, !16, i64 26, !11, i64 28}
!26 = !{!"XMap", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 32, !11, 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.XSocket = type { i32, %union.xsock_addr_t, i32, i32, i16, i32, i32, i32, i32, ptr }
%union.xsock_addr_t = type { %struct.sockaddr_in, [96 x i8] }
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }

@.str.12 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [31 x i8], align 1

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

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

declare void @XLog_Display(i32 noundef, i8 noundef zeroext, ptr noundef, ...) local_unnamed_addr #2

; 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
define dso_local i32 @read_event(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.XSocket, align 8
  %4 = alloca %struct.XSocket, align 8
  %5 = icmp eq ptr %0, null
  %6 = icmp eq ptr %1, null
  %or.cond = or i1 %5, %6
  br i1 %or.cond, label %65, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 128
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  %13 = load i32, ptr %12, align 8, !tbaa !16
  %14 = icmp eq i32 %11, %13
  br i1 %14, label %15, label %39

15:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 152, ptr nonnull %3) #5
  %16 = call i32 @XSock_Accept(ptr noundef nonnull %9, ptr noundef nonnull %3) #5
  %17 = icmp eq i32 %16, -1
  br i1 %17, label %21, label %18

18:                                               ; preds = %15
  %19 = call i32 @XSock_NonBlock(ptr noundef nonnull %3, i8 noundef zeroext 1) #5
  %20 = icmp eq i32 %19, -1
  br i1 %20, label %21, label %23

21:                                               ; preds = %18, %15
  %22 = call ptr @XSock_ErrStr(ptr noundef nonnull %3) #5
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 8, i8 noundef zeroext 1, ptr noundef nonnull @.str.12, ptr noundef %22) #5
  br label %38

23:                                               ; preds = %18
  %24 = call ptr @XHTTP_Alloc(i32 noundef 0, i64 noundef 0) #5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %29

26:                                               ; preds = %23
  %27 = tail call ptr @__errno_location() #6
  %28 = load i32, ptr %27, align 4, !tbaa !18
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef nonnull @.str.13, i32 noundef %28) #5
  call void @XSock_Close(ptr noundef nonnull %3) #5
  br label %38

29:                                               ; preds = %23
  %30 = getelementptr inbounds i8, ptr %3, i64 128
  %31 = load i32, ptr %30, align 8, !tbaa !13
  %32 = call ptr @XEvents_RegisterEvent(ptr noundef nonnull %0, ptr noundef nonnull %24, i32 noundef %31, i32 noundef 1, i32 noundef 0) #5
  %33 = icmp eq ptr %32, null
  %34 = load i32, ptr %30, align 8, !tbaa !13
  br i1 %33, label %35, label %37

35:                                               ; preds = %29
  %36 = call ptr @XSTR_Error()
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef nonnull @.str.14, i32 noundef %34, ptr noundef %36) #5
  call void @XSock_Close(ptr noundef nonnull %3) #5
  call void @XHTTP_Clear(ptr noundef nonnull %24) #5
  br label %38

37:                                               ; preds = %29
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef nonnull @.str.15, i32 noundef %34) #5
  br label %38

38:                                               ; preds = %26, %35, %37, %21
  %.1 = phi i32 [ 0, %21 ], [ 0, %26 ], [ 0, %35 ], [ 2, %37 ]
  call void @llvm.lifetime.end.p0(i64 152, ptr nonnull %3) #5
  br label %65

39:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 152, ptr nonnull %4) #5
  %40 = call i32 @XSock_Init(ptr noundef nonnull %4, i32 noundef 16641, i32 noundef %13) #5
  %41 = load ptr, ptr %1, align 8, !tbaa !19
  %42 = call i32 @XHTTP_Receive(ptr noundef %41, ptr noundef nonnull %4) #5
  switch i32 %42, label %59 [
    i32 20, label %43
    i32 5, label %50
    i32 23, label %61
    i32 17, label %61
  ]

43:                                               ; preds = %39
  %44 = call i32 @handle_request(ptr noundef nonnull %1)
  %.not45 = icmp eq i32 %44, 0
  br i1 %.not45, label %45, label %.thread

45:                                               ; preds = %43
  %46 = call i32 @XEvents_Modify(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef 4) #5
  %.not46 = icmp eq i32 %46, 11
  br i1 %.not46, label %.thread, label %47

47:                                               ; preds = %45
  %48 = call ptr @XEvents_GetStatusStr(i32 noundef %46) #5
  %49 = call ptr @XSTR_Error()
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef nonnull @.str.16, ptr noundef %48, ptr noundef %49) #5
  br label %.thread

50:                                               ; preds = %39
  %51 = call ptr @XSock_ErrStr(ptr noundef nonnull %4) #5
  %52 = load i32, ptr %4, align 8, !tbaa !20
  switch i32 %52, label %55 [
    i32 38, label %53
    i32 0, label %57
  ]

53:                                               ; preds = %50
  %54 = load i32, ptr %12, align 8, !tbaa !16
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef nonnull @.str.17, ptr noundef %51, i32 noundef %54) #5
  br label %57

55:                                               ; preds = %50
  %56 = call ptr @XSTR_Error()
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef nonnull @.str.18, ptr noundef %51, ptr noundef %56) #5
  br label %57

57:                                               ; preds = %50, %55, %53
  %58 = getelementptr inbounds i8, ptr %1, i64 12
  store i8 0, ptr %58, align 4, !tbaa !21
  br label %.thread

59:                                               ; preds = %39
  %60 = call ptr @XHTTP_GetStatusStr(i32 noundef %42) #5
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef nonnull @.str.12, ptr noundef %60) #5
  br label %.thread

.thread:                                          ; preds = %57, %59, %47, %45, %43
  %.4.ph = phi i32 [ 0, %45 ], [ -1, %47 ], [ %44, %43 ], [ -1, %59 ], [ -1, %57 ]
  call void @llvm.lifetime.end.p0(i64 152, ptr nonnull %4) #5
  br label %65

61:                                               ; preds = %39, %39
  %62 = load i32, ptr %12, align 8, !tbaa !16
  %63 = getelementptr inbounds i8, ptr %41, i64 48
  %64 = load i64, ptr %63, align 8, !tbaa !22
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 16, i8 noundef zeroext 1, ptr noundef nonnull @.str.19, i32 noundef %62, i64 noundef %64) #5
  call void @llvm.lifetime.end.p0(i64 152, ptr nonnull %4) #5
  br label %65

65:                                               ; preds = %61, %.thread, %38, %2
  %.6 = phi i32 [ -1, %2 ], [ %.1, %38 ], [ 0, %61 ], [ %.4.ph, %.thread ]
  ret i32 %.6
}

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

declare i32 @XSock_NonBlock(ptr noundef, i8 noundef zeroext) local_unnamed_addr #2

declare ptr @XSock_ErrStr(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

declare void @XSock_Close(ptr noundef) local_unnamed_addr #2

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

declare void @XHTTP_Clear(ptr noundef) local_unnamed_addr #2

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

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

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

declare ptr @XEvents_GetStatusStr(i32 noundef) local_unnamed_addr #2

declare ptr @XHTTP_GetStatusStr(i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @XSTR_Error() local_unnamed_addr #4

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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #4 = { inlinehint 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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 24}
!6 = !{!"XEvents", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36, !8, i64 40, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"XHash", !7, i64 0, !7, i64 8, !12, i64 16, !8, i64 24}
!12 = !{!"long", !8, i64 0}
!13 = !{!14, !10, i64 128}
!14 = !{!"XSocket", !10, i64 0, !8, i64 4, !10, i64 116, !10, i64 120, !15, i64 124, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !7, i64 144}
!15 = !{!"short", !8, i64 0}
!16 = !{!17, !10, i64 16}
!17 = !{!"XEventData", !7, i64 0, !10, i64 8, !8, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!18 = !{!10, !10, i64 0}
!19 = !{!17, !7, i64 0}
!20 = !{!14, !10, i64 0}
!21 = !{!17, !8, i64 12}
!22 = !{!23, !12, i64 48}
!23 = !{!"xhttp_", !7, i64 0, !15, i64 8, !7, i64 16, !10, i64 24, !24, i64 32, !10, i64 64, !25, i64 72, !15, i64 120, !15, i64 122, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !8, i64 168, !8, i64 169, !8, i64 170, !8, i64 171, !8, i64 427, !8, i64 555}
!24 = !{!"XByteBuffer", !7, i64 0, !12, i64 8, !12, i64 16, !15, i64 24, !15, i64 26, !10, i64 28}
!25 = !{!"XMap", !7, i64 0, !7, i64 8, !7, i64 16, !12, i64 24, !12, i64 32, !10, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass