; 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.xapi_data_ = type { [128 x i8], [128 x i8], [2048 x i8], i16, %struct.XSocket, i32, i8, i8, i8, i8, i8, i8, %struct.XByteBuffer, %struct.XByteBuffer, ptr, i32, i32, ptr, ptr, ptr }
%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.XByteBuffer = type { ptr, i64, i64, i16, i16, i32 }
%struct.session_data_t = type { i64, i64 }
%struct.xweb_frame_ = type { i32, %struct.XByteBuffer, i64, i64, i32, i8, i8, i8, i8, i8 }

@.str.12 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [24 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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @send_pong(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @send_response(ptr noundef, ptr noundef, i64 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @handle_frame(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.xapi_data_, ptr %11, i32 0, i32 19
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.xapi_data_, ptr %14, i32 0, i32 18
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  store ptr %16, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.session_data_t, ptr %17, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !17
  %20 = add i64 %19, 1
  store i64 %20, ptr %18, align 8, !tbaa !17
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.xapi_data_, ptr %21, i32 0, i32 4
  %23 = getelementptr inbounds %struct.XSocket, ptr %22, i32 0, i32 5
  %24 = load i32, ptr %23, align 8, !tbaa !19
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.xweb_frame_, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !20
  %28 = call ptr @XWS_FrameTypeStr(i32 noundef %27)
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.xweb_frame_, ptr %29, i32 0, i32 9
  %31 = load i8, ptr %30, align 8, !tbaa !22
  %32 = zext i8 %31 to i32
  %33 = icmp ne i32 %32, 0
  %34 = zext i1 %33 to i64
  %35 = select i1 %33, ptr @.str.13, ptr @.str.14
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.xweb_frame_, ptr %36, i32 0, i32 3
  %38 = load i64, ptr %37, align 8, !tbaa !23
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.xweb_frame_, ptr %39, i32 0, i32 2
  %41 = load i64, ptr %40, align 8, !tbaa !24
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.xweb_frame_, ptr %42, i32 0, i32 1
  %44 = getelementptr inbounds %struct.XByteBuffer, ptr %43, i32 0, i32 2
  %45 = load i64, ptr %44, align 8, !tbaa !25
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef @.str.12, i32 noundef %24, ptr noundef %28, ptr noundef %35, i64 noundef %38, i64 noundef %41, i64 noundef %45)
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.xweb_frame_, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !20
  %49 = icmp eq i32 %48, 9
  br i1 %49, label %50, label %53

50:                                               ; preds = %2
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = call i32 @send_pong(ptr noundef %51)
  store i32 %52, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %93

53:                                               ; preds = %2
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.xweb_frame_, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !20
  %57 = icmp eq i32 %56, 8
  br i1 %57, label %58, label %59

58:                                               ; preds = %53
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %93

59:                                               ; preds = %53
  br label %60

60:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = call ptr @XWebFrame_GetPayload(ptr noundef %61)
  store ptr %62, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = call i64 @XWebFrame_GetPayloadLength(ptr noundef %63)
  store i64 %64, ptr %10, align 8, !tbaa !26
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %70

67:                                               ; preds = %60
  %68 = load i64, ptr %10, align 8, !tbaa !26
  %69 = icmp ne i64 %68, 0
  br i1 %69, label %71, label %70

70:                                               ; preds = %67, %60
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %92

71:                                               ; preds = %67
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.xweb_frame_, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 8, !tbaa !20
  %75 = icmp eq i32 %74, 1
  br i1 %75, label %76, label %84

76:                                               ; preds = %71
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = call zeroext i8 @xstrused(ptr noundef %77)
  %79 = zext i8 %78 to i32
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %84

81:                                               ; preds = %76
  %82 = load i64, ptr %10, align 8, !tbaa !26
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef @.str.15, i64 noundef %82, ptr noundef %83)
  br label %84

84:                                               ; preds = %81, %76, %71
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  %87 = load i64, ptr %10, align 8, !tbaa !26
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.xweb_frame_, ptr %88, i32 0, i32 0
  %90 = load i32, ptr %89, align 8, !tbaa !20
  %91 = call i32 @send_response(ptr noundef %85, ptr noundef %86, i64 noundef %87, i32 noundef %90)
  store i32 %91, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %92

92:                                               ; preds = %84, %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %93

93:                                               ; preds = %92, %58, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %94 = load i32, ptr %3, align 4
  ret i32 %94
}

declare ptr @XWS_FrameTypeStr(i32 noundef) #1

declare ptr @XWebFrame_GetPayload(ptr noundef) #1

declare i64 @XWebFrame_GetPayloadLength(ptr noundef) #1

declare zeroext i8 @xstrused(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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, !6, i64 2576}
!10 = !{!"xapi_data_", !7, i64 0, !7, i64 128, !7, i64 256, !11, i64 2304, !12, i64 2312, !13, i64 2464, !7, i64 2468, !7, i64 2469, !7, i64 2470, !7, i64 2471, !7, i64 2472, !7, i64 2473, !14, i64 2480, !14, i64 2512, !6, i64 2544, !13, i64 2552, !13, i64 2556, !6, i64 2560, !6, i64 2568, !6, i64 2576}
!11 = !{!"short", !7, i64 0}
!12 = !{!"XSocket", !13, i64 0, !7, i64 4, !13, i64 116, !13, i64 120, !11, i64 124, !13, i64 128, !13, i64 132, !13, i64 136, !13, i64 140, !6, i64 144}
!13 = !{!"int", !7, i64 0}
!14 = !{!"XByteBuffer", !6, i64 0, !15, i64 8, !15, i64 16, !11, i64 24, !11, i64 26, !13, i64 28}
!15 = !{!"long", !7, i64 0}
!16 = !{!10, !6, i64 2568}
!17 = !{!18, !15, i64 0}
!18 = !{!"", !15, i64 0, !15, i64 8}
!19 = !{!10, !13, i64 2440}
!20 = !{!21, !13, i64 0}
!21 = !{!"xweb_frame_", !13, i64 0, !14, i64 8, !15, i64 40, !15, i64 48, !13, i64 56, !7, i64 60, !7, i64 61, !7, i64 62, !7, i64 63, !7, i64 64}
!22 = !{!21, !7, i64 64}
!23 = !{!21, !15, i64 48}
!24 = !{!21, !15, i64 40}
!25 = !{!21, !15, i64 24}
!26 = !{!15, !15, i64 0}


; 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.12 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [24 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @handle_frame(ptr nocapture noundef readnone %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 2576
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 2568
  %6 = load ptr, ptr %5, align 8, !tbaa !15
  %7 = load i64, ptr %6, align 8, !tbaa !16
  %8 = add i64 %7, 1
  store i64 %8, ptr %6, align 8, !tbaa !16
  %9 = getelementptr inbounds i8, ptr %1, i64 2440
  %10 = load i32, ptr %9, align 8, !tbaa !18
  %11 = load i32, ptr %4, align 8, !tbaa !19
  %12 = tail call ptr @XWS_FrameTypeStr(i32 noundef %11) #2
  %13 = getelementptr inbounds i8, ptr %4, i64 64
  %14 = load i8, ptr %13, align 8, !tbaa !21
  %.not = icmp eq i8 %14, 0
  %15 = select i1 %.not, ptr @.str.14, ptr @.str.13
  %16 = getelementptr inbounds i8, ptr %4, i64 48
  %17 = load i64, ptr %16, align 8, !tbaa !22
  %18 = getelementptr inbounds i8, ptr %4, i64 40
  %19 = load i64, ptr %18, align 8, !tbaa !23
  %20 = getelementptr inbounds i8, ptr %4, i64 24
  %21 = load i64, ptr %20, align 8, !tbaa !24
  tail call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef nonnull @.str.12, i32 noundef %10, ptr noundef %12, ptr noundef nonnull %15, i64 noundef %17, i64 noundef %19, i64 noundef %21) #2
  %22 = load i32, ptr %4, align 8, !tbaa !19
  switch i32 %22, label %25 [
    i32 9, label %23
    i32 8, label %39
  ]

23:                                               ; preds = %2
  %24 = tail call i32 @send_pong(ptr noundef nonnull %1)
  br label %39

25:                                               ; preds = %2
  %26 = tail call ptr @XWebFrame_GetPayload(ptr noundef nonnull %4) #2
  %27 = tail call i64 @XWebFrame_GetPayloadLength(ptr noundef nonnull %4) #2
  %28 = icmp ne ptr %26, null
  %29 = icmp ne i64 %27, 0
  %or.cond = select i1 %28, i1 %29, i1 false
  br i1 %or.cond, label %30, label %39

30:                                               ; preds = %25
  %31 = load i32, ptr %4, align 8, !tbaa !19
  %32 = icmp eq i32 %31, 1
  br i1 %32, label %33, label %36

33:                                               ; preds = %30
  %34 = tail call zeroext i8 @xstrused(ptr noundef nonnull %26) #2
  %.not28 = icmp eq i8 %34, 0
  br i1 %.not28, label %36, label %35

35:                                               ; preds = %33
  tail call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef nonnull @.str.15, i64 noundef %27, ptr noundef nonnull %26) #2
  br label %36

36:                                               ; preds = %35, %33, %30
  %37 = load i32, ptr %4, align 8, !tbaa !19
  %38 = tail call i32 @send_response(ptr noundef nonnull %1, ptr noundef nonnull %26, i64 noundef %27, i32 noundef %37)
  br label %39

39:                                               ; preds = %36, %25, %2, %23
  %.1 = phi i32 [ %24, %23 ], [ -1, %2 ], [ %38, %36 ], [ 1, %25 ]
  ret i32 %.1
}

declare ptr @XWS_FrameTypeStr(i32 noundef) local_unnamed_addr #0

declare ptr @XWebFrame_GetPayload(ptr noundef) local_unnamed_addr #0

declare i64 @XWebFrame_GetPayloadLength(ptr noundef) local_unnamed_addr #0

declare zeroext i8 @xstrused(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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, !12, i64 2576}
!6 = !{!"xapi_data_", !7, i64 0, !7, i64 128, !7, i64 256, !9, i64 2304, !10, i64 2312, !11, i64 2464, !7, i64 2468, !7, i64 2469, !7, i64 2470, !7, i64 2471, !7, i64 2472, !7, i64 2473, !13, i64 2480, !13, i64 2512, !12, i64 2544, !11, i64 2552, !11, i64 2556, !12, i64 2560, !12, i64 2568, !12, i64 2576}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!"XSocket", !11, i64 0, !7, i64 4, !11, i64 116, !11, i64 120, !9, i64 124, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !12, i64 144}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"XByteBuffer", !12, i64 0, !14, i64 8, !14, i64 16, !9, i64 24, !9, i64 26, !11, i64 28}
!14 = !{!"long", !7, i64 0}
!15 = !{!6, !12, i64 2568}
!16 = !{!17, !14, i64 0}
!17 = !{!"", !14, i64 0, !14, i64 8}
!18 = !{!6, !11, i64 2440}
!19 = !{!20, !11, i64 0}
!20 = !{!"xweb_frame_", !11, i64 0, !13, i64 8, !14, i64 40, !14, i64 48, !11, i64 56, !7, i64 60, !7, i64 61, !7, i64 62, !7, i64 63, !7, i64 64}
!21 = !{!20, !7, i64 64}
!22 = !{!20, !14, i64 48}
!23 = !{!20, !14, i64 40}
!24 = !{!20, !14, i64 24}


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