; 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.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.4 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @net_set_nonblocking(i32 noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @net_socket(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 1, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 -1, ptr %11, align 4, !tbaa !9
  %13 = load ptr, ptr @gconf, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.gconf_t, ptr %13, i32 0, i32 11
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %24

17:                                               ; preds = %4
  %18 = load ptr, ptr @gconf, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.gconf_t, ptr %18, i32 0, i32 11
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp ne i32 %20, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %17
  br label %75

24:                                               ; preds = %17, %4
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = icmp eq i32 %26, 6
  %28 = zext i1 %27 to i64
  %29 = select i1 %27, i32 1, i32 2
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = call i32 @socket(i32 noundef %25, i32 noundef %29, i32 noundef %30) #6
  store i32 %31, ptr %11, align 4, !tbaa !9
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %33, label %38

33:                                               ; preds = %24
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call ptr @__errno_location() #7
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = call ptr @strerror(i32 noundef %36) #6
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef @.str.4, ptr noundef %34, ptr noundef %37)
  br label %75

38:                                               ; preds = %24
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = call i32 @net_set_nonblocking(i32 noundef %39)
  %41 = icmp slt i32 %40, 0
  br i1 %41, label %42, label %47

42:                                               ; preds = %38
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = call ptr @__errno_location() #7
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = call ptr @strerror(i32 noundef %45) #6
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef @.str.5, ptr noundef %43, ptr noundef %46)
  br label %75

47:                                               ; preds = %38
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %64

50:                                               ; preds = %47
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = call i64 @strlen(ptr noundef %53) #8
  %55 = trunc i64 %54 to i32
  %56 = call i32 @setsockopt(i32 noundef %51, i32 noundef 1, i32 noundef 25, ptr noundef %52, i32 noundef %55) #6
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %64

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

64:                                               ; preds = %50, %47
  %65 = load i32, ptr %11, align 4, !tbaa !9
  %66 = call i32 @setsockopt(i32 noundef %65, i32 noundef 1, i32 noundef 2, ptr noundef %10, i32 noundef 4) #6
  %67 = icmp slt i32 %66, 0
  br i1 %67, label %68, label %73

68:                                               ; preds = %64
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = call ptr @__errno_location() #7
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = call ptr @strerror(i32 noundef %71) #6
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef @.str.7, ptr noundef %69, ptr noundef %72)
  br label %75

73:                                               ; preds = %64
  %74 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %74, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %78

75:                                               ; preds = %68, %58, %42, %33, %23
  %76 = load i32, ptr %11, align 4, !tbaa !9
  %77 = call i32 @close(i32 noundef %76)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %78

78:                                               ; preds = %75, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  %79 = load i32, ptr %5, align 4
  ret i32 %79
}

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

; 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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #5

declare i32 @close(i32 noundef) #1

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

!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, !10, i64 68}
!12 = !{!"gconf_t", !13, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !14, i64 56, !14, i64 57, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !6, i64 80, !7, i64 88, !7, i64 89, !13, i64 104, !13, i64 112, !13, i64 120, !7, i64 128, !7, i64 160}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_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"

@gconf = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [35 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, -2147483648) i32 @net_socket(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #6
  store i32 1, ptr %5, align 4, !tbaa !5
  %6 = load ptr, ptr @gconf, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %6, i64 68
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %.not = icmp eq i32 %8, 0
  %.not21 = icmp eq i32 %8, %3
  %or.cond = or i1 %.not, %.not21
  br i1 %or.cond, label %9, label %41

9:                                                ; preds = %4
  %10 = icmp eq i32 %2, 6
  %11 = select i1 %10, i32 1, i32 2
  %12 = tail call i32 @socket(i32 noundef %3, i32 noundef %11, i32 noundef %2) #6
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %14, label %18

14:                                               ; preds = %9
  %15 = tail call ptr @__errno_location() #7
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = tail call ptr @strerror(i32 noundef %16) #6
  tail call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef nonnull @.str.4, ptr noundef %0, ptr noundef %17) #6
  br label %41

18:                                               ; preds = %9
  %19 = tail call i32 @net_set_nonblocking(i32 noundef %12)
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %21, label %25

21:                                               ; preds = %18
  %22 = tail call ptr @__errno_location() #7
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = tail call ptr @strerror(i32 noundef %23) #6
  tail call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef nonnull @.str.5, ptr noundef %0, ptr noundef %24) #6
  br label %41

25:                                               ; preds = %18
  %.not22 = icmp eq ptr %1, null
  br i1 %.not22, label %34, label %26

26:                                               ; preds = %25
  %27 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #8
  %28 = trunc i64 %27 to i32
  %29 = tail call i32 @setsockopt(i32 noundef %12, i32 noundef 1, i32 noundef 25, ptr noundef nonnull %1, i32 noundef %28) #6
  %.not23 = icmp eq i32 %29, 0
  br i1 %.not23, label %34, label %30

30:                                               ; preds = %26
  %31 = tail call ptr @__errno_location() #7
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = tail call ptr @strerror(i32 noundef %32) #6
  tail call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef nonnull @.str.6, ptr noundef %0, ptr noundef nonnull %1, ptr noundef %33) #6
  br label %41

34:                                               ; preds = %26, %25
  %35 = call i32 @setsockopt(i32 noundef %12, i32 noundef 1, i32 noundef 2, ptr noundef nonnull %5, i32 noundef 4) #6
  %36 = icmp slt i32 %35, 0
  br i1 %36, label %37, label %43

37:                                               ; preds = %34
  %38 = tail call ptr @__errno_location() #7
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = call ptr @strerror(i32 noundef %39) #6
  call void (i32, ptr, ...) @log_print(i32 noundef 3, ptr noundef nonnull @.str.7, ptr noundef %0, ptr noundef %40) #6
  br label %41

41:                                               ; preds = %4, %37, %30, %21, %14
  %.0 = phi i32 [ %12, %14 ], [ %12, %21 ], [ %12, %30 ], [ %12, %37 ], [ -1, %4 ]
  %42 = call i32 @close(i32 noundef %.0) #6
  br label %43

43:                                               ; preds = %34, %41
  %.017 = phi i32 [ -1, %41 ], [ %12, %34 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  ret i32 %.017
}

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

; 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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #5

declare i32 @close(i32 noundef) local_unnamed_addr #1

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

!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, !6, i64 68}
!12 = !{!"gconf_t", !13, i64 0, !13, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !14, i64 56, !14, i64 57, !6, i64 60, !6, i64 64, !6, i64 68, !6, i64 72, !10, i64 80, !7, i64 88, !7, i64 89, !13, i64 104, !13, i64 112, !13, i64 120, !7, i64 128, !7, i64 160}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}


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