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

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

%"class.tracy::ListenSocket" = type { i32 }
%struct.addrinfo = type { i32, i32, i32, i32, i32, ptr, ptr, ptr }

@.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__._ZN5tracy12ListenSocket6ListenEti = external hidden unnamed_addr constant [48 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nounwind
declare void @freeaddrinfo(ptr 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: mustprogress uwtable
declare dso_local void @_ZN5tracy12ListenSocket5CloseEv(ptr noundef nonnull align 4 dereferenceable(4)) #3 align 2

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

16:                                               ; preds = %3
  br label %19

17:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 474, ptr noundef @__PRETTY_FUNCTION__._ZN5tracy12ListenSocket6ListenEti) #5
  unreachable

18:                                               ; No predecessors!
  br label %19

19:                                               ; preds = %18, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %20 = call noundef ptr @_ZN5tracy9GetEnvVarEPKc(ptr noundef @.str.6)
  store ptr %20, ptr %9, align 8, !tbaa !5
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %29

23:                                               ; preds = %19
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 0
  %26 = load i8, ptr %25, align 1, !tbaa !15
  %27 = sext i8 %26 to i32
  %28 = icmp ne i32 %27, 49
  br i1 %28, label %29, label %33

29:                                               ; preds = %23, %19
  %30 = load i16, ptr %6, align 2, !tbaa !9
  %31 = call noundef i32 @_ZN5tracyL30addrinfo_and_socket_for_familyEtiPP8addrinfo(i16 noundef zeroext %30, i32 noundef 10, ptr noundef %8)
  %32 = getelementptr inbounds %"class.tracy::ListenSocket", ptr %12, i32 0, i32 0
  store i32 %31, ptr %32, align 4, !tbaa !13
  br label %33

33:                                               ; preds = %29, %23
  %34 = getelementptr inbounds %"class.tracy::ListenSocket", ptr %12, i32 0, i32 0
  %35 = load i32, ptr %34, align 4, !tbaa !13
  %36 = icmp eq i32 %35, -1
  br i1 %36, label %37, label %46

37:                                               ; preds = %33
  %38 = load i16, ptr %6, align 2, !tbaa !9
  %39 = call noundef i32 @_ZN5tracyL30addrinfo_and_socket_for_familyEtiPP8addrinfo(i16 noundef zeroext %38, i32 noundef 2, ptr noundef %8)
  %40 = getelementptr inbounds %"class.tracy::ListenSocket", ptr %12, i32 0, i32 0
  store i32 %39, ptr %40, align 4, !tbaa !13
  %41 = getelementptr inbounds %"class.tracy::ListenSocket", ptr %12, i32 0, i32 0
  %42 = load i32, ptr %41, align 4, !tbaa !13
  %43 = icmp eq i32 %42, -1
  br i1 %43, label %44, label %45

44:                                               ; preds = %37
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %73

45:                                               ; preds = %37
  br label %46

46:                                               ; preds = %45, %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 1, ptr %11, align 4, !tbaa !11
  %47 = getelementptr inbounds %"class.tracy::ListenSocket", ptr %12, i32 0, i32 0
  %48 = load i32, ptr %47, align 4, !tbaa !13
  %49 = call i32 @setsockopt(i32 noundef %48, i32 noundef 1, i32 noundef 2, ptr noundef %11, i32 noundef 4) #6
  %50 = getelementptr inbounds %"class.tracy::ListenSocket", ptr %12, i32 0, i32 0
  %51 = load i32, ptr %50, align 4, !tbaa !13
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.addrinfo, ptr %52, i32 0, i32 5
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.addrinfo, ptr %55, i32 0, i32 4
  %57 = load i32, ptr %56, align 8, !tbaa !18
  %58 = call i32 @bind(i32 noundef %51, ptr noundef %54, i32 noundef %57) #6
  %59 = icmp eq i32 %58, -1
  br i1 %59, label %60, label %62

60:                                               ; preds = %46
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  call void @freeaddrinfo(ptr noundef %61) #6
  call void @_ZN5tracy12ListenSocket5CloseEv(ptr noundef nonnull align 4 dereferenceable(4) %12)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %72

62:                                               ; preds = %46
  %63 = getelementptr inbounds %"class.tracy::ListenSocket", ptr %12, i32 0, i32 0
  %64 = load i32, ptr %63, align 4, !tbaa !13
  %65 = load i32, ptr %7, align 4, !tbaa !11
  %66 = call i32 @listen(i32 noundef %64, i32 noundef %65) #6
  %67 = icmp eq i32 %66, -1
  br i1 %67, label %68, label %70

68:                                               ; preds = %62
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  call void @freeaddrinfo(ptr noundef %69) #6
  call void @_ZN5tracy12ListenSocket5CloseEv(ptr noundef nonnull align 4 dereferenceable(4) %12)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %72

70:                                               ; preds = %62
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  call void @freeaddrinfo(ptr noundef %71) #6
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %72

72:                                               ; preds = %70, %68, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %73

73:                                               ; preds = %72, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %74 = load i1, ptr %4, align 1
  ret i1 %74
}

