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

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

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

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

declare zeroext i8 @xstrused(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @XSock_CreateAdv(ptr noundef %0, i32 noundef %1, i64 noundef %2, ptr noundef %3, i16 noundef zeroext %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i16, align 2
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !11
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i16 %4, ptr %11, align 2, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = call i32 @XSock_Init(ptr noundef %15, i32 noundef %16, i32 noundef -1)
  store i32 %17, ptr %12, align 4, !tbaa !9
  %18 = load i32, ptr %12, align 4, !tbaa !9
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %21

20:                                               ; preds = %5
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %95

21:                                               ; preds = %5
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = call zeroext i8 @xstrused(ptr noundef %22)
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %25, label %32

25:                                               ; preds = %21
  %26 = load i16, ptr %11, align 2, !tbaa !13
  %27 = icmp ne i16 %26, 0
  br i1 %27, label %37, label %28

28:                                               ; preds = %25
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = and i32 %29, 8
  %31 = icmp eq i32 %30, 8
  br i1 %31, label %37, label %32

32:                                               ; preds = %28, %21
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.XSocket, ptr %33, i32 0, i32 0
  store i32 2, ptr %34, align 8, !tbaa !15
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XSocket, ptr %35, i32 0, i32 5
  store i32 -1, ptr %36, align 8, !tbaa !17
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %95

37:                                               ; preds = %28, %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.XSocket, ptr %38, i32 0, i32 8
  %40 = load i32, ptr %39, align 4, !tbaa !18
  store i32 %40, ptr %14, align 4, !tbaa !9
  %41 = load i32, ptr %14, align 4, !tbaa !9
  %42 = or i32 %41, 1
  store i32 %42, ptr %14, align 4, !tbaa !9
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.XSocket, ptr %43, i32 0, i32 6
  %45 = load i32, ptr %44, align 4, !tbaa !19
  %46 = load i32, ptr %14, align 4, !tbaa !9
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.XSocket, ptr %47, i32 0, i32 7
  %49 = load i32, ptr %48, align 8, !tbaa !20
  %50 = call i32 @socket(i32 noundef %45, i32 noundef %46, i32 noundef %49) #4
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.XSocket, ptr %51, i32 0, i32 5
  store i32 %50, ptr %52, align 8, !tbaa !17
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.XSocket, ptr %53, i32 0, i32 5
  %55 = load i32, ptr %54, align 8, !tbaa !17
  %56 = icmp eq i32 %55, -1
  br i1 %56, label %57, label %60

57:                                               ; preds = %37
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.XSocket, ptr %58, i32 0, i32 0
  store i32 6, ptr %59, align 8, !tbaa !15
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %94

60:                                               ; preds = %37
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = load i16, ptr %11, align 2, !tbaa !13
  call void @XSock_SetupAddr(ptr noundef %61, ptr noundef %62, i16 noundef zeroext %63)
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.XSocket, ptr %64, i32 0, i32 8
  %66 = load i32, ptr %65, align 4, !tbaa !18
  %67 = icmp eq i32 %66, 1
  br i1 %67, label %68, label %72

68:                                               ; preds = %60
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = load i64, ptr %9, align 8, !tbaa !11
  %71 = call i32 @XSock_SetupStream(ptr noundef %69, i64 noundef %70)
  br label %81

72:                                               ; preds = %60
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.XSocket, ptr %73, i32 0, i32 8
  %75 = load i32, ptr %74, align 4, !tbaa !18
  %76 = icmp eq i32 %75, 2
  br i1 %76, label %77, label %80

77:                                               ; preds = %72
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = call i32 @XSock_SetupDgram(ptr noundef %78)
  br label %80

80:                                               ; preds = %77, %72
  br label %81

81:                                               ; preds = %80, %68
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.XSocket, ptr %82, i32 0, i32 2
  %84 = load i32, ptr %83, align 4, !tbaa !21
  %85 = and i32 %84, 16384
  %86 = icmp eq i32 %85, 16384
  br i1 %86, label %87, label %90

87:                                               ; preds = %81
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = call i32 @XSock_NonBlock(ptr noundef %88, i8 noundef zeroext 1)
  store i32 %89, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %94

90:                                               ; preds = %81
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.XSocket, ptr %91, i32 0, i32 5
  %93 = load i32, ptr %92, align 8, !tbaa !17
  store i32 %93, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %94

94:                                               ; preds = %90, %87, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %95

95:                                               ; preds = %94, %32, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %96 = load i32, ptr %6, align 4
  ret i32 %96
}

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @XSock_SetupAddr(ptr noundef, ptr noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @XSock_SetupStream(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @XSock_SetupDgram(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 "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 }

!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"XSocket", !10, i64 0, !7, i64 4, !10, i64 116, !10, i64 120, !14, i64 124, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !6, i64 144}
!17 = !{!16, !10, i64 128}
!18 = !{!16, !10, i64 140}
!19 = !{!16, !10, i64 132}
!20 = !{!16, !10, i64 136}
!21 = !{!16, !10, i64 116}


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

; Function Attrs: nounwind uwtable
declare dso_local i32 @XSock_Init(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @XSock_NonBlock(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @XSock_CreateAdv(ptr noundef %0, i32 noundef %1, i64 noundef %2, ptr noundef %3, i16 noundef zeroext %4) local_unnamed_addr #0 {
  %6 = tail call i32 @XSock_Init(ptr noundef %0, i32 noundef %1, i32 noundef -1)
  %7 = icmp eq i32 %6, -1
  br i1 %7, label %40, label %8

8:                                                ; preds = %5
  %9 = tail call zeroext i8 @xstrused(ptr noundef %3) #3
  %.not = icmp eq i8 %9, 0
  br i1 %.not, label %12, label %10

10:                                               ; preds = %8
  %.not28 = icmp eq i16 %4, 0
  %11 = and i32 %1, 8
  %.not29 = icmp eq i32 %11, 0
  %or.cond = and i1 %.not29, %.not28
  br i1 %or.cond, label %12, label %14

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

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %0, i64 140
  %16 = load i32, ptr %15, align 4, !tbaa !13
  %17 = or i32 %16, 1
  %18 = getelementptr inbounds i8, ptr %0, i64 132
  %19 = load i32, ptr %18, align 4, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %0, i64 136
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = tail call i32 @socket(i32 noundef %19, i32 noundef %17, i32 noundef %21) #3
  %23 = getelementptr inbounds i8, ptr %0, i64 128
  store i32 %22, ptr %23, align 8, !tbaa !12
  %24 = icmp eq i32 %22, -1
  br i1 %24, label %25, label %26

25:                                               ; preds = %14
  store i32 6, ptr %0, align 8, !tbaa !5
  br label %40

26:                                               ; preds = %14
  tail call void @XSock_SetupAddr(ptr noundef nonnull %0, ptr noundef %3, i16 noundef zeroext %4)
  %27 = load i32, ptr %15, align 4, !tbaa !13
  switch i32 %27, label %32 [
    i32 1, label %28
    i32 2, label %30
  ]

28:                                               ; preds = %26
  %29 = tail call i32 @XSock_SetupStream(ptr noundef nonnull %0, i64 noundef %2)
  br label %32

30:                                               ; preds = %26
  %31 = tail call i32 @XSock_SetupDgram(ptr noundef nonnull %0)
  br label %32

32:                                               ; preds = %26, %30, %28
  %33 = getelementptr inbounds i8, ptr %0, i64 116
  %34 = load i32, ptr %33, align 4, !tbaa !16
  %35 = and i32 %34, 16384
  %.not30 = icmp eq i32 %35, 0
  br i1 %.not30, label %38, label %36

36:                                               ; preds = %32
  %37 = tail call i32 @XSock_NonBlock(ptr noundef nonnull %0, i8 noundef zeroext 1)
  br label %40

38:                                               ; preds = %32
  %39 = load i32, ptr %23, align 8, !tbaa !12
  br label %40

40:                                               ; preds = %25, %36, %38, %5, %12
  %.1 = phi i32 [ -1, %12 ], [ -1, %5 ], [ -1, %25 ], [ %37, %36 ], [ %39, %38 ]
  ret i32 %.1
}

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @XSock_SetupAddr(ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @XSock_SetupStream(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @XSock_SetupDgram(ptr noundef) local_unnamed_addr #0

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 = { 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 #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, !7, i64 0}
!6 = !{!"XSocket", !7, i64 0, !8, i64 4, !7, i64 116, !7, i64 120, !10, i64 124, !7, i64 128, !7, i64 132, !7, i64 136, !7, i64 140, !11, i64 144}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 128}
!13 = !{!6, !7, i64 140}
!14 = !{!6, !7, i64 132}
!15 = !{!6, !7, i64 136}
!16 = !{!6, !7, i64 116}


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