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

; 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_CLOSE_TOKEN = type { %struct.EFI_TCP6_COMPLETION_TOKEN, i8 }
%struct.EFI_TCP6_COMPLETION_TOKEN = type { ptr, i64 }
%struct._EFI_TCP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

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

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

14:                                               ; preds = %9, %1
  store i32 1, ptr %6, align 4
  br label %90

15:                                               ; preds = %9
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.TCP_IO, ptr %16, i32 0, i32 14
  store i8 0, ptr %17, align 1, !tbaa !10
  store ptr null, ptr %3, align 8, !tbaa !5
  store ptr null, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.TCP_IO, ptr %18, i32 0, i32 0
  %20 = load i8, ptr %19, align 8, !tbaa !12
  %21 = zext i8 %20 to i32
  %22 = icmp eq i32 %21, 4
  br i1 %22, label %23, label %37

23:                                               ; preds = %15
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TCP_IO, ptr %24, i32 0, i32 9
  %26 = getelementptr inbounds %struct.EFI_TCP4_CLOSE_TOKEN, ptr %25, i32 0, i32 1
  store i8 1, ptr %26, align 8, !tbaa !9
  %27 = load ptr, ptr %2, 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 %3, align 8, !tbaa !5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._EFI_TCP4_PROTOCOL, ptr %30, i32 0, i32 7
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.TCP_IO, ptr %34, i32 0, i32 9
  %36 = call i64 %32(ptr noundef %33, ptr noundef %35)
  store i64 %36, ptr %5, align 8, !tbaa !15
  br label %59

37:                                               ; preds = %15
  %38 = load ptr, ptr %2, 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 %57

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

57:                                               ; preds = %37
  store i32 1, ptr %6, align 4
  br label %90

58:                                               ; preds = %43
  br label %59

59:                                               ; preds = %58, %23
  %60 = load i64, ptr %5, align 8, !tbaa !15
  %61 = icmp slt i64 %60, 0
  br i1 %61, label %62, label %63

62:                                               ; preds = %59
  store i32 1, ptr %6, align 4
  br label %90

63:                                               ; preds = %59
  br label %64

64:                                               ; preds = %88, %63
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.TCP_IO, ptr %65, i32 0, i32 14
  %67 = load i8, ptr %66, align 1, !tbaa !10
  %68 = icmp ne i8 %67, 0
  %69 = xor i1 %68, true
  br i1 %69, label %70, label %89

70:                                               ; preds = %64
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.TCP_IO, ptr %71, i32 0, i32 0
  %73 = load i8, ptr %72, align 8, !tbaa !12
  %74 = zext i8 %73 to i32
  %75 = icmp eq i32 %74, 4
  br i1 %75, label %76, label %82

76:                                               ; preds = %70
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._EFI_TCP4_PROTOCOL, ptr %77, i32 0, i32 9
  %79 = load ptr, ptr %78, align 8, !tbaa !19
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = call i64 %79(ptr noundef %80)
  br label %88

82:                                               ; preds = %70
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct._EFI_TCP6_PROTOCOL, ptr %83, i32 0, i32 8
  %85 = load ptr, ptr %84, align 8, !tbaa !20
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = call i64 %85(ptr noundef %86)
  br label %88

88:                                               ; preds = %82, %76
  br label %64, !llvm.loop !21

89:                                               ; preds = %64
  store i32 0, ptr %6, align 4
  br label %90

90:                                               ; preds = %89, %62, %57, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  %91 = load i32, ptr %6, align 4
  switch i32 %91, label %93 [
    i32 0, label %92
    i32 1, label %92
  ]

92:                                               ; preds = %90, %90
  ret void

93:                                               ; preds = %90
  unreachable
}

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 163}
!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 56}
!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 48}
!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 = !{!14, !6, i64 72}
!20 = !{!18, !6, i64 64}
!21 = distinct !{!21, !22}
!22 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local void @TcpIoReset(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.loopexit, label %3

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

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 163
  store i8 0, ptr %8, align 1, !tbaa !8
  %9 = load i8, ptr %0, align 8, !tbaa !11
  switch i8 %9, label %.loopexit [
    i8 4, label %11
    i8 6, label %10
  ]

10:                                               ; preds = %7
  br label %11

11:                                               ; preds = %7, %10
  %.sink28 = phi i64 [ 48, %10 ], [ 56, %7 ]
  %.022 = phi ptr [ null, %10 ], [ %5, %7 ]
  %.021 = phi ptr [ %5, %10 ], [ null, %7 ]
  %12 = getelementptr inbounds i8, ptr %0, i64 112
  %13 = getelementptr inbounds i8, ptr %0, i64 128
  store i8 1, ptr %13, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %5, i64 %.sink28
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = tail call i64 %15(ptr noundef nonnull %5, ptr noundef nonnull %12) #1
  %17 = icmp slt i64 %16, 0
  br i1 %17, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %11
  %18 = load i8, ptr %8, align 1, !tbaa !8
  %.not25 = icmp eq i8 %18, 0
  br i1 %.not25, label %.lr.ph, label %.loopexit

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

21:                                               ; preds = %.lr.ph, %21
  %22 = load i8, ptr %0, align 8, !tbaa !11
  %23 = icmp eq i8 %22, 4
  %. = select i1 %23, ptr %20, ptr %19
  %.022..021 = select i1 %23, ptr %.022, ptr %.021
  %24 = load ptr, ptr %., align 8, !tbaa !12
  %25 = tail call i64 %24(ptr noundef %.022..021) #1
  %26 = load i8, ptr %8, align 1, !tbaa !8
  %.not = icmp eq i8 %26, 0
  br i1 %.not, label %21, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %21, %.preheader, %11, %7, %1, %3
  ret void
}

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 163}
!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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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