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

declare zeroext i8 @xstrused(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @XSock_New(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = and i32 %6, 8
  %8 = icmp eq i32 %7, 8
  br i1 %8, label %9, label %22

9:                                                ; preds = %2
  %10 = load ptr, ptr %5, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.XSocketInfo, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds [128 x i8], ptr %11, i64 0, i64 0
  %13 = call zeroext i8 @xstrused(ptr noundef %12)
  %14 = icmp ne i8 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %9
  store ptr null, ptr %3, align 8
  br label %43

16:                                               ; preds = %9
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.XSocketInfo, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds [128 x i8], ptr %19, i64 0, i64 0
  %21 = call ptr @XSock_Alloc(i32 noundef %17, ptr noundef %20, i16 noundef zeroext 0)
  store ptr %21, ptr %3, align 8
  br label %43

22:                                               ; preds = %2
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.XSocketInfo, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds [128 x i8], ptr %24, i64 0, i64 0
  %26 = call zeroext i8 @xstrused(ptr noundef %25)
  %27 = icmp ne i8 %26, 0
  br i1 %27, label %28, label %33

28:                                               ; preds = %22
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.XSocketInfo, ptr %29, i32 0, i32 4
  %31 = load i16, ptr %30, align 4, !tbaa !11
  %32 = icmp ne i16 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %28, %22
  store ptr null, ptr %3, align 8
  br label %43

34:                                               ; preds = %28
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.XSocketInfo, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds [128 x i8], ptr %37, i64 0, i64 0
  %39 = load ptr, ptr %5, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.XSocketInfo, ptr %39, i32 0, i32 4
  %41 = load i16, ptr %40, align 4, !tbaa !11
  %42 = call ptr @XSock_Alloc(i32 noundef %35, ptr noundef %38, i16 noundef zeroext %41)
  store ptr %42, ptr %3, align 8
  br label %43

43:                                               ; preds = %34, %33, %16, %15
  %44 = load ptr, ptr %3, align 8
  ret ptr %44
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 392}
!12 = !{!"XSocketInfo", !7, i64 0, !7, i64 128, !6, i64 384, !6, i64 388, !13, i64 392}
!13 = !{!"short", !7, i64 0}


; 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 ptr @XSock_Alloc(i32 noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

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

5:                                                ; preds = %2
  br i1 %.not10, label %14, label %6

6:                                                ; preds = %5
  %7 = tail call ptr @XSock_Alloc(i32 noundef %0, ptr noundef %1, i16 noundef zeroext 0)
  br label %14

8:                                                ; preds = %2
  br i1 %.not10, label %14, label %9

9:                                                ; preds = %8
  %10 = getelementptr inbounds i8, ptr %1, i64 392
  %11 = load i16, ptr %10, align 4, !tbaa !5
  %.not11 = icmp eq i16 %11, 0
  br i1 %.not11, label %14, label %12

12:                                               ; preds = %9
  %13 = tail call ptr @XSock_Alloc(i32 noundef %0, ptr noundef nonnull %1, i16 noundef zeroext %11)
  br label %14

14:                                               ; preds = %8, %9, %5, %12, %6
  %.0 = phi ptr [ %7, %6 ], [ %13, %12 ], [ null, %5 ], [ null, %9 ], [ null, %8 ]
  ret ptr %.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}


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