; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/IpSecDxe (IpSecTunnelOutboundPacket)

; 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.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_UDP_HEADER = type { i16, i16, i16, i16 }
%struct.TCP_HEAD = type { i16, i16, i32, i32, i8, i8, i16, i16, i16 }
%struct.IP6_ICMP_HEAD = type { i8, i8, i16 }
%struct.IP4_HEAD = type { i8, i8, i16, i16, i16, i8, i8, i16, i32, i32 }
%struct._IPSEC_SAD_DATA = type { i32, i64, i8, [4 x i64], %union.EFI_IPSEC_ALGO_INFO, %struct._EFI_IPSEC_SA_LIFETIME, i32, ptr, ptr, i8, i8, %union.EFI_IP_ADDRESS, %union.EFI_IP_ADDRESS }
%union.EFI_IPSEC_ALGO_INFO = type { %struct._EFI_IPSEC_ESP_ALGO_INFO }
%struct._EFI_IPSEC_ESP_ALGO_INFO = type { i8, i64, ptr, i8, i64, ptr }
%struct._EFI_IPSEC_SA_LIFETIME = type { i64, i64, i64 }
%union.EFI_IP_ADDRESS = type { [4 x i32] }
%struct._EFI_IPSEC_SPD_SELECTOR = type { i32, ptr, i32, ptr, i16, i16, i16, i16, i16 }
%struct._EFI_IP_ADDRESS_INFO = type { %union.EFI_IP_ADDRESS, i8 }
%struct._EFI_IP6_HEADER = type { i16, i16, i16, i8, i8, %struct.EFI_IPv6_ADDRESS, %struct.EFI_IPv6_ADDRESS }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }

@.str = external hidden unnamed_addr constant [133 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [25 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 ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) #1

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

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

declare zeroext i16 @NetPseudoHeadChecksum(i32 noundef, i32 noundef, i8 noundef zeroext, i16 noundef zeroext) #1

declare zeroext i16 @NetAddChecksum(i16 noundef zeroext, i16 noundef zeroext) #1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @IpSecTunnelOutboundPacket(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7) #2 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i16, align 2
  %21 = alloca ptr, align 8
  %22 = alloca i16, align 2
  %23 = alloca ptr, align 8
  %24 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store i8 %1, ptr %11, align 1, !tbaa !9
  store ptr %2, ptr %12, align 8, !tbaa !5
  store ptr %3, ptr %13, align 8, !tbaa !5
  store ptr %4, ptr %14, align 8, !tbaa !5
  store ptr %5, ptr %15, align 8, !tbaa !5
  store ptr %6, ptr %16, align 8, !tbaa !5
  store ptr %7, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %20) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %22) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #3
  store ptr null, ptr %21, align 8, !tbaa !5
  %25 = load ptr, ptr %15, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %8
  store ptr null, ptr %9, align 8
  store i32 1, ptr %24, align 4
  br label %258

28:                                               ; preds = %8
  %29 = load i8, ptr %11, align 1, !tbaa !9
  %30 = zext i8 %29 to i32
  %31 = icmp eq i32 %30, 4
  br i1 %31, label %32, label %60

32:                                               ; preds = %28
  %33 = load ptr, ptr %15, align 8, !tbaa !5
  %34 = load i32, ptr %33, align 4, !tbaa !10
  %35 = zext i32 %34 to i64
  %36 = add i64 20, %35
  %37 = call ptr @AllocateZeroPool(i64 noundef %36)
  store ptr %37, ptr %18, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %32
  %39 = call zeroext i8 @DebugAssertEnabled()
  %40 = icmp ne i8 %39, 0
  br i1 %40, label %41, label %46

41:                                               ; preds = %38
  %42 = load ptr, ptr %18, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1226, ptr noundef @.str.3)
  br label %45

45:                                               ; preds = %44, %41
  br label %46

46:                                               ; preds = %45, %38
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %18, align 8, !tbaa !5
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = call ptr @CopyMem(ptr noundef %49, ptr noundef %50, i64 noundef 20)
  %52 = load ptr, ptr %18, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 20
  %54 = load ptr, ptr %14, align 8, !tbaa !5
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = load ptr, ptr %15, align 8, !tbaa !5
  %57 = load i32, ptr %56, align 4, !tbaa !10
  %58 = zext i32 %57 to i64
  %59 = call ptr @CopyMem(ptr noundef %53, ptr noundef %55, i64 noundef %58)
  br label %88

60:                                               ; preds = %28
  %61 = load ptr, ptr %15, align 8, !tbaa !5
  %62 = load i32, ptr %61, align 4, !tbaa !10
  %63 = zext i32 %62 to i64
  %64 = add i64 40, %63
  %65 = call ptr @AllocateZeroPool(i64 noundef %64)
  store ptr %65, ptr %18, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %60
  %67 = call zeroext i8 @DebugAssertEnabled()
  %68 = icmp ne i8 %67, 0
  br i1 %68, label %69, label %74

69:                                               ; preds = %66
  %70 = load ptr, ptr %18, align 8, !tbaa !5
  %71 = icmp ne ptr %70, null
  br i1 %71, label %73, label %72

72:                                               ; preds = %69
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1239, ptr noundef @.str.3)
  br label %73

73:                                               ; preds = %72, %69
  br label %74

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

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  %77 = load ptr, ptr %18, align 8, !tbaa !5
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = call ptr @CopyMem(ptr noundef %77, ptr noundef %78, i64 noundef 40)
  %80 = load ptr, ptr %18, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i64 40
  %82 = load ptr, ptr %14, align 8, !tbaa !5
  %83 = load ptr, ptr %82, align 8, !tbaa !5
  %84 = load ptr, ptr %15, align 8, !tbaa !5
  %85 = load i32, ptr %84, align 4, !tbaa !10
  %86 = zext i32 %85 to i64
  %87 = call ptr @CopyMem(ptr noundef %81, ptr noundef %83, i64 noundef %86)
  br label %88

88:                                               ; preds = %76, %48
  %89 = load ptr, ptr %14, align 8, !tbaa !5
  %90 = icmp ne ptr %89, null
  br i1 %90, label %91, label %99

91:                                               ; preds = %88
  %92 = load ptr, ptr %15, align 8, !tbaa !5
  %93 = load i32, ptr %92, align 4, !tbaa !10
  %94 = icmp ne i32 %93, 0
  br i1 %94, label %95, label %98

95:                                               ; preds = %91
  %96 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr null, ptr %96, align 8, !tbaa !5
  %97 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 0, ptr %97, align 4, !tbaa !10
  br label %98

98:                                               ; preds = %95, %91
  br label %99

99:                                               ; preds = %98, %88
  %100 = load ptr, ptr %16, align 8, !tbaa !5
  %101 = load ptr, ptr %100, align 8, !tbaa !5
  %102 = load ptr, ptr %17, align 8, !tbaa !5
  %103 = load i32, ptr %102, align 4, !tbaa !10
  %104 = call ptr @NetbufFromExt(ptr noundef %101, i32 noundef %103, i32 noundef 0, i32 noundef 0, ptr noundef @IpSecOnRecyclePacket, ptr noundef null)
  store ptr %104, ptr %19, align 8, !tbaa !5
  br label %105

105:                                              ; preds = %99
  %106 = call zeroext i8 @DebugAssertEnabled()
  %107 = icmp ne i8 %106, 0
  br i1 %107, label %108, label %113

108:                                              ; preds = %105
  %109 = load ptr, ptr %19, align 8, !tbaa !5
  %110 = icmp ne ptr %109, null
  br i1 %110, label %112, label %111

111:                                              ; preds = %108
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1270, ptr noundef @.str.4)
  br label %112

112:                                              ; preds = %111, %108
  br label %113

113:                                              ; preds = %112, %105
  br label %114

114:                                              ; preds = %113
  br label %115

115:                                              ; preds = %114
  %116 = load ptr, ptr %13, align 8, !tbaa !5
  %117 = load i8, ptr %116, align 1, !tbaa !9
  %118 = zext i8 %117 to i32
  switch i32 %118, label %182 [
    i32 17, label %119
    i32 6, label %142
    i32 58, label %165
  ]

119:                                              ; preds = %115
  %120 = load ptr, ptr %19, align 8, !tbaa !5
  %121 = call ptr @NetbufGetByte(ptr noundef %120, i32 noundef 0, ptr noundef null)
  %122 = load ptr, ptr %19, align 8, !tbaa !5
  %123 = getelementptr inbounds %struct.NET_BUF, ptr %122, i32 0, i32 5
  store ptr %121, ptr %123, align 8, !tbaa !12
  br label %124

124:                                              ; preds = %119
  %125 = call zeroext i8 @DebugAssertEnabled()
  %126 = icmp ne i8 %125, 0
  br i1 %126, label %127, label %134

127:                                              ; preds = %124
  %128 = load ptr, ptr %19, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.NET_BUF, ptr %128, i32 0, i32 5
  %130 = load ptr, ptr %129, align 8, !tbaa !12
  %131 = icmp ne ptr %130, null
  br i1 %131, label %133, label %132

132:                                              ; preds = %127
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1278, ptr noundef @.str.5)
  br label %133

133:                                              ; preds = %132, %127
  br label %134

134:                                              ; preds = %133, %124
  br label %135

135:                                              ; preds = %134
  br label %136

136:                                              ; preds = %135
  %137 = load ptr, ptr %19, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.NET_BUF, ptr %137, i32 0, i32 5
  %139 = load ptr, ptr %138, align 8, !tbaa !12
  %140 = getelementptr inbounds %struct.EFI_UDP_HEADER, ptr %139, i32 0, i32 3
  store ptr %140, ptr %21, align 8, !tbaa !5
  %141 = load ptr, ptr %21, align 8, !tbaa !5
  store i16 0, ptr %141, align 2, !tbaa !16
  br label %183

142:                                              ; preds = %115
  %143 = load ptr, ptr %19, align 8, !tbaa !5
  %144 = call ptr @NetbufGetByte(ptr noundef %143, i32 noundef 0, ptr noundef null)
  %145 = load ptr, ptr %19, align 8, !tbaa !5
  %146 = getelementptr inbounds %struct.NET_BUF, ptr %145, i32 0, i32 4
  store ptr %144, ptr %146, align 8, !tbaa !18
  br label %147

147:                                              ; preds = %142
  %148 = call zeroext i8 @DebugAssertEnabled()
  %149 = icmp ne i8 %148, 0
  br i1 %149, label %150, label %157

150:                                              ; preds = %147
  %151 = load ptr, ptr %19, align 8, !tbaa !5
  %152 = getelementptr inbounds %struct.NET_BUF, ptr %151, i32 0, i32 4
  %153 = load ptr, ptr %152, align 8, !tbaa !18
  %154 = icmp ne ptr %153, null
  br i1 %154, label %156, label %155

155:                                              ; preds = %150
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1285, ptr noundef @.str.6)
  br label %156

156:                                              ; preds = %155, %150
  br label %157

157:                                              ; preds = %156, %147
  br label %158

158:                                              ; preds = %157
  br label %159

159:                                              ; preds = %158
  %160 = load ptr, ptr %19, align 8, !tbaa !5
  %161 = getelementptr inbounds %struct.NET_BUF, ptr %160, i32 0, i32 4
  %162 = load ptr, ptr %161, align 8, !tbaa !18
  %163 = getelementptr inbounds %struct.TCP_HEAD, ptr %162, i32 0, i32 7
  store ptr %163, ptr %21, align 8, !tbaa !5
  %164 = load ptr, ptr %21, align 8, !tbaa !5
  store i16 0, ptr %164, align 2, !tbaa !16
  br label %183

165:                                              ; preds = %115
  %166 = load ptr, ptr %19, align 8, !tbaa !5
  %167 = call ptr @NetbufGetByte(ptr noundef %166, i32 noundef 0, ptr noundef null)
  store ptr %167, ptr %23, align 8, !tbaa !5
  br label %168

168:                                              ; preds = %165
  %169 = call zeroext i8 @DebugAssertEnabled()
  %170 = icmp ne i8 %169, 0
  br i1 %170, label %171, label %176

171:                                              ; preds = %168
  %172 = load ptr, ptr %23, align 8, !tbaa !5
  %173 = icmp ne ptr %172, null
  br i1 %173, label %175, label %174

174:                                              ; preds = %171
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1292, ptr noundef @.str.7)
  br label %175

175:                                              ; preds = %174, %171
  br label %176

176:                                              ; preds = %175, %168
  br label %177

177:                                              ; preds = %176
  br label %178

178:                                              ; preds = %177
  %179 = load ptr, ptr %23, align 8, !tbaa !5
  %180 = getelementptr inbounds %struct.IP6_ICMP_HEAD, ptr %179, i32 0, i32 2
  store ptr %180, ptr %21, align 8, !tbaa !5
  %181 = load ptr, ptr %21, align 8, !tbaa !5
  store i16 0, ptr %181, align 2, !tbaa !16
  br label %183

182:                                              ; preds = %115
  br label %183

183:                                              ; preds = %182, %178, %159, %136
  %184 = load ptr, ptr %19, align 8, !tbaa !5
  %185 = call zeroext i16 @NetbufChecksum(ptr noundef %184)
  store i16 %185, ptr %20, align 2, !tbaa !16
  %186 = load i8, ptr %11, align 1, !tbaa !9
  %187 = zext i8 %186 to i32
  %188 = icmp eq i32 %187, 4
  br i1 %188, label %189, label %211

189:                                              ; preds = %183
  %190 = load ptr, ptr %18, align 8, !tbaa !5
  %191 = getelementptr inbounds %struct.IP4_HEAD, ptr %190, i32 0, i32 8
  %192 = load ptr, ptr %12, align 8, !tbaa !5
  %193 = getelementptr inbounds %struct._IPSEC_SAD_DATA, ptr %192, i32 0, i32 8
  %194 = load ptr, ptr %193, align 8, !tbaa !19
  %195 = getelementptr inbounds %struct._EFI_IPSEC_SPD_SELECTOR, ptr %194, i32 0, i32 1
  %196 = load ptr, ptr %195, align 8, !tbaa !22
  %197 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %196, i64 0
  %198 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %197, i32 0, i32 0
  %199 = call ptr @CopyMem(ptr noundef %191, ptr noundef %198, i64 noundef 4)
  %200 = load ptr, ptr %19, align 8, !tbaa !5
  %201 = call zeroext i16 @NetbufChecksum(ptr noundef %200)
  store i16 %201, ptr %20, align 2, !tbaa !16
  %202 = load ptr, ptr %18, align 8, !tbaa !5
  %203 = getelementptr inbounds %struct.IP4_HEAD, ptr %202, i32 0, i32 8
  %204 = load i32, ptr %203, align 1, !tbaa !24
  %205 = load ptr, ptr %18, align 8, !tbaa !5
  %206 = getelementptr inbounds %struct.IP4_HEAD, ptr %205, i32 0, i32 9
  %207 = load i32, ptr %206, align 1, !tbaa !26
  %208 = load ptr, ptr %13, align 8, !tbaa !5
  %209 = load i8, ptr %208, align 1, !tbaa !9
  %210 = call zeroext i16 @NetPseudoHeadChecksum(i32 noundef %204, i32 noundef %207, i8 noundef zeroext %209, i16 noundef zeroext 0)
  store i16 %210, ptr %22, align 2, !tbaa !16
  br label %231

211:                                              ; preds = %183
  %212 = load ptr, ptr %18, align 8, !tbaa !5
  %213 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %212, i32 0, i32 5
  %214 = load ptr, ptr %12, align 8, !tbaa !5
  %215 = getelementptr inbounds %struct._IPSEC_SAD_DATA, ptr %214, i32 0, i32 8
  %216 = load ptr, ptr %215, align 8, !tbaa !19
  %217 = getelementptr inbounds %struct._EFI_IPSEC_SPD_SELECTOR, ptr %216, i32 0, i32 1
  %218 = load ptr, ptr %217, align 8, !tbaa !22
  %219 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %218, i64 0
  %220 = getelementptr inbounds %struct._EFI_IP_ADDRESS_INFO, ptr %219, i32 0, i32 0
  %221 = call ptr @CopyMem(ptr noundef %213, ptr noundef %220, i64 noundef 16)
  %222 = load ptr, ptr %19, align 8, !tbaa !5
  %223 = call zeroext i16 @NetbufChecksum(ptr noundef %222)
  store i16 %223, ptr %20, align 2, !tbaa !16
  %224 = load ptr, ptr %18, align 8, !tbaa !5
  %225 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %224, i32 0, i32 5
  %226 = load ptr, ptr %18, align 8, !tbaa !5
  %227 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %226, i32 0, i32 6
  %228 = load ptr, ptr %13, align 8, !tbaa !5
  %229 = load i8, ptr %228, align 1, !tbaa !9
  %230 = call zeroext i16 @NetIp6PseudoHeadChecksum(ptr noundef %225, ptr noundef %227, i8 noundef zeroext %229, i32 noundef 0)
  store i16 %230, ptr %22, align 2, !tbaa !16
  br label %231

231:                                              ; preds = %211, %189
  %232 = load ptr, ptr %21, align 8, !tbaa !5
  %233 = icmp ne ptr %232, null
  br i1 %233, label %234, label %251

234:                                              ; preds = %231
  %235 = load i16, ptr %20, align 2, !tbaa !16
  %236 = load i16, ptr %22, align 2, !tbaa !16
  %237 = call zeroext i16 @NetAddChecksum(i16 noundef zeroext %235, i16 noundef zeroext %236)
  %238 = load ptr, ptr %21, align 8, !tbaa !5
  store i16 %237, ptr %238, align 2, !tbaa !16
  %239 = load ptr, ptr %21, align 8, !tbaa !5
  %240 = load i16, ptr %239, align 2, !tbaa !16
  %241 = load ptr, ptr %19, align 8, !tbaa !5
  %242 = getelementptr inbounds %struct.NET_BUF, ptr %241, i32 0, i32 9
  %243 = load i32, ptr %242, align 4, !tbaa !27
  %244 = trunc i32 %243 to i16
  %245 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %244)
  %246 = call zeroext i16 @NetAddChecksum(i16 noundef zeroext %240, i16 noundef zeroext %245)
  %247 = zext i16 %246 to i32
  %248 = xor i32 %247, -1
  %249 = trunc i32 %248 to i16
  %250 = load ptr, ptr %21, align 8, !tbaa !5
  store i16 %249, ptr %250, align 2, !tbaa !16
  br label %251

251:                                              ; preds = %234, %231
  %252 = load ptr, ptr %19, align 8, !tbaa !5
  %253 = icmp ne ptr %252, null
  br i1 %253, label %254, label %256

254:                                              ; preds = %251
  %255 = load ptr, ptr %19, align 8, !tbaa !5
  call void @NetbufFree(ptr noundef %255)
  br label %256

256:                                              ; preds = %254, %251
  %257 = load ptr, ptr %18, align 8, !tbaa !5
  store ptr %257, ptr %9, align 8
  store i32 1, ptr %24, align 4
  br label %258

258:                                              ; preds = %256, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  %259 = load ptr, ptr %9, align 8
  ret ptr %259
}

declare ptr @AllocateZeroPool(i64 noundef) #1

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

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

declare zeroext i16 @NetbufChecksum(ptr noundef) #1

declare void @NetbufFree(ptr 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 48}
!13 = !{!"", !11, i64 0, !14, i64 8, !15, 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}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!13, !6, i64 40}
!19 = !{!20, !6, i64 144}
!20 = !{!"_IPSEC_SAD_DATA", !11, i64 0, !14, i64 8, !7, i64 16, !7, i64 24, !7, i64 56, !21, i64 104, !11, i64 128, !6, i64 136, !6, i64 144, !7, i64 152, !7, i64 153, !7, i64 156, !7, i64 172}
!21 = !{!"_EFI_IPSEC_SA_LIFETIME", !14, i64 0, !14, i64 8, !14, i64 16}
!22 = !{!23, !6, i64 8}
!23 = !{!"_EFI_IPSEC_SPD_SELECTOR", !11, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !17, i64 32, !17, i64 34, !17, i64 36, !17, i64 38, !17, i64 40}
!24 = !{!25, !11, i64 12}
!25 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !17, i64 2, !17, i64 4, !17, i64 6, !7, i64 8, !7, i64 9, !17, i64 10, !11, i64 12, !11, i64 16}
!26 = !{!25, !11, i64 16}
!27 = !{!13, !11, i64 132}


; 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 = external hidden unnamed_addr constant [133 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [25 x i8], align 1

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

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) 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

; Function Attrs: nounwind uwtable
declare dso_local void @IpSecOnRecyclePacket(ptr noundef) #1

declare zeroext i16 @NetPseudoHeadChecksum(i32 noundef, i32 noundef, i8 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #0

declare zeroext i16 @NetAddChecksum(i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #0

declare zeroext i16 @NetIp6PseudoHeadChecksum(ptr noundef, ptr noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @IpSecTunnelOutboundPacket(ptr noundef %0, i8 noundef zeroext %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef %4, ptr noundef %5, ptr nocapture noundef readonly %6, ptr nocapture noundef readonly %7) local_unnamed_addr #1 {
  %9 = icmp eq ptr %5, null
  br i1 %9, label %107, label %10

10:                                               ; preds = %8
  %11 = icmp eq i8 %1, 4
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = zext i32 %12 to i64
  br i1 %11, label %14, label %24

14:                                               ; preds = %10
  %15 = add nuw nsw i64 %13, 20
  %16 = tail call ptr @AllocateZeroPool(i64 noundef %15) #2
  %17 = tail call zeroext i8 @DebugAssertEnabled() #2
  %18 = icmp eq i8 %17, 0
  %19 = icmp ne ptr %16, null
  %or.cond = select i1 %18, i1 true, i1 %19
  br i1 %or.cond, label %21, label %20

20:                                               ; preds = %14
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1226, ptr noundef nonnull @.str.3) #2
  br label %21

21:                                               ; preds = %20, %14
  %22 = tail call ptr @CopyMem(ptr noundef %16, ptr noundef %0, i64 noundef 20) #2
  %23 = getelementptr inbounds i8, ptr %16, i64 20
  br label %34

24:                                               ; preds = %10
  %25 = add nuw nsw i64 %13, 40
  %26 = tail call ptr @AllocateZeroPool(i64 noundef %25) #2
  %27 = tail call zeroext i8 @DebugAssertEnabled() #2
  %28 = icmp eq i8 %27, 0
  %29 = icmp ne ptr %26, null
  %or.cond3 = select i1 %28, i1 true, i1 %29
  br i1 %or.cond3, label %31, label %30

30:                                               ; preds = %24
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1239, ptr noundef nonnull @.str.3) #2
  br label %31

31:                                               ; preds = %30, %24
  %32 = tail call ptr @CopyMem(ptr noundef %26, ptr noundef %0, i64 noundef 40) #2
  %33 = getelementptr inbounds i8, ptr %26, i64 40
  br label %34

34:                                               ; preds = %21, %31
  %.sink = phi ptr [ %23, %21 ], [ %33, %31 ]
  %.072 = phi ptr [ %16, %21 ], [ %26, %31 ]
  %35 = load ptr, ptr %4, align 8, !tbaa !9
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = zext i32 %36 to i64
  %38 = tail call ptr @CopyMem(ptr noundef nonnull %.sink, ptr noundef %35, i64 noundef %37) #2
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %.not76 = icmp eq i32 %39, 0
  br i1 %.not76, label %41, label %40

40:                                               ; preds = %34
  store ptr null, ptr %4, align 8, !tbaa !9
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %34, %40
  %42 = load ptr, ptr %6, align 8, !tbaa !9
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = tail call ptr @NetbufFromExt(ptr noundef %42, i32 noundef %43, i32 noundef 0, i32 noundef 0, ptr noundef nonnull @IpSecOnRecyclePacket, ptr noundef null) #2
  %45 = tail call zeroext i8 @DebugAssertEnabled() #2
  %46 = icmp eq i8 %45, 0
  %47 = icmp ne ptr %44, null
  %or.cond5 = select i1 %46, i1 true, i1 %47
  br i1 %or.cond5, label %49, label %48

48:                                               ; preds = %41
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1270, ptr noundef nonnull @.str.4) #2
  br label %49

49:                                               ; preds = %48, %41
  %50 = load i8, ptr %3, align 1, !tbaa !11
  switch i8 %50, label %75 [
    i8 17, label %51
    i8 6, label %59
    i8 58, label %67
  ]

51:                                               ; preds = %49
  %52 = tail call ptr @NetbufGetByte(ptr noundef %44, i32 noundef 0, ptr noundef null) #2
  %53 = getelementptr inbounds i8, ptr %44, i64 48
  store ptr %52, ptr %53, align 8, !tbaa !12
  %54 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not79 = icmp ne i8 %54, 0
  %.pre84 = load ptr, ptr %53, align 8, !tbaa !12
  %.not80 = icmp eq ptr %.pre84, null
  %or.cond88 = select i1 %.not79, i1 %.not80, i1 false
  br i1 %or.cond88, label %55, label %56

55:                                               ; preds = %51
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1278, ptr noundef nonnull @.str.5) #2
  %.pre83 = load ptr, ptr %53, align 8, !tbaa !12
  br label %56

56:                                               ; preds = %55, %51
  %57 = phi ptr [ %.pre83, %55 ], [ %.pre84, %51 ]
  %58 = getelementptr inbounds i8, ptr %57, i64 6
  br label %.sink.split

59:                                               ; preds = %49
  %60 = tail call ptr @NetbufGetByte(ptr noundef %44, i32 noundef 0, ptr noundef null) #2
  %61 = getelementptr inbounds i8, ptr %44, i64 40
  store ptr %60, ptr %61, align 8, !tbaa !16
  %62 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not77 = icmp ne i8 %62, 0
  %.pre82 = load ptr, ptr %61, align 8, !tbaa !16
  %.not78 = icmp eq ptr %.pre82, null
  %or.cond89 = select i1 %.not77, i1 %.not78, i1 false
  br i1 %or.cond89, label %63, label %64

63:                                               ; preds = %59
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1285, ptr noundef nonnull @.str.6) #2
  %.pre = load ptr, ptr %61, align 8, !tbaa !16
  br label %64

64:                                               ; preds = %63, %59
  %65 = phi ptr [ %.pre, %63 ], [ %.pre82, %59 ]
  %66 = getelementptr inbounds i8, ptr %65, i64 16
  br label %.sink.split

67:                                               ; preds = %49
  %68 = tail call ptr @NetbufGetByte(ptr noundef %44, i32 noundef 0, ptr noundef null) #2
  %69 = tail call zeroext i8 @DebugAssertEnabled() #2
  %70 = icmp eq i8 %69, 0
  %71 = icmp ne ptr %68, null
  %or.cond7 = select i1 %70, i1 true, i1 %71
  br i1 %or.cond7, label %73, label %72

72:                                               ; preds = %67
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1292, ptr noundef nonnull @.str.7) #2
  br label %73

73:                                               ; preds = %72, %67
  %74 = getelementptr inbounds i8, ptr %68, i64 2
  br label %.sink.split

.sink.split:                                      ; preds = %56, %64, %73
  %.sink90 = phi ptr [ %74, %73 ], [ %66, %64 ], [ %58, %56 ]
  store i16 0, ptr %.sink90, align 2, !tbaa !17
  br label %75

75:                                               ; preds = %.sink.split, %49
  %.070 = phi ptr [ null, %49 ], [ %.sink90, %.sink.split ]
  %76 = tail call zeroext i16 @NetbufChecksum(ptr noundef %44) #2
  %77 = getelementptr inbounds i8, ptr %2, i64 144
  %78 = load ptr, ptr %77, align 8, !tbaa !19
  %79 = getelementptr inbounds i8, ptr %78, i64 8
  %80 = load ptr, ptr %79, align 8, !tbaa !22
  br i1 %11, label %81, label %90

81:                                               ; preds = %75
  %82 = getelementptr inbounds i8, ptr %.072, i64 12
  %83 = tail call ptr @CopyMem(ptr noundef nonnull %82, ptr noundef %80, i64 noundef 4) #2
  %84 = tail call zeroext i16 @NetbufChecksum(ptr noundef %44) #2
  %85 = load i32, ptr %82, align 1, !tbaa !24
  %86 = getelementptr inbounds i8, ptr %.072, i64 16
  %87 = load i32, ptr %86, align 1, !tbaa !26
  %88 = load i8, ptr %3, align 1, !tbaa !11
  %89 = tail call zeroext i16 @NetPseudoHeadChecksum(i32 noundef %85, i32 noundef %87, i8 noundef zeroext %88, i16 noundef zeroext 0) #2
  br label %97

90:                                               ; preds = %75
  %91 = getelementptr inbounds i8, ptr %.072, i64 8
  %92 = tail call ptr @CopyMem(ptr noundef nonnull %91, ptr noundef %80, i64 noundef 16) #2
  %93 = tail call zeroext i16 @NetbufChecksum(ptr noundef %44) #2
  %94 = getelementptr inbounds i8, ptr %.072, i64 24
  %95 = load i8, ptr %3, align 1, !tbaa !11
  %96 = tail call zeroext i16 @NetIp6PseudoHeadChecksum(ptr noundef nonnull %91, ptr noundef nonnull %94, i8 noundef zeroext %95, i32 noundef 0) #2
  br label %97

97:                                               ; preds = %90, %81
  %.071 = phi i16 [ %84, %81 ], [ %93, %90 ]
  %.069 = phi i16 [ %89, %81 ], [ %96, %90 ]
  %.not81 = icmp eq ptr %.070, null
  br i1 %.not81, label %105, label %.thread

.thread:                                          ; preds = %97
  %98 = tail call zeroext i16 @NetAddChecksum(i16 noundef zeroext %.071, i16 noundef zeroext %.069) #2
  store i16 %98, ptr %.070, align 2, !tbaa !17
  %99 = getelementptr inbounds i8, ptr %44, i64 132
  %100 = load i32, ptr %99, align 4, !tbaa !27
  %101 = trunc i32 %100 to i16
  %102 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %101) #2
  %103 = tail call zeroext i16 @NetAddChecksum(i16 noundef zeroext %98, i16 noundef zeroext %102) #2
  %104 = xor i16 %103, -1
  store i16 %104, ptr %.070, align 2, !tbaa !17
  br label %106

105:                                              ; preds = %97
  br i1 %47, label %106, label %107

106:                                              ; preds = %.thread, %105
  tail call void @NetbufFree(ptr noundef nonnull %44) #2
  br label %107

107:                                              ; preds = %105, %106, %8
  %.0 = phi ptr [ null, %8 ], [ %.072, %106 ], [ %.072, %105 ]
  ret ptr %.0
}

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #0

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

declare ptr @NetbufGetByte(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare zeroext i16 @NetbufChecksum(ptr noundef) local_unnamed_addr #0

declare void @NetbufFree(ptr noundef) local_unnamed_addr #0

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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 48}
!13 = !{!"", !6, i64 0, !14, i64 8, !15, i64 16, !7, i64 32, !10, i64 40, !10, i64 48, !7, i64 56, !10, i64 120, !6, i64 128, !6, i64 132, !7, i64 136}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!16 = !{!13, !10, i64 40}
!17 = !{!18, !18, i64 0}
!18 = !{!"short", !7, i64 0}
!19 = !{!20, !10, i64 144}
!20 = !{!"_IPSEC_SAD_DATA", !6, i64 0, !14, i64 8, !7, i64 16, !7, i64 24, !7, i64 56, !21, i64 104, !6, i64 128, !10, i64 136, !10, i64 144, !7, i64 152, !7, i64 153, !7, i64 156, !7, i64 172}
!21 = !{!"_EFI_IPSEC_SA_LIFETIME", !14, i64 0, !14, i64 8, !14, i64 16}
!22 = !{!23, !10, i64 8}
!23 = !{!"_EFI_IPSEC_SPD_SELECTOR", !6, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !18, i64 32, !18, i64 34, !18, i64 36, !18, i64 38, !18, i64 40}
!24 = !{!25, !6, i64 12}
!25 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !18, i64 2, !18, i64 4, !18, i64 6, !7, i64 8, !7, i64 9, !18, i64 10, !6, i64 12, !6, i64 16}
!26 = !{!25, !6, i64 16}
!27 = !{!13, !6, i64 132}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass