; LLVM IR from kala13x/libxutils :: src/net (sock)

; 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.XSocketInfo = type { [128 x i8], [256 x i8], i32, i32, i16 }
%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 }

declare zeroext i8 @xstrused(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @XSock_Create(ptr noundef, i32 noundef, ptr noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XSock_Open(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.XSocketInfo, ptr %8, i32 0, i32 0
  %10 = getelementptr inbounds [128 x i8], ptr %9, i64 0, i64 0
  %11 = call zeroext i8 @xstrused(ptr noundef %10)
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %13, label %22

13:                                               ; preds = %3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.XSocketInfo, ptr %14, i32 0, i32 4
  %16 = load i16, ptr %15, align 4, !tbaa !11
  %17 = icmp ne i16 %16, 0
  br i1 %17, label %27, label %18

18:                                               ; preds = %13
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = and i32 %19, 8
  %21 = icmp eq i32 %20, 8
  br i1 %21, label %27, label %22

22:                                               ; preds = %18, %3
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.XSocket, ptr %23, i32 0, i32 0
  store i32 2, ptr %24, align 8, !tbaa !14
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.XSocket, ptr %25, i32 0, i32 5
  store i32 -1, ptr %26, align 8, !tbaa !16
  store i32 -1, ptr %4, align 4
  br label %37

27:                                               ; preds = %18, %13
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.XSocketInfo, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [128 x i8], ptr %31, i64 0, i64 0
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.XSocketInfo, ptr %33, i32 0, i32 4
  %35 = load i16, ptr %34, align 4, !tbaa !11
  %36 = call i32 @XSock_Create(ptr noundef %28, i32 noundef %29, ptr noundef %32, i16 noundef zeroext %35)
  store i32 %36, ptr %4, align 4
  br label %37

37:                                               ; preds = %27, %22
  %38 = load i32, ptr %4, align 4
  ret i32 %38
}

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

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 392}
!12 = !{!"XSocketInfo", !7, i64 0, !7, i64 128, !10, i64 384, !10, i64 388, !13, i64 392}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"XSocket", !10, i64 0, !7, i64 4, !10, i64 116, !10, i64 120, !13, i64 124, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !6, i64 144}
!16 = !{!15, !10, i64 128}


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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @XSock_Create(ptr noundef, i32 noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XSock_Open(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = tail call zeroext i8 @xstrused(ptr noundef %2) #2
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %9, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %2, i64 392
  %7 = load i16, ptr %6, align 4, !tbaa !5
  %.not9 = icmp eq i16 %7, 0
  %8 = and i32 %1, 8
  %.not10 = icmp eq i32 %8, 0
  %or.cond = and i1 %.not10, %.not9
  br i1 %or.cond, label %9, label %11

9:                                                ; preds = %5, %3
  store i32 2, ptr %0, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %0, i64 128
  store i32 -1, ptr %10, align 8, !tbaa !14
  br label %13

11:                                               ; preds = %5
  %12 = tail call i32 @XSock_Create(ptr noundef %0, i32 noundef %1, ptr noundef nonnull %2, i16 noundef zeroext %7)
  br label %13

13:                                               ; preds = %11, %9
  %.0 = phi i32 [ %12, %11 ], [ -1, %9 ]
  ret i32 %.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, !10, i64 392}
!6 = !{!"XSocketInfo", !7, i64 0, !7, i64 128, !9, i64 384, !9, i64 388, !10, i64 392}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !9, i64 0}
!12 = !{!"XSocket", !9, i64 0, !7, i64 4, !9, i64 116, !9, i64 120, !10, i64 124, !9, i64 128, !9, i64 132, !9, i64 136, !9, i64 140, !13, i64 144}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!12, !9, i64 128}


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