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

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

@.str.1 = external hidden unnamed_addr constant [156 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [57 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 @DebugPrintEnabled() #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #1

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

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

6:                                                ; preds = %1
  %7 = call zeroext i8 @DebugAssertEnabled()
  %8 = icmp ne i8 %7, 0
  br i1 %8, label %9, label %19

9:                                                ; preds = %6
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %17

12:                                               ; preds = %9
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._SOCKET, ptr %13, i32 0, i32 25
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %12, %9
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 149, ptr noundef @.str.2)
  br label %18

18:                                               ; preds = %17, %12
  br label %19

19:                                               ; preds = %18, %6
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._SOCKET, ptr %22, i32 0, i32 14
  %24 = load i8, ptr %23, align 8, !tbaa !17
  %25 = icmp ne i8 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store i64 0, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %104

27:                                               ; preds = %21
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._SOCKET, ptr %28, i32 0, i32 14
  store i8 1, ptr %29, align 8, !tbaa !17
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._SOCKET, ptr %30, i32 0, i32 10
  %32 = call i64 @EfiAcquireLockOrFail(ptr noundef %31)
  store i64 %32, ptr %4, align 8, !tbaa !18
  %33 = load i64, ptr %4, align 8, !tbaa !18
  %34 = icmp slt i64 %33, 0
  br i1 %34, label %35, label %51

35:                                               ; preds = %27
  br label %36

36:                                               ; preds = %35
  %37 = call zeroext i8 @DebugPrintEnabled()
  %38 = icmp ne i8 %37, 0
  br i1 %38, label %39, label %48

39:                                               ; preds = %36
  br label %40

40:                                               ; preds = %39
  %41 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %42 = icmp ne i8 %41, 0
  br i1 %42, label %43, label %45

43:                                               ; preds = %40
  %44 = load i64, ptr %4, align 8, !tbaa !18
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.3, i64 noundef %44)
  br label %45

45:                                               ; preds = %43, %40
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47, %36
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  store i64 -9223372036854775793, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %104

51:                                               ; preds = %27
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._SOCKET, ptr %52, i32 0, i32 25
  %54 = load ptr, ptr %53, align 8, !tbaa !9
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = call i64 %54(ptr noundef %55, i8 noundef zeroext 1, ptr noundef null)
  store i64 %56, ptr %4, align 8, !tbaa !18
  %57 = load i64, ptr %4, align 8, !tbaa !18
  %58 = icmp slt i64 %57, 0
  br i1 %58, label %59, label %77

59:                                               ; preds = %51
  br label %60

60:                                               ; preds = %59
  %61 = call zeroext i8 @DebugPrintEnabled()
  %62 = icmp ne i8 %61, 0
  br i1 %62, label %63, label %72

63:                                               ; preds = %60
  br label %64

64:                                               ; preds = %63
  %65 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %66 = icmp ne i8 %65, 0
  br i1 %66, label %67, label %69

67:                                               ; preds = %64
  %68 = load i64, ptr %4, align 8, !tbaa !18
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.4, i64 noundef %68)
  br label %69

69:                                               ; preds = %67, %64
  br label %70

70:                                               ; preds = %69
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71, %60
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._SOCKET, ptr %75, i32 0, i32 14
  store i8 0, ptr %76, align 8, !tbaa !17
  br label %95

77:                                               ; preds = %51
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct._SOCKET, ptr %78, i32 0, i32 6
  %80 = load i8, ptr %79, align 8, !tbaa !19
  %81 = zext i8 %80 to i32
  %82 = icmp eq i32 %81, 1
  br i1 %82, label %89, label %83

83:                                               ; preds = %77
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._SOCKET, ptr %84, i32 0, i32 6
  %86 = load i8, ptr %85, align 8, !tbaa !19
  %87 = zext i8 %86 to i32
  %88 = icmp eq i32 %87, 2
  br i1 %88, label %89, label %94

89:                                               ; preds = %83, %77
  %90 = load ptr, ptr %3, align 8, !tbaa !5
  call void @SockConnFlush(ptr noundef %90)
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  call void @SockSetState(ptr noundef %91, i8 noundef zeroext 0)
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct._SOCKET, ptr %92, i32 0, i32 6
  store i8 0, ptr %93, align 8, !tbaa !19
  br label %94

94:                                               ; preds = %89, %83
  br label %95

95:                                               ; preds = %94, %74
  %96 = load ptr, ptr %3, 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 %4, align 8, !tbaa !18
  %99 = icmp slt i64 %98, 0
  br i1 %99, label %100, label %102

100:                                              ; preds = %95
  %101 = load i64, ptr %4, align 8, !tbaa !18
  store i64 %101, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %104

102:                                              ; preds = %95
  %103 = load ptr, ptr %3, align 8, !tbaa !5
  call void @SockDestroy(ptr noundef %103)
  store i64 0, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %104

104:                                              ; preds = %102, %100, %50, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %105 = load i64, ptr %2, align 8
  ret i64 %105
}

declare zeroext i8 @DebugAssertEnabled() #1

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

declare i64 @EfiAcquireLockOrFail(ptr noundef) #1

declare void @SockConnFlush(ptr noundef) #1

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

declare void @EfiReleaseLock(ptr noundef) #1

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


; 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.2 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [57 x i8], align 1

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @SockDestroyChild(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %2, 0
  br i1 %.not, label %8, label %3

3:                                                ; preds = %1
  %.not25 = icmp eq ptr %0, null
  br i1 %.not25, label %7, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 256
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not26 = icmp eq ptr %6, null
  br i1 %.not26, label %7, label %8

7:                                                ; preds = %4, %3
  tail call void @DebugAssert(ptr noundef nonnull @.str.1, i64 noundef 149, ptr noundef nonnull @.str.2) #2
  br label %8

8:                                                ; preds = %4, %7, %1
  %9 = getelementptr inbounds i8, ptr %0, i64 136
  %10 = load i8, ptr %9, align 8, !tbaa !16
  %.not27 = icmp eq i8 %10, 0
  br i1 %.not27, label %11, label %36

11:                                               ; preds = %8
  store i8 1, ptr %9, align 8, !tbaa !16
  %12 = getelementptr inbounds i8, ptr %0, i64 72
  %13 = tail call i64 @EfiAcquireLockOrFail(ptr noundef nonnull %12) #2
  %14 = icmp slt i64 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %11
  %16 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not30 = icmp eq i8 %16, 0
  br i1 %.not30, label %36, label %17

17:                                               ; preds = %15
  %18 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not31 = icmp eq i8 %18, 0
  br i1 %.not31, label %36, label %19

19:                                               ; preds = %17
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.3, i64 noundef %13) #2
  br label %36

20:                                               ; preds = %11
  %21 = getelementptr inbounds i8, ptr %0, i64 256
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = tail call i64 %22(ptr noundef nonnull %0, i8 noundef zeroext 1, ptr noundef null) #2
  %24 = icmp slt i64 %23, 0
  br i1 %24, label %25, label %30

25:                                               ; preds = %20
  %26 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not28 = icmp eq i8 %26, 0
  br i1 %.not28, label %34, label %27

27:                                               ; preds = %25
  %28 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not29 = icmp eq i8 %28, 0
  br i1 %.not29, label %34, label %29

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

30:                                               ; preds = %20
  %31 = getelementptr inbounds i8, ptr %0, i64 56
  %32 = load i8, ptr %31, align 8, !tbaa !17
  %.off = add i8 %32, -1
  %switch = icmp ult i8 %.off, 2
  br i1 %switch, label %33, label %35

33:                                               ; preds = %30
  tail call void @SockConnFlush(ptr noundef nonnull %0) #2
  tail call void @SockSetState(ptr noundef nonnull %0, i8 noundef zeroext 0) #2
  store i8 0, ptr %31, align 8, !tbaa !17
  br label %35

34:                                               ; preds = %25, %29, %27
  store i8 0, ptr %9, align 8, !tbaa !16
  tail call void @EfiReleaseLock(ptr noundef nonnull %12) #2
  br label %36

35:                                               ; preds = %30, %33
  tail call void @EfiReleaseLock(ptr noundef nonnull %12) #2
  tail call void @SockDestroy(ptr noundef nonnull %0) #2
  br label %36

36:                                               ; preds = %34, %15, %19, %17, %8, %35
  %.0 = phi i64 [ 0, %35 ], [ 0, %8 ], [ -9223372036854775793, %17 ], [ -9223372036854775793, %19 ], [ -9223372036854775793, %15 ], [ %23, %34 ]
  ret i64 %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

declare i64 @EfiAcquireLockOrFail(ptr noundef) local_unnamed_addr #0

declare void @SockConnFlush(ptr noundef) local_unnamed_addr #0

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

declare void @EfiReleaseLock(ptr noundef) local_unnamed_addr #0

declare void @SockDestroy(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, !10, i64 256}
!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 136}
!17 = !{!6, !8, i64 56}


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