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

; 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"

%union.IP_IO_IP_PROTOCOL = type { ptr }
%struct._IP_IO = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, ptr, ptr, %union.IP_IO_IP_PROTOCOL, i8, i8, %union.IP_IO_IP_COMPLETION_TOKEN, %struct._LIST_ENTRY, ptr, ptr, ptr, ptr, i8 }
%union.IP_IO_IP_COMPLETION_TOKEN = type { %struct.EFI_IP4_COMPLETION_TOKEN }
%struct.EFI_IP4_COMPLETION_TOKEN = type { ptr, i64, %union.anon }
%union.anon = type { ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct._IP_IO_IP_INFO = type { %union.EFI_IP_ADDRESS, %union.IP_IO_IP_MASK, %struct._LIST_ENTRY, ptr, %union.IP_IO_IP_PROTOCOL, %union.IP_IO_IP_COMPLETION_TOKEN, i64, i8 }
%union.EFI_IP_ADDRESS = type { [4 x i32] }
%union.IP_IO_IP_MASK = type { i32 }
%struct._EFI_IP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct._IP_IO_SEND_ENTRY = type { %struct._LIST_ENTRY, ptr, ptr, ptr, %union.IP_IO_IP_PROTOCOL, ptr, %union.IP_IO_IP_COMPLETION_TOKEN }
%struct._EFI_IP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

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

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

declare zeroext i8 @DebugAssertEnabled() #1

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare dso_local void @IpIoDestroySndEntry(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @IpIoSend(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #2 {
  %8 = alloca i64, align 8
  %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 ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca %union.IP_IO_IP_PROTOCOL, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store ptr %6, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  br label %20

20:                                               ; preds = %7
  %21 = call zeroext i8 @DebugAssertEnabled()
  %22 = icmp ne i8 %21, 0
  br i1 %22, label %23, label %34

23:                                               ; preds = %20
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._IP_IO, ptr %24, i32 0, i32 14
  %26 = load i8, ptr %25, align 8, !tbaa !9
  %27 = zext i8 %26 to i32
  %28 = icmp ne i32 %27, 4
  br i1 %28, label %33, label %29

29:                                               ; preds = %23
  %30 = load ptr, ptr %14, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1515, ptr noundef @.str.6)
  br label %33

33:                                               ; preds = %32, %29, %23
  br label %34

34:                                               ; preds = %33, %20
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._IP_IO, ptr %37, i32 0, i32 6
  %39 = load i8, ptr %38, align 8, !tbaa !12
  %40 = icmp ne i8 %39, 0
  br i1 %40, label %42, label %41

41:                                               ; preds = %36
  store i64 -9223372036854775789, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %93

42:                                               ; preds = %36
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = icmp eq ptr null, %43
  br i1 %44, label %45, label %48

45:                                               ; preds = %42
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._IP_IO, ptr %46, i32 0, i32 5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %17, ptr align 8 %47, i64 8, i1 false), !tbaa.struct !13
  br label %51

48:                                               ; preds = %42
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._IP_IO_IP_INFO, ptr %49, i32 0, i32 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %17, ptr align 8 %50, i64 8, i1 false), !tbaa.struct !13
  br label %51

51:                                               ; preds = %48, %45
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = load ptr, ptr %15, align 8, !tbaa !5
  %58 = getelementptr inbounds %union.IP_IO_IP_PROTOCOL, ptr %17, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8
  %60 = call ptr @IpIoCreateSndEntry(ptr noundef %52, ptr noundef %53, ptr %59, ptr noundef %54, ptr noundef %55, ptr noundef %56, ptr noundef %57)
  store ptr %60, ptr %18, align 8, !tbaa !5
  %61 = load ptr, ptr %18, align 8, !tbaa !5
  %62 = icmp eq ptr null, %61
  br i1 %62, label %63, label %64

63:                                               ; preds = %51
  store i64 -9223372036854775799, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %93

64:                                               ; preds = %51
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._IP_IO, ptr %65, i32 0, i32 14
  %67 = load i8, ptr %66, align 8, !tbaa !9
  %68 = zext i8 %67 to i32
  %69 = icmp eq i32 %68, 4
  br i1 %69, label %70, label %78

70:                                               ; preds = %64
  %71 = load ptr, ptr %17, align 8, !tbaa !14
  %72 = getelementptr inbounds %struct._EFI_IP4_PROTOCOL, ptr %71, i32 0, i32 4
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  %74 = load ptr, ptr %17, align 8, !tbaa !14
  %75 = load ptr, ptr %18, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %75, i32 0, i32 6
  %77 = call i64 %73(ptr noundef %74, ptr noundef %76)
  store i64 %77, ptr %16, align 8, !tbaa !17
  br label %86

78:                                               ; preds = %64
  %79 = load ptr, ptr %17, align 8, !tbaa !14
  %80 = getelementptr inbounds %struct._EFI_IP6_PROTOCOL, ptr %79, i32 0, i32 5
  %81 = load ptr, ptr %80, align 8, !tbaa !19
  %82 = load ptr, ptr %17, align 8, !tbaa !14
  %83 = load ptr, ptr %18, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %83, i32 0, i32 6
  %85 = call i64 %81(ptr noundef %82, ptr noundef %84)
  store i64 %85, ptr %16, align 8, !tbaa !17
  br label %86

86:                                               ; preds = %78, %70
  %87 = load i64, ptr %16, align 8, !tbaa !17
  %88 = icmp slt i64 %87, 0
  br i1 %88, label %89, label %91

89:                                               ; preds = %86
  %90 = load ptr, ptr %18, align 8, !tbaa !5
  call void @IpIoDestroySndEntry(ptr noundef %90)
  br label %91

91:                                               ; preds = %89, %86
  %92 = load i64, ptr %16, align 8, !tbaa !17
  store i64 %92, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %93

93:                                               ; preds = %91, %63, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  %94 = load i64, ptr %8, align 8
  ret i64 %94
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !7, i64 144}
!10 = !{!"_IP_IO", !11, i64 0, !11, i64 16, !6, i64 32, !6, i64 40, !6, i64 48, !7, i64 56, !7, i64 64, !7, i64 65, !7, i64 72, !11, i64 96, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !7, i64 144}
!11 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!12 = !{!10, !7, i64 64}
!13 = !{i64 0, i64 8, !14}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !6, i64 32}
!16 = !{!"_EFI_IP4_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!17 = !{!18, !18, i64 0}
!18 = !{!"long long", !7, i64 0}
!19 = !{!20, !6, i64 40}
!20 = !{!"_EFI_IP6_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}


; 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"

@.str = external hidden unnamed_addr constant [146 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [49 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @IpIoCreateSndEntry(ptr noundef, ptr noundef, ptr, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @IpIoDestroySndEntry(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @IpIoSend(ptr noundef %0, ptr noundef %1, ptr noundef readonly %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) local_unnamed_addr #1 {
  %8 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %8, 0
  br i1 %.not, label %15, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 144
  %11 = load i8, ptr %10, align 8, !tbaa !5
  %12 = icmp ne i8 %11, 4
  %13 = icmp ne ptr %5, null
  %or.cond = or i1 %13, %12
  br i1 %or.cond, label %15, label %14

14:                                               ; preds = %9
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1515, ptr noundef nonnull @.str.6) #2
  br label %15

15:                                               ; preds = %9, %14, %7
  %16 = getelementptr inbounds i8, ptr %0, i64 64
  %17 = load i8, ptr %16, align 8, !tbaa !11
  %.not28 = icmp eq i8 %17, 0
  br i1 %.not28, label %34, label %18

18:                                               ; preds = %15
  %19 = icmp eq ptr %2, null
  %20 = getelementptr inbounds i8, ptr %0, i64 56
  %21 = getelementptr inbounds i8, ptr %2, i64 48
  %.sroa.0.0.in = select i1 %19, ptr %20, ptr %21
  %.sroa.0.0 = load ptr, ptr %.sroa.0.0.in, align 8, !tbaa !12
  %22 = tail call ptr @IpIoCreateSndEntry(ptr noundef nonnull %0, ptr noundef %1, ptr %.sroa.0.0, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6)
  %23 = icmp eq ptr %22, null
  br i1 %23, label %34, label %24

24:                                               ; preds = %18
  %25 = getelementptr inbounds i8, ptr %0, i64 144
  %26 = load i8, ptr %25, align 8, !tbaa !5
  %27 = icmp eq i8 %26, 4
  %28 = getelementptr inbounds i8, ptr %22, i64 56
  %. = select i1 %27, i64 32, i64 40
  %29 = getelementptr inbounds i8, ptr %.sroa.0.0, i64 %.
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = tail call i64 %30(ptr noundef %.sroa.0.0, ptr noundef nonnull %28) #2
  %32 = icmp slt i64 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %24
  tail call void @IpIoDestroySndEntry(ptr noundef nonnull %22)
  br label %34

34:                                               ; preds = %24, %33, %18, %15
  %.0 = phi i64 [ -9223372036854775789, %15 ], [ -9223372036854775799, %18 ], [ %31, %33 ], [ %31, %24 ]
  ret i64 %.0
}

attributes #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 = { 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 #2 = { 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, !9, i64 144}
!6 = !{!"_IP_IO", !7, i64 0, !7, i64 16, !8, i64 32, !8, i64 40, !8, i64 48, !9, i64 56, !9, i64 64, !9, i64 65, !9, i64 72, !7, i64 96, !8, i64 112, !8, i64 120, !8, i64 128, !8, i64 136, !9, i64 144}
!7 = !{!"_LIST_ENTRY", !8, i64 0, !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!6, !9, i64 64}
!12 = !{!9, !9, i64 0}
!13 = !{!8, !8, i64 0}


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