; LLVM IR from kala13x/libxutils :: examples (ws-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.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.xweb_frame_ = type { i32, %struct.XByteBuffer, i64, i64, i32, i8, i8, i8, i8, i8 }
%struct.session_data_t = type { i64, i64 }

@.str.9 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [21 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

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

; 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 i32 @send_pong(ptr noundef) #2

declare i32 @XAPI_EnableEvent(ptr noundef, i32 noundef) #1

; 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
  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
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.xapi_data_, ptr %10, i32 0, i32 19
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.xapi_data_, ptr %13, i32 0, i32 18
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  store ptr %15, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.xapi_data_, ptr %16, i32 0, i32 4
  %18 = getelementptr inbounds %struct.XSocket, ptr %17, i32 0, i32 5
  %19 = load i32, ptr %18, align 8, !tbaa !17
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.xweb_frame_, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !18
  %23 = call ptr @XWS_FrameTypeStr(i32 noundef %22)
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.xweb_frame_, ptr %24, i32 0, i32 9
  %26 = load i8, ptr %25, align 8, !tbaa !20
  %27 = zext i8 %26 to i32
  %28 = icmp ne i32 %27, 0
  %29 = zext i1 %28 to i64
  %30 = select i1 %28, ptr @.str.10, ptr @.str.11
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.xweb_frame_, ptr %31, i32 0, i32 3
  %33 = load i64, ptr %32, align 8, !tbaa !21
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.xweb_frame_, ptr %34, i32 0, i32 2
  %36 = load i64, ptr %35, align 8, !tbaa !22
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.xweb_frame_, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds %struct.XByteBuffer, ptr %38, i32 0, i32 2
  %40 = load i64, ptr %39, align 8, !tbaa !23
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef @.str.9, i32 noundef %19, ptr noundef %23, ptr noundef %30, i64 noundef %33, i64 noundef %36, i64 noundef %40)
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.xweb_frame_, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !18
  %44 = icmp eq i32 %43, 9
  br i1 %44, label %45, label %56

45:                                               ; preds = %2
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.session_data_t, ptr %46, i32 0, i32 0
  %48 = load i64, ptr %47, align 8, !tbaa !24
  %49 = add i64 %48, 1
  store i64 %49, ptr %47, align 8, !tbaa !24
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.session_data_t, ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !26
  %53 = add i64 %52, 1
  store i64 %53, ptr %51, align 8, !tbaa !26
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = call i32 @send_pong(ptr noundef %54)
  store i32 %55, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %81

56:                                               ; preds = %2
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.xweb_frame_, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !18
  %60 = icmp eq i32 %59, 8
  br i1 %60, label %61, label %62

61:                                               ; preds = %56
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %81

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

67:                                               ; preds = %62
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.xweb_frame_, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 8, !tbaa !18
  %71 = icmp eq i32 %70, 1
  br i1 %71, label %72, label %74

72:                                               ; preds = %67
  %73 = 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.12, ptr noundef %73)
  br label %74

74:                                               ; preds = %72, %67, %62
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.session_data_t, ptr %75, i32 0, i32 0
  %77 = load i64, ptr %76, align 8, !tbaa !24
  %78 = add i64 %77, 1
  store i64 %78, ptr %76, align 8, !tbaa !24
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = call i32 @XAPI_EnableEvent(ptr noundef %79, i32 noundef 4)
  store i32 %80, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %81

81:                                               ; preds = %74, %61, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %82 = load i32, ptr %3, align 4
  ret i32 %82
}

declare ptr @XWS_FrameTypeStr(i32 noundef) #1

declare ptr @XWebFrame_GetPayload(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 = !{!10, !13, i64 2440}
!18 = !{!19, !13, i64 0}
!19 = !{!"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}
!20 = !{!19, !7, i64 64}
!21 = !{!19, !15, i64 48}
!22 = !{!19, !15, i64 40}
!23 = !{!19, !15, i64 24}
!24 = !{!25, !15, i64 0}
!25 = !{!"", !15, i64 0, !15, i64 8}
!26 = !{!25, !15, i64 8}


; 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.9 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [21 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

declare i32 @XAPI_EnableEvent(ptr noundef, i32 noundef) local_unnamed_addr #0

; 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 = getelementptr inbounds i8, ptr %1, i64 2440
  %8 = load i32, ptr %7, align 8, !tbaa !16
  %9 = load i32, ptr %4, align 8, !tbaa !17
  %10 = tail call ptr @XWS_FrameTypeStr(i32 noundef %9) #2
  %11 = getelementptr inbounds i8, ptr %4, i64 64
  %12 = load i8, ptr %11, align 8, !tbaa !19
  %.not = icmp eq i8 %12, 0
  %13 = select i1 %.not, ptr @.str.11, ptr @.str.10
  %14 = getelementptr inbounds i8, ptr %4, i64 48
  %15 = load i64, ptr %14, align 8, !tbaa !20
  %16 = getelementptr inbounds i8, ptr %4, i64 40
  %17 = load i64, ptr %16, align 8, !tbaa !21
  %18 = getelementptr inbounds i8, ptr %4, i64 24
  %19 = load i64, ptr %18, align 8, !tbaa !22
  tail call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef nonnull @.str.9, i32 noundef %8, ptr noundef %10, ptr noundef nonnull %13, i64 noundef %15, i64 noundef %17, i64 noundef %19) #2
  %20 = load i32, ptr %4, align 8, !tbaa !17
  switch i32 %20, label %25 [
    i32 9, label %21
    i32 8, label %35
  ]

21:                                               ; preds = %2
  %22 = load <2 x i64>, ptr %6, align 8, !tbaa !23
  %23 = add <2 x i64> %22, <i64 1, i64 1>
  store <2 x i64> %23, ptr %6, align 8, !tbaa !23
  %24 = tail call i32 @send_pong(ptr noundef nonnull %1)
  br label %35

25:                                               ; preds = %2
  %26 = tail call ptr @XWebFrame_GetPayload(ptr noundef nonnull %4) #2
  %.not21 = icmp eq ptr %26, null
  br i1 %.not21, label %31, label %27

27:                                               ; preds = %25
  %28 = load i32, ptr %4, align 8, !tbaa !17
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  tail call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef nonnull @.str.12, ptr noundef nonnull %26) #2
  br label %31

31:                                               ; preds = %30, %27, %25
  %32 = load i64, ptr %6, align 8, !tbaa !24
  %33 = add i64 %32, 1
  store i64 %33, ptr %6, align 8, !tbaa !24
  %34 = tail call i32 @XAPI_EnableEvent(ptr noundef nonnull %1, i32 noundef 4) #2
  br label %35

35:                                               ; preds = %2, %31, %21
  %.0 = phi i32 [ %24, %21 ], [ %34, %31 ], [ -1, %2 ]
  ret i32 %.0
}

declare ptr @XWS_FrameTypeStr(i32 noundef) local_unnamed_addr #0

declare ptr @XWebFrame_GetPayload(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 = !{!6, !11, i64 2440}
!17 = !{!18, !11, i64 0}
!18 = !{!"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}
!19 = !{!18, !7, i64 64}
!20 = !{!18, !14, i64 48}
!21 = !{!18, !14, i64 40}
!22 = !{!18, !14, i64 24}
!23 = !{!14, !14, i64 0}
!24 = !{!25, !14, i64 0}
!25 = !{!"", !14, i64 0, !14, i64 8}


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