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

; 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.8 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [17 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 @EfiReleaseLock(ptr noundef) #1

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

13:                                               ; preds = %2
  br label %14

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

17:                                               ; preds = %14
  br label %18

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

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

23:                                               ; preds = %21, %18
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25, %14
  br label %27

27:                                               ; preds = %26
  br label %28

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

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

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

41:                                               ; preds = %35, %29
  store i64 -9223372036854775793, ptr %6, align 8, !tbaa !9
  br label %63

42:                                               ; preds = %35
  br label %43

43:                                               ; preds = %42
  %44 = call zeroext i8 @DebugAssertEnabled()
  %45 = icmp ne i8 %44, 0
  br i1 %45, label %46, label %54

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

52:                                               ; preds = %46
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 287, ptr noundef @.str.9)
  br label %53

53:                                               ; preds = %52, %46
  br label %54

54:                                               ; preds = %53, %43
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._SOCKET, ptr %57, i32 0, i32 25
  %59 = load ptr, ptr %58, align 8, !tbaa !19
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = call i64 %59(ptr noundef %60, i8 noundef zeroext 2, ptr noundef %61)
  store i64 %62, ptr %6, align 8, !tbaa !9
  br label %63

63:                                               ; preds = %56, %41
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._SOCKET, ptr %64, i32 0, i32 10
  call void @EfiReleaseLock(ptr noundef %65)
  %66 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %66, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %67

67:                                               ; preds = %63, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %68 = load i64, ptr %3, align 8
  ret i64 %68
}

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, !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 = !{!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.1 = external hidden unnamed_addr constant [156 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [17 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 @EfiReleaseLock(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @SockConfigure(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %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
  %.not14 = icmp eq i8 %7, 0
  br i1 %.not14, label %26, label %8

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

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

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 56
  %13 = load i8, ptr %12, align 8, !tbaa !5
  %.off = add i8 %13, -1
  %switch = icmp ult i8 %.off, 2
  br i1 %switch, label %25, label %14

14:                                               ; preds = %11
  %15 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %15, 0
  br i1 %.not, label %21, label %16

16:                                               ; preds = %14
  %17 = getelementptr inbounds i8, ptr %0, i64 64
  %18 = load i8, ptr %17, align 8, !tbaa !16
  %19 = icmp eq i8 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  tail call void @DebugAssert(ptr noundef nonnull @.str.1, i64 noundef 287, ptr noundef nonnull @.str.9) #2
  br label %21

21:                                               ; preds = %16, %20, %14
  %22 = getelementptr inbounds i8, ptr %0, i64 256
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  %24 = tail call i64 %23(ptr noundef nonnull %0, i8 noundef zeroext 2, ptr noundef %1) #2
  br label %25

25:                                               ; preds = %11, %21
  %.0 = phi i64 [ %24, %21 ], [ -9223372036854775793, %11 ]
  tail call void @EfiReleaseLock(ptr noundef nonnull %3) #2
  br label %26

26:                                               ; preds = %6, %10, %8, %25
  %.011 = phi i64 [ %.0, %25 ], [ -9223372036854775793, %8 ], [ -9223372036854775793, %10 ], [ -9223372036854775793, %6 ]
  ret i64 %.011
}

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


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