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

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

@mIcmpClass = external dso_local global [17 x %struct.IP4_ICMP_CLASS], align 16

; 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 @Ip4ProcessIcmpError(ptr noundef, ptr noundef, ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip4IcmpHandle(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.IP4_ICMP_HEAD, align 1
  %9 = alloca i16, align 2
  %10 = 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 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #3
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.NET_BUF, ptr %11, i32 0, i32 9
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = zext i32 %13 to i64
  %15 = icmp ult i64 %14, 4
  br i1 %15, label %16, label %17

16:                                               ; preds = %3
  br label %70

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

24:                                               ; preds = %17
  br label %70

25:                                               ; preds = %17
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = call zeroext i16 @NetbufChecksum(ptr noundef %26)
  %28 = zext i16 %27 to i32
  %29 = xor i32 %28, -1
  %30 = trunc i32 %29 to i16
  store i16 %30, ptr %9, align 2, !tbaa !17
  %31 = getelementptr inbounds %struct.IP4_ICMP_HEAD, ptr %8, i32 0, i32 2
  %32 = load i16, ptr %31, align 1, !tbaa !18
  %33 = zext i16 %32 to i32
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %40

35:                                               ; preds = %25
  %36 = load i16, ptr %9, align 2, !tbaa !17
  %37 = zext i16 %36 to i32
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %35
  br label %70

40:                                               ; preds = %35, %25
  %41 = getelementptr inbounds %struct.IP4_ICMP_HEAD, ptr %8, i32 0, i32 0
  %42 = load i8, ptr %41, align 1, !tbaa !14
  %43 = zext i8 %42 to i64
  %44 = getelementptr inbounds [17 x %struct.IP4_ICMP_CLASS], ptr @mIcmpClass, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.IP4_ICMP_CLASS, ptr %44, i32 0, i32 1
  %46 = load i8, ptr %45, align 1, !tbaa !19
  %47 = zext i8 %46 to i32
  %48 = icmp eq i32 %47, 1
  br i1 %48, label %49, label %54

49:                                               ; preds = %40
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = call i64 @Ip4ProcessIcmpError(ptr noundef %50, ptr noundef %51, ptr noundef %52)
  store i64 %53, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %72

54:                                               ; preds = %40
  %55 = getelementptr inbounds %struct.IP4_ICMP_HEAD, ptr %8, i32 0, i32 0
  %56 = load i8, ptr %55, align 1, !tbaa !14
  %57 = zext i8 %56 to i64
  %58 = getelementptr inbounds [17 x %struct.IP4_ICMP_CLASS], ptr @mIcmpClass, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.IP4_ICMP_CLASS, ptr %58, i32 0, i32 1
  %60 = load i8, ptr %59, align 1, !tbaa !19
  %61 = zext i8 %60 to i32
  %62 = icmp eq i32 %61, 2
  br i1 %62, label %63, label %68

63:                                               ; preds = %54
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = call i64 @Ip4ProcessIcmpQuery(ptr noundef %64, ptr noundef %65, ptr noundef %66)
  store i64 %67, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %72

68:                                               ; preds = %54
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69, %39, %24, %16
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  call void @NetbufFree(ptr noundef %71)
  store i64 -9223372036854775806, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %72

72:                                               ; preds = %70, %63, %49
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %73 = load i64, ptr %4, align 8
  ret i64 %73
}

declare zeroext i16 @NetbufChecksum(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 = !{!"", !7, i64 0, !7, i64 1, !16, i64 2}
!16 = !{!"short", !7, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{!15, !16, i64 2}
!19 = !{!20, !7, i64 1}
!20 = !{!"", !7, i64 0, !7, i64 1}


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

@mIcmpClass = external dso_local local_unnamed_addr global [17 x %struct.IP4_ICMP_CLASS], align 16

; 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 @Ip4ProcessIcmpError(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
declare dso_local i64 @Ip4ProcessIcmpQuery(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

12:                                               ; preds = %8
  %13 = call zeroext i16 @NetbufChecksum(ptr noundef nonnull %2) #3
  %14 = getelementptr inbounds i8, ptr %4, i64 2
  %15 = load i16, ptr %14, align 1, !tbaa !16
  %16 = icmp ne i16 %15, 0
  %17 = icmp ne i16 %13, -1
  %or.cond = select i1 %16, i1 %17, i1 false
  br i1 %or.cond, label %27, label %18

18:                                               ; preds = %12
  %19 = load i8, ptr %4, align 1, !tbaa !13
  %20 = zext i8 %19 to i64
  %21 = getelementptr inbounds [17 x %struct.IP4_ICMP_CLASS], ptr @mIcmpClass, i64 0, i64 %20, i32 1
  %22 = load i8, ptr %21, align 1, !tbaa !17
  switch i8 %22, label %27 [
    i8 1, label %23
    i8 2, label %25
  ]

23:                                               ; preds = %18
  %24 = call i64 @Ip4ProcessIcmpError(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %2)
  br label %28

25:                                               ; preds = %18
  %26 = call i64 @Ip4ProcessIcmpQuery(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %2)
  br label %28

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

28:                                               ; preds = %27, %25, %23
  %.0 = phi i64 [ -9223372036854775806, %27 ], [ %24, %23 ], [ %26, %25 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  ret i64 %.0
}

declare zeroext i16 @NetbufChecksum(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 = !{!"", !8, i64 0, !8, i64 1, !15, i64 2}
!15 = !{!"short", !8, i64 0}
!16 = !{!14, !15, i64 2}
!17 = !{!18, !8, i64 1}
!18 = !{!"", !8, i64 0, !8, i64 1}


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