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

; 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._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 }
%struct._SOCK_COMPLETION_TOKEN = type { ptr, i64 }

@.str.10 = external hidden unnamed_addr constant [54 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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @SockTokenExisted(ptr noundef, ptr noundef) #1

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

declare void @DebugPrint(i64 noundef, ptr noundef, ...) #2

declare i64 @EfiAcquireLockOrFail(ptr noundef) #2

declare void @SockSetState(ptr noundef, i8 noundef zeroext) #2

declare void @EfiReleaseLock(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @SockConnect(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._SOCKET, ptr %9, i32 0, i32 10
  %11 = call i64 @EfiAcquireLockOrFail(ptr noundef %10)
  store i64 %11, ptr %6, align 8, !tbaa !9
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = icmp slt i64 %12, 0
  br i1 %13, label %14, label %30

14:                                               ; preds = %2
  br label %15

15:                                               ; preds = %14
  %16 = call zeroext i8 @DebugPrintEnabled()
  %17 = icmp ne i8 %16, 0
  br i1 %17, label %18, label %27

18:                                               ; preds = %15
  br label %19

19:                                               ; preds = %18
  %20 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %21 = icmp ne i8 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %19
  %23 = load i64, ptr %6, align 8, !tbaa !9
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.10, i64 noundef %23)
  br label %24

24:                                               ; preds = %22, %19
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26, %15
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  store i64 -9223372036854775793, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %80

30:                                               ; preds = %2
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._SOCKET, ptr %31, i32 0, i32 6
  %33 = load i8, ptr %32, align 8, !tbaa !11
  %34 = zext i8 %33 to i32
  %35 = icmp eq i32 %34, 3
  br i1 %35, label %36, label %37

36:                                               ; preds = %30
  store i64 -9223372036854775791, ptr %6, align 8, !tbaa !9
  br label %76

37:                                               ; preds = %30
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._SOCKET, ptr %38, i32 0, i32 6
  %40 = load i8, ptr %39, align 8, !tbaa !11
  %41 = zext i8 %40 to i32
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %37
  store i64 -9223372036854775789, ptr %6, align 8, !tbaa !9
  br label %76

44:                                               ; preds = %37
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._SOCKET, ptr %45, i32 0, i32 8
  %47 = load i8, ptr %46, align 8, !tbaa !18
  %48 = zext i8 %47 to i32
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %56

50:                                               ; preds = %44
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._SOCKET, ptr %51, i32 0, i32 6
  %53 = load i8, ptr %52, align 8, !tbaa !11
  %54 = zext i8 %53 to i32
  %55 = icmp eq i32 %54, 1
  br i1 %55, label %57, label %56

56:                                               ; preds = %50, %44
  store i64 -9223372036854775793, ptr %6, align 8, !tbaa !9
  br label %76

57:                                               ; preds = %50
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._SOCK_COMPLETION_TOKEN, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !19
  store ptr %60, ptr %7, align 8, !tbaa !5
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = call zeroext i8 @SockTokenExisted(ptr noundef %61, ptr noundef %62)
  %64 = icmp ne i8 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %57
  store i64 -9223372036854775793, ptr %6, align 8, !tbaa !9
  br label %76

66:                                               ; preds = %57
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._SOCKET, ptr %68, i32 0, i32 23
  store ptr %67, ptr %69, align 8, !tbaa !21
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  call void @SockSetState(ptr noundef %70, i8 noundef zeroext 2)
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._SOCKET, ptr %71, i32 0, i32 25
  %73 = load ptr, ptr %72, align 8, !tbaa !22
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = call i64 %73(ptr noundef %74, i8 noundef zeroext 8, ptr noundef null)
  store i64 %75, ptr %6, align 8, !tbaa !9
  br label %76

76:                                               ; preds = %66, %65, %56, %43, %36
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._SOCKET, ptr %77, i32 0, i32 10
  call void @EfiReleaseLock(ptr noundef %78)
  %79 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %79, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %80

80:                                               ; preds = %76, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %81 = load i64, ptr %3, align 8
  ret i64 %81
}

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 = { "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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !7, i64 56}
!12 = !{!"_SOCKET", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !7, i64 56, !13, i64 60, !7, i64 64, !15, i64 66, !16, i64 72, !17, i64 96, !17, i64 112, !10, i64 128, !7, i64 136, !13, i64 140, !13, i64 144, !6, i64 152, !14, i64 160, !14, i64 176, !14, i64 192, !14, i64 208, !14, 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}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 8, !13, i64 16}
!17 = !{!"_SOCK_BUFFER", !13, i64 0, !13, i64 4, !6, i64 8}
!18 = !{!12, !7, i64 64}
!19 = !{!20, !6, i64 0}
!20 = !{!"_SOCK_COMPLETION_TOKEN", !6, i64 0, !10, i64 8}
!21 = !{!12, !6, i64 240}
!22 = !{!12, !6, i64 256}


; 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.10 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @SockTokenExisted(ptr noundef, ptr noundef) local_unnamed_addr #0

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #1

declare void @DebugPrint(i64 noundef, ptr noundef, ...) local_unnamed_addr #1

declare i64 @EfiAcquireLockOrFail(ptr noundef) local_unnamed_addr #1

declare void @SockSetState(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

declare void @EfiReleaseLock(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @SockConnect(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 72
  %4 = tail call i64 @EfiAcquireLockOrFail(ptr noundef nonnull %3) #2
  %5 = icmp slt i64 %4, 0
  br i1 %5, label %6, label %11

6:                                                ; preds = %2
  %7 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not20 = icmp eq i8 %7, 0
  br i1 %.not20, label %29, label %8

8:                                                ; preds = %6
  %9 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not21 = icmp eq i8 %9, 0
  br i1 %.not21, label %29, label %10

10:                                               ; preds = %8
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.10, i64 noundef %4) #2
  br label %29

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 56
  %13 = load i8, ptr %12, align 8, !tbaa !5
  switch i8 %13, label %15 [
    i8 3, label %28
    i8 0, label %14
  ]

14:                                               ; preds = %11
  br label %28

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %0, i64 64
  %17 = load i8, ptr %16, align 8, !tbaa !16
  %18 = icmp eq i8 %17, 0
  %19 = icmp eq i8 %13, 1
  %or.cond = and i1 %19, %18
  br i1 %or.cond, label %20, label %28

20:                                               ; preds = %15
  %21 = load ptr, ptr %1, align 8, !tbaa !17
  %22 = tail call zeroext i8 @SockTokenExisted(ptr noundef nonnull %0, ptr noundef %21)
  %.not = icmp eq i8 %22, 0
  br i1 %.not, label %23, label %28

23:                                               ; preds = %20
  %24 = getelementptr inbounds i8, ptr %0, i64 240
  store ptr %1, ptr %24, align 8, !tbaa !19
  tail call void @SockSetState(ptr noundef nonnull %0, i8 noundef zeroext 2) #2
  %25 = getelementptr inbounds i8, ptr %0, i64 256
  %26 = load ptr, ptr %25, align 8, !tbaa !20
  %27 = tail call i64 %26(ptr noundef nonnull %0, i8 noundef zeroext 8, ptr noundef null) #2
  br label %28

28:                                               ; preds = %20, %15, %11, %23, %14
  %.017 = phi i64 [ -9223372036854775789, %14 ], [ %27, %23 ], [ -9223372036854775791, %11 ], [ -9223372036854775793, %15 ], [ -9223372036854775793, %20 ]
  tail call void @EfiReleaseLock(ptr noundef nonnull %3) #2
  br label %29

29:                                               ; preds = %6, %10, %8, %28
  %.0 = phi i64 [ %.017, %28 ], [ -9223372036854775793, %8 ], [ -9223372036854775793, %10 ], [ -9223372036854775793, %6 ]
  ret i64 %.0
}

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


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