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

%struct.storage = type { [20 x i8], i32, i32, ptr, ptr }
%struct.peer = type { i64, [16 x i8], i16, i16 }

@storage = external hidden global ptr, align 8
@.str.85 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.86 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.87 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.88 = external hidden unnamed_addr constant [54 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

declare ptr @str_id(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @str_addr2(ptr noundef, i8 noundef zeroext, i16 noundef zeroext) #3

; Function Attrs: nounwind uwtable
define dso_local void @kad_print_storage(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = load ptr, ptr @storage, align 8, !tbaa !5
  store ptr %7, ptr %5, align 8, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %55, %1
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %58

11:                                               ; preds = %8
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.storage, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds [20 x i8], ptr %14, i64 0, i64 0
  %16 = call ptr @str_id(ptr noundef %15)
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef @.str.85, ptr noundef %16) #4
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %44, %11
  %19 = load i64, ptr %4, align 8, !tbaa !9
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.storage, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = icmp ult i64 %19, %23
  br i1 %24, label %25, label %47

25:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.storage, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load i64, ptr %4, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.peer, ptr %28, i64 %29
  store ptr %30, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.peer, ptr %32, i32 0, i32 1
  %34 = getelementptr inbounds [16 x i8], ptr %33, i64 0, i64 0
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.peer, ptr %35, i32 0, i32 2
  %37 = load i16, ptr %36, align 8, !tbaa !15
  %38 = trunc i16 %37 to i8
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.peer, ptr %39, i32 0, i32 3
  %41 = load i16, ptr %40, align 2, !tbaa !18
  %42 = call ptr @str_addr2(ptr noundef %34, i8 noundef zeroext %38, i16 noundef zeroext %41)
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef @.str.86, ptr noundef %42) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %44

44:                                               ; preds = %25
  %45 = load i64, ptr %4, align 8, !tbaa !9
  %46 = add i64 %45, 1
  store i64 %46, ptr %4, align 8, !tbaa !9
  br label %18, !llvm.loop !19

47:                                               ; preds = %18
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = load i64, ptr %4, align 8, !tbaa !9
  %50 = trunc i64 %49 to i32
  %51 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %48, ptr noundef @.str.87, i32 noundef %50) #4
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.storage, ptr %52, i32 0, i32 4
  %54 = load ptr, ptr %53, align 8, !tbaa !21
  store ptr %54, ptr %5, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %47
  %56 = load i64, ptr %3, align 8, !tbaa !9
  %57 = add i64 %56, 1
  store i64 %57, ptr %3, align 8, !tbaa !9
  br label %8, !llvm.loop !22

58:                                               ; preds = %8
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = load i64, ptr %3, align 8, !tbaa !9
  %61 = trunc i64 %60 to i32
  %62 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %59, ptr noundef @.str.88, i32 noundef %61) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 20}
!12 = !{!"storage", !7, i64 0, !13, i64 20, !13, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 32}
!15 = !{!16, !17, i64 24}
!16 = !{!"peer", !10, i64 0, !7, i64 8, !17, i64 24, !17, i64 26}
!17 = !{!"short", !7, i64 0}
!18 = !{!16, !17, i64 26}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!12, !6, i64 40}
!22 = distinct !{!22, !20}


; 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.peer = type { i64, [16 x i8], i16, i16 }

@storage = external hidden local_unnamed_addr global ptr, align 8
@.str.85 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.86 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.87 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.88 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

declare ptr @str_id(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @str_addr2(ptr noundef, i8 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @kad_print_storage(ptr nocapture noundef %0) local_unnamed_addr #2 {
  %.01720 = load ptr, ptr @storage, align 8, !tbaa !5
  %.not21 = icmp eq ptr %.01720, null
  br i1 %.not21, label %._crit_edge26, label %.lr.ph25

.lr.ph25:                                         ; preds = %1, %._crit_edge
  %.01723 = phi ptr [ %.017, %._crit_edge ], [ %.01720, %1 ]
  %.022 = phi i32 [ %25, %._crit_edge ], [ 0, %1 ]
  %2 = tail call ptr @str_id(ptr noundef nonnull %.01723) #3
  %3 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.85, ptr noundef %2) #3
  %4 = getelementptr inbounds i8, ptr %.01723, i64 20
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %.not28 = icmp eq i32 %5, 0
  br i1 %.not28, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph25
  %6 = getelementptr inbounds i8, ptr %.01723, i64 32
  br label %7

7:                                                ; preds = %.lr.ph, %7
  %.01819 = phi i64 [ 0, %.lr.ph ], [ %18, %7 ]
  %8 = load ptr, ptr %6, align 8, !tbaa !12
  %9 = getelementptr inbounds %struct.peer, ptr %8, i64 %.01819
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = getelementptr inbounds i8, ptr %9, i64 24
  %12 = load i16, ptr %11, align 8, !tbaa !13
  %13 = trunc i16 %12 to i8
  %14 = getelementptr inbounds i8, ptr %9, i64 26
  %15 = load i16, ptr %14, align 2, !tbaa !17
  %16 = tail call ptr @str_addr2(ptr noundef nonnull %10, i8 noundef zeroext %13, i16 noundef zeroext %15)
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.86, ptr noundef %16) #3
  %18 = add nuw i64 %.01819, 1
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = icmp ult i64 %18, %20
  br i1 %21, label %7, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %7, %.lr.ph25
  %.018.lcssa = phi i64 [ 0, %.lr.ph25 ], [ %18, %7 ]
  %22 = trunc i64 %.018.lcssa to i32
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.87, i32 noundef %22) #3
  %24 = getelementptr inbounds i8, ptr %.01723, i64 40
  %25 = add i32 %.022, 1
  %.017 = load ptr, ptr %24, align 8, !tbaa !5
  %.not = icmp eq ptr %.017, null
  br i1 %.not, label %._crit_edge26, label %.lr.ph25, !llvm.loop !20

._crit_edge26:                                    ; preds = %._crit_edge, %1
  %.0.lcssa = phi i32 [ 0, %1 ], [ %25, %._crit_edge ]
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.88, i32 noundef %.0.lcssa) #3
  ret void
}

attributes #0 = { nofree 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 #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 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 }

!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, !11, i64 20}
!10 = !{!"storage", !7, i64 0, !11, i64 20, !11, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 32}
!13 = !{!14, !16, i64 24}
!14 = !{!"peer", !15, i64 0, !7, i64 8, !16, i64 24, !16, i64 26}
!15 = !{!"long", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!14, !16, i64 26}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass