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

; 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.IP6_ICMP_ERROR_HEAD = type { %struct.IP6_ICMP_HEAD, i32, %struct._EFI_IP6_HEADER }
%struct.IP6_ICMP_HEAD = type { i8, i8, 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.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.IP6_CLIP_INFO = type { i32, i32, i32, i32, i32, i32, i64, i32, i16, i8, i8, i32 }

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

declare void @NetbufFree(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @Ip6ProcessPacketTooBig(ptr noundef, ptr noundef, ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip6ProcessIcmpError(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.IP6_ICMP_ERROR_HEAD, align 1
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 48, ptr %8) #3
  %10 = load ptr, ptr %7, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.NET_BUF, ptr %10, i32 0, i32 9
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = zext i32 %12 to i64
  %14 = icmp ult i64 %13, 48
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  br label %38

16:                                               ; preds = %3
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call i32 @NetbufCopy(ptr noundef %17, i32 noundef 0, i32 noundef 48, ptr noundef %8)
  %19 = getelementptr inbounds %struct.IP6_ICMP_ERROR_HEAD, ptr %8, i32 0, i32 0
  %20 = getelementptr inbounds %struct.IP6_ICMP_HEAD, ptr %19, i32 0, i32 0
  %21 = load i8, ptr %20, align 1, !tbaa !14
  %22 = zext i8 %21 to i32
  %23 = icmp eq i32 %22, 2
  br i1 %23, label %24, label %29

24:                                               ; preds = %16
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = call i64 @Ip6ProcessPacketTooBig(ptr noundef %25, ptr noundef %26, ptr noundef %27)
  store i64 %28, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %40

29:                                               ; preds = %16
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.NET_BUF, ptr %30, i32 0, i32 6
  %32 = getelementptr inbounds [64 x i8], ptr %31, i64 0, i64 0
  %33 = getelementptr inbounds %struct.IP6_CLIP_INFO, ptr %32, i32 0, i32 6
  store i64 -9223372036854775786, ptr %33, align 8, !tbaa !20
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = call i64 @Ip6Demultiplex(ptr noundef %34, ptr noundef %35, ptr noundef %36)
  store i64 %37, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %40

38:                                               ; preds = %15
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  call void @NetbufFree(ptr noundef %39)
  store ptr null, ptr %7, align 8, !tbaa !5
  store i64 -9223372036854775806, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %40

40:                                               ; preds = %38, %29, %24
  call void @llvm.lifetime.end.p0(i64 48, ptr %8) #3
  %41 = load i64, ptr %4, align 8
  ret i64 %41
}

declare i64 @Ip6Demultiplex(ptr noundef, ptr noundef, 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 = !{!10, !11, i64 132}
!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 = !{!15, !7, i64 0}
!15 = !{!"", !16, i64 0, !11, i64 4, !18, i64 8}
!16 = !{!"", !7, i64 0, !7, i64 1, !17, i64 2}
!17 = !{!"short", !7, i64 0}
!18 = !{!"_EFI_IP6_HEADER", !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 1, !17, i64 2, !17, i64 4, !7, i64 6, !7, i64 7, !19, i64 8, !19, i64 24}
!19 = !{!"", !7, i64 0}
!20 = !{!21, !12, i64 24}
!21 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !12, i64 24, !11, i64 32, !17, i64 36, !7, i64 38, !7, i64 39, !11, i64 40}


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

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

declare void @NetbufFree(ptr 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

; Function Attrs: nounwind uwtable
declare dso_local i64 @Ip6ProcessPacketTooBig(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip6ProcessIcmpError(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.IP6_ICMP_ERROR_HEAD, align 1
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %4) #3
  %5 = getelementptr inbounds i8, ptr %2, i64 132
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp ult i32 %6, 48
  br i1 %7, label %17, label %8

8:                                                ; preds = %3
  %9 = call i32 @NetbufCopy(ptr noundef nonnull %2, i32 noundef 0, i32 noundef 48, ptr noundef nonnull %4) #3
  %10 = load i8, ptr %4, align 1, !tbaa !13
  %11 = icmp eq i8 %10, 2
  br i1 %11, label %12, label %14

12:                                               ; preds = %8
  %13 = call i64 @Ip6ProcessPacketTooBig(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %2)
  br label %18

14:                                               ; preds = %8
  %15 = getelementptr inbounds i8, ptr %2, i64 80
  store i64 -9223372036854775786, ptr %15, align 8, !tbaa !19
  %16 = call i64 @Ip6Demultiplex(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %2) #3
  br label %18

17:                                               ; preds = %3
  tail call void @NetbufFree(ptr noundef nonnull %2) #3
  br label %18

18:                                               ; preds = %17, %14, %12
  %.0 = phi i64 [ -9223372036854775806, %17 ], [ %13, %12 ], [ %16, %14 ]
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #3
  ret i64 %.0
}

declare i64 @Ip6Demultiplex(ptr noundef, ptr noundef, ptr 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, !7, i64 132}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 16, !8, i64 32, !12, i64 40, !12, i64 48, !8, i64 56, !12, i64 120, !7, i64 128, !7, i64 132, !8, i64 136}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"_LIST_ENTRY", !12, i64 0, !12, i64 8}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !8, i64 0}
!14 = !{!"", !15, i64 0, !7, i64 4, !17, i64 8}
!15 = !{!"", !8, i64 0, !8, i64 1, !16, i64 2}
!16 = !{!"short", !8, i64 0}
!17 = !{!"_EFI_IP6_HEADER", !8, i64 0, !8, i64 0, !8, i64 1, !8, i64 1, !16, i64 2, !16, i64 4, !8, i64 6, !8, i64 7, !18, i64 8, !18, i64 24}
!18 = !{!"", !8, i64 0}
!19 = !{!20, !10, i64 24}
!20 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !10, i64 24, !7, i64 32, !16, i64 36, !8, i64 38, !8, i64 39, !7, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass