; LLVM IR from goldsborough/ipc-bench :: source/tcp (server)

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

; 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 uwtable
declare dso_local void @handle_blocking(i32 noundef) #1

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

8:                                                ; preds = %46, %2
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %50

11:                                               ; preds = %8
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.addrinfo, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.addrinfo, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !12
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.addrinfo, ptr %18, i32 0, i32 3
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = call i32 @socket(i32 noundef %14, i32 noundef %17, i32 noundef %20) #4
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 %21, ptr %22, align 4, !tbaa !14
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = icmp eq i32 %24, -1
  br i1 %25, label %26, label %27

26:                                               ; preds = %11
  br label %46

27:                                               ; preds = %11
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i32, ptr %28, align 4, !tbaa !14
  call void @handle_blocking(i32 noundef %29)
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load i32, ptr %30, align 4, !tbaa !14
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.addrinfo, ptr %32, i32 0, i32 5
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.addrinfo, ptr %35, i32 0, i32 4
  %37 = load i32, ptr %36, align 8, !tbaa !16
  %38 = call i32 @bind(i32 noundef %31, ptr noundef %34, i32 noundef %37) #4
  store i32 %38, ptr %6, align 4, !tbaa !14
  %39 = load i32, ptr %6, align 4, !tbaa !14
  %40 = icmp eq i32 %39, 1
  br i1 %40, label %41, label %45

41:                                               ; preds = %27
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load i32, ptr %42, align 4, !tbaa !14
  %44 = call i32 @close(i32 noundef %43)
  br label %45

45:                                               ; preds = %41, %27
  br label %50

46:                                               ; preds = %26
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.addrinfo, ptr %47, i32 0, i32 7
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  store ptr %49, ptr %5, align 8, !tbaa !5
  br label %8, !llvm.loop !18

50:                                               ; preds = %45, %8
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret ptr %51
}

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

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

declare i32 @close(i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { "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, !11, i64 4}
!10 = !{!"addrinfo", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 12}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !6, i64 24}
!16 = !{!10, !11, i64 16}
!17 = !{!10, !6, i64 40}
!18 = distinct !{!18, !19}
!19 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local void @handle_blocking(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @get_address(ptr noundef readonly %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %.not17 = icmp eq ptr %0, null
  br i1 %.not17, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %2, %22
  %.018 = phi ptr [ %24, %22 ], [ %0, %2 ]
  %3 = getelementptr inbounds i8, ptr %.018, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %.018, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %.018, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !12
  %9 = tail call i32 @socket(i32 noundef %4, i32 noundef %6, i32 noundef %8) #3
  store i32 %9, ptr %1, align 4, !tbaa !13
  %10 = icmp eq i32 %9, -1
  br i1 %10, label %22, label %11

11:                                               ; preds = %.lr.ph
  tail call void @handle_blocking(i32 noundef %9)
  %12 = load i32, ptr %1, align 4, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %.018, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %.018, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !15
  %17 = tail call i32 @bind(i32 noundef %12, ptr noundef %14, i32 noundef %16) #3
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %.loopexit

19:                                               ; preds = %11
  %20 = load i32, ptr %1, align 4, !tbaa !13
  %21 = tail call i32 @close(i32 noundef %20) #3
  br label %.loopexit

22:                                               ; preds = %.lr.ph
  %23 = getelementptr inbounds i8, ptr %.018, i64 40
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %.not = icmp eq ptr %24, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !17

.loopexit:                                        ; preds = %22, %2, %11, %19
  %.016 = phi ptr [ %.018, %11 ], [ %.018, %19 ], [ null, %2 ], [ null, %22 ]
  ret ptr %.016
}

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

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

declare i32 @close(i32 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 = { 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 }

!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 4}
!6 = !{!"addrinfo", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 12}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !10, i64 24}
!15 = !{!6, !7, i64 16}
!16 = !{!6, !10, i64 40}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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