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

; 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._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_PROTOCOL = type { ptr }
%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.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }
%struct.EFI_IP6_COMPLETION_TOKEN = type { ptr, i64, %union.anon.0 }
%union.anon.0 = type { ptr }

@gBS = external global ptr, align 8
@.str = external hidden unnamed_addr constant [146 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [37 x i8], align 1

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

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

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

declare zeroext i8 @DebugAssertEnabled() #2

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @IpIoCreate(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i8 %2, ptr %7, align 1, !tbaa !9
  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 8, ptr %10) #3
  br label %12

12:                                               ; preds = %3
  %13 = call zeroext i8 @DebugAssertEnabled()
  %14 = icmp ne i8 %13, 0
  br i1 %14, label %15, label %25

15:                                               ; preds = %12
  %16 = load i8, ptr %7, align 1, !tbaa !9
  %17 = zext i8 %16 to i32
  %18 = icmp eq i32 %17, 4
  br i1 %18, label %24, label %19

19:                                               ; preds = %15
  %20 = load i8, ptr %7, align 1, !tbaa !9
  %21 = zext i8 %20 to i32
  %22 = icmp eq i32 %21, 6
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1181, ptr noundef @.str.4)
  br label %24

24:                                               ; preds = %23, %19, %15
  br label %25

25:                                               ; preds = %24, %12
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = call ptr @AllocateZeroPool(i64 noundef 152)
  store ptr %28, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = icmp eq ptr null, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %99

32:                                               ; preds = %27
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._IP_IO, ptr %33, i32 0, i32 9
  %35 = call ptr @InitializeListHead(ptr noundef %34)
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._IP_IO, ptr %36, i32 0, i32 1
  %38 = call ptr @InitializeListHead(ptr noundef %37)
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._IP_IO, ptr %40, i32 0, i32 2
  store ptr %39, ptr %41, align 8, !tbaa !10
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._IP_IO, ptr %43, i32 0, i32 3
  store ptr %42, ptr %44, align 8, !tbaa !13
  %45 = load i8, ptr %7, align 1, !tbaa !9
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._IP_IO, ptr %46, i32 0, i32 14
  store i8 %45, ptr %47, align 8, !tbaa !14
  store ptr null, ptr %10, align 8, !tbaa !5
  %48 = load ptr, ptr @gBS, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %48, i32 0, i32 8
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = call i64 %50(i32 noundef 512, i64 noundef 16, ptr noundef @IpIoListenHandler, ptr noundef %51, ptr noundef %10)
  store i64 %52, ptr %8, align 8, !tbaa !20
  %53 = load i64, ptr %8, align 8, !tbaa !20
  %54 = icmp slt i64 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %32
  br label %84

56:                                               ; preds = %32
  %57 = load i8, ptr %7, align 1, !tbaa !9
  %58 = zext i8 %57 to i32
  %59 = icmp eq i32 %58, 4
  br i1 %59, label %60, label %65

60:                                               ; preds = %56
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._IP_IO, ptr %62, i32 0, i32 8
  %64 = getelementptr inbounds %struct.EFI_IP4_COMPLETION_TOKEN, ptr %63, i32 0, i32 0
  store ptr %61, ptr %64, align 8, !tbaa !9
  br label %70

65:                                               ; preds = %56
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._IP_IO, ptr %67, i32 0, i32 8
  %69 = getelementptr inbounds %struct.EFI_IP6_COMPLETION_TOKEN, ptr %68, i32 0, i32 0
  store ptr %66, ptr %69, align 8, !tbaa !9
  br label %70

70:                                               ; preds = %65, %60
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._IP_IO, ptr %73, i32 0, i32 4
  %75 = load i8, ptr %7, align 1, !tbaa !9
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._IP_IO, ptr %76, i32 0, i32 5
  %78 = call i64 @IpIoCreateIpChildOpenProtocol(ptr noundef %71, ptr noundef %72, ptr noundef %74, i8 noundef zeroext %75, ptr noundef %77)
  store i64 %78, ptr %8, align 8, !tbaa !20
  %79 = load i64, ptr %8, align 8, !tbaa !20
  %80 = icmp slt i64 %79, 0
  br i1 %80, label %81, label %82

81:                                               ; preds = %70
  br label %84

82:                                               ; preds = %70
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %83, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %99

84:                                               ; preds = %81, %55
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  %86 = icmp ne ptr %85, null
  br i1 %86, label %87, label %93

87:                                               ; preds = %84
  %88 = load ptr, ptr @gBS, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %88, i32 0, i32 12
  %90 = load ptr, ptr %89, align 8, !tbaa !21
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  %92 = call i64 %90(ptr noundef %91)
  br label %93

93:                                               ; preds = %87, %84
  %94 = load ptr, ptr @gBS, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %94, i32 0, i32 7
  %96 = load ptr, ptr %95, align 8, !tbaa !22
  %97 = load ptr, ptr %9, align 8, !tbaa !5
  %98 = call i64 %96(ptr noundef %97)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %99

99:                                               ; preds = %93, %82, %31
  call void @llvm.lifetime.end.p0(i64 8, 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
  %100 = load ptr, ptr %4, align 8
  ret ptr %100
}

declare ptr @AllocateZeroPool(i64 noundef) #2

declare ptr @InitializeListHead(ptr 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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 32}
!11 = !{!"_IP_IO", !12, i64 0, !12, i64 16, !6, i64 32, !6, i64 40, !6, i64 48, !7, i64 56, !7, i64 64, !7, i64 65, !7, i64 72, !12, i64 96, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !7, i64 144}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!11, !6, i64 40}
!14 = !{!11, !7, i64 144}
!15 = !{!16, !6, i64 80}
!16 = !{!"", !17, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!17 = !{!"", !18, i64 0, !19, i64 8, !19, i64 12, !19, i64 16, !19, i64 20}
!18 = !{!"long long", !7, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!18, !18, i64 0}
!21 = !{!16, !6, i64 112}
!22 = !{!16, !6, i64 72}


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

@gBS = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [146 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @IpIoCreateIpChildOpenProtocol(ptr noundef, ptr noundef, ptr noundef, i8 noundef zeroext, 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

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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @IpIoCreate(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %5 = tail call zeroext i8 @DebugAssertEnabled() #3
  %.not = icmp eq i8 %5, 0
  %6 = and i8 %2, -3
  %or.cond = icmp eq i8 %6, 4
  %or.cond29 = or i1 %or.cond, %.not
  br i1 %or.cond29, label %8, label %7

7:                                                ; preds = %3
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1181, ptr noundef nonnull @.str.4) #3
  br label %8

8:                                                ; preds = %7, %3
  %9 = tail call ptr @AllocateZeroPool(i64 noundef 152) #3
  %10 = icmp eq ptr %9, null
  br i1 %10, label %42, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %9, i64 96
  %13 = tail call ptr @InitializeListHead(ptr noundef nonnull %12) #3
  %14 = getelementptr inbounds i8, ptr %9, i64 16
  %15 = tail call ptr @InitializeListHead(ptr noundef nonnull %14) #3
  %16 = getelementptr inbounds i8, ptr %9, i64 32
  store ptr %1, ptr %16, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %9, i64 40
  store ptr %0, ptr %17, align 8, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %9, i64 144
  store i8 %2, ptr %18, align 8, !tbaa !12
  store ptr null, ptr %4, align 8, !tbaa !13
  %19 = load ptr, ptr @gBS, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %19, i64 80
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = call i64 %21(i32 noundef 512, i64 noundef 16, ptr noundef nonnull @IpIoListenHandler, ptr noundef nonnull %9, ptr noundef nonnull %4) #3
  %23 = icmp slt i64 %22, 0
  br i1 %23, label %30, label %24

24:                                               ; preds = %11
  %.sink = load ptr, ptr %4, align 8, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %9, i64 72
  store ptr %.sink, ptr %25, align 8
  %26 = getelementptr inbounds i8, ptr %9, i64 48
  %27 = getelementptr inbounds i8, ptr %9, i64 56
  %28 = call i64 @IpIoCreateIpChildOpenProtocol(ptr noundef %1, ptr noundef %0, ptr noundef nonnull %26, i8 noundef zeroext %2, ptr noundef nonnull %27)
  %29 = icmp slt i64 %28, 0
  br i1 %29, label %30, label %42

30:                                               ; preds = %24, %11
  %31 = load ptr, ptr %4, align 8, !tbaa !13
  %.not28 = icmp eq ptr %31, null
  br i1 %.not28, label %37, label %32

32:                                               ; preds = %30
  %33 = load ptr, ptr @gBS, align 8, !tbaa !13
  %34 = getelementptr inbounds i8, ptr %33, i64 112
  %35 = load ptr, ptr %34, align 8, !tbaa !19
  %36 = call i64 %35(ptr noundef nonnull %31) #3
  br label %37

37:                                               ; preds = %32, %30
  %38 = load ptr, ptr @gBS, align 8, !tbaa !13
  %39 = getelementptr inbounds i8, ptr %38, i64 72
  %40 = load ptr, ptr %39, align 8, !tbaa !20
  %41 = call i64 %40(ptr noundef nonnull %9) #3
  br label %42

42:                                               ; preds = %24, %8, %37
  %.0 = phi ptr [ null, %37 ], [ null, %8 ], [ %9, %24 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret ptr %.0
}

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #2

declare ptr @InitializeListHead(ptr 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, !8, i64 32}
!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, !8, i64 40}
!12 = !{!6, !9, i64 144}
!13 = !{!8, !8, i64 0}
!14 = !{!15, !8, i64 80}
!15 = !{!"", !16, i64 0, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !8, i64 96, !8, i64 104, !8, i64 112, !8, i64 120, !8, i64 128, !8, i64 136, !8, i64 144, !8, i64 152, !8, i64 160, !8, i64 168, !8, i64 176, !8, i64 184, !8, i64 192, !8, i64 200, !8, i64 208, !8, i64 216, !8, i64 224, !8, i64 232, !8, i64 240, !8, i64 248, !8, i64 256, !8, i64 264, !8, i64 272, !8, i64 280, !8, i64 288, !8, i64 296, !8, i64 304, !8, i64 312, !8, i64 320, !8, i64 328, !8, i64 336, !8, i64 344, !8, i64 352, !8, i64 360, !8, i64 368}
!16 = !{!"", !17, i64 0, !18, i64 8, !18, i64 12, !18, i64 16, !18, i64 20}
!17 = !{!"long long", !9, i64 0}
!18 = !{!"int", !9, i64 0}
!19 = !{!15, !8, i64 112}
!20 = !{!15, !8, i64 72}


; Effective O3 passes: ADCEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass