; 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.xweb_frame_ = type { i32, %struct.XByteBuffer, i64, i64, i32, i8, i8, i8, i8, i8 }
%struct.XByteBuffer = type { ptr, i64, i64, i16, i16, i32 }
%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.session_data_t = type { i64, i64 }

@.str.13 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [20 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

declare i32 @XWebFrame_Create(ptr noundef, ptr noundef, i64 noundef, i32 noundef, i8 noundef zeroext) #1

declare ptr @XWebSock_GetStatusStr(i32 noundef) #1

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

declare void @XWebFrame_Clear(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @send_request(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 i32, align 4
  %8 = alloca %struct.xweb_frame_, align 8
  %9 = alloca [2048 x i8], align 16
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  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) #4
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.xapi_data_, ptr %12, i32 0, i32 18
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 72, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 2048, ptr %9) #4
  %15 = getelementptr inbounds [2048 x i8], ptr %9, i64 0, i64 0
  %16 = call i32 @XCLI_GetInput(ptr noundef @.str.13, ptr noundef %15, i64 noundef 2048, i8 noundef zeroext 1)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %17 = getelementptr inbounds [2048 x i8], ptr %9, i64 0, i64 0
  %18 = call i64 @strlen(ptr noundef %17) #5
  store i64 %18, ptr %10, align 8, !tbaa !16
  %19 = load i64, ptr %10, align 8, !tbaa !16
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %22, label %21

21:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %50

22:                                               ; preds = %2
  %23 = getelementptr inbounds [2048 x i8], ptr %9, i64 0, i64 0
  %24 = load i64, ptr %10, align 8, !tbaa !16
  %25 = call i32 @XWebFrame_Create(ptr noundef %8, ptr noundef %23, i64 noundef %24, i32 noundef 1, i8 noundef zeroext 1)
  store i32 %25, ptr %7, align 4, !tbaa !17
  %26 = load i32, ptr %7, align 4, !tbaa !17
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %22
  %29 = load i32, ptr %7, align 4, !tbaa !17
  %30 = call ptr @XWebSock_GetStatusStr(i32 noundef %29)
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.14, ptr noundef %30)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %50

31:                                               ; preds = %22
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.xapi_data_, ptr %32, i32 0, i32 4
  %34 = getelementptr inbounds %struct.XSocket, ptr %33, i32 0, i32 5
  %35 = load i32, ptr %34, align 8, !tbaa !18
  %36 = getelementptr inbounds %struct.xweb_frame_, ptr %8, i32 0, i32 1
  %37 = getelementptr inbounds %struct.XByteBuffer, ptr %36, i32 0, i32 2
  %38 = load i64, ptr %37, align 8, !tbaa !19
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef @.str.15, i32 noundef %35, i64 noundef %38)
  %39 = getelementptr inbounds [2048 x i8], ptr %9, i64 0, i64 0
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef @.str.16, ptr noundef %39)
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.xapi_data_, ptr %40, i32 0, i32 13
  %42 = getelementptr inbounds %struct.xweb_frame_, ptr %8, i32 0, i32 1
  %43 = call i32 @XByteBuffer_AddBuff(ptr noundef %41, ptr noundef %42)
  call void @XWebFrame_Clear(ptr noundef %8)
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.session_data_t, ptr %44, i32 0, i32 1
  %46 = load i64, ptr %45, align 8, !tbaa !21
  %47 = add i64 %46, 1
  store i64 %47, ptr %45, align 8, !tbaa !21
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = call i32 @XAPI_EnableEvent(ptr noundef %48, i32 noundef 4)
  store i32 %49, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %50

50:                                               ; preds = %31, %28, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 2048, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %51 = load i32, ptr %3, align 4
  ret i32 %51
}

declare i32 @XCLI_GetInput(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

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

!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 2568}
!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 = !{!15, !15, i64 0}
!17 = !{!13, !13, i64 0}
!18 = !{!10, !13, i64 2440}
!19 = !{!20, !15, i64 24}
!20 = !{!"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}
!21 = !{!22, !15, i64 8}
!22 = !{!"", !15, i64 0, !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"

%struct.xweb_frame_ = type { i32, %struct.XByteBuffer, i64, i64, i32, i8, i8, i8, i8, i8 }
%struct.XByteBuffer = type { ptr, i64, i64, i16, i16, i32 }

@.str.13 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: mustprogress 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, ...) local_unnamed_addr #1

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

declare i32 @XWebFrame_Create(ptr noundef, ptr noundef, i64 noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

declare ptr @XWebSock_GetStatusStr(i32 noundef) local_unnamed_addr #1

declare i32 @XByteBuffer_AddBuff(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @XWebFrame_Clear(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @send_request(ptr nocapture noundef readnone %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.xweb_frame_, align 8
  %4 = alloca [2048 x i8], align 16
  %5 = getelementptr inbounds i8, ptr %1, i64 2568
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %4) #4
  %7 = call i32 @XCLI_GetInput(ptr noundef nonnull @.str.13, ptr noundef nonnull %4, i64 noundef 2048, i8 noundef zeroext 1) #4
  %8 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %4) #5
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %25, label %9

9:                                                ; preds = %2
  %10 = call i32 @XWebFrame_Create(ptr noundef nonnull %3, ptr noundef nonnull %4, i64 noundef %8, i32 noundef 1, i8 noundef zeroext 1) #4
  %.not11 = icmp eq i32 %10, 0
  br i1 %.not11, label %13, label %11

11:                                               ; preds = %9
  %12 = call ptr @XWebSock_GetStatusStr(i32 noundef %10) #4
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef nonnull @.str.14, ptr noundef %12) #4
  br label %25

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %1, i64 2440
  %15 = load i32, ptr %14, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %3, i64 8
  %17 = getelementptr inbounds i8, ptr %3, i64 24
  %18 = load i64, ptr %17, align 8, !tbaa !16
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef nonnull @.str.15, i32 noundef %15, i64 noundef %18) #4
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef nonnull @.str.16, ptr noundef nonnull %4) #4
  %19 = getelementptr inbounds i8, ptr %1, i64 2512
  %20 = call i32 @XByteBuffer_AddBuff(ptr noundef nonnull %19, ptr noundef nonnull %16) #4
  call void @XWebFrame_Clear(ptr noundef nonnull %3) #4
  %21 = getelementptr inbounds i8, ptr %6, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !18
  %23 = add i64 %22, 1
  store i64 %23, ptr %21, align 8, !tbaa !18
  %24 = call i32 @XAPI_EnableEvent(ptr noundef nonnull %1, i32 noundef 4) #4
  br label %25

25:                                               ; preds = %2, %13, %11
  %.0 = phi i32 [ -1, %11 ], [ %24, %13 ], [ 0, %2 ]
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %3) #4
  ret i32 %.0
}

declare i32 @XCLI_GetInput(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 2568}
!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, !11, i64 2440}
!16 = !{!17, !14, i64 24}
!17 = !{!"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}
!18 = !{!19, !14, i64 8}
!19 = !{!"", !14, i64 0, !14, i64 8}


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