; 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 }

@.str.17 = external hidden unnamed_addr constant [26 x i8], align 1

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @destroy_session(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.xapi_data_, ptr %5, i32 0, i32 4
  %7 = getelementptr inbounds %struct.XSocket, ptr %6, i32 0, i32 5
  %8 = load i32, ptr %7, align 8, !tbaa !9
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef @.str.17, i32 noundef %8)
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.xapi_data_, ptr %9, i32 0, i32 18
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %19

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, 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
  call void @free(ptr noundef %16) #3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.xapi_data_, ptr %17, i32 0, i32 18
  store ptr null, ptr %18, align 8, !tbaa !16
  br label %19

19:                                               ; preds = %13, %2
  ret i32 -1
}

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 "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, !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 = !{!10, !6, i64 2568}


; 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.17 = external hidden unnamed_addr constant [26 x i8], align 1

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @destroy_session(ptr nocapture noundef readnone %0, ptr nocapture noundef %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 2440
  %4 = load i32, ptr %3, align 8, !tbaa !5
  tail call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 2, i8 noundef zeroext 1, ptr noundef nonnull @.str.17, i32 noundef %4) #3
  %5 = getelementptr inbounds i8, ptr %1, i64 2568
  %6 = load ptr, ptr %5, align 8, !tbaa !15
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %8, label %7

7:                                                ; preds = %2
  tail call void @free(ptr noundef nonnull %6) #3
  store ptr null, ptr %5, align 8, !tbaa !15
  br label %8

8:                                                ; preds = %7, %2
  ret i32 -1
}

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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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, !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 = !{!6, !12, i64 2568}


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