; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (Tcp4Connect)

; 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.EFI_TCP4_CONNECTION_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN }
%struct.EFI_TCP4_COMPLETION_TOKEN = type { ptr, i64 }
%struct._SOCKET = type { i32, ptr, ptr, ptr, ptr, %struct._LIST_ENTRY, i8, i32, i8, i16, %struct.EFI_LOCK, %struct._SOCK_BUFFER, %struct._SOCK_BUFFER, i64, i8, i32, i32, ptr, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, ptr, ptr, [20 x i8], %union._NET_PROTOCOL, ptr, ptr, ptr }
%struct.EFI_LOCK = type { i64, i64, i32 }
%struct._SOCK_BUFFER = type { i32, i32, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%union._NET_PROTOCOL = type { %struct._EFI_TCP4_PROTOCOL }
%struct._EFI_TCP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; 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

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

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

10:                                               ; preds = %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr null, %11
  br i1 %12, label %19, label %13

13:                                               ; preds = %10
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.EFI_TCP4_CONNECTION_TOKEN, ptr %14, i32 0, i32 0
  %16 = getelementptr inbounds %struct.EFI_TCP4_COMPLETION_TOKEN, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = icmp eq ptr null, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %13, %10, %2
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %44

20:                                               ; preds = %13
  %21 = call zeroext i8 @DebugAssertEnabled()
  %22 = zext i8 %21 to i32
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %34

24:                                               ; preds = %20
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = ptrtoint ptr %25 to i64
  %27 = sub i64 %26, ptrtoint (ptr getelementptr inbounds (%struct._SOCKET, ptr null, i32 0, i32 27) to i64)
  %28 = inttoptr i64 %27 to ptr
  %29 = getelementptr inbounds %struct._SOCKET, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !13
  %31 = icmp ne i32 %30, 1262702419
  br i1 %31, label %32, label %34

32:                                               ; preds = %24
  call void @DebugAssert(ptr noundef @.str, i64 noundef 331, ptr noundef @.str.1)
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  br label %39

34:                                               ; preds = %24, %20
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = ptrtoint ptr %35 to i64
  %37 = sub i64 %36, ptrtoint (ptr getelementptr inbounds (%struct._SOCKET, ptr null, i32 0, i32 27) to i64)
  %38 = inttoptr i64 %37 to ptr
  br label %39

39:                                               ; preds = %34, %32
  %40 = phi ptr [ %33, %32 ], [ %38, %34 ]
  store ptr %40, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = call i64 @SockConnect(ptr noundef %41, ptr noundef %42)
  store i64 %43, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %44

44:                                               ; preds = %39, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %45 = load i64, ptr %3, align 8
  ret i64 %45
}

declare i64 @SockConnect(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !11, i64 0}
!11 = !{!"", !6, i64 0, !12, i64 8}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"_SOCKET", !15, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !16, i64 40, !7, i64 56, !15, i64 60, !7, i64 64, !17, i64 66, !18, i64 72, !19, i64 96, !19, i64 112, !12, i64 128, !7, i64 136, !15, i64 140, !15, i64 144, !6, i64 152, !16, i64 160, !16, i64 176, !16, i64 192, !16, i64 208, !16, i64 224, !6, i64 240, !6, i64 248, !6, i64 256, !7, i64 264, !7, i64 288, !6, i64 368, !6, i64 376, !6, i64 384}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!17 = !{!"short", !7, i64 0}
!18 = !{!"", !12, i64 0, !12, i64 8, !15, i64 16}
!19 = !{!"_SOCK_BUFFER", !15, i64 0, !15, i64 4, !6, i64 8}


; 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 = external hidden unnamed_addr constant [151 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @Tcp4Connect(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %15, label %5

5:                                                ; preds = %2
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %15, label %8

8:                                                ; preds = %5
  %9 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %9, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre12 = add i64 %.pre, -288
  %.pre14 = inttoptr i64 %.pre12 to ptr
  br i1 %.not, label %._crit_edge, label %10

10:                                               ; preds = %8
  %11 = load i32, ptr %.pre14, align 8, !tbaa !12
  %.not11 = icmp eq i32 %11, 1262702419
  br i1 %.not11, label %._crit_edge, label %12

12:                                               ; preds = %10
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 331, ptr noundef nonnull @.str.1) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %8, %10, %12
  %13 = phi ptr [ %0, %12 ], [ %.pre14, %10 ], [ %.pre14, %8 ]
  %14 = tail call i64 @SockConnect(ptr noundef %13, ptr noundef nonnull %1) #2
  br label %15

15:                                               ; preds = %2, %5, %._crit_edge
  %.0 = phi i64 [ %14, %._crit_edge ], [ -9223372036854775806, %5 ], [ -9223372036854775806, %2 ]
  ret i64 %.0
}

declare i64 @SockConnect(ptr noundef, ptr noundef) local_unnamed_addr #0

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 = { 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 }

!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, !8, i64 0}
!6 = !{!"", !7, i64 0}
!7 = !{!"", !8, i64 0, !11, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long long", !9, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"_SOCKET", !14, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !15, i64 40, !9, i64 56, !14, i64 60, !9, i64 64, !16, i64 66, !17, i64 72, !18, i64 96, !18, i64 112, !11, i64 128, !9, i64 136, !14, i64 140, !14, i64 144, !8, i64 152, !15, i64 160, !15, i64 176, !15, i64 192, !15, i64 208, !15, i64 224, !8, i64 240, !8, i64 248, !8, i64 256, !9, i64 264, !9, i64 288, !8, i64 368, !8, i64 376, !8, i64 384}
!14 = !{!"int", !9, i64 0}
!15 = !{!"_LIST_ENTRY", !8, i64 0, !8, i64 8}
!16 = !{!"short", !9, i64 0}
!17 = !{!"", !11, i64 0, !11, i64 8, !14, i64 16}
!18 = !{!"_SOCK_BUFFER", !14, i64 0, !14, i64 4, !8, i64 8}


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