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

; 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.1 = external hidden unnamed_addr constant [156 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [52 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 zeroext i8 @DebugAssertEnabled() #2

declare void @DebugAssert(ptr noundef, 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 @SockClose(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i8 %2, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  br label %11

11:                                               ; preds = %3
  %12 = call zeroext i8 @DebugAssertEnabled()
  %13 = icmp ne i8 %12, 0
  br i1 %13, label %14, label %21

14:                                               ; preds = %11
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._SOCKET, ptr %15, i32 0, i32 7
  %17 = load i32, ptr %16, align 4, !tbaa !10
  %18 = icmp eq i32 1, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 801, ptr noundef @.str.11)
  br label %20

20:                                               ; preds = %19, %14
  br label %21

21:                                               ; preds = %20, %11
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._SOCKET, ptr %24, i32 0, i32 10
  %26 = call i64 @EfiAcquireLockOrFail(ptr noundef %25)
  store i64 %26, ptr %8, align 8, !tbaa !18
  %27 = load i64, ptr %8, align 8, !tbaa !18
  %28 = icmp slt i64 %27, 0
  br i1 %28, label %29, label %45

29:                                               ; preds = %23
  br label %30

30:                                               ; preds = %29
  %31 = call zeroext i8 @DebugPrintEnabled()
  %32 = icmp ne i8 %31, 0
  br i1 %32, label %33, label %42

33:                                               ; preds = %30
  br label %34

34:                                               ; preds = %33
  %35 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %36 = icmp ne i8 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %34
  %38 = load i64, ptr %8, align 8, !tbaa !18
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.21, i64 noundef %38)
  br label %39

39:                                               ; preds = %37, %34
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41, %30
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  store i64 -9223372036854775793, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %99

45:                                               ; preds = %23
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._SOCKET, ptr %46, i32 0, i32 6
  %48 = load i8, ptr %47, align 8, !tbaa !19
  %49 = zext i8 %48 to i32
  %50 = icmp eq i32 %49, 3
  br i1 %50, label %51, label %52

51:                                               ; preds = %45
  store i64 -9223372036854775791, ptr %8, align 8, !tbaa !18
  br label %95

52:                                               ; preds = %45
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._SOCKET, ptr %53, i32 0, i32 6
  %55 = load i8, ptr %54, align 8, !tbaa !19
  %56 = zext i8 %55 to i32
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %52
  store i64 -9223372036854775789, ptr %8, align 8, !tbaa !18
  br label %95

59:                                               ; preds = %52
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._SOCKET, ptr %60, i32 0, i32 8
  %62 = load i8, ptr %61, align 8, !tbaa !20
  %63 = zext i8 %62 to i32
  %64 = icmp eq i32 %63, 4
  br i1 %64, label %65, label %66

65:                                               ; preds = %59
  store i64 -9223372036854775793, ptr %8, align 8, !tbaa !18
  br label %95

66:                                               ; preds = %59
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._SOCK_COMPLETION_TOKEN, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !21
  store ptr %69, ptr %9, align 8, !tbaa !5
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = call zeroext i8 @SockTokenExisted(ptr noundef %70, ptr noundef %71)
  %73 = icmp ne i8 %72, 0
  br i1 %73, label %74, label %75

74:                                               ; preds = %66
  store i64 -9223372036854775793, ptr %8, align 8, !tbaa !18
  br label %95

75:                                               ; preds = %66
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._SOCKET, ptr %77, i32 0, i32 24
  store ptr %76, ptr %78, align 8, !tbaa !23
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  call void @SockSetState(ptr noundef %79, i8 noundef zeroext 4)
  %80 = load i8, ptr %7, align 1, !tbaa !9
  %81 = icmp ne i8 %80, 0
  br i1 %81, label %82, label %88

82:                                               ; preds = %75
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct._SOCKET, ptr %83, i32 0, i32 25
  %85 = load ptr, ptr %84, align 8, !tbaa !24
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = call i64 %85(ptr noundef %86, i8 noundef zeroext 10, ptr noundef null)
  store i64 %87, ptr %8, align 8, !tbaa !18
  br label %94

88:                                               ; preds = %75
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct._SOCKET, ptr %89, i32 0, i32 25
  %91 = load ptr, ptr %90, align 8, !tbaa !24
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = call i64 %91(ptr noundef %92, i8 noundef zeroext 9, ptr noundef null)
  store i64 %93, ptr %8, align 8, !tbaa !18
  br label %94

94:                                               ; preds = %88, %82
  br label %95

95:                                               ; preds = %94, %74, %65, %58, %51
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct._SOCKET, ptr %96, i32 0, i32 10
  call void @EfiReleaseLock(ptr noundef %97)
  %98 = load i64, ptr %8, align 8, !tbaa !18
  store i64 %98, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %99

99:                                               ; preds = %95, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %100 = load i64, ptr %4, align 8
  ret i64 %100
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 60}
!11 = !{!"_SOCKET", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !7, i64 56, !12, i64 60, !7, i64 64, !14, i64 66, !15, i64 72, !17, i64 96, !17, i64 112, !16, i64 128, !7, i64 136, !12, i64 140, !12, i64 144, !6, i64 152, !13, i64 160, !13, i64 176, !13, i64 192, !13, i64 208, !13, 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}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!14 = !{!"short", !7, i64 0}
!15 = !{!"", !16, i64 0, !16, i64 8, !12, i64 16}
!16 = !{!"long long", !7, i64 0}
!17 = !{!"_SOCK_BUFFER", !12, i64 0, !12, i64 4, !6, i64 8}
!18 = !{!16, !16, i64 0}
!19 = !{!11, !7, i64 56}
!20 = !{!11, !7, i64 64}
!21 = !{!22, !6, i64 0}
!22 = !{!"_SOCK_COMPLETION_TOKEN", !6, i64 0, !16, i64 8}
!23 = !{!11, !6, i64 248}
!24 = !{!11, !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.1 = external hidden unnamed_addr constant [156 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [52 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 zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, 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 @SockClose(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %10, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 60
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %10, label %9

9:                                                ; preds = %5
  tail call void @DebugAssert(ptr noundef nonnull @.str.1, i64 noundef 801, ptr noundef nonnull @.str.11) #2
  br label %10

10:                                               ; preds = %5, %9, %3
  %11 = getelementptr inbounds i8, ptr %0, i64 72
  %12 = tail call i64 @EfiAcquireLockOrFail(ptr noundef nonnull %11) #2
  %13 = icmp slt i64 %12, 0
  br i1 %13, label %14, label %19

14:                                               ; preds = %10
  %15 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not25 = icmp eq i8 %15, 0
  br i1 %.not25, label %39, label %16

16:                                               ; preds = %14
  %17 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not26 = icmp eq i8 %17, 0
  br i1 %.not26, label %39, label %18

18:                                               ; preds = %16
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.21, i64 noundef %12) #2
  br label %39

19:                                               ; preds = %10
  %20 = getelementptr inbounds i8, ptr %0, i64 56
  %21 = load i8, ptr %20, align 8, !tbaa !16
  switch i8 %21, label %23 [
    i8 3, label %38
    i8 0, label %22
  ]

22:                                               ; preds = %19
  br label %38

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %0, i64 64
  %25 = load i8, ptr %24, align 8, !tbaa !17
  %26 = icmp eq i8 %25, 4
  br i1 %26, label %38, label %27

27:                                               ; preds = %23
  %28 = load ptr, ptr %1, align 8, !tbaa !18
  %29 = tail call zeroext i8 @SockTokenExisted(ptr noundef nonnull %0, ptr noundef %28)
  %.not23 = icmp eq i8 %29, 0
  br i1 %.not23, label %30, label %38

30:                                               ; preds = %27
  %31 = getelementptr inbounds i8, ptr %0, i64 248
  store ptr %1, ptr %31, align 8, !tbaa !20
  tail call void @SockSetState(ptr noundef nonnull %0, i8 noundef zeroext 4) #2
  %.not24 = icmp eq i8 %2, 0
  %32 = getelementptr inbounds i8, ptr %0, i64 256
  %33 = load ptr, ptr %32, align 8, !tbaa !21
  br i1 %.not24, label %36, label %34

34:                                               ; preds = %30
  %35 = tail call i64 %33(ptr noundef nonnull %0, i8 noundef zeroext 10, ptr noundef null) #2
  br label %38

36:                                               ; preds = %30
  %37 = tail call i64 %33(ptr noundef nonnull %0, i8 noundef zeroext 9, ptr noundef null) #2
  br label %38

38:                                               ; preds = %27, %23, %19, %34, %36, %22
  %.020 = phi i64 [ -9223372036854775789, %22 ], [ %35, %34 ], [ %37, %36 ], [ -9223372036854775791, %19 ], [ -9223372036854775793, %23 ], [ -9223372036854775793, %27 ]
  tail call void @EfiReleaseLock(ptr noundef nonnull %11) #2
  br label %39

39:                                               ; preds = %14, %18, %16, %38
  %.0 = phi i64 [ %.020, %38 ], [ -9223372036854775793, %16 ], [ -9223372036854775793, %18 ], [ -9223372036854775793, %14 ]
  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, !7, i64 60}
!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 56}
!17 = !{!6, !8, i64 64}
!18 = !{!19, !10, i64 0}
!19 = !{!"_SOCK_COMPLETION_TOKEN", !10, i64 0, !14, i64 8}
!20 = !{!6, !10, i64 248}
!21 = !{!6, !10, i64 256}


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