; LLVM IR from mwarning/KadNode :: src (net)

; 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.sockaddr_storage = type { i16, [118 x i8], i64 }
%struct.gconf_t = type { i64, i64, ptr, ptr, ptr, ptr, ptr, i8, i8, i32, i32, i32, i32, ptr, i8, [8 x i8], i64, i64, i64, [8 x i32], [8 x i32] }

@gconf = external global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [15 x i8], align 1

declare void @log_print(i32 noundef, ptr noundef, ...) #0

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

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

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

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #3

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

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

declare i32 @close(i32 noundef) #0

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

19:                                               ; preds = %5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef @.str.9, ptr noundef %20, ptr noundef %21)
  br label %95

22:                                               ; preds = %5
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = trunc i32 %23 to i16
  %25 = call zeroext i1 @port_set(ptr noundef %13, i16 noundef zeroext %24)
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = getelementptr inbounds %struct.sockaddr_storage, ptr %13, i32 0, i32 0
  %30 = load i16, ptr %29, align 8, !tbaa !11
  %31 = zext i16 %30 to i32
  %32 = call i32 @net_socket(ptr noundef %26, ptr noundef %27, i32 noundef %28, i32 noundef %31)
  store i32 %32, ptr %14, align 4, !tbaa !9
  %33 = icmp eq i32 %32, -1
  br i1 %33, label %34, label %35

34:                                               ; preds = %22
  br label %95

35:                                               ; preds = %22
  %36 = getelementptr inbounds %struct.sockaddr_storage, ptr %13, i32 0, i32 0
  %37 = load i16, ptr %36, align 8, !tbaa !11
  %38 = zext i16 %37 to i32
  %39 = icmp eq i32 %38, 10
  br i1 %39, label %40, label %51

40:                                               ; preds = %35
  %41 = load i32, ptr %14, align 4, !tbaa !9
  %42 = call i32 @setsockopt(i32 noundef %41, i32 noundef 41, i32 noundef 26, ptr noundef %12, i32 noundef 4) #5
  %43 = icmp eq i32 %42, -1
  br i1 %43, label %44, label %50

44:                                               ; preds = %40
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = call ptr @str_addr(ptr noundef %13)
  %47 = call ptr @__errno_location() #6
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = call ptr @strerror(i32 noundef %48) #5
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef @.str.10, ptr noundef %45, ptr noundef %46, ptr noundef %49)
  br label %95

50:                                               ; preds = %40
  br label %51

51:                                               ; preds = %50, %35
  %52 = call i32 @addr_len(ptr noundef %13)
  store i32 %52, ptr %15, align 4, !tbaa !9
  %53 = load i32, ptr %14, align 4, !tbaa !9
  %54 = load i32, ptr %15, align 4, !tbaa !9
  %55 = call i32 @bind(i32 noundef %53, ptr noundef %13, i32 noundef %54) #5
  %56 = icmp eq i32 %55, -1
  br i1 %56, label %57, label %63

57:                                               ; preds = %51
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = call ptr @str_addr(ptr noundef %13)
  %60 = call ptr @__errno_location() #6
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = call ptr @strerror(i32 noundef %61) #5
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef @.str.11, ptr noundef %58, ptr noundef %59, ptr noundef %62)
  br label %95

63:                                               ; preds = %51
  %64 = load i32, ptr %11, align 4, !tbaa !9
  %65 = icmp eq i32 %64, 6
  br i1 %65, label %66, label %77

66:                                               ; preds = %63
  %67 = load i32, ptr %14, align 4, !tbaa !9
  %68 = call i32 @listen(i32 noundef %67, i32 noundef 5) #5
  %69 = icmp eq i32 %68, -1
  br i1 %69, label %70, label %76

70:                                               ; preds = %66
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = call ptr @str_addr(ptr noundef %13)
  %73 = call ptr @__errno_location() #6
  %74 = load i32, ptr %73, align 4, !tbaa !9
  %75 = call ptr @strerror(i32 noundef %74) #5
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef @.str.12, ptr noundef %71, ptr noundef %72, ptr noundef %75)
  br label %95

76:                                               ; preds = %66
  br label %77

77:                                               ; preds = %76, %63
  br label %78

78:                                               ; preds = %77
  %79 = load ptr, ptr @gconf, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.gconf_t, ptr %79, i32 0, i32 9
  %81 = load i32, ptr %80, align 4, !tbaa !15
  %82 = icmp ne i32 %81, 2
  br i1 %82, label %83, label %91

83:                                               ; preds = %78
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = icmp ne ptr %84, null
  %86 = zext i1 %85 to i64
  %87 = select i1 %85, ptr @.str.13, ptr @.str.14
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = call ptr @str_addr(ptr noundef %13)
  %90 = load ptr, ptr %10, align 8, !tbaa !5
  call void (i32, ptr, ...) @log_print(i32 noundef 6, ptr noundef %87, ptr noundef %88, ptr noundef %89, ptr noundef %90)
  br label %91

91:                                               ; preds = %83, %78
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %94, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %98

95:                                               ; preds = %70, %57, %44, %34, %19
  %96 = load i32, ptr %14, align 4, !tbaa !9
  %97 = call i32 @close(i32 noundef %96)
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %98

98:                                               ; preds = %95, %93
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  %99 = load i32, ptr %6, align 4
  ret i32 %99
}

