; LLVM IR from kala13x/libxutils :: examples (async-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.xapi_ctx_ = type { i32, i32, i8, ptr }
%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.xasync_srv_args_t = type { [2048 x i8], [2048 x i8], [2048 x i8], [128 x i8], i16, i8, i8, i8 }

@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @handle_status(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call ptr @XAPI_GetStatus(ptr noundef %9)
  store ptr %10, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %18

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.xapi_data_, ptr %14, i32 0, i32 4
  %16 = getelementptr inbounds %struct.XSocket, ptr %15, i32 0, i32 5
  %17 = load i32, ptr %16, align 8, !tbaa !9
  br label %19

18:                                               ; preds = %2
  br label %19

19:                                               ; preds = %18, %13
  %20 = phi i32 [ %17, %13 ], [ -1, %18 ]
  store i32 %20, ptr %6, align 4, !tbaa !16
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.xapi_ctx_, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !17
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %25, label %28

25:                                               ; preds = %19
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i32, ptr %6, align 4, !tbaa !16
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef @.str.1, ptr noundef %26, i32 noundef %27)
  br label %39

28:                                               ; preds = %19
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.xapi_ctx_, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !17
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %38

33:                                               ; preds = %28
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !16
  %36 = call ptr @__errno_location() #5
  %37 = load i32, ptr %36, align 4, !tbaa !16
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.2, ptr noundef %34, i32 noundef %35, i32 noundef %37)
  br label %38

38:                                               ; preds = %33, %28
  br label %39

39:                                               ; preds = %38, %25
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.xapi_ctx_, ptr %40, i32 0, i32 2
  %42 = load i8, ptr %41, align 8, !tbaa !19
  %43 = zext i8 %42 to i32
  %44 = icmp eq i32 %43, 15
  br i1 %44, label %45, label %62

45:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.xapi_ctx_, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !20
  store ptr %48, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.xapi_, ptr %49, i32 0, i32 3
  %51 = load ptr, ptr %50, align 8, !tbaa !21
  store ptr %51, ptr %8, align 8, !tbaa !5
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.xasync_srv_args_t, ptr %52, i32 0, i32 6
  %54 = load i8, ptr %53, align 1, !tbaa !25
  %55 = icmp ne i8 %54, 0
  br i1 %55, label %56, label %61

56:                                               ; preds = %45
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.xasync_srv_args_t, ptr %57, i32 0, i32 3
  %59 = getelementptr inbounds [128 x i8], ptr %58, i64 0, i64 0
  %60 = call i32 @XPath_Remove(ptr noundef %59)
  br label %61

61:                                               ; preds = %56, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %62

62:                                               ; preds = %61, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i32 1
}

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

declare ptr @XAPI_GetStatus(ptr noundef) #2

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

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

declare i32 @XPath_Remove(ptr noundef) #2

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

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 = { nounwind }
attributes #5 = { 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, !13, i64 2440}
!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 = !{!13, !13, i64 0}
!17 = !{!18, !13, i64 0}
!18 = !{!"xapi_ctx_", !13, i64 0, !13, i64 4, !7, i64 8, !6, i64 16}
!19 = !{!18, !7, i64 8}
!20 = !{!18, !6, i64 16}
!21 = !{!22, !6, i64 1880}
!22 = !{!"xapi_", !6, i64 0, !23, i64 8, !15, i64 1872, !6, i64 1880, !7, i64 1888, !7, i64 1889, !7, i64 1890}
!23 = !{!"XEvents", !6, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !13, i64 36, !7, i64 40, !24, i64 48}
!24 = !{!"XHash", !6, i64 0, !6, i64 8, !15, i64 16, !7, i64 24}
!25 = !{!26, !7, i64 6275}
!26 = !{!"", !7, i64 0, !7, i64 2048, !7, i64 4096, !7, i64 6144, !11, i64 6272, !7, i64 6274, !7, i64 6275, !7, i64 6276}


; 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.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @handle_status(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = tail call ptr @XAPI_GetStatus(ptr noundef %0) #3
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %7, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 2440
  %6 = load i32, ptr %5, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %2, %4
  %8 = phi i32 [ %6, %4 ], [ -1, %2 ]
  %9 = load i32, ptr %0, align 8, !tbaa !15
  switch i32 %9, label %14 [
    i32 1, label %10
    i32 0, label %11
  ]

10:                                               ; preds = %7
  tail call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef nonnull @.str.1, ptr noundef %3, i32 noundef %8) #3
  br label %14

11:                                               ; preds = %7
  %12 = tail call ptr @__errno_location() #4
  %13 = load i32, ptr %12, align 4, !tbaa !17
  tail call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef nonnull @.str.2, ptr noundef %3, i32 noundef %8, i32 noundef %13) #3
  br label %14

14:                                               ; preds = %7, %11, %10
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i8, ptr %15, align 8, !tbaa !18
  %17 = icmp eq i8 %16, 15
  br i1 %17, label %18, label %28

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !19
  %21 = getelementptr inbounds i8, ptr %20, i64 1880
  %22 = load ptr, ptr %21, align 8, !tbaa !20
  %23 = getelementptr inbounds i8, ptr %22, i64 6275
  %24 = load i8, ptr %23, align 1, !tbaa !24
  %.not14 = icmp eq i8 %24, 0
  br i1 %.not14, label %28, label %25

25:                                               ; preds = %18
  %26 = getelementptr inbounds i8, ptr %22, i64 6144
  %27 = tail call i32 @XPath_Remove(ptr noundef nonnull %26) #3
  br label %28

28:                                               ; preds = %18, %25, %14
  ret i32 1
}

declare ptr @XAPI_GetStatus(ptr noundef) local_unnamed_addr #1

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

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

declare i32 @XPath_Remove(ptr noundef) local_unnamed_addr #1

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 = { "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 = { 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 #3 = { nounwind }
attributes #4 = { 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, !11, i64 2440}
!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 = !{!16, !11, i64 0}
!16 = !{!"xapi_ctx_", !11, i64 0, !11, i64 4, !7, i64 8, !12, i64 16}
!17 = !{!11, !11, i64 0}
!18 = !{!16, !7, i64 8}
!19 = !{!16, !12, i64 16}
!20 = !{!21, !12, i64 1880}
!21 = !{!"xapi_", !12, i64 0, !22, i64 8, !14, i64 1872, !12, i64 1880, !7, i64 1888, !7, i64 1889, !7, i64 1890}
!22 = !{!"XEvents", !12, i64 0, !11, i64 8, !12, i64 16, !12, i64 24, !11, i64 32, !11, i64 36, !7, i64 40, !23, i64 48}
!23 = !{!"XHash", !12, i64 0, !12, i64 8, !14, i64 16, !7, i64 24}
!24 = !{!25, !7, i64 6275}
!25 = !{!"", !7, i64 0, !7, i64 2048, !7, i64 4096, !7, i64 6144, !9, i64 6272, !7, i64 6274, !7, i64 6275, !7, i64 6276}


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