declare noundef ptr @_ZN5tracy9GetEnvVarEPKc(ptr noundef) #4

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZN5tracyL30addrinfo_and_socket_for_familyEtiPP8addrinfo(i16 noundef zeroext, i32 noundef, ptr noundef) #3

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

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

; Function Attrs: nounwind
declare i32 @listen(i32 noundef, i32 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 = { 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 = { 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 #4 = { "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 = { noreturn nounwind }
attributes #6 = { 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTSN5tracy12ListenSocketE", !12, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !6, i64 24}
!17 = !{!"_ZTS8addrinfo", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!18 = !{!17, !12, i64 16}


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

@.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__._ZN5tracy12ListenSocket6ListenEti = external hidden unnamed_addr constant [48 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nounwind
declare void @freeaddrinfo(ptr 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: mustprogress uwtable
declare dso_local void @_ZN5tracy12ListenSocket5CloseEv(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5tracy12ListenSocket6ListenEti(ptr noundef nonnull align 4 dereferenceable(4) %0, i16 noundef zeroext %1, i32 noundef %2) local_unnamed_addr #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, 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 = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 474, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5tracy12ListenSocket6ListenEti) #5
  unreachable

9:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  store ptr null, ptr %4, align 8, !tbaa !10
  %10 = tail call noundef ptr @_ZN5tracy9GetEnvVarEPKc(ptr noundef nonnull @.str.6)
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %13, label %11

11:                                               ; preds = %9
  %12 = load i8, ptr %10, align 1, !tbaa !12
  %.not7 = icmp eq i8 %12, 49
  br i1 %.not7, label %thread-pre-split, label %13

13:                                               ; preds = %11, %9
  %14 = call noundef i32 @_ZN5tracyL30addrinfo_and_socket_for_familyEtiPP8addrinfo(i16 noundef zeroext %1, i32 noundef 10, ptr noundef nonnull %4)
  store i32 %14, ptr %0, align 4, !tbaa !5
  br label %15

thread-pre-split:                                 ; preds = %11
  %.pr = load i32, ptr %0, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %thread-pre-split, %13
  %16 = phi i32 [ %.pr, %thread-pre-split ], [ %14, %13 ]
  %17 = icmp eq i32 %16, -1
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  %19 = call noundef i32 @_ZN5tracyL30addrinfo_and_socket_for_familyEtiPP8addrinfo(i16 noundef zeroext %1, i32 noundef 2, ptr noundef nonnull %4)
  store i32 %19, ptr %0, align 4, !tbaa !5
  %20 = icmp eq i32 %19, -1
  br i1 %20, label %40, label %21

21:                                               ; preds = %18, %15
  %22 = phi i32 [ %19, %18 ], [ %16, %15 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #6
  store i32 1, ptr %5, align 4, !tbaa !13
  %23 = call i32 @setsockopt(i32 noundef %22, i32 noundef 1, i32 noundef 2, ptr noundef nonnull %5, i32 noundef 4) #6
  %24 = load i32, ptr %0, align 4, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !10
  %26 = getelementptr inbounds i8, ptr %25, i64 24
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %25, i64 16
  %29 = load i32, ptr %28, align 8, !tbaa !16
  %30 = call i32 @bind(i32 noundef %24, ptr noundef %27, i32 noundef %29) #6
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %34

32:                                               ; preds = %21
  %33 = load ptr, ptr %4, align 8, !tbaa !10
  call void @freeaddrinfo(ptr noundef %33) #6
  br label %.sink.split

34:                                               ; preds = %21
  %35 = load i32, ptr %0, align 4, !tbaa !5
  %36 = call i32 @listen(i32 noundef %35, i32 noundef %2) #6
  %37 = icmp eq i32 %36, -1
  %38 = load ptr, ptr %4, align 8, !tbaa !10
  call void @freeaddrinfo(ptr noundef %38) #6
  br i1 %37, label %.sink.split, label %39

.sink.split:                                      ; preds = %34, %32
  call void @_ZN5tracy12ListenSocket5CloseEv(ptr noundef nonnull align 4 dereferenceable(4) %0)
  br label %39

39:                                               ; preds = %.sink.split, %34
  %.0 = phi i1 [ true, %34 ], [ false, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  br label %40

40:                                               ; preds = %18, %39
  %.1 = phi i1 [ %.0, %39 ], [ false, %18 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  ret i1 %.1
}

declare noundef ptr @_ZN5tracy9GetEnvVarEPKc(ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZN5tracyL30addrinfo_and_socket_for_familyEtiPP8addrinfo(i16 noundef zeroext, i32 noundef, ptr noundef) local_unnamed_addr #3

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

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

; Function Attrs: nounwind
declare i32 @listen(i32 noundef, i32 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 = { 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 = { 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 #4 = { "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 = { noreturn nounwind }
attributes #6 = { 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 = !{!"_ZTSN5tracy12ListenSocketE", !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!8, !8, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !11, i64 24}
!15 = !{!"_ZTS8addrinfo", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !11, i64 24, !11, i64 32, !11, i64 40}
!16 = !{!15, !7, i64 16}


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