declare zeroext i1 @addr_parse(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #0

declare zeroext i1 @port_set(ptr noundef, i16 noundef zeroext) #0

declare ptr @str_addr(ptr noundef) #0

declare i32 @addr_len(ptr noundef) #0

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 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 #5 = { nounwind }
attributes #6 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"sockaddr_storage", !13, i64 0, !7, i64 2, !14, i64 120}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !10, i64 60}
!16 = !{!"gconf_t", !14, i64 0, !14, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !17, i64 56, !17, i64 57, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !6, i64 80, !7, i64 88, !7, i64 89, !14, i64 104, !14, i64 112, !14, i64 120, !7, i64 128, !7, i64 160}
!17 = !{!"_Bool", !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"

%struct.sockaddr_storage = type { i16, [118 x i8], i64 }

@gconf = external local_unnamed_addr global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [15 x i8], align 1

declare void @log_print(i32 noundef, ptr noundef, ...) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind
declare i32 @setsockopt(i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @close(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @net_bind(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca i32, align 4
  %7 = alloca %struct.sockaddr_storage, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #5
  store i32 1, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %7) #5
  %8 = call zeroext i1 @addr_parse(ptr noundef nonnull %7, ptr noundef %1, ptr noundef nonnull @.str.8, i32 noundef 0) #5
  br i1 %8, label %10, label %9

9:                                                ; preds = %5
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef nonnull @.str.9, ptr noundef %0, ptr noundef %1) #5
  br label %54

10:                                               ; preds = %5
  %11 = trunc i32 %2 to i16
  %12 = call zeroext i1 @port_set(ptr noundef nonnull %7, i16 noundef zeroext %11) #5
  %13 = load i16, ptr %7, align 8, !tbaa !9
  %14 = zext i16 %13 to i32
  %15 = call i32 @net_socket(ptr noundef %0, ptr noundef %3, i32 noundef %4, i32 noundef %14)
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %54, label %17

17:                                               ; preds = %10
  %18 = load i16, ptr %7, align 8, !tbaa !9
  %19 = icmp eq i16 %18, 10
  br i1 %19, label %20, label %28

20:                                               ; preds = %17
  %21 = call i32 @setsockopt(i32 noundef %15, i32 noundef 41, i32 noundef 26, ptr noundef nonnull %6, i32 noundef 4) #5
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %23, label %28

23:                                               ; preds = %20
  %24 = call ptr @str_addr(ptr noundef nonnull %7) #5
  %25 = tail call ptr @__errno_location() #6
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = call ptr @strerror(i32 noundef %26) #5
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef nonnull @.str.10, ptr noundef %0, ptr noundef %24, ptr noundef %27) #5
  br label %54

28:                                               ; preds = %20, %17
  %29 = call i32 @addr_len(ptr noundef nonnull %7) #5
  %30 = call i32 @bind(i32 noundef %15, ptr noundef nonnull %7, i32 noundef %29) #5
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %37

32:                                               ; preds = %28
  %33 = call ptr @str_addr(ptr noundef nonnull %7) #5
  %34 = tail call ptr @__errno_location() #6
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = call ptr @strerror(i32 noundef %35) #5
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef nonnull @.str.11, ptr noundef %0, ptr noundef %33, ptr noundef %36) #5
  br label %54

37:                                               ; preds = %28
  %38 = icmp eq i32 %4, 6
  br i1 %38, label %39, label %47

39:                                               ; preds = %37
  %40 = call i32 @listen(i32 noundef %15, i32 noundef 5) #5
  %41 = icmp eq i32 %40, -1
  br i1 %41, label %42, label %47

42:                                               ; preds = %39
  %43 = call ptr @str_addr(ptr noundef nonnull %7) #5
  %44 = tail call ptr @__errno_location() #6
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = call ptr @strerror(i32 noundef %45) #5
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef nonnull @.str.12, ptr noundef %0, ptr noundef %43, ptr noundef %46) #5
  br label %54

47:                                               ; preds = %37, %39
  %48 = load ptr, ptr @gconf, align 8, !tbaa !13
  %49 = getelementptr inbounds i8, ptr %48, i64 60
  %50 = load i32, ptr %49, align 4, !tbaa !15
  %.not = icmp eq i32 %50, 2
  br i1 %.not, label %56, label %51

51:                                               ; preds = %47
  %.not22 = icmp eq ptr %3, null
  %52 = select i1 %.not22, ptr @.str.14, ptr @.str.13
  %53 = call ptr @str_addr(ptr noundef nonnull %7) #5
  call void (i32, ptr, ...) @log_print(i32 noundef 6, ptr noundef nonnull %52, ptr noundef %0, ptr noundef %53, ptr noundef %3) #5
  br label %56

54:                                               ; preds = %10, %42, %32, %23, %9
  %.020 = phi i32 [ -1, %10 ], [ %15, %23 ], [ %15, %32 ], [ %15, %42 ], [ -1, %9 ]
  %55 = call i32 @close(i32 noundef %.020) #5
  br label %56

56:                                               ; preds = %47, %51, %54
  %.0 = phi i32 [ -1, %54 ], [ %15, %51 ], [ %15, %47 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #5
  ret i32 %.0
}

declare zeroext i1 @addr_parse(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare zeroext i1 @port_set(ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

declare ptr @str_addr(ptr noundef) local_unnamed_addr #0

declare i32 @addr_len(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare i32 @bind(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

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

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"sockaddr_storage", !11, i64 0, !7, i64 2, !12, i64 120}
!11 = !{!"short", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!16, !6, i64 60}
!16 = !{!"gconf_t", !12, i64 0, !12, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !17, i64 56, !17, i64 57, !6, i64 60, !6, i64 64, !6, i64 68, !6, i64 72, !14, i64 80, !7, i64 88, !7, i64 89, !12, i64 104, !12, i64 112, !12, i64 120, !7, i64 128, !7, i64 160}
!17 = !{!"_Bool", !7, i64 0}


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