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

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

%union.__CONST_SOCKADDR_ARG = type { ptr }
%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.62 = external hidden unnamed_addr constant [39 x i8], align 1

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 hidden void @record_traffic(i32 noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @dht_sendto(i32 noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca [1500 x i8], align 16
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca %union.__CONST_SOCKADDR_ARG, align 8
  %19 = alloca %union.__CONST_SOCKADDR_ARG, align 8
  store i32 %0, ptr %8, align 4, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %20 = load ptr, ptr @gconf, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.gconf_t, ptr %20, i32 0, i32 14
  %22 = load i8, ptr %21, align 8, !tbaa !11
  %23 = zext i8 %22 to i64
  store i64 %23, ptr %14, align 8, !tbaa !15
  %24 = load i64, ptr %14, align 8, !tbaa !15
  %25 = icmp ugt i64 %24, 0
  br i1 %25, label %26, label %69

26:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 1500, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %27 = load i32, ptr %10, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = load i64, ptr %14, align 8, !tbaa !15
  %30 = add i64 %28, %29
  %31 = trunc i64 %30 to i32
  store i32 %31, ptr %16, align 4, !tbaa !5
  %32 = load i32, ptr %16, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = icmp ugt i64 %33, 1500
  br i1 %34, label %35, label %45

35:                                               ; preds = %26
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr @gconf, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.gconf_t, ptr %37, i32 0, i32 9
  %39 = load i32, ptr %38, align 4, !tbaa !16
  %40 = icmp ne i32 %39, 2
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  call void (i32, ptr, ...) @log_print(i32 noundef 4, ptr noundef @.str.62)
  br label %42

42:                                               ; preds = %41, %36
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %68

45:                                               ; preds = %26
  %46 = getelementptr inbounds [1500 x i8], ptr %15, i64 0, i64 0
  %47 = load ptr, ptr @gconf, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.gconf_t, ptr %47, i32 0, i32 15
  %49 = getelementptr inbounds [8 x i8], ptr %48, i64 0, i64 0
  %50 = load i64, ptr %14, align 8, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %46, ptr align 1 %49, i64 %50, i1 false)
  %51 = load i64, ptr %14, align 8, !tbaa !15
  %52 = getelementptr inbounds [1500 x i8], ptr %15, i64 0, i64 %51
  %53 = load ptr, ptr %9, align 8, !tbaa !9
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %52, ptr align 1 %53, i64 %55, i1 false)
  %56 = load i32, ptr %16, align 4, !tbaa !5
  call void @record_traffic(i32 noundef 0, i32 noundef %56)
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = getelementptr inbounds [1500 x i8], ptr %15, i64 0, i64 0
  %59 = load i32, ptr %16, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = load i32, ptr %11, align 4, !tbaa !5
  %62 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %62, ptr %18, align 8, !tbaa !17
  %63 = load i32, ptr %13, align 4, !tbaa !5
  %64 = getelementptr inbounds %union.__CONST_SOCKADDR_ARG, ptr %18, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8
  %66 = call i64 @sendto(i32 noundef %57, ptr noundef %58, i64 noundef %60, i32 noundef %61, ptr %65, i32 noundef %63)
  %67 = trunc i64 %66 to i32
  store i32 %67, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %68

68:                                               ; preds = %45, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 1500, ptr %15) #4
  br label %82

69:                                               ; preds = %6
  %70 = load i32, ptr %10, align 4, !tbaa !5
  call void @record_traffic(i32 noundef 0, i32 noundef %70)
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = load ptr, ptr %9, align 8, !tbaa !9
  %73 = load i32, ptr %10, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = load i32, ptr %11, align 4, !tbaa !5
  %76 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %76, ptr %19, align 8, !tbaa !17
  %77 = load i32, ptr %13, align 4, !tbaa !5
  %78 = getelementptr inbounds %union.__CONST_SOCKADDR_ARG, ptr %19, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8
  %80 = call i64 @sendto(i32 noundef %71, ptr noundef %72, i64 noundef %74, i32 noundef %75, ptr %79, i32 noundef %77)
  %81 = trunc i64 %80 to i32
  store i32 %81, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %82

82:                                               ; preds = %69, %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %83 = load i32, ptr %7, align 4
  ret i32 %83
}

declare i64 @sendto(i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = { "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 = !{!"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, !7, i64 88}
!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}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !6, i64 60}
!17 = !{!7, !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.62 = external hidden unnamed_addr constant [39 x i8], align 1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
declare hidden void @record_traffic(i32 noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @dht_sendto(i32 noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5) local_unnamed_addr #2 {
  %7 = alloca [1500 x i8], align 16
  %8 = load ptr, ptr @gconf, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 88
  %10 = load i8, ptr %9, align 8, !tbaa !9
  %11 = zext i8 %10 to i64
  %.not = icmp eq i8 %10, 0
  br i1 %.not, label %28, label %12

12:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 1500, ptr nonnull %7) #4
  %13 = zext i8 %10 to i32
  %14 = add i32 %13, %2
  %15 = icmp ugt i32 %14, 1500
  br i1 %15, label %16, label %20

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %8, i64 60
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %.not24 = icmp eq i32 %18, 2
  br i1 %.not24, label %27, label %19

19:                                               ; preds = %16
  tail call void (i32, ptr, ...) @log_print(i32 noundef 4, ptr noundef nonnull @.str.62) #4
  br label %27

20:                                               ; preds = %12
  %21 = zext nneg i32 %14 to i64
  %22 = sext i32 %2 to i64
  %23 = getelementptr inbounds i8, ptr %8, i64 89
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %7, ptr nonnull align 1 %23, i64 %11, i1 false)
  %24 = getelementptr inbounds [1500 x i8], ptr %7, i64 0, i64 %11
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %24, ptr align 1 %1, i64 %22, i1 false)
  tail call void @record_traffic(i32 noundef 0, i32 noundef %14)
  %25 = call i64 @sendto(i32 noundef %0, ptr noundef nonnull %7, i64 noundef %21, i32 noundef %3, ptr %4, i32 noundef %5) #4
  %26 = trunc i64 %25 to i32
  br label %27

27:                                               ; preds = %16, %19, %20
  %.0 = phi i32 [ %26, %20 ], [ -1, %19 ], [ -1, %16 ]
  call void @llvm.lifetime.end.p0(i64 1500, ptr nonnull %7) #4
  br label %32

28:                                               ; preds = %6
  tail call void @record_traffic(i32 noundef 0, i32 noundef %2)
  %29 = sext i32 %2 to i64
  %30 = tail call i64 @sendto(i32 noundef %0, ptr noundef %1, i64 noundef %29, i32 noundef %3, ptr %4, i32 noundef %5) #4
  %31 = trunc i64 %30 to i32
  br label %32

32:                                               ; preds = %28, %27
  %.1 = phi i32 [ %.0, %27 ], [ %31, %28 ]
  ret i32 %.1
}

declare i64 @sendto(i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr, i32 noundef) local_unnamed_addr #3

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


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