; LLVM IR from TobiasKozel/VAE :: external/tracy/common/TracySocket.ll (ZN5tracy12UdpBroadcast4OpenEPKct)

; 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.addrinfo = type { i32, i32, i32, i32, i32, ptr, ptr, ptr }
%"class.tracy::UdpBroadcast" = type { i32, i32 }

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [13 x i8], align 1
@__PRETTY_FUNCTION__._ZN5tracy12UdpBroadcast4OpenEPKct = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: nounwind
declare void @freeaddrinfo(ptr noundef) #0

declare i32 @close(i32 noundef) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #0

declare i32 @getaddrinfo(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5tracy12UdpBroadcast4OpenEPKct(ptr noundef nonnull align 4 dereferenceable(8) %0, ptr noundef %1, i16 noundef zeroext %2) #5 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca %struct.addrinfo, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca [32 x i8], align 16
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i16 %2, ptr %7, align 2, !tbaa !9
  %15 = load ptr, ptr %5, align 8
  %16 = getelementptr inbounds %"class.tracy::UdpBroadcast", ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %19, label %20

19:                                               ; preds = %3
  br label %22

20:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 565, ptr noundef @__PRETTY_FUNCTION__._ZN5tracy12UdpBroadcast4OpenEPKct) #6
  unreachable

21:                                               ; No predecessors!
  br label %22

22:                                               ; preds = %21, %19
  call void @llvm.lifetime.start.p0(i64 48, ptr %8) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  call void @llvm.memset.p0.i64(ptr align 8 %8, i8 0, i64 48, i1 false)
  %23 = getelementptr inbounds %struct.addrinfo, ptr %8, i32 0, i32 1
  store i32 2, ptr %23, align 4, !tbaa !14
  %24 = getelementptr inbounds %struct.addrinfo, ptr %8, i32 0, i32 2
  store i32 2, ptr %24, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #7
  %25 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 0
  %26 = load i16, ptr %7, align 2, !tbaa !9
  %27 = zext i16 %26 to i32
  %28 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %25, ptr noundef @.str.2, i32 noundef %27) #7
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 0
  %31 = call i32 @getaddrinfo(ptr noundef %29, ptr noundef %30, ptr noundef %8, ptr noundef %9)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %22
  store i1 false, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %78

34:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  store i32 0, ptr %13, align 4, !tbaa !17
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %35, ptr %10, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %62, %34
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %66

39:                                               ; preds = %36
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.addrinfo, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !14
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.addrinfo, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 8, !tbaa !16
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.addrinfo, ptr %46, i32 0, i32 3
  %48 = load i32, ptr %47, align 4, !tbaa !18
  %49 = call i32 @socket(i32 noundef %42, i32 noundef %45, i32 noundef %48) #7
  store i32 %49, ptr %13, align 4, !tbaa !17
  %50 = icmp eq i32 %49, -1
  br i1 %50, label %51, label %52

51:                                               ; preds = %39
  br label %62

52:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #7
  store i32 1, ptr %14, align 4, !tbaa !17
  %53 = load i32, ptr %13, align 4, !tbaa !17
  %54 = call i32 @setsockopt(i32 noundef %53, i32 noundef 1, i32 noundef 6, ptr noundef %14, i32 noundef 4) #7
  %55 = icmp eq i32 %54, -1
  br i1 %55, label %56, label %59

56:                                               ; preds = %52
  %57 = load i32, ptr %13, align 4, !tbaa !17
  %58 = call i32 @close(i32 noundef %57)
  store i32 4, ptr %12, align 4
  br label %60

59:                                               ; preds = %52
  store i32 2, ptr %12, align 4
  br label %60

60:                                               ; preds = %59, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #7
  %61 = load i32, ptr %12, align 4
  switch i32 %61, label %80 [
    i32 4, label %62
    i32 2, label %66
  ]

62:                                               ; preds = %60, %51
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.addrinfo, ptr %63, i32 0, i32 7
  %65 = load ptr, ptr %64, align 8, !tbaa !19
  store ptr %65, ptr %10, align 8, !tbaa !5
  br label %36, !llvm.loop !20

66:                                               ; preds = %60, %36
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  call void @freeaddrinfo(ptr noundef %67) #7
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %71, label %70

70:                                               ; preds = %66
  store i1 false, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %77

71:                                               ; preds = %66
  %72 = load i32, ptr %13, align 4, !tbaa !17
  %73 = getelementptr inbounds %"class.tracy::UdpBroadcast", ptr %15, i32 0, i32 0
  store i32 %72, ptr %73, align 4, !tbaa !11
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %"class.tracy::UdpBroadcast", ptr %15, i32 0, i32 1
  %76 = call i32 @inet_pton(i32 noundef 2, ptr noundef %74, ptr noundef %75) #7
  store i1 true, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %77

77:                                               ; preds = %71, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  br label %78

78:                                               ; preds = %77, %33
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 48, ptr %8) #7
  %79 = load i1, ptr %4, align 1
  ret i1 %79

80:                                               ; preds = %60
  unreachable
}

; Function Attrs: nounwind
declare i32 @inet_pton(i32 noundef, ptr noundef, ptr noundef) #0

attributes #0 = { 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 = { noreturn 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { mustprogress 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 #6 = { noreturn nounwind }
attributes #7 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN5tracy12UdpBroadcastE", !13, i64 0, !13, i64 4}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 4}
!15 = !{!"_ZTS8addrinfo", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!16 = !{!15, !13, i64 8}
!17 = !{!13, !13, i64 0}
!18 = !{!15, !13, i64 12}
!19 = !{!15, !6, i64 40}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; 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.addrinfo = type { i32, i32, i32, i32, i32, ptr, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [13 x i8], align 1
@__PRETTY_FUNCTION__._ZN5tracy12UdpBroadcast4OpenEPKct = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: nounwind
declare void @freeaddrinfo(ptr noundef) local_unnamed_addr #0

declare i32 @close(i32 noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #5

declare i32 @getaddrinfo(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5tracy12UdpBroadcast4OpenEPKct(ptr noundef nonnull align 4 dereferenceable(8) %0, ptr noundef %1, i16 noundef zeroext %2) local_unnamed_addr #6 align 2 {
  %4 = alloca %struct.addrinfo, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [32 x i8], align 16
  %7 = alloca i32, align 4
  %8 = load i32, ptr %0, align 4, !tbaa !5
  %9 = icmp eq i32 %8, -1
  br i1 %9, label %11, label %10

10:                                               ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 565, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5tracy12UdpBroadcast4OpenEPKct) #7
  unreachable

11:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %4) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %4, i8 0, i64 48, i1 false)
  %12 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 2, ptr %12, align 4, !tbaa !10
  %13 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 2, ptr %13, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #8
  %14 = zext i16 %2 to i32
  %15 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %14) #8
  %16 = call i32 @getaddrinfo(ptr noundef %1, ptr noundef nonnull %6, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %.preheader, label %36

.preheader:                                       ; preds = %11
  %.01526 = load ptr, ptr %5, align 8, !tbaa !14
  %.not19.not27 = icmp eq ptr %.01526, null
  br i1 %.not19.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %29
  %.01528 = phi ptr [ %.015, %29 ], [ %.01526, %.preheader ]
  %17 = getelementptr inbounds i8, ptr %.01528, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !10
  %19 = getelementptr inbounds i8, ptr %.01528, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %.01528, i64 12
  %22 = load i32, ptr %21, align 4, !tbaa !15
  %23 = call i32 @socket(i32 noundef %18, i32 noundef %20, i32 noundef %22) #8
  %24 = icmp eq i32 %23, -1
  br i1 %24, label %29, label %25

25:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #8
  store i32 1, ptr %7, align 4, !tbaa !16
  %26 = call i32 @setsockopt(i32 noundef %23, i32 noundef 1, i32 noundef 6, ptr noundef nonnull %7, i32 noundef 4) #8
  %27 = icmp eq i32 %26, -1
  br i1 %27, label %.thread, label %32

.thread:                                          ; preds = %25
  %28 = call i32 @close(i32 noundef %23)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #8
  br label %29

29:                                               ; preds = %.thread, %.lr.ph
  %30 = getelementptr inbounds i8, ptr %.01528, i64 40
  %.015 = load ptr, ptr %30, align 8, !tbaa !14
  %.not19.not = icmp eq ptr %.015, null
  br i1 %.not19.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !17

._crit_edge.loopexit:                             ; preds = %29
  %.pre = load ptr, ptr %5, align 8, !tbaa !14
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %31 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ null, %.preheader ]
  call void @freeaddrinfo(ptr noundef %31) #8
  br label %36

32:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #8
  %33 = load ptr, ptr %5, align 8, !tbaa !14
  call void @freeaddrinfo(ptr noundef %33) #8
  store i32 %23, ptr %0, align 4, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %0, i64 4
  %35 = call i32 @inet_pton(i32 noundef 2, ptr noundef %1, ptr noundef nonnull %34) #8
  br label %36

36:                                               ; preds = %._crit_edge, %32, %11
  %.117 = phi i1 [ false, %11 ], [ false, %._crit_edge ], [ true, %32 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #8
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #8
  ret i1 %.117
}

; Function Attrs: nounwind
declare i32 @inet_pton(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #0 = { 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 = { noreturn 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 #6 = { mustprogress 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 #7 = { noreturn nounwind }
attributes #8 = { 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, !7, i64 0}
!6 = !{!"_ZTSN5tracy12UdpBroadcastE", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !7, i64 4}
!11 = !{!"_ZTS8addrinfo", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !12, i64 24, !12, i64 32, !12, i64 40}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!11, !7, i64 8}
!14 = !{!12, !12, i64 0}
!15 = !{!11, !7, i64 12}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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