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

; 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.11 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [55 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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @SockFlush(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 %16

9:                                                ; preds = %6
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._SOCKET, ptr %10, i32 0, i32 7
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = icmp eq i32 1, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %9
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 736, ptr noundef @.str.11)
  br label %15

15:                                               ; preds = %14, %9
  br label %16

16:                                               ; preds = %15, %6
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._SOCKET, ptr %19, i32 0, i32 10
  %21 = call i64 @EfiAcquireLockOrFail(ptr noundef %20)
  store i64 %21, ptr %4, align 8, !tbaa !17
  %22 = load i64, ptr %4, align 8, !tbaa !17
  %23 = icmp slt i64 %22, 0
  br i1 %23, label %24, label %40

24:                                               ; preds = %18
  br label %25

25:                                               ; preds = %24
  %26 = call zeroext i8 @DebugPrintEnabled()
  %27 = icmp ne i8 %26, 0
  br i1 %27, label %28, label %37

28:                                               ; preds = %25
  br label %29

29:                                               ; preds = %28
  %30 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %31 = icmp ne i8 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %29
  %33 = load i64, ptr %4, align 8, !tbaa !17
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.19, i64 noundef %33)
  br label %34

34:                                               ; preds = %32, %29
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36, %25
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  store i64 -9223372036854775793, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %88

40:                                               ; preds = %18
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._SOCKET, ptr %41, i32 0, i32 6
  %43 = load i8, ptr %42, align 8, !tbaa !18
  %44 = zext i8 %43 to i32
  %45 = icmp eq i32 %44, 1
  br i1 %45, label %53, label %46

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

52:                                               ; preds = %46
  br label %84

53:                                               ; preds = %46, %40
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._SOCKET, ptr %54, i32 0, i32 25
  %56 = load ptr, ptr %55, align 8, !tbaa !19
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = call i64 %56(ptr noundef %57, i8 noundef zeroext 3, ptr noundef null)
  store i64 %58, ptr %4, align 8, !tbaa !17
  %59 = load i64, ptr %4, align 8, !tbaa !17
  %60 = icmp slt i64 %59, 0
  br i1 %60, label %61, label %77

61:                                               ; preds = %53
  br label %62

62:                                               ; preds = %61
  %63 = call zeroext i8 @DebugPrintEnabled()
  %64 = icmp ne i8 %63, 0
  br i1 %64, label %65, label %74

65:                                               ; preds = %62
  br label %66

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

69:                                               ; preds = %66
  %70 = load i64, ptr %4, align 8, !tbaa !17
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.20, i64 noundef %70)
  br label %71

71:                                               ; preds = %69, %66
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73, %62
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  br label %84

77:                                               ; preds = %53
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct._SOCKET, ptr %78, i32 0, i32 13
  store i64 -9223372036854775787, ptr %79, align 8, !tbaa !20
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  call void @SockConnFlush(ptr noundef %80)
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  call void @SockSetState(ptr noundef %81, i8 noundef zeroext 0)
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct._SOCKET, ptr %82, i32 0, i32 6
  store i8 0, ptr %83, align 8, !tbaa !18
  br label %84

84:                                               ; preds = %77, %76, %52
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct._SOCKET, ptr %85, i32 0, i32 10
  call void @EfiReleaseLock(ptr noundef %86)
  %87 = load i64, ptr %4, align 8, !tbaa !17
  store i64 %87, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %88

88:                                               ; preds = %84, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %89 = load i64, ptr %2, align 8
  ret i64 %89
}

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, !11, i64 60}
!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 = !{!15, !15, i64 0}
!18 = !{!10, !7, i64 56}
!19 = !{!10, !6, i64 256}
!20 = !{!10, !15, i64 128}


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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @SockFlush(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
  %4 = getelementptr inbounds i8, ptr %0, i64 60
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %8, label %7

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

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

12:                                               ; preds = %8
  %13 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not23 = icmp eq i8 %13, 0
  br i1 %.not23, label %33, label %14

14:                                               ; preds = %12
  %15 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not24 = icmp eq i8 %15, 0
  br i1 %.not24, label %33, label %16

16:                                               ; preds = %14
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.19, i64 noundef %10) #2
  br label %33

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

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %0, i64 256
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = tail call i64 %22(ptr noundef nonnull %0, i8 noundef zeroext 3, 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
  %.not21 = icmp eq i8 %26, 0
  br i1 %.not21, label %32, label %27

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

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

30:                                               ; preds = %20
  %31 = getelementptr inbounds i8, ptr %0, i64 128
  store i64 -9223372036854775787, ptr %31, align 8, !tbaa !18
  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 %18, align 8, !tbaa !16
  br label %32

32:                                               ; preds = %17, %25, %29, %27, %30
  %.0 = phi i64 [ %23, %29 ], [ %23, %27 ], [ %23, %25 ], [ %23, %30 ], [ %10, %17 ]
  tail call void @EfiReleaseLock(ptr noundef nonnull %9) #2
  br label %33

33:                                               ; preds = %12, %16, %14, %32
  %.016 = phi i64 [ %.0, %32 ], [ -9223372036854775793, %14 ], [ -9223372036854775793, %16 ], [ -9223372036854775793, %12 ]
  ret i64 %.016
}

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, !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, !10, i64 256}
!18 = !{!6, !14, i64 128}


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