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

; 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_ICMP_ERROR_HEAD = type { %struct.IP4_ICMP_HEAD, i32, %struct.IP4_HEAD }
%struct.IP4_ICMP_HEAD = type { i8, i8, i16 }
%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.IP4_CLIP_INFO = type { i64, i64, i64, i64, i64, i32, i64 }

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

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

declare void @NetbufFree(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip4ProcessIcmpError(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.IP4_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 28, 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, 28
  br i1 %14, label %15, label %17

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

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

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

30:                                               ; preds = %17
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.NET_BUF, ptr %31, i32 0, i32 6
  %33 = getelementptr inbounds [64 x i8], ptr %32, i64 0, i64 0
  %34 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %33, i32 0, i32 6
  store i64 -9223372036854775786, ptr %34, align 8, !tbaa !19
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = call i64 @Ip4Demultiplex(ptr noundef %35, ptr noundef %36, ptr noundef %37, ptr noundef null, i32 noundef 0)
  store i64 %38, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %39

39:                                               ; preds = %30, %25, %15
  call void @llvm.lifetime.end.p0(i64 28, ptr %8) #3
  %40 = load i64, ptr %4, align 8
  ret i64 %40
}

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

declare i64 @Ip4Demultiplex(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"", !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}
!19 = !{!20, !12, i64 48}
!20 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !11, i64 40, !12, i64 48}


; 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.IP4_ICMP_ERROR_HEAD = type { %struct.IP4_ICMP_HEAD, i32, %struct.IP4_HEAD }
%struct.IP4_ICMP_HEAD = type { i8, i8, i16 }
%struct.IP4_HEAD = type { i8, i8, i16, i16, i16, i8, i8, i16, i32, i32 }

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

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

declare void @NetbufFree(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip4ProcessIcmpError(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.IP4_ICMP_ERROR_HEAD, align 1
  call void @llvm.lifetime.start.p0(i64 28, 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, 28
  br i1 %7, label %8, label %9

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

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

13:                                               ; preds = %9
  %14 = call i64 @Ip4ProcessIcmpRedirect(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %2, ptr noundef nonnull %4)
  br label %18

15:                                               ; preds = %9
  %16 = getelementptr inbounds i8, ptr %2, i64 104
  store i64 -9223372036854775786, ptr %16, align 8, !tbaa !18
  %17 = call i64 @Ip4Demultiplex(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %2, ptr noundef null, i32 noundef 0) #3
  br label %18

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

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

declare i64 @Ip4Demultiplex(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"", !8, i64 0, !8, i64 0, !8, i64 1, !16, i64 2, !16, i64 4, !16, i64 6, !8, i64 8, !8, i64 9, !16, i64 10, !7, i64 12, !7, i64 16}
!18 = !{!19, !10, i64 48}
!19 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !10, i64 48}


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