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

; 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.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%"class.tracy::UdpListen" = type { i32 }

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [13 x i8], align 1
@__PRETTY_FUNCTION__._ZN5tracy9UdpListen6ListenEt = external hidden unnamed_addr constant [40 x i8], align 1

declare i32 @close(i32 noundef) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, 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
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) #3

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i16 @_ZL10__bswap_16t(i16 noundef zeroext) #4

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5tracy9UdpListen6ListenEt(ptr noundef nonnull align 4 dereferenceable(4) %0, i16 noundef zeroext %1) #5 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.sockaddr_in, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  %12 = getelementptr inbounds %"class.tracy::UdpListen", ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = icmp eq i32 %13, -1
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  br label %18

16:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 670, ptr noundef @__PRETTY_FUNCTION__._ZN5tracy9UdpListen6ListenEt) #6
  unreachable

17:                                               ; No predecessors!
  br label %18

18:                                               ; preds = %17, %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  %19 = call i32 @socket(i32 noundef 2, i32 noundef 2, i32 noundef 0) #7
  store i32 %19, ptr %6, align 4, !tbaa !14
  %20 = icmp eq i32 %19, -1
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %50

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  store i32 1, ptr %8, align 4, !tbaa !14
  %23 = getelementptr inbounds %"class.tracy::UdpListen", ptr %11, i32 0, i32 0
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = call i32 @setsockopt(i32 noundef %24, i32 noundef 1, i32 noundef 2, ptr noundef %8, i32 noundef 4) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  store i32 1, ptr %9, align 4, !tbaa !14
  %26 = load i32, ptr %6, align 4, !tbaa !14
  %27 = call i32 @setsockopt(i32 noundef %26, i32 noundef 1, i32 noundef 6, ptr noundef %9, i32 noundef 4) #7
  %28 = icmp eq i32 %27, -1
  br i1 %28, label %29, label %32

29:                                               ; preds = %22
  %30 = load i32, ptr %6, align 4, !tbaa !14
  %31 = call i32 @close(i32 noundef %30)
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %49

32:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #7
  %33 = getelementptr inbounds %struct.sockaddr_in, ptr %10, i32 0, i32 0
  store i16 2, ptr %33, align 4, !tbaa !15
  %34 = load i16, ptr %5, align 2, !tbaa !9
  %35 = call noundef zeroext i16 @_ZL10__bswap_16t(i16 noundef zeroext %34)
  %36 = getelementptr inbounds %struct.sockaddr_in, ptr %10, i32 0, i32 1
  store i16 %35, ptr %36, align 2, !tbaa !18
  %37 = getelementptr inbounds %struct.sockaddr_in, ptr %10, i32 0, i32 2
  %38 = getelementptr inbounds %struct.in_addr, ptr %37, i32 0, i32 0
  store i32 0, ptr %38, align 4, !tbaa !19
  %39 = load i32, ptr %6, align 4, !tbaa !14
  %40 = call i32 @bind(i32 noundef %39, ptr noundef %10, i32 noundef 16) #7
  %41 = icmp eq i32 %40, -1
  br i1 %41, label %42, label %45

42:                                               ; preds = %32
  %43 = load i32, ptr %6, align 4, !tbaa !14
  %44 = call i32 @close(i32 noundef %43)
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %48

45:                                               ; preds = %32
  %46 = load i32, ptr %6, align 4, !tbaa !14
  %47 = getelementptr inbounds %"class.tracy::UdpListen", ptr %11, i32 0, i32 0
  store i32 %46, ptr %47, align 4, !tbaa !11
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %48

48:                                               ; preds = %45, %42
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #7
  br label %49

49:                                               ; preds = %48, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  br label %50

50:                                               ; preds = %49, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  %51 = load i1, ptr %3, align 1
  ret i1 %51
}

attributes #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 = { 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 #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 = { inlinehint mustprogress 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 #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 = !{!"_ZTSN5tracy9UdpListenE", !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTS11sockaddr_in", !10, i64 0, !10, i64 2, !17, i64 4, !7, i64 8}
!17 = !{!"_ZTS7in_addr", !13, i64 0}
!18 = !{!16, !10, i64 2}
!19 = !{!16, !13, i64 4}


; 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.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [13 x i8], align 1
@__PRETTY_FUNCTION__._ZN5tracy9UdpListen6ListenEt = external hidden unnamed_addr constant [40 x i8], align 1

declare i32 @close(i32 noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, 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
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i16 @_ZL10__bswap_16t(i16 noundef zeroext) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5tracy9UdpListen6ListenEt(ptr nocapture noundef nonnull align 4 dereferenceable(4) %0, i16 noundef zeroext %1) local_unnamed_addr #5 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %struct.sockaddr_in, align 4
  %6 = load i32, ptr %0, align 4, !tbaa !5
  %7 = icmp eq i32 %6, -1
  br i1 %7, label %9, label %8

8:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 670, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5tracy9UdpListen6ListenEt) #6
  unreachable

9:                                                ; preds = %2
  %10 = tail call i32 @socket(i32 noundef 2, i32 noundef 2, i32 noundef 0) #7
  %11 = icmp eq i32 %10, -1
  br i1 %11, label %30, label %12

12:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #7
  store i32 1, ptr %3, align 4, !tbaa !10
  %13 = load i32, ptr %0, align 4, !tbaa !5
  %14 = call i32 @setsockopt(i32 noundef %13, i32 noundef 1, i32 noundef 2, ptr noundef nonnull %3, i32 noundef 4) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #7
  store i32 1, ptr %4, align 4, !tbaa !10
  %15 = call i32 @setsockopt(i32 noundef %10, i32 noundef 1, i32 noundef 6, ptr noundef nonnull %4, i32 noundef 4) #7
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %19

17:                                               ; preds = %12
  %18 = call i32 @close(i32 noundef %10)
  br label %29

19:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #7
  store i16 2, ptr %5, align 4, !tbaa !11
  %20 = call noundef zeroext i16 @_ZL10__bswap_16t(i16 noundef zeroext %1)
  %21 = getelementptr inbounds i8, ptr %5, i64 2
  store i16 %20, ptr %21, align 2, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %5, i64 4
  store i32 0, ptr %22, align 4, !tbaa !16
  %23 = call i32 @bind(i32 noundef %10, ptr noundef nonnull %5, i32 noundef 16) #7
  %24 = icmp ne i32 %23, -1
  br i1 %24, label %27, label %25

25:                                               ; preds = %19
  %26 = call i32 @close(i32 noundef %10)
  br label %28

27:                                               ; preds = %19
  store i32 %10, ptr %0, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %27, %25
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #7
  br label %29

29:                                               ; preds = %28, %17
  %.1 = phi i1 [ false, %17 ], [ %24, %28 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #7
  br label %30

30:                                               ; preds = %9, %29
  %.2 = phi i1 [ %.1, %29 ], [ false, %9 ]
  ret i1 %.2
}

attributes #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 = { 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 #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 = { inlinehint mustprogress 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 #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, !7, i64 0}
!6 = !{!"_ZTSN5tracy9UdpListenE", !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS11sockaddr_in", !13, i64 0, !13, i64 2, !14, i64 4, !8, i64 8}
!13 = !{!"short", !8, i64 0}
!14 = !{!"_ZTS7in_addr", !7, i64 0}
!15 = !{!12, !13, i64 2}
!16 = !{!12, !7, i64 4}


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