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

; 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 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @peerfile_export() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %5 = load ptr, ptr @gconf, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.gconf_t, ptr %5, i32 0, i32 5
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %7, ptr %1, align 8, !tbaa !5
  %8 = load ptr, ptr %1, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %0
  store i32 1, ptr %4, align 4
  br label %101

11:                                               ; preds = %0
  %12 = load ptr, ptr @gconf, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.gconf_t, ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !14
  %15 = load ptr, ptr @gconf, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.gconf_t, ptr %15, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %18 = sub nsw i64 %14, %17
  %19 = icmp slt i64 %18, 300
  br i1 %19, label %20, label %30

20:                                               ; preds = %11
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr @gconf, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.gconf_t, ptr %22, i32 0, i32 9
  %24 = load i32, ptr %23, align 4, !tbaa !16
  %25 = icmp ne i32 %24, 2
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  call void (i32, ptr, ...) @log_print(i32 noundef 6, ptr noundef @.str)
  br label %27

27:                                               ; preds = %26, %21
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  store i32 1, ptr %4, align 4
  br label %101

30:                                               ; preds = %11
  %31 = call i32 @kad_count_nodes(i1 noundef zeroext true)
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %43

33:                                               ; preds = %30
  br label %34

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

39:                                               ; preds = %34
  call void (i32, ptr, ...) @log_print(i32 noundef 6, ptr noundef @.str.1)
  br label %40

40:                                               ; preds = %39, %34
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  store i32 1, ptr %4, align 4
  br label %101

43:                                               ; preds = %30
  %44 = load ptr, ptr %1, align 8, !tbaa !5
  %45 = call noalias ptr @fopen(ptr noundef %44, ptr noundef @.str.2)
  store ptr %45, ptr %2, align 8, !tbaa !5
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = icmp eq ptr %46, null
  br i1 %47, label %48, label %62

48:                                               ; preds = %43
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr @gconf, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.gconf_t, ptr %50, i32 0, i32 9
  %52 = load i32, ptr %51, align 4, !tbaa !16
  %53 = icmp ne i32 %52, 2
  br i1 %53, label %54, label %59

54:                                               ; preds = %49
  %55 = load ptr, ptr %1, align 8, !tbaa !5
  %56 = call ptr @__errno_location() #6
  %57 = load i32, ptr %56, align 4, !tbaa !17
  %58 = call ptr @strerror(i32 noundef %57) #5
  call void (i32, ptr, ...) @log_print(i32 noundef 4, ptr noundef @.str.3, ptr noundef %55, ptr noundef %58)
  br label %59

59:                                               ; preds = %54, %49
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  store i32 1, ptr %4, align 4
  br label %101

62:                                               ; preds = %43
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr @gconf, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.gconf_t, ptr %64, i32 0, i32 9
  %66 = load i32, ptr %65, align 4, !tbaa !16
  %67 = icmp ne i32 %66, 2
  br i1 %67, label %68, label %70

68:                                               ; preds = %63
  %69 = load ptr, ptr %1, align 8, !tbaa !5
  call void (i32, ptr, ...) @log_print(i32 noundef 6, ptr noundef @.str.4, ptr noundef %69)
  br label %70

70:                                               ; preds = %68, %63
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = call i32 @kad_export_peers(ptr noundef %73)
  store i32 %74, ptr %3, align 4, !tbaa !17
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = call i32 @fclose(ptr noundef %75)
  %77 = load i32, ptr %3, align 4, !tbaa !17
  %78 = icmp sle i32 %77, 0
  br i1 %78, label %79, label %89

79:                                               ; preds = %72
  br label %80

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

85:                                               ; preds = %80
  call void (i32, ptr, ...) @log_print(i32 noundef 6, ptr noundef @.str.1)
  br label %86

86:                                               ; preds = %85, %80
  br label %87

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87
  store i32 1, ptr %4, align 4
  br label %101

89:                                               ; preds = %72
  br label %90

90:                                               ; preds = %89
  %91 = load ptr, ptr @gconf, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.gconf_t, ptr %91, i32 0, i32 9
  %93 = load i32, ptr %92, align 4, !tbaa !16
  %94 = icmp ne i32 %93, 2
  br i1 %94, label %95, label %98

95:                                               ; preds = %90
  %96 = load i32, ptr %3, align 4, !tbaa !17
  %97 = load ptr, ptr %1, align 8, !tbaa !5
  call void (i32, ptr, ...) @log_print(i32 noundef 6, ptr noundef @.str.5, i32 noundef %96, ptr noundef %97)
  br label %98

98:                                               ; preds = %95, %90
  br label %99

99:                                               ; preds = %98
  br label %100

100:                                              ; preds = %99
  store i32 0, ptr %4, align 4
  br label %101

101:                                              ; preds = %100, %88, %61, %42, %29, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  %102 = load i32, ptr %4, align 4
  switch i32 %102, label %104 [
    i32 0, label %103
    i32 1, label %103
  ]

103:                                              ; preds = %101, %101
  ret void

104:                                              ; preds = %101
  unreachable
}

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

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

declare i32 @kad_count_nodes(i1 noundef zeroext) #2

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

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

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

declare i32 @kad_export_peers(ptr noundef) #2

declare i32 @fclose(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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, !6, i64 40}
!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, !11, i64 0}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !13, i64 60}
!17 = !{!13, !13, 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 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @peerfile_export() local_unnamed_addr #0 {
  %1 = load ptr, ptr @gconf, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %1, i64 40
  %3 = load ptr, ptr %2, align 8, !tbaa !9
  %4 = icmp eq ptr %3, null
  br i1 %4, label %47, label %5

5:                                                ; preds = %0
  %6 = load i64, ptr %1, align 8, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !15
  %9 = sub nsw i64 %6, %8
  %10 = icmp slt i64 %9, 300
  br i1 %10, label %11, label %15

11:                                               ; preds = %5
  %12 = getelementptr inbounds i8, ptr %1, i64 60
  %13 = load i32, ptr %12, align 4, !tbaa !16
  %.not15 = icmp eq i32 %13, 2
  br i1 %.not15, label %47, label %14

14:                                               ; preds = %11
  tail call void (i32, ptr, ...) @log_print(i32 noundef 6, ptr noundef nonnull @.str) #5
  br label %47

15:                                               ; preds = %5
  %16 = tail call i32 @kad_count_nodes(i1 noundef zeroext true) #5
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %23

18:                                               ; preds = %15
  %19 = load ptr, ptr @gconf, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 60
  %21 = load i32, ptr %20, align 4, !tbaa !16
  %.not14 = icmp eq i32 %21, 2
  br i1 %.not14, label %47, label %22

22:                                               ; preds = %18
  tail call void (i32, ptr, ...) @log_print(i32 noundef 6, ptr noundef nonnull @.str.1) #5
  br label %47

23:                                               ; preds = %15
  %24 = tail call noalias ptr @fopen(ptr noundef nonnull %3, ptr noundef nonnull @.str.2)
  %25 = icmp eq ptr %24, null
  %26 = load ptr, ptr @gconf, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 60
  %28 = load i32, ptr %27, align 4, !tbaa !16
  %.not13 = icmp eq i32 %28, 2
  br i1 %25, label %29, label %34

29:                                               ; preds = %23
  br i1 %.not13, label %47, label %30

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

34:                                               ; preds = %23
  br i1 %.not13, label %36, label %35

35:                                               ; preds = %34
  tail call void (i32, ptr, ...) @log_print(i32 noundef 6, ptr noundef nonnull @.str.4, ptr noundef nonnull %3) #5
  br label %36

36:                                               ; preds = %35, %34
  %37 = tail call i32 @kad_export_peers(ptr noundef nonnull %24) #5
  %38 = tail call i32 @fclose(ptr noundef nonnull %24)
  %39 = icmp slt i32 %37, 1
  %40 = load ptr, ptr @gconf, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 60
  %42 = load i32, ptr %41, align 4, !tbaa !16
  %.not12 = icmp eq i32 %42, 2
  br i1 %39, label %43, label %45

43:                                               ; preds = %36
  br i1 %.not12, label %47, label %44

44:                                               ; preds = %43
  tail call void (i32, ptr, ...) @log_print(i32 noundef 6, ptr noundef nonnull @.str.1) #5
  br label %47

45:                                               ; preds = %36
  br i1 %.not12, label %47, label %46

46:                                               ; preds = %45
  tail call void (i32, ptr, ...) @log_print(i32 noundef 6, ptr noundef nonnull @.str.5, i32 noundef %37, ptr noundef nonnull %3) #5
  br label %47

47:                                               ; preds = %45, %46, %43, %44, %29, %30, %18, %22, %11, %14, %0
  ret void
}

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

declare i32 @kad_count_nodes(i1 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) 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

declare i32 @kad_export_peers(ptr noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 40}
!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, !11, i64 0}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !13, i64 60}
!17 = !{!13, !13, i64 0}


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