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

; 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.TCP_IO = type { i8, ptr, ptr, ptr, %union.TCP_IO_PROTOCOL, %union.TCP_IO_PROTOCOL, %union.TCP_IO_CONNECTION_TOKEN, %union.TCP_IO_IO_TOKEN, %union.TCP_IO_IO_TOKEN, %union.TCP_IO_CLOSE_TOKEN, %union.TCP_IO_LISTEN_TOKEN, i8, i8, i8, i8, i8 }
%union.TCP_IO_PROTOCOL = type { ptr }
%union.TCP_IO_CONNECTION_TOKEN = type { %struct.EFI_TCP4_CONNECTION_TOKEN }
%struct.EFI_TCP4_CONNECTION_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN }
%struct.EFI_TCP4_COMPLETION_TOKEN = type { ptr, i64 }
%union.TCP_IO_IO_TOKEN = type { %struct.EFI_TCP4_IO_TOKEN }
%struct.EFI_TCP4_IO_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN, %union.anon }
%union.anon = type { ptr }
%union.TCP_IO_CLOSE_TOKEN = type { %struct.EFI_TCP4_CLOSE_TOKEN }
%struct.EFI_TCP4_CLOSE_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN, i8 }
%union.TCP_IO_LISTEN_TOKEN = type { %struct.EFI_TCP4_LISTEN_TOKEN }
%struct.EFI_TCP4_LISTEN_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN, ptr }
%struct._EFI_TCP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct._EFI_TCP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }

@gBS = external global ptr, align 8

; 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
define dso_local i64 @TcpIoConnect(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = 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) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %17, label %12

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

17:                                               ; preds = %12, %2
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %109

18:                                               ; preds = %12
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TCP_IO, ptr %19, i32 0, i32 11
  store i8 0, ptr %20, align 8, !tbaa !10
  store ptr null, ptr %6, align 8, !tbaa !5
  store ptr null, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.TCP_IO, ptr %21, i32 0, i32 0
  %23 = load i8, ptr %22, align 8, !tbaa !12
  %24 = zext i8 %23 to i32
  %25 = icmp eq i32 %24, 4
  br i1 %25, label %26, label %37

26:                                               ; preds = %18
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.TCP_IO, ptr %27, i32 0, i32 4
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  store ptr %29, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._EFI_TCP4_PROTOCOL, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.TCP_IO, ptr %34, i32 0, i32 6
  %36 = call i64 %32(ptr noundef %33, ptr noundef %35)
  store i64 %36, ptr %8, align 8, !tbaa !15
  br label %56

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

43:                                               ; preds = %37
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.TCP_IO, ptr %44, i32 0, i32 4
  %46 = load ptr, ptr %45, align 8, !tbaa !9
  store ptr %46, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._EFI_TCP6_PROTOCOL, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.TCP_IO, ptr %51, i32 0, i32 6
  %53 = call i64 %49(ptr noundef %50, ptr noundef %52)
  store i64 %53, ptr %8, align 8, !tbaa !15
  br label %55

54:                                               ; preds = %37
  store i64 -9223372036854775805, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %109

55:                                               ; preds = %43
  br label %56

56:                                               ; preds = %55, %26
  %57 = load i64, ptr %8, align 8, !tbaa !15
  %58 = icmp slt i64 %57, 0
  br i1 %58, label %59, label %61

59:                                               ; preds = %56
  %60 = load i64, ptr %8, align 8, !tbaa !15
  store i64 %60, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %109

61:                                               ; preds = %56
  br label %62

62:                                               ; preds = %94, %61
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.TCP_IO, ptr %63, i32 0, i32 11
  %65 = load i8, ptr %64, align 8, !tbaa !10
  %66 = icmp ne i8 %65, 0
  br i1 %66, label %74, label %67

67:                                               ; preds = %62
  %68 = load ptr, ptr @gBS, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %68, i32 0, i32 13
  %70 = load ptr, ptr %69, align 8, !tbaa !19
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = call i64 %70(ptr noundef %71)
  %73 = icmp slt i64 %72, 0
  br label %74

74:                                               ; preds = %67, %62
  %75 = phi i1 [ false, %62 ], [ %73, %67 ]
  br i1 %75, label %76, label %95

76:                                               ; preds = %74
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.TCP_IO, ptr %77, i32 0, i32 0
  %79 = load i8, ptr %78, align 8, !tbaa !12
  %80 = zext i8 %79 to i32
  %81 = icmp eq i32 %80, 4
  br i1 %81, label %82, label %88

82:                                               ; preds = %76
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct._EFI_TCP4_PROTOCOL, ptr %83, i32 0, i32 9
  %85 = load ptr, ptr %84, align 8, !tbaa !23
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = call i64 %85(ptr noundef %86)
  br label %94

88:                                               ; preds = %76
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct._EFI_TCP6_PROTOCOL, ptr %89, i32 0, i32 8
  %91 = load ptr, ptr %90, align 8, !tbaa !24
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = call i64 %91(ptr noundef %92)
  br label %94

94:                                               ; preds = %88, %82
  br label %62, !llvm.loop !25

95:                                               ; preds = %74
  %96 = load ptr, ptr %4, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.TCP_IO, ptr %96, i32 0, i32 11
  %98 = load i8, ptr %97, align 8, !tbaa !10
  %99 = icmp ne i8 %98, 0
  br i1 %99, label %101, label %100

100:                                              ; preds = %95
  store i64 -9223372036854775790, ptr %8, align 8, !tbaa !15
  br label %107

101:                                              ; preds = %95
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.TCP_IO, ptr %102, i32 0, i32 6
  %104 = getelementptr inbounds %struct.EFI_TCP4_CONNECTION_TOKEN, ptr %103, i32 0, i32 0
  %105 = getelementptr inbounds %struct.EFI_TCP4_COMPLETION_TOKEN, ptr %104, i32 0, i32 1
  %106 = load i64, ptr %105, align 8, !tbaa !9
  store i64 %106, ptr %8, align 8, !tbaa !15
  br label %107

107:                                              ; preds = %101, %100
  %108 = load i64, ptr %8, align 8, !tbaa !15
  store i64 %108, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %109

109:                                              ; preds = %107, %59, %54, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %110 = load i64, ptr %3, align 8
  ret i64 %110
}

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 = { 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, !7, i64 160}
!11 = !{!"", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 64, !7, i64 88, !7, i64 112, !7, i64 136, !7, i64 160, !7, i64 161, !7, i64 162, !7, i64 163, !7, i64 164}
!12 = !{!11, !7, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"_EFI_TCP4_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = !{!18, !6, i64 16}
!18 = !{!"_EFI_TCP6_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!19 = !{!20, !6, i64 120}
!20 = !{!"", !21, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!21 = !{!"", !16, i64 0, !22, i64 8, !22, i64 12, !22, i64 16, !22, i64 20}
!22 = !{!"int", !7, i64 0}
!23 = !{!14, !6, i64 72}
!24 = !{!18, !6, i64 64}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


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

@gBS = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @TcpIoConnect(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %35, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %35, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 160
  store i8 0, ptr %9, align 8, !tbaa !8
  %10 = load i8, ptr %0, align 8, !tbaa !11
  switch i8 %10, label %35 [
    i8 4, label %12
    i8 6, label %11
  ]

11:                                               ; preds = %8
  br label %12

12:                                               ; preds = %8, %11
  %.sink34 = phi i64 [ 16, %11 ], [ 24, %8 ]
  %.026 = phi ptr [ null, %11 ], [ %6, %8 ]
  %.025 = phi ptr [ %6, %11 ], [ null, %8 ]
  %13 = getelementptr inbounds i8, ptr %6, i64 %.sink34
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  %16 = tail call i64 %14(ptr noundef nonnull %6, ptr noundef nonnull %15) #1
  %17 = icmp slt i64 %16, 0
  br i1 %17, label %35, label %.preheader

.preheader:                                       ; preds = %12
  %18 = load i8, ptr %9, align 8, !tbaa !8
  %.not32 = icmp eq i8 %18, 0
  br i1 %.not32, label %.lr.ph, label %.critedge.thread

.lr.ph:                                           ; preds = %.preheader
  %19 = getelementptr inbounds i8, ptr %.025, i64 64
  %20 = getelementptr inbounds i8, ptr %.026, i64 72
  br label %21

21:                                               ; preds = %.lr.ph, %27
  %22 = load ptr, ptr @gBS, align 8, !tbaa !12
  %23 = getelementptr inbounds i8, ptr %22, i64 120
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = tail call i64 %24(ptr noundef %1) #1
  %26 = icmp slt i64 %25, 0
  br i1 %26, label %27, label %.critedge

27:                                               ; preds = %21
  %28 = load i8, ptr %0, align 8, !tbaa !11
  %29 = icmp eq i8 %28, 4
  %. = select i1 %29, ptr %20, ptr %19
  %.026..025 = select i1 %29, ptr %.026, ptr %.025
  %30 = load ptr, ptr %., align 8, !tbaa !12
  %31 = tail call i64 %30(ptr noundef %.026..025) #1
  %32 = load i8, ptr %9, align 8, !tbaa !8
  %.not = icmp eq i8 %32, 0
  br i1 %.not, label %21, label %.critedge.thread, !llvm.loop !18

.critedge:                                        ; preds = %21
  %.pr = load i8, ptr %9, align 8, !tbaa !8
  %.not30 = icmp eq i8 %.pr, 0
  br i1 %.not30, label %35, label %.critedge.thread

.critedge.thread:                                 ; preds = %27, %.preheader, %.critedge
  %33 = getelementptr inbounds i8, ptr %0, i64 56
  %34 = load i64, ptr %33, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %.critedge.thread, %.critedge, %12, %8, %2, %4
  %.027 = phi i64 [ -9223372036854775806, %4 ], [ -9223372036854775806, %2 ], [ -9223372036854775805, %8 ], [ %16, %12 ], [ %34, %.critedge.thread ], [ -9223372036854775790, %.critedge ]
  ret i64 %.027
}

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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !6, i64 160}
!9 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 64, !6, i64 88, !6, i64 112, !6, i64 136, !6, i64 160, !6, i64 161, !6, i64 162, !6, i64 163, !6, i64 164}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!9, !6, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !10, i64 120}
!14 = !{!"", !15, i64 0, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !10, i64 312, !10, i64 320, !10, i64 328, !10, i64 336, !10, i64 344, !10, i64 352, !10, i64 360, !10, i64 368}
!15 = !{!"", !16, i64 0, !17, i64 8, !17, i64 12, !17, i64 16, !17, i64 20}
!16 = !{!"long long", !6, i64 0}
!17 = !{!"int", !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass