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

; 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.GUID = type { i32, i16, i16, [8 x i8] }
%struct.IP4_HEAD = type { i8, i8, i16, i16, i16, i8, i8, i16, i32, i32 }
%struct.NET_BUF = type { i32, i64, %struct._LIST_ENTRY, %union.NET_IP_HEAD, ptr, ptr, [64 x i8], ptr, i32, i32, [1 x %struct.NET_BLOCK_OP] }
%struct._LIST_ENTRY = type { ptr, ptr }
%union.NET_IP_HEAD = type { ptr }
%struct.NET_BLOCK_OP = type { ptr, ptr, ptr, ptr, i32 }
%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 }
%struct._EFI_IPSEC2_PROTOCOL = type { ptr, ptr, i8 }
%struct._IP4_SERVICE = type { i32, %struct._EFI_SERVICE_BINDING_PROTOCOL, i64, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, ptr, %struct.IP4_ASSEMBLE_TABLE, %struct.IGMP_SERVICE_DATA, ptr, ptr, ptr, ptr, %struct.EFI_MANAGED_NETWORK_CONFIG_DATA, %struct.EFI_SIMPLE_NETWORK_MODE, ptr, ptr, ptr, ptr, ptr, i32, i32 }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }
%struct.IP4_ASSEMBLE_TABLE = type { [31 x %struct._LIST_ENTRY] }
%struct.IGMP_SERVICE_DATA = type { i64, %struct._LIST_ENTRY }
%struct.EFI_MANAGED_NETWORK_CONFIG_DATA = type { i32, i32, i16, i8, i8, i8, i8, i8, i8, i8 }
%struct.EFI_SIMPLE_NETWORK_MODE = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x %struct.EFI_MAC_ADDRESS], %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, i8, i8, i8, i8, i8 }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct.IP4_TXTOKEN_WRAP = type { ptr, ptr, ptr, ptr, i8, i64 }
%struct.IP4_IPSEC_WRAP = type { ptr, ptr }

@gBS = external global ptr, align 8
@mIpSec = external global ptr, align 8
@gEfiIpSec2ProtocolGuid = external global %struct.GUID, align 4

; 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 void @FreePool(ptr noundef) #1

declare i32 @NetbufTrim(ptr noundef, i32 noundef, i8 noundef zeroext) #1

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @Ip4IpSecFree(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip4IpSecProcessPacket(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, ptr noundef %6) #2 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca i64, align 8
  %24 = alloca %struct.IP4_HEAD, align 1
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store i32 %5, ptr %13, align 4, !tbaa !9
  store ptr %6, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #3
  call void @llvm.lifetime.start.p0(i64 20, ptr %24) #3
  store i64 0, ptr %23, align 8, !tbaa !11
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  store ptr %26, ptr %20, align 8, !tbaa !5
  store ptr null, ptr %19, align 8, !tbaa !5
  store ptr null, ptr %22, align 8, !tbaa !5
  store ptr null, ptr %15, align 8, !tbaa !5
  %27 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %27, ptr %21, align 8, !tbaa !5
  %28 = load ptr, ptr %20, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.NET_BUF, ptr %28, i32 0, i32 8
  %30 = load i32, ptr %29, align 8, !tbaa !13
  store i32 %30, ptr %17, align 4, !tbaa !9
  %31 = call ptr @ZeroMem(ptr noundef %24, i64 noundef 20)
  %32 = load ptr, ptr @mIpSec, align 8, !tbaa !5
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %43

34:                                               ; preds = %7
  %35 = load ptr, ptr @gBS, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %35, i32 0, i32 38
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = call i64 %37(ptr noundef @gEfiIpSec2ProtocolGuid, ptr noundef null, ptr noundef @mIpSec)
  %39 = load ptr, ptr @mIpSec, align 8, !tbaa !5
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %42

41:                                               ; preds = %34
  br label %225

42:                                               ; preds = %34
  br label %43

43:                                               ; preds = %42, %7
  %44 = load ptr, ptr @mIpSec, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._EFI_IPSEC2_PROTOCOL, ptr %44, i32 0, i32 2
  %46 = load i8, ptr %45, align 8, !tbaa !19
  %47 = icmp ne i8 %46, 0
  br i1 %47, label %48, label %54

48:                                               ; preds = %43
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._IP4_SERVICE, ptr %49, i32 0, i32 22
  %51 = load i32, ptr %50, align 4, !tbaa !21
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._IP4_SERVICE, ptr %52, i32 0, i32 21
  store i32 %51, ptr %53, align 8, !tbaa !29
  br label %225

54:                                               ; preds = %43
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._IP4_SERVICE, ptr %55, i32 0, i32 22
  %57 = load i32, ptr %56, align 4, !tbaa !21
  %58 = sub i32 %57, 54
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._IP4_SERVICE, ptr %59, i32 0, i32 21
  store i32 %58, ptr %60, align 8, !tbaa !29
  br label %61

61:                                               ; preds = %54
  %62 = load i32, ptr %17, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = mul i64 %63, 16
  %65 = call ptr @AllocateZeroPool(i64 noundef %64)
  store ptr %65, ptr %15, align 8, !tbaa !5
  %66 = load ptr, ptr %15, align 8, !tbaa !5
  %67 = icmp eq ptr %66, null
  br i1 %67, label %68, label %69

68:                                               ; preds = %61
  store i64 -9223372036854775799, ptr %23, align 8, !tbaa !11
  br label %225

69:                                               ; preds = %61
  %70 = load ptr, ptr %20, align 8, !tbaa !5
  %71 = load ptr, ptr %15, align 8, !tbaa !5
  %72 = call i64 @NetbufBuildExt(ptr noundef %70, ptr noundef %71, ptr noundef %17)
  store i64 %72, ptr %23, align 8, !tbaa !11
  %73 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %73, ptr %16, align 8, !tbaa !5
  %74 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %74, ptr %18, align 4, !tbaa !9
  %75 = load i64, ptr %23, align 8, !tbaa !11
  %76 = icmp slt i64 %75, 0
  br i1 %76, label %77, label %79

77:                                               ; preds = %69
  %78 = load ptr, ptr %15, align 8, !tbaa !5
  call void @FreePool(ptr noundef %78)
  br label %225

79:                                               ; preds = %69
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = load ptr, ptr %80, align 8, !tbaa !5
  %82 = call ptr @Ip4NtohHead(ptr noundef %81)
  %83 = load ptr, ptr @mIpSec, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct._EFI_IPSEC2_PROTOCOL, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !30
  %86 = load ptr, ptr @mIpSec, align 8, !tbaa !5
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct._IP4_SERVICE, ptr %87, i32 0, i32 11
  %89 = load ptr, ptr %88, align 8, !tbaa !31
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  %91 = load ptr, ptr %90, align 8, !tbaa !5
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = load ptr, ptr %92, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.IP4_HEAD, ptr %93, i32 0, i32 6
  %95 = load ptr, ptr %11, align 8, !tbaa !5
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  %97 = load i32, ptr %13, align 4, !tbaa !9
  %98 = call i64 %85(ptr noundef %86, ptr noundef %89, i8 noundef zeroext 4, ptr noundef %91, ptr noundef %94, ptr noundef %95, ptr noundef %96, ptr noundef %15, ptr noundef %17, i32 noundef %97, ptr noundef %19)
  store i64 %98, ptr %23, align 8, !tbaa !11
  %99 = load ptr, ptr %9, align 8, !tbaa !5
  %100 = load ptr, ptr %99, align 8, !tbaa !5
  %101 = call ptr @Ip4NtohHead(ptr noundef %100)
  %102 = load i64, ptr %23, align 8, !tbaa !11
  %103 = icmp slt i64 %102, 0
  br i1 %103, label %104, label %106

104:                                              ; preds = %79
  %105 = load ptr, ptr %16, align 8, !tbaa !5
  call void @FreePool(ptr noundef %105)
  br label %225

106:                                              ; preds = %79
  %107 = load ptr, ptr %16, align 8, !tbaa !5
  %108 = load ptr, ptr %15, align 8, !tbaa !5
  %109 = icmp eq ptr %107, %108
  br i1 %109, label %110, label %116

110:                                              ; preds = %106
  %111 = load i32, ptr %18, align 4, !tbaa !9
  %112 = load i32, ptr %17, align 4, !tbaa !9
  %113 = icmp eq i32 %111, %112
  br i1 %113, label %114, label %116

114:                                              ; preds = %110
  %115 = load ptr, ptr %15, align 8, !tbaa !5
  call void @FreePool(ptr noundef %115)
  br label %225

116:                                              ; preds = %110, %106
  %117 = load ptr, ptr %16, align 8, !tbaa !5
  call void @FreePool(ptr noundef %117)
  br label %118

118:                                              ; preds = %116
  %119 = load i32, ptr %13, align 4, !tbaa !9
  %120 = icmp eq i32 %119, 1
  br i1 %120, label %121, label %150

121:                                              ; preds = %118
  %122 = load ptr, ptr %21, align 8, !tbaa !5
  %123 = icmp ne ptr %122, null
  br i1 %123, label %124, label %150

124:                                              ; preds = %121
  %125 = load ptr, ptr %19, align 8, !tbaa !5
  %126 = load ptr, ptr %21, align 8, !tbaa !5
  %127 = getelementptr inbounds %struct.IP4_TXTOKEN_WRAP, ptr %126, i32 0, i32 2
  store ptr %125, ptr %127, align 8, !tbaa !32
  %128 = load ptr, ptr %15, align 8, !tbaa !5
  %129 = load i32, ptr %17, align 4, !tbaa !9
  %130 = load ptr, ptr %21, align 8, !tbaa !5
  %131 = call ptr @NetbufFromExt(ptr noundef %128, i32 noundef %129, i32 noundef 60, i32 noundef 0, ptr noundef @Ip4FreeTxToken, ptr noundef %130)
  %132 = load ptr, ptr %21, align 8, !tbaa !5
  %133 = getelementptr inbounds %struct.IP4_TXTOKEN_WRAP, ptr %132, i32 0, i32 3
  store ptr %131, ptr %133, align 8, !tbaa !34
  %134 = load ptr, ptr %21, align 8, !tbaa !5
  %135 = getelementptr inbounds %struct.IP4_TXTOKEN_WRAP, ptr %134, i32 0, i32 3
  %136 = load ptr, ptr %135, align 8, !tbaa !34
  %137 = icmp eq ptr %136, null
  br i1 %137, label %138, label %143

138:                                              ; preds = %124
  %139 = load ptr, ptr %10, align 8, !tbaa !5
  %140 = load ptr, ptr %139, align 8, !tbaa !5
  %141 = load ptr, ptr %21, align 8, !tbaa !5
  %142 = getelementptr inbounds %struct.IP4_TXTOKEN_WRAP, ptr %141, i32 0, i32 3
  store ptr %140, ptr %142, align 8, !tbaa !34
  store i64 -9223372036854775799, ptr %23, align 8, !tbaa !11
  br label %225

143:                                              ; preds = %124
  %144 = load ptr, ptr %10, align 8, !tbaa !5
  %145 = load ptr, ptr %144, align 8, !tbaa !5
  call void @NetIpSecNetbufFree(ptr noundef %145)
  %146 = load ptr, ptr %21, align 8, !tbaa !5
  %147 = getelementptr inbounds %struct.IP4_TXTOKEN_WRAP, ptr %146, i32 0, i32 3
  %148 = load ptr, ptr %147, align 8, !tbaa !34
  %149 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %148, ptr %149, align 8, !tbaa !5
  br label %224

150:                                              ; preds = %121, %118
  %151 = call ptr @AllocateZeroPool(i64 noundef 16)
  store ptr %151, ptr %22, align 8, !tbaa !5
  %152 = load ptr, ptr %22, align 8, !tbaa !5
  %153 = icmp eq ptr %152, null
  br i1 %153, label %154, label %160

154:                                              ; preds = %150
  store i64 -9223372036854775799, ptr %23, align 8, !tbaa !11
  %155 = load ptr, ptr @gBS, align 8, !tbaa !5
  %156 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %155, i32 0, i32 11
  %157 = load ptr, ptr %156, align 8, !tbaa !35
  %158 = load ptr, ptr %19, align 8, !tbaa !5
  %159 = call i64 %157(ptr noundef %158)
  br label %225

160:                                              ; preds = %150
  %161 = load ptr, ptr %19, align 8, !tbaa !5
  %162 = load ptr, ptr %22, align 8, !tbaa !5
  %163 = getelementptr inbounds %struct.IP4_IPSEC_WRAP, ptr %162, i32 0, i32 0
  store ptr %161, ptr %163, align 8, !tbaa !36
  %164 = load ptr, ptr %20, align 8, !tbaa !5
  %165 = load ptr, ptr %22, align 8, !tbaa !5
  %166 = getelementptr inbounds %struct.IP4_IPSEC_WRAP, ptr %165, i32 0, i32 1
  store ptr %164, ptr %166, align 8, !tbaa !38
  %167 = load ptr, ptr %15, align 8, !tbaa !5
  %168 = load i32, ptr %17, align 4, !tbaa !9
  %169 = load ptr, ptr %22, align 8, !tbaa !5
  %170 = call ptr @NetbufFromExt(ptr noundef %167, i32 noundef %168, i32 noundef 60, i32 noundef 0, ptr noundef @Ip4IpSecFree, ptr noundef %169)
  store ptr %170, ptr %20, align 8, !tbaa !5
  %171 = load ptr, ptr %20, align 8, !tbaa !5
  %172 = icmp eq ptr %171, null
  br i1 %172, label %173, label %183

173:                                              ; preds = %160
  %174 = load ptr, ptr %22, align 8, !tbaa !5
  %175 = getelementptr inbounds %struct.IP4_IPSEC_WRAP, ptr %174, i32 0, i32 1
  %176 = load ptr, ptr %175, align 8, !tbaa !38
  store ptr %176, ptr %20, align 8, !tbaa !5
  %177 = load ptr, ptr @gBS, align 8, !tbaa !5
  %178 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %177, i32 0, i32 11
  %179 = load ptr, ptr %178, align 8, !tbaa !35
  %180 = load ptr, ptr %19, align 8, !tbaa !5
  %181 = call i64 %179(ptr noundef %180)
  %182 = load ptr, ptr %22, align 8, !tbaa !5
  call void @FreePool(ptr noundef %182)
  store i64 -9223372036854775799, ptr %23, align 8, !tbaa !11
  br label %225

183:                                              ; preds = %160
  %184 = load i32, ptr %13, align 4, !tbaa !9
  %185 = icmp eq i32 %184, 0
  br i1 %185, label %186, label %221

186:                                              ; preds = %183
  %187 = load ptr, ptr %9, align 8, !tbaa !5
  %188 = load ptr, ptr %187, align 8, !tbaa !5
  %189 = call i64 @CompareMem(ptr noundef %188, ptr noundef %24, i64 noundef 20)
  %190 = icmp ne i64 0, %189
  br i1 %190, label %191, label %221

191:                                              ; preds = %186
  %192 = load ptr, ptr %20, align 8, !tbaa !5
  %193 = load ptr, ptr %9, align 8, !tbaa !5
  %194 = load ptr, ptr %193, align 8, !tbaa !5
  %195 = load ptr, ptr %11, align 8, !tbaa !5
  %196 = load ptr, ptr %195, align 8, !tbaa !5
  %197 = load ptr, ptr %12, align 8, !tbaa !5
  %198 = load i32, ptr %197, align 4, !tbaa !9
  %199 = call i64 @Ip4PrependHead(ptr noundef %192, ptr noundef %194, ptr noundef %196, i32 noundef %198)
  %200 = load ptr, ptr %20, align 8, !tbaa !5
  %201 = getelementptr inbounds %struct.NET_BUF, ptr %200, i32 0, i32 3
  %202 = load ptr, ptr %201, align 8, !tbaa !39
  %203 = call ptr @Ip4NtohHead(ptr noundef %202)
  %204 = load ptr, ptr %20, align 8, !tbaa !5
  %205 = load ptr, ptr %9, align 8, !tbaa !5
  %206 = load ptr, ptr %205, align 8, !tbaa !5
  %207 = load i8, ptr %206, align 1
  %208 = and i8 %207, 15
  %209 = zext i8 %208 to i32
  %210 = shl i32 %209, 2
  %211 = call i32 @NetbufTrim(ptr noundef %204, i32 noundef %210, i8 noundef zeroext 1)
  %212 = load ptr, ptr %20, align 8, !tbaa !5
  %213 = getelementptr inbounds %struct.NET_BUF, ptr %212, i32 0, i32 6
  %214 = getelementptr inbounds [64 x i8], ptr %213, i64 0, i64 0
  %215 = load ptr, ptr %22, align 8, !tbaa !5
  %216 = getelementptr inbounds %struct.IP4_IPSEC_WRAP, ptr %215, i32 0, i32 1
  %217 = load ptr, ptr %216, align 8, !tbaa !38
  %218 = getelementptr inbounds %struct.NET_BUF, ptr %217, i32 0, i32 6
  %219 = getelementptr inbounds [64 x i8], ptr %218, i64 0, i64 0
  %220 = call ptr @CopyMem(ptr noundef %214, ptr noundef %219, i64 noundef 56)
  br label %221

221:                                              ; preds = %191, %186, %183
  %222 = load ptr, ptr %20, align 8, !tbaa !5
  %223 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %222, ptr %223, align 8, !tbaa !5
  br label %224

224:                                              ; preds = %221, %143
  br label %225

225:                                              ; preds = %224, %173, %154, %138, %114, %104, %77, %68, %48, %41
  %226 = load i64, ptr %23, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 20, ptr %24) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  ret i64 %226
}

declare ptr @ZeroMem(ptr noundef, i64 noundef) #1

declare ptr @AllocateZeroPool(i64 noundef) #1

declare i64 @NetbufBuildExt(ptr noundef, ptr noundef, ptr noundef) #1

declare ptr @Ip4NtohHead(ptr noundef) #1

declare ptr @NetbufFromExt(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) #1

declare void @Ip4FreeTxToken(ptr noundef) #1

declare void @NetIpSecNetbufFree(ptr noundef) #1

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) #1

declare i64 @Ip4PrependHead(ptr noundef, ptr noundef, ptr noundef, i32 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !10, i64 128}
!14 = !{!"", !10, i64 0, !12, i64 8, !15, i64 16, !7, i64 32, !6, i64 40, !6, i64 48, !7, i64 56, !6, i64 120, !10, i64 128, !10, i64 132, !7, i64 136}
!15 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!16 = !{!17, !6, i64 320}
!17 = !{!"", !18, 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}
!18 = !{!"", !12, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!19 = !{!20, !7, i64 16}
!20 = !{!"_EFI_IPSEC2_PROTOCOL", !6, i64 0, !6, i64 8, !7, i64 16}
!21 = !{!22, !10, i64 1364}
!22 = !{!"_IP4_SERVICE", !10, i64 0, !23, i64 8, !12, i64 24, !12, i64 32, !15, i64 40, !15, i64 56, !6, i64 72, !6, i64 80, !24, i64 88, !25, i64 584, !6, i64 608, !6, i64 616, !6, i64 624, !6, i64 632, !26, i64 640, !28, i64 660, !6, i64 1320, !6, i64 1328, !6, i64 1336, !6, i64 1344, !6, i64 1352, !10, i64 1360, !10, i64 1364}
!23 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!24 = !{!"", !7, i64 0}
!25 = !{!"", !12, i64 0, !15, i64 8}
!26 = !{!"", !10, i64 0, !10, i64 4, !27, i64 8, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16}
!27 = !{!"short", !7, i64 0}
!28 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !7, i64 40, !24, i64 552, !24, i64 584, !24, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!29 = !{!22, !10, i64 1360}
!30 = !{!20, !6, i64 0}
!31 = !{!22, !6, i64 616}
!32 = !{!33, !6, i64 16}
!33 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !12, i64 40}
!34 = !{!33, !6, i64 24}
!35 = !{!17, !6, i64 104}
!36 = !{!37, !6, i64 0}
!37 = !{!"", !6, i64 0, !6, i64 8}
!38 = !{!37, !6, i64 8}
!39 = !{!7, !7, i64 0}


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

%struct.GUID = type { i32, i16, i16, [8 x i8] }
%struct.IP4_HEAD = type { i8, i8, i16, i16, i16, i8, i8, i16, i32, i32 }

@gBS = external local_unnamed_addr global ptr, align 8
@mIpSec = external global ptr, align 8
@gEfiIpSec2ProtocolGuid = external global %struct.GUID, align 4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare void @FreePool(ptr noundef) local_unnamed_addr #1

declare i32 @NetbufTrim(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @Ip4IpSecFree(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip4IpSecProcessPacket(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, ptr noundef %6) local_unnamed_addr #2 {
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca %struct.IP4_HEAD, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #3
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %11) #3
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr null, ptr %10, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 128
  %14 = load i32, ptr %13, align 8, !tbaa !9
  store i32 %14, ptr %9, align 4, !tbaa !14
  %15 = call ptr @ZeroMem(ptr noundef nonnull %11, i64 noundef 20) #3
  %16 = load ptr, ptr @mIpSec, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %25

18:                                               ; preds = %7
  %19 = load ptr, ptr @gBS, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 320
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = call i64 %21(ptr noundef nonnull @gEfiIpSec2ProtocolGuid, ptr noundef null, ptr noundef nonnull @mIpSec) #3
  %23 = load ptr, ptr @mIpSec, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %126, label %25

25:                                               ; preds = %18, %7
  %26 = phi ptr [ %23, %18 ], [ %16, %7 ]
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %28 = load i8, ptr %27, align 8, !tbaa !18
  %.not = icmp eq i8 %28, 0
  %29 = getelementptr inbounds i8, ptr %0, i64 1364
  %30 = load i32, ptr %29, align 4, !tbaa !20
  br i1 %.not, label %33, label %31

31:                                               ; preds = %25
  %32 = getelementptr inbounds i8, ptr %0, i64 1360
  store i32 %30, ptr %32, align 8, !tbaa !28
  br label %126

33:                                               ; preds = %25
  %34 = add i32 %30, -54
  %35 = getelementptr inbounds i8, ptr %0, i64 1360
  store i32 %34, ptr %35, align 8, !tbaa !28
  %36 = zext i32 %14 to i64
  %37 = shl nuw nsw i64 %36, 4
  %38 = call ptr @AllocateZeroPool(i64 noundef %37) #3
  store ptr %38, ptr %8, align 8, !tbaa !5
  %39 = icmp eq ptr %38, null
  br i1 %39, label %126, label %40

40:                                               ; preds = %33
  %41 = call i64 @NetbufBuildExt(ptr noundef nonnull %12, ptr noundef nonnull %38, ptr noundef nonnull %9) #3
  %42 = load i32, ptr %9, align 4, !tbaa !14
  %43 = icmp slt i64 %41, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %40
  call void @FreePool(ptr noundef nonnull %38) #3
  br label %126

45:                                               ; preds = %40
  %46 = load ptr, ptr %1, align 8, !tbaa !5
  %47 = call ptr @Ip4NtohHead(ptr noundef %46) #3
  %48 = load ptr, ptr @mIpSec, align 8, !tbaa !5
  %49 = load ptr, ptr %48, align 8, !tbaa !29
  %50 = getelementptr inbounds i8, ptr %0, i64 616
  %51 = load ptr, ptr %50, align 8, !tbaa !30
  %52 = load ptr, ptr %1, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 9
  %54 = call i64 %49(ptr noundef nonnull %48, ptr noundef %51, i8 noundef zeroext 4, ptr noundef %52, ptr noundef nonnull %53, ptr noundef %3, ptr noundef %4, ptr noundef nonnull %8, ptr noundef nonnull %9, i32 noundef %5, ptr noundef nonnull %10) #3
  %55 = load ptr, ptr %1, align 8, !tbaa !5
  %56 = call ptr @Ip4NtohHead(ptr noundef %55) #3
  %57 = icmp slt i64 %54, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %45
  call void @FreePool(ptr noundef nonnull %38) #3
  br label %126

59:                                               ; preds = %45
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = icmp eq ptr %38, %60
  %62 = load i32, ptr %9, align 4
  %63 = icmp eq i32 %42, %62
  %or.cond64 = select i1 %61, i1 %63, i1 false
  br i1 %or.cond64, label %64, label %65

64:                                               ; preds = %59
  call void @FreePool(ptr noundef %60) #3
  br label %126

65:                                               ; preds = %59
  call void @FreePool(ptr noundef nonnull %38) #3
  %66 = icmp eq i32 %5, 1
  %67 = icmp ne ptr %6, null
  %or.cond = and i1 %66, %67
  br i1 %or.cond, label %68, label %80

68:                                               ; preds = %65
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %6, i64 16
  store ptr %69, ptr %70, align 8, !tbaa !31
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load i32, ptr %9, align 4, !tbaa !14
  %73 = call ptr @NetbufFromExt(ptr noundef %71, i32 noundef %72, i32 noundef 60, i32 noundef 0, ptr noundef nonnull @Ip4FreeTxToken, ptr noundef nonnull %6) #3
  %74 = getelementptr inbounds i8, ptr %6, i64 24
  store ptr %73, ptr %74, align 8, !tbaa !33
  %75 = icmp eq ptr %73, null
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  br i1 %75, label %77, label %78

77:                                               ; preds = %68
  store ptr %76, ptr %74, align 8, !tbaa !33
  br label %126

78:                                               ; preds = %68
  call void @NetIpSecNetbufFree(ptr noundef %76) #3
  %79 = load ptr, ptr %74, align 8, !tbaa !33
  store ptr %79, ptr %2, align 8, !tbaa !5
  br label %126

80:                                               ; preds = %65
  %81 = call ptr @AllocateZeroPool(i64 noundef 16) #3
  %82 = icmp eq ptr %81, null
  br i1 %82, label %83, label %89

83:                                               ; preds = %80
  %84 = load ptr, ptr @gBS, align 8, !tbaa !5
  %85 = getelementptr inbounds i8, ptr %84, i64 104
  %86 = load ptr, ptr %85, align 8, !tbaa !34
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = call i64 %86(ptr noundef %87) #3
  br label %126

89:                                               ; preds = %80
  %90 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %90, ptr %81, align 8, !tbaa !35
  %91 = getelementptr inbounds i8, ptr %81, i64 8
  store ptr %12, ptr %91, align 8, !tbaa !37
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = load i32, ptr %9, align 4, !tbaa !14
  %94 = call ptr @NetbufFromExt(ptr noundef %92, i32 noundef %93, i32 noundef 60, i32 noundef 0, ptr noundef nonnull @Ip4IpSecFree, ptr noundef nonnull %81) #3
  %95 = icmp eq ptr %94, null
  br i1 %95, label %96, label %102

96:                                               ; preds = %89
  %97 = load ptr, ptr @gBS, align 8, !tbaa !5
  %98 = getelementptr inbounds i8, ptr %97, i64 104
  %99 = load ptr, ptr %98, align 8, !tbaa !34
  %100 = load ptr, ptr %10, align 8, !tbaa !5
  %101 = call i64 %99(ptr noundef %100) #3
  call void @FreePool(ptr noundef nonnull %81) #3
  br label %126

102:                                              ; preds = %89
  %103 = icmp eq i32 %5, 0
  br i1 %103, label %104, label %125

104:                                              ; preds = %102
  %105 = load ptr, ptr %1, align 8, !tbaa !5
  %106 = call i64 @CompareMem(ptr noundef %105, ptr noundef nonnull %11, i64 noundef 20) #3
  %.not62 = icmp eq i64 %106, 0
  br i1 %.not62, label %125, label %107

107:                                              ; preds = %104
  %108 = load ptr, ptr %1, align 8, !tbaa !5
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  %110 = load i32, ptr %4, align 4, !tbaa !14
  %111 = call i64 @Ip4PrependHead(ptr noundef nonnull %94, ptr noundef %108, ptr noundef %109, i32 noundef %110) #3
  %112 = getelementptr inbounds i8, ptr %94, i64 32
  %113 = load ptr, ptr %112, align 8, !tbaa !38
  %114 = call ptr @Ip4NtohHead(ptr noundef %113) #3
  %115 = load ptr, ptr %1, align 8, !tbaa !5
  %116 = load i8, ptr %115, align 1
  %117 = shl i8 %116, 2
  %118 = and i8 %117, 60
  %119 = zext nneg i8 %118 to i32
  %120 = call i32 @NetbufTrim(ptr noundef nonnull %94, i32 noundef %119, i8 noundef zeroext 1) #3
  %121 = getelementptr inbounds i8, ptr %94, i64 56
  %122 = load ptr, ptr %91, align 8, !tbaa !37
  %123 = getelementptr inbounds i8, ptr %122, i64 56
  %124 = call ptr @CopyMem(ptr noundef nonnull %121, ptr noundef nonnull %123, i64 noundef 56) #3
  br label %125

125:                                              ; preds = %107, %104, %102
  store ptr %94, ptr %2, align 8, !tbaa !5
  br label %126

126:                                              ; preds = %33, %78, %125, %18, %96, %83, %77, %64, %58, %44, %31
  %.0 = phi i64 [ 0, %18 ], [ 0, %31 ], [ %41, %44 ], [ %54, %58 ], [ %54, %64 ], [ -9223372036854775799, %77 ], [ %54, %78 ], [ -9223372036854775799, %83 ], [ -9223372036854775799, %96 ], [ %54, %125 ], [ -9223372036854775799, %33 ]
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #3
  ret i64 %.0
}

declare ptr @ZeroMem(ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #1

declare i64 @NetbufBuildExt(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @Ip4NtohHead(ptr noundef) local_unnamed_addr #1

declare ptr @NetbufFromExt(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @Ip4FreeTxToken(ptr noundef) #1

declare void @NetIpSecNetbufFree(ptr noundef) local_unnamed_addr #1

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare i64 @Ip4PrependHead(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 128}
!10 = !{!"", !11, i64 0, !12, i64 8, !13, i64 16, !7, i64 32, !6, i64 40, !6, i64 48, !7, i64 56, !6, i64 120, !11, i64 128, !11, i64 132, !7, i64 136}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !6, i64 320}
!16 = !{!"", !17, 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}
!17 = !{!"", !12, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!18 = !{!19, !7, i64 16}
!19 = !{!"_EFI_IPSEC2_PROTOCOL", !6, i64 0, !6, i64 8, !7, i64 16}
!20 = !{!21, !11, i64 1364}
!21 = !{!"_IP4_SERVICE", !11, i64 0, !22, i64 8, !12, i64 24, !12, i64 32, !13, i64 40, !13, i64 56, !6, i64 72, !6, i64 80, !23, i64 88, !24, i64 584, !6, i64 608, !6, i64 616, !6, i64 624, !6, i64 632, !25, i64 640, !27, i64 660, !6, i64 1320, !6, i64 1328, !6, i64 1336, !6, i64 1344, !6, i64 1352, !11, i64 1360, !11, i64 1364}
!22 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!23 = !{!"", !7, i64 0}
!24 = !{!"", !12, i64 0, !13, i64 8}
!25 = !{!"", !11, i64 0, !11, i64 4, !26, i64 8, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16}
!26 = !{!"short", !7, i64 0}
!27 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !7, i64 40, !23, i64 552, !23, i64 584, !23, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!28 = !{!21, !11, i64 1360}
!29 = !{!19, !6, i64 0}
!30 = !{!21, !6, i64 616}
!31 = !{!32, !6, i64 16}
!32 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !12, i64 40}
!33 = !{!32, !6, i64 24}
!34 = !{!16, !6, i64 104}
!35 = !{!36, !6, i64 0}
!36 = !{!"", !6, i64 0, !6, i64 8}
!37 = !{!36, !6, i64 8}
!38 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass