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

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

@.str = external hidden unnamed_addr constant [149 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 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

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
define dso_local i64 @Ip4IcmpReplyEcho(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca %struct.IP4_HEAD, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 20, ptr %10) #3
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = call ptr @NetbufDuplicate(ptr noundef %11, ptr noundef null, i32 noundef 60)
  store ptr %12, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store i64 -9223372036854775799, ptr %9, align 8, !tbaa !9
  br label %59

16:                                               ; preds = %3
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = call ptr @NetbufGetByte(ptr noundef %17, i32 noundef 0, ptr noundef null)
  store ptr %18, ptr %7, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %16
  %20 = call zeroext i8 @DebugAssertEnabled()
  %21 = icmp ne i8 %20, 0
  br i1 %21, label %22, label %27

22:                                               ; preds = %19
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  call void @DebugAssert(ptr noundef @.str, i64 noundef 243, ptr noundef @.str.1)
  br label %26

26:                                               ; preds = %25, %22
  br label %27

27:                                               ; preds = %26, %19
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.IP4_ICMP_QUERY_HEAD, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.IP4_ICMP_HEAD, ptr %31, i32 0, i32 0
  store i8 0, ptr %32, align 1, !tbaa !11
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.IP4_ICMP_QUERY_HEAD, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds %struct.IP4_ICMP_HEAD, ptr %34, i32 0, i32 2
  store i16 0, ptr %35, align 1, !tbaa !15
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.NET_BUF, ptr %37, i32 0, i32 9
  %39 = load i32, ptr %38, align 4, !tbaa !16
  %40 = call zeroext i16 @NetblockChecksum(ptr noundef %36, i32 noundef %39)
  %41 = zext i16 %40 to i32
  %42 = xor i32 %41, -1
  %43 = trunc i32 %42 to i16
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.IP4_ICMP_QUERY_HEAD, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds %struct.IP4_ICMP_HEAD, ptr %45, i32 0, i32 2
  store i16 %43, ptr %46, align 1, !tbaa !15
  %47 = getelementptr inbounds %struct.IP4_HEAD, ptr %10, i32 0, i32 1
  store i8 0, ptr %47, align 1, !tbaa !20
  %48 = getelementptr inbounds %struct.IP4_HEAD, ptr %10, i32 0, i32 4
  store i16 0, ptr %48, align 1, !tbaa !22
  %49 = getelementptr inbounds %struct.IP4_HEAD, ptr %10, i32 0, i32 5
  store i8 64, ptr %49, align 1, !tbaa !23
  %50 = getelementptr inbounds %struct.IP4_HEAD, ptr %10, i32 0, i32 6
  store i8 1, ptr %50, align 1, !tbaa !24
  %51 = getelementptr inbounds %struct.IP4_HEAD, ptr %10, i32 0, i32 8
  store i32 0, ptr %51, align 1, !tbaa !25
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.IP4_HEAD, ptr %52, i32 0, i32 8
  %54 = load i32, ptr %53, align 1, !tbaa !25
  %55 = getelementptr inbounds %struct.IP4_HEAD, ptr %10, i32 0, i32 9
  store i32 %54, ptr %55, align 1, !tbaa !26
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = call i64 @Ip4Output(ptr noundef %56, ptr noundef null, ptr noundef %57, ptr noundef %10, ptr noundef null, i32 noundef 0, i32 noundef 0, ptr noundef @Ip4SysPacketSent, ptr noundef null)
  store i64 %58, ptr %9, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %29, %15
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  call void @NetbufFree(ptr noundef %60)
  %61 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 20, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %61
}

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

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

declare zeroext i8 @DebugAssertEnabled() #1

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

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

declare i64 @Ip4Output(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) #1

declare void @Ip4SysPacketSent(ptr noundef, ptr noundef, i64 noundef, i32 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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"", !13, i64 0, !14, i64 4, !14, i64 6}
!13 = !{!"", !7, i64 0, !7, i64 1, !14, i64 2}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !14, i64 2}
!16 = !{!17, !18, i64 132}
!17 = !{!"", !18, i64 0, !10, i64 8, !19, i64 16, !7, i64 32, !6, i64 40, !6, i64 48, !7, i64 56, !6, i64 120, !18, i64 128, !18, i64 132, !7, i64 136}
!18 = !{!"int", !7, i64 0}
!19 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!20 = !{!21, !7, i64 1}
!21 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !14, i64 2, !14, i64 4, !14, i64 6, !7, i64 8, !7, i64 9, !14, i64 10, !18, i64 12, !18, i64 16}
!22 = !{!21, !14, i64 6}
!23 = !{!21, !7, i64 8}
!24 = !{!21, !7, i64 9}
!25 = !{!21, !18, i64 12}
!26 = !{!21, !18, i64 16}


; 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_HEAD = type { i8, i8, i16, i16, i16, i8, i8, i16, i32, i32 }

@.str = external hidden unnamed_addr constant [149 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; 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
define dso_local i64 @Ip4IcmpReplyEcho(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.IP4_HEAD, align 1
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %4) #3
  %5 = tail call ptr @NetbufDuplicate(ptr noundef %2, ptr noundef null, i32 noundef 60) #3
  %6 = icmp eq ptr %5, null
  br i1 %6, label %28, label %7

7:                                                ; preds = %3
  %8 = tail call ptr @NetbufGetByte(ptr noundef nonnull %5, i32 noundef 0, ptr noundef null) #3
  %9 = tail call zeroext i8 @DebugAssertEnabled() #3
  %10 = icmp eq i8 %9, 0
  %11 = icmp ne ptr %8, null
  %or.cond = select i1 %10, i1 true, i1 %11
  br i1 %or.cond, label %13, label %12

12:                                               ; preds = %7
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 243, ptr noundef nonnull @.str.1) #3
  br label %13

13:                                               ; preds = %12, %7
  store i8 0, ptr %8, align 1, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %8, i64 2
  store i16 0, ptr %14, align 1, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %5, i64 132
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = tail call zeroext i16 @NetblockChecksum(ptr noundef nonnull %8, i32 noundef %16) #3
  %18 = xor i16 %17, -1
  store i16 %18, ptr %14, align 1, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %4, i64 1
  store i8 0, ptr %19, align 1, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %4, i64 6
  store i16 0, ptr %20, align 1, !tbaa !20
  %21 = getelementptr inbounds i8, ptr %4, i64 8
  store i8 64, ptr %21, align 1, !tbaa !21
  %22 = getelementptr inbounds i8, ptr %4, i64 9
  store i8 1, ptr %22, align 1, !tbaa !22
  %23 = getelementptr inbounds i8, ptr %4, i64 12
  store i32 0, ptr %23, align 1, !tbaa !23
  %24 = getelementptr inbounds i8, ptr %1, i64 12
  %25 = load i32, ptr %24, align 1, !tbaa !23
  %26 = getelementptr inbounds i8, ptr %4, i64 16
  store i32 %25, ptr %26, align 1, !tbaa !24
  %27 = call i64 @Ip4Output(ptr noundef %0, ptr noundef null, ptr noundef nonnull %5, ptr noundef nonnull %4, ptr noundef null, i32 noundef 0, i32 noundef 0, ptr noundef nonnull @Ip4SysPacketSent, ptr noundef null) #3
  br label %28

28:                                               ; preds = %3, %13
  %.0 = phi i64 [ %27, %13 ], [ -9223372036854775799, %3 ]
  call void @NetbufFree(ptr noundef %2) #3
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %4) #3
  ret i64 %.0
}

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

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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

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

declare i64 @Ip4Output(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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


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