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

; 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_SEND_ENTRY = type { %struct._LIST_ENTRY, ptr, ptr, ptr, %union.IP_IO_IP_PROTOCOL, ptr, %union.IP_IO_IP_COMPLETION_TOKEN }
%struct._EFI_IP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%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.7 = external hidden unnamed_addr constant [51 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: 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) #2

; Function Attrs: nounwind uwtable
define dso_local void @IpIoCancelTxToken(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %union.IP_IO_IP_PROTOCOL, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  br label %8

8:                                                ; preds = %2
  %9 = call zeroext i8 @DebugAssertEnabled()
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %11, label %19

11:                                               ; preds = %8
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %17

14:                                               ; preds = %11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %14, %11
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1572, ptr noundef @.str.7)
  br label %18

18:                                               ; preds = %17, %14
  br label %19

19:                                               ; preds = %18, %8
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._IP_IO, ptr %22, i32 0, i32 9
  %24 = getelementptr inbounds %struct._LIST_ENTRY, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  store ptr %25, ptr %5, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %67, %21
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._IP_IO, ptr %28, i32 0, i32 9
  %30 = icmp ne ptr %27, %29
  br i1 %30, label %31, label %71

31:                                               ; preds = %26
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = ptrtoint ptr %32 to i64
  %34 = sub i64 %33, 0
  %35 = inttoptr i64 %34 to ptr
  store ptr %35, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %36, i32 0, i32 5
  %38 = load ptr, ptr %37, align 8, !tbaa !12
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = icmp eq ptr %38, %39
  br i1 %40, label %41, label %66

41:                                               ; preds = %31
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %42, i32 0, i32 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %43, i64 8, i1 false), !tbaa.struct !14
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._IP_IO, ptr %44, i32 0, i32 14
  %46 = load i8, ptr %45, align 8, !tbaa !16
  %47 = zext i8 %46 to i32
  %48 = icmp eq i32 %47, 4
  br i1 %48, label %49, label %57

49:                                               ; preds = %41
  %50 = load ptr, ptr %7, align 8, !tbaa !15
  %51 = getelementptr inbounds %struct._EFI_IP4_PROTOCOL, ptr %50, i32 0, i32 6
  %52 = load ptr, ptr %51, align 8, !tbaa !17
  %53 = load ptr, ptr %7, align 8, !tbaa !15
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %54, i32 0, i32 6
  %56 = call i64 %52(ptr noundef %53, ptr noundef %55)
  br label %65

57:                                               ; preds = %41
  %58 = load ptr, ptr %7, align 8, !tbaa !15
  %59 = getelementptr inbounds %struct._EFI_IP6_PROTOCOL, ptr %58, i32 0, i32 7
  %60 = load ptr, ptr %59, align 8, !tbaa !19
  %61 = load ptr, ptr %7, align 8, !tbaa !15
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._IP_IO_SEND_ENTRY, ptr %62, i32 0, i32 6
  %64 = call i64 %60(ptr noundef %61, ptr noundef %63)
  br label %65

65:                                               ; preds = %57, %49
  br label %71

66:                                               ; preds = %31
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._LIST_ENTRY, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !21
  store ptr %70, ptr %5, align 8, !tbaa !5
  br label %26, !llvm.loop !22

71:                                               ; preds = %65, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !6, i64 96}
!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 = !{!13, !6, i64 48}
!13 = !{!"_IP_IO_SEND_ENTRY", !11, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !6, i64 48, !7, i64 56}
!14 = !{i64 0, i64 8, !15}
!15 = !{!7, !7, i64 0}
!16 = !{!10, !7, i64 144}
!17 = !{!18, !6, i64 48}
!18 = !{!"_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}
!19 = !{!20, !6, i64 56}
!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}
!21 = !{!11, !6, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; 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.7 = external hidden unnamed_addr constant [51 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
define dso_local void @IpIoCancelTxToken(ptr noundef readonly %0, ptr noundef readnone %1) local_unnamed_addr #1 {
  %3 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %8, label %4

4:                                                ; preds = %2
  %5 = icmp ne ptr %0, null
  %6 = icmp ne ptr %1, null
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %8, label %7

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

8:                                                ; preds = %7, %4, %2
  %9 = getelementptr inbounds i8, ptr %0, i64 96
  br label %10

10:                                               ; preds = %11, %8
  %.0.in = phi ptr [ %9, %8 ], [ %.0, %11 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not17 = icmp eq ptr %.0, %9
  br i1 %.not17, label %.loopexit, label %11

11:                                               ; preds = %10
  %12 = getelementptr inbounds i8, ptr %.0, i64 48
  %13 = load ptr, ptr %12, align 8, !tbaa !10
  %14 = icmp eq ptr %13, %1
  br i1 %14, label %.loopexit.sink.split, label %10, !llvm.loop !12

.loopexit.sink.split:                             ; preds = %11
  %15 = getelementptr inbounds i8, ptr %.0, i64 40
  %.sroa.0.0.copyload = load ptr, ptr %15, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %0, i64 144
  %17 = load i8, ptr %16, align 8, !tbaa !15
  %18 = icmp eq i8 %17, 4
  %19 = getelementptr inbounds i8, ptr %.0, i64 56
  %. = select i1 %18, i64 48, i64 56
  %20 = getelementptr inbounds i8, ptr %.sroa.0.0.copyload, i64 %.
  %21 = load ptr, ptr %20, align 8, !tbaa !17
  %22 = tail call i64 %21(ptr noundef %.sroa.0.0.copyload, ptr noundef nonnull %19) #2
  br label %.loopexit

.loopexit:                                        ; preds = %10, %.loopexit.sink.split
  ret void
}

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, !7, i64 0}
!6 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 48}
!11 = !{!"_IP_IO_SEND_ENTRY", !6, i64 0, !7, i64 16, !7, i64 24, !7, i64 32, !8, i64 40, !7, i64 48, !8, i64 56}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !8, i64 144}
!16 = !{!"_IP_IO", !6, i64 0, !6, i64 16, !7, i64 32, !7, i64 40, !7, i64 48, !8, i64 56, !8, i64 64, !8, i64 65, !8, i64 72, !6, i64 96, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !8, i64 144}
!17 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass