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

; 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.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_UDP_HEADER = type { i16, i16, i16, i16 }
%struct.TCP_HEAD = type { i16, i16, i32, i32, i8, i8, i16, i16, i16 }
%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] }
%struct.IP6_ICMP_HEAD = type { i8, i8, i16 }

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

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

; 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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @IpSecIsIp6ExtsValid(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) #2

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

21:                                               ; preds = %5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = call ptr @ZeroMem(ptr noundef %22, i64 noundef 20)
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.IP4_HEAD, ptr %24, i32 0, i32 9
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._IPSEC_SAD_DATA, ptr %26, i32 0, i32 11
  %28 = call ptr @CopyMem(ptr noundef %25, ptr noundef %27, i64 noundef 4)
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.IP4_HEAD, ptr %29, i32 0, i32 7
  %31 = load i16, ptr %30, align 1, !tbaa !10
  %32 = zext i16 %31 to i32
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %49

34:                                               ; preds = %21
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.IP4_HEAD, ptr %35, i32 0, i32 7
  store i16 0, ptr %36, align 1, !tbaa !10
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load i8, ptr %38, align 1
  %40 = and i8 %39, 15
  %41 = zext i8 %40 to i32
  %42 = shl i32 %41, 2
  %43 = call zeroext i16 @NetblockChecksum(ptr noundef %37, i32 noundef %42)
  %44 = zext i16 %43 to i32
  %45 = xor i32 %44, -1
  %46 = trunc i32 %45 to i16
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.IP4_HEAD, ptr %47, i32 0, i32 7
  store i16 %46, ptr %48, align 1, !tbaa !10
  br label %49

49:                                               ; preds = %34, %21
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.IP4_HEAD, ptr %50, i32 0, i32 6
  %52 = load i8, ptr %51, align 1, !tbaa !14
  %53 = zext i8 %52 to i32
  switch i32 %53, label %78 [
    i32 17, label %54
    i32 6, label %66
  ]

54:                                               ; preds = %49
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load i8, ptr %56, align 1
  %58 = and i8 %57, 15
  %59 = zext i8 %58 to i32
  %60 = shl i32 %59, 2
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i8, ptr %55, i64 %61
  store ptr %62, ptr %11, align 8, !tbaa !5
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.EFI_UDP_HEADER, ptr %63, i32 0, i32 3
  store ptr %64, ptr %13, align 8, !tbaa !5
  %65 = load ptr, ptr %13, align 8, !tbaa !5
  store i16 0, ptr %65, align 2, !tbaa !15
  br label %79

66:                                               ; preds = %49
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load i8, ptr %68, align 1
  %70 = and i8 %69, 15
  %71 = zext i8 %70 to i32
  %72 = shl i32 %71, 2
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %67, i64 %73
  store ptr %74, ptr %12, align 8, !tbaa !5
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.TCP_HEAD, ptr %75, i32 0, i32 7
  store ptr %76, ptr %13, align 8, !tbaa !5
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  store i16 0, ptr %77, align 2, !tbaa !15
  br label %79

78:                                               ; preds = %49
  br label %79

79:                                               ; preds = %78, %66, %54
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = load i8, ptr %81, align 1
  %83 = and i8 %82, 15
  %84 = zext i8 %83 to i32
  %85 = shl i32 %84, 2
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds i8, ptr %80, i64 %86
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.IP4_HEAD, ptr %88, i32 0, i32 2
  %90 = load i16, ptr %89, align 1, !tbaa !16
  %91 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %90)
  %92 = zext i16 %91 to i32
  %93 = load ptr, ptr %7, align 8, !tbaa !5
  %94 = load i8, ptr %93, align 1
  %95 = and i8 %94, 15
  %96 = zext i8 %95 to i32
  %97 = shl i32 %96, 2
  %98 = sub nsw i32 %92, %97
  %99 = call zeroext i16 @NetblockChecksum(ptr noundef %87, i32 noundef %98)
  store i16 %99, ptr %15, align 2, !tbaa !15
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.IP4_HEAD, ptr %100, i32 0, i32 8
  %102 = load i32, ptr %101, align 1, !tbaa !17
  %103 = load ptr, ptr %7, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.IP4_HEAD, ptr %103, i32 0, i32 9
  %105 = load i32, ptr %104, align 1, !tbaa !18
  %106 = load ptr, ptr %7, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.IP4_HEAD, ptr %106, i32 0, i32 6
  %108 = load i8, ptr %107, align 1, !tbaa !14
  %109 = call zeroext i16 @NetPseudoHeadChecksum(i32 noundef %102, i32 noundef %105, i8 noundef zeroext %108, i16 noundef zeroext 0)
  store i16 %109, ptr %14, align 2, !tbaa !15
  %110 = load ptr, ptr %13, align 8, !tbaa !5
  %111 = icmp ne ptr %110, null
  br i1 %111, label %112, label %137

112:                                              ; preds = %79
  %113 = load i16, ptr %15, align 2, !tbaa !15
  %114 = load i16, ptr %14, align 2, !tbaa !15
  %115 = call zeroext i16 @NetAddChecksum(i16 noundef zeroext %113, i16 noundef zeroext %114)
  %116 = load ptr, ptr %13, align 8, !tbaa !5
  store i16 %115, ptr %116, align 2, !tbaa !15
  %117 = load ptr, ptr %13, align 8, !tbaa !5
  %118 = load i16, ptr %117, align 2, !tbaa !15
  %119 = load ptr, ptr %7, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.IP4_HEAD, ptr %119, i32 0, i32 2
  %121 = load i16, ptr %120, align 1, !tbaa !16
  %122 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %121)
  %123 = zext i16 %122 to i32
  %124 = load ptr, ptr %7, align 8, !tbaa !5
  %125 = load i8, ptr %124, align 1
  %126 = and i8 %125, 15
  %127 = zext i8 %126 to i32
  %128 = shl i32 %127, 2
  %129 = sub nsw i32 %123, %128
  %130 = trunc i32 %129 to i16
  %131 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %130)
  %132 = call zeroext i16 @NetAddChecksum(i16 noundef zeroext %118, i16 noundef zeroext %131)
  %133 = zext i16 %132 to i32
  %134 = xor i32 %133, -1
  %135 = trunc i32 %134 to i16
  %136 = load ptr, ptr %13, align 8, !tbaa !5
  store i16 %135, ptr %136, align 2, !tbaa !15
  br label %137

137:                                              ; preds = %112, %79
  br label %230

138:                                              ; preds = %5
  %139 = load ptr, ptr %6, align 8, !tbaa !5
  %140 = call ptr @ZeroMem(ptr noundef %139, i64 noundef 40)
  %141 = load ptr, ptr %7, align 8, !tbaa !5
  %142 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %141, i32 0, i32 6
  %143 = load ptr, ptr %9, align 8, !tbaa !5
  %144 = getelementptr inbounds %struct._IPSEC_SAD_DATA, ptr %143, i32 0, i32 11
  %145 = call ptr @CopyMem(ptr noundef %142, ptr noundef %144, i64 noundef 16)
  %146 = load ptr, ptr %7, align 8, !tbaa !5
  %147 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %146, i32 0, i32 3
  %148 = load ptr, ptr %7, align 8, !tbaa !5
  %149 = getelementptr inbounds i8, ptr %148, i64 40
  %150 = load ptr, ptr %7, align 8, !tbaa !5
  %151 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %150, i32 0, i32 2
  %152 = load i16, ptr %151, align 1, !tbaa !19
  %153 = zext i16 %152 to i32
  %154 = call zeroext i8 @IpSecIsIp6ExtsValid(ptr noundef %147, ptr noundef %149, i32 noundef %153, ptr noundef %10, ptr noundef %16)
  %155 = load ptr, ptr %10, align 8, !tbaa !5
  %156 = load i8, ptr %155, align 1, !tbaa !9
  %157 = zext i8 %156 to i32
  switch i32 %157, label %185 [
    i32 17, label %158
    i32 6, label %167
    i32 58, label %176
  ]

158:                                              ; preds = %138
  %159 = load ptr, ptr %7, align 8, !tbaa !5
  %160 = getelementptr inbounds i8, ptr %159, i64 40
  %161 = load i32, ptr %16, align 4, !tbaa !22
  %162 = zext i32 %161 to i64
  %163 = getelementptr inbounds i8, ptr %160, i64 %162
  store ptr %163, ptr %11, align 8, !tbaa !5
  %164 = load ptr, ptr %11, align 8, !tbaa !5
  %165 = getelementptr inbounds %struct.EFI_UDP_HEADER, ptr %164, i32 0, i32 3
  store ptr %165, ptr %13, align 8, !tbaa !5
  %166 = load ptr, ptr %13, align 8, !tbaa !5
  store i16 0, ptr %166, align 2, !tbaa !15
  br label %185

167:                                              ; preds = %138
  %168 = load ptr, ptr %7, align 8, !tbaa !5
  %169 = getelementptr inbounds i8, ptr %168, i64 40
  %170 = load i32, ptr %16, align 4, !tbaa !22
  %171 = zext i32 %170 to i64
  %172 = getelementptr inbounds i8, ptr %169, i64 %171
  store ptr %172, ptr %12, align 8, !tbaa !5
  %173 = load ptr, ptr %12, align 8, !tbaa !5
  %174 = getelementptr inbounds %struct.TCP_HEAD, ptr %173, i32 0, i32 7
  store ptr %174, ptr %13, align 8, !tbaa !5
  %175 = load ptr, ptr %13, align 8, !tbaa !5
  store i16 0, ptr %175, align 2, !tbaa !15
  br label %185

176:                                              ; preds = %138
  %177 = load ptr, ptr %7, align 8, !tbaa !5
  %178 = getelementptr inbounds i8, ptr %177, i64 40
  %179 = load i32, ptr %16, align 4, !tbaa !22
  %180 = zext i32 %179 to i64
  %181 = getelementptr inbounds i8, ptr %178, i64 %180
  store ptr %181, ptr %17, align 8, !tbaa !5
  %182 = load ptr, ptr %17, align 8, !tbaa !5
  %183 = getelementptr inbounds %struct.IP6_ICMP_HEAD, ptr %182, i32 0, i32 2
  store ptr %183, ptr %13, align 8, !tbaa !5
  %184 = load ptr, ptr %13, align 8, !tbaa !5
  store i16 0, ptr %184, align 2, !tbaa !15
  br label %185

185:                                              ; preds = %176, %167, %158, %138
  %186 = load ptr, ptr %7, align 8, !tbaa !5
  %187 = getelementptr inbounds i8, ptr %186, i64 40
  %188 = load i32, ptr %16, align 4, !tbaa !22
  %189 = zext i32 %188 to i64
  %190 = getelementptr inbounds i8, ptr %187, i64 %189
  %191 = load ptr, ptr %7, align 8, !tbaa !5
  %192 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %191, i32 0, i32 2
  %193 = load i16, ptr %192, align 1, !tbaa !19
  %194 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %193)
  %195 = zext i16 %194 to i32
  %196 = load i32, ptr %16, align 4, !tbaa !22
  %197 = sub i32 %195, %196
  %198 = call zeroext i16 @NetblockChecksum(ptr noundef %190, i32 noundef %197)
  store i16 %198, ptr %15, align 2, !tbaa !15
  %199 = load ptr, ptr %7, align 8, !tbaa !5
  %200 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %199, i32 0, i32 5
  %201 = load ptr, ptr %7, align 8, !tbaa !5
  %202 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %201, i32 0, i32 6
  %203 = load ptr, ptr %10, align 8, !tbaa !5
  %204 = load i8, ptr %203, align 1, !tbaa !9
  %205 = call zeroext i16 @NetIp6PseudoHeadChecksum(ptr noundef %200, ptr noundef %202, i8 noundef zeroext %204, i32 noundef 0)
  store i16 %205, ptr %14, align 2, !tbaa !15
  %206 = load ptr, ptr %13, align 8, !tbaa !5
  %207 = icmp ne ptr %206, null
  br i1 %207, label %208, label %229

208:                                              ; preds = %185
  %209 = load i16, ptr %15, align 2, !tbaa !15
  %210 = load i16, ptr %14, align 2, !tbaa !15
  %211 = call zeroext i16 @NetAddChecksum(i16 noundef zeroext %209, i16 noundef zeroext %210)
  %212 = load ptr, ptr %13, align 8, !tbaa !5
  store i16 %211, ptr %212, align 2, !tbaa !15
  %213 = load ptr, ptr %13, align 8, !tbaa !5
  %214 = load i16, ptr %213, align 2, !tbaa !15
  %215 = load ptr, ptr %7, align 8, !tbaa !5
  %216 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %215, i32 0, i32 2
  %217 = load i16, ptr %216, align 1, !tbaa !19
  %218 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %217)
  %219 = zext i16 %218 to i32
  %220 = load i32, ptr %16, align 4, !tbaa !22
  %221 = sub i32 %219, %220
  %222 = trunc i32 %221 to i16
  %223 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %222)
  %224 = call zeroext i16 @NetAddChecksum(i16 noundef zeroext %214, i16 noundef zeroext %223)
  %225 = zext i16 %224 to i32
  %226 = xor i32 %225, -1
  %227 = trunc i32 %226 to i16
  %228 = load ptr, ptr %13, align 8, !tbaa !5
  store i16 %227, ptr %228, align 2, !tbaa !15
  br label %229

229:                                              ; preds = %208, %185
  br label %230

230:                                              ; preds = %229, %137
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

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

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

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, !12, i64 10}
!11 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !12, i64 2, !12, i64 4, !12, i64 6, !7, i64 8, !7, i64 9, !12, i64 10, !13, i64 12, !13, i64 16}
!12 = !{!"short", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!11, !7, i64 9}
!15 = !{!12, !12, i64 0}
!16 = !{!11, !12, i64 2}
!17 = !{!11, !13, i64 12}
!18 = !{!11, !13, i64 16}
!19 = !{!20, !12, i64 4}
!20 = !{!"_EFI_IP6_HEADER", !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 1, !12, i64 2, !12, i64 4, !7, i64 6, !7, i64 7, !21, i64 8, !21, i64 24}
!21 = !{!"", !7, i64 0}
!22 = !{!13, !13, 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"

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

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

; Function Attrs: mustprogress 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) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @IpSecIsIp6ExtsValid(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @IpSecTunnelInboundPacket(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %4, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  %8 = icmp eq i8 %2, 4
  %9 = getelementptr inbounds i8, ptr %3, i64 156
  br i1 %8, label %10, label %56

10:                                               ; preds = %5
  %11 = tail call ptr @ZeroMem(ptr noundef %0, i64 noundef 20) #3
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  %13 = tail call ptr @CopyMem(ptr noundef nonnull %12, ptr noundef nonnull %9, i64 noundef 4) #3
  %14 = getelementptr inbounds i8, ptr %1, i64 10
  %15 = load i16, ptr %14, align 1, !tbaa !9
  %.not58 = icmp eq i16 %15, 0
  br i1 %.not58, label %23, label %16

16:                                               ; preds = %10
  store i16 0, ptr %14, align 1, !tbaa !9
  %17 = load i8, ptr %1, align 1
  %18 = shl i8 %17, 2
  %19 = and i8 %18, 60
  %20 = zext nneg i8 %19 to i32
  %21 = tail call zeroext i16 @NetblockChecksum(ptr noundef nonnull %1, i32 noundef %20) #3
  %22 = xor i16 %21, -1
  store i16 %22, ptr %14, align 1, !tbaa !9
  br label %23

23:                                               ; preds = %16, %10
  %24 = getelementptr inbounds i8, ptr %1, i64 9
  %25 = load i8, ptr %24, align 1, !tbaa !13
  %.pre61 = load i8, ptr %1, align 1
  %.pre62 = shl i8 %.pre61, 2
  %.pre63 = and i8 %.pre62, 60
  %.pre65 = zext nneg i8 %.pre63 to i64
  switch i8 %25, label %._crit_edge60 [
    i8 17, label %._crit_edge60.sink.split
    i8 6, label %26
  ]

26:                                               ; preds = %23
  br label %._crit_edge60.sink.split

._crit_edge60.sink.split:                         ; preds = %23, %26
  %.sink70 = phi i64 [ 16, %26 ], [ 6, %23 ]
  %27 = getelementptr inbounds i8, ptr %1, i64 %.pre65
  %28 = getelementptr inbounds i8, ptr %27, i64 %.sink70
  store i16 0, ptr %28, align 2, !tbaa !14
  br label %._crit_edge60

._crit_edge60:                                    ; preds = %._crit_edge60.sink.split, %23
  %.0 = phi ptr [ null, %23 ], [ %28, %._crit_edge60.sink.split ]
  %29 = getelementptr inbounds i8, ptr %1, i64 %.pre65
  %30 = getelementptr inbounds i8, ptr %1, i64 2
  %31 = load i16, ptr %30, align 1, !tbaa !15
  %32 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %31) #3
  %33 = zext i16 %32 to i32
  %34 = load i8, ptr %1, align 1
  %35 = shl i8 %34, 2
  %36 = and i8 %35, 60
  %37 = zext nneg i8 %36 to i32
  %38 = sub nsw i32 %33, %37
  %39 = tail call zeroext i16 @NetblockChecksum(ptr noundef nonnull %29, i32 noundef %38) #3
  %40 = getelementptr inbounds i8, ptr %1, i64 12
  %41 = load i32, ptr %40, align 1, !tbaa !16
  %42 = load i32, ptr %12, align 1, !tbaa !17
  %43 = load i8, ptr %24, align 1, !tbaa !13
  %44 = tail call zeroext i16 @NetPseudoHeadChecksum(i32 noundef %41, i32 noundef %42, i8 noundef zeroext %43, i16 noundef zeroext 0) #3
  %.not59 = icmp eq ptr %.0, null
  br i1 %.not59, label %93, label %45

45:                                               ; preds = %._crit_edge60
  %46 = tail call zeroext i16 @NetAddChecksum(i16 noundef zeroext %39, i16 noundef zeroext %44) #3
  store i16 %46, ptr %.0, align 2, !tbaa !14
  %47 = load i16, ptr %30, align 1, !tbaa !15
  %48 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %47) #3
  %49 = load i8, ptr %1, align 1
  %50 = shl i8 %49, 2
  %51 = and i8 %50, 60
  %52 = zext nneg i8 %51 to i16
  %53 = sub i16 %48, %52
  %54 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %53) #3
  %55 = tail call zeroext i16 @NetAddChecksum(i16 noundef zeroext %46, i16 noundef zeroext %54) #3
  br label %.sink.split

56:                                               ; preds = %5
  %57 = tail call ptr @ZeroMem(ptr noundef %0, i64 noundef 40) #3
  %58 = getelementptr inbounds i8, ptr %1, i64 24
  %59 = tail call ptr @CopyMem(ptr noundef nonnull %58, ptr noundef nonnull %9, i64 noundef 16) #3
  %60 = getelementptr inbounds i8, ptr %1, i64 6
  %61 = getelementptr inbounds i8, ptr %1, i64 40
  %62 = getelementptr inbounds i8, ptr %1, i64 4
  %63 = load i16, ptr %62, align 1, !tbaa !18
  %64 = zext i16 %63 to i32
  %65 = call zeroext i8 @IpSecIsIp6ExtsValid(ptr noundef nonnull %60, ptr noundef nonnull %61, i32 noundef %64, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load i8, ptr %66, align 1, !tbaa !21
  %.pre = load i32, ptr %7, align 4, !tbaa !22
  %.pre67 = zext i32 %.pre to i64
  switch i8 %67, label %._crit_edge [
    i8 17, label %._crit_edge.sink.split
    i8 6, label %68
    i8 58, label %69
  ]

68:                                               ; preds = %56
  br label %._crit_edge.sink.split

69:                                               ; preds = %56
  br label %._crit_edge.sink.split

._crit_edge.sink.split:                           ; preds = %56, %68, %69
  %.sink72 = phi i64 [ 2, %69 ], [ 16, %68 ], [ 6, %56 ]
  %70 = getelementptr inbounds i8, ptr %61, i64 %.pre67
  %71 = getelementptr inbounds i8, ptr %70, i64 %.sink72
  store i16 0, ptr %71, align 2, !tbaa !14
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.sink.split, %56
  %.1 = phi ptr [ null, %56 ], [ %71, %._crit_edge.sink.split ]
  %72 = getelementptr inbounds i8, ptr %61, i64 %.pre67
  %73 = load i16, ptr %62, align 1, !tbaa !18
  %74 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %73) #3
  %75 = zext i16 %74 to i32
  %76 = load i32, ptr %7, align 4, !tbaa !22
  %77 = sub i32 %75, %76
  %78 = call zeroext i16 @NetblockChecksum(ptr noundef nonnull %72, i32 noundef %77) #3
  %79 = getelementptr inbounds i8, ptr %1, i64 8
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = load i8, ptr %80, align 1, !tbaa !21
  %82 = call zeroext i16 @NetIp6PseudoHeadChecksum(ptr noundef nonnull %79, ptr noundef nonnull %58, i8 noundef zeroext %81, i32 noundef 0) #3
  %.not = icmp eq ptr %.1, null
  br i1 %.not, label %93, label %83

83:                                               ; preds = %._crit_edge
  %84 = call zeroext i16 @NetAddChecksum(i16 noundef zeroext %78, i16 noundef zeroext %82) #3
  store i16 %84, ptr %.1, align 2, !tbaa !14
  %85 = load i16, ptr %62, align 1, !tbaa !18
  %86 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %85) #3
  %87 = load i32, ptr %7, align 4, !tbaa !22
  %88 = trunc i32 %87 to i16
  %89 = sub i16 %86, %88
  %90 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %89) #3
  %91 = call zeroext i16 @NetAddChecksum(i16 noundef zeroext %84, i16 noundef zeroext %90) #3
  br label %.sink.split

.sink.split:                                      ; preds = %45, %83
  %.sink73 = phi i16 [ %91, %83 ], [ %55, %45 ]
  %.1.sink = phi ptr [ %.1, %83 ], [ %.0, %45 ]
  %92 = xor i16 %.sink73, -1
  store i16 %92, ptr %.1.sink, align 2, !tbaa !14
  br label %93

93:                                               ; preds = %.sink.split, %._crit_edge, %._crit_edge60
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  ret void
}

declare zeroext i16 @NetblockChecksum(ptr noundef, i32 noundef) local_unnamed_addr #1

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

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

declare zeroext i16 @NetIp6PseudoHeadChecksum(ptr noundef, ptr noundef, i8 noundef zeroext, 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 10}
!10 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !11, i64 2, !11, i64 4, !11, i64 6, !7, i64 8, !7, i64 9, !11, i64 10, !12, i64 12, !12, i64 16}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !7, i64 9}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 2}
!16 = !{!10, !12, i64 12}
!17 = !{!10, !12, i64 16}
!18 = !{!19, !11, i64 4}
!19 = !{!"_EFI_IP6_HEADER", !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 1, !11, i64 2, !11, i64 4, !7, i64 6, !7, i64 7, !20, i64 8, !20, i64 24}
!20 = !{!"", !7, i64 0}
!21 = !{!7, !7, i64 0}
!22 = !{!12, !12, i64 0}


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