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

; 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_PROTOCOL = type { i32, %struct._EFI_IP4_PROTOCOL, ptr, i64, ptr, %struct._LIST_ENTRY, %struct.NET_MAP, %struct.NET_MAP, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct.EFI_LOCK, ptr, %struct._LIST_ENTRY, ptr, ptr, i32, ptr, i32, %struct.EFI_IP4_CONFIG_DATA }
%struct._EFI_IP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct.EFI_LOCK = type { i64, i64, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_IP4_CONFIG_DATA = type { i8, i8, i8, i8, i8, i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i8, i8, i8, i8, i32, i32 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }

; 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

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip4Cancel(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._IP4_PROTOCOL, ptr %8, i32 0, i32 7
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = call i64 @NetMapIterate(ptr noundef %9, ptr noundef @Ip4CancelTxTokens, ptr noundef %10)
  store i64 %11, ptr %6, align 8, !tbaa !9
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = icmp slt i64 %12, 0
  br i1 %13, label %14, label %23

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

17:                                               ; preds = %14
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = icmp eq i64 %18, -9223372036854775787
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  store i64 0, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %56

21:                                               ; preds = %17, %14
  %22 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %22, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %56

23:                                               ; preds = %2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._IP4_PROTOCOL, ptr %24, i32 0, i32 6
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call i64 @NetMapIterate(ptr noundef %25, ptr noundef @Ip4CancelRxTokens, ptr noundef %26)
  store i64 %27, ptr %6, align 8, !tbaa !9
  %28 = call i64 @DispatchDpc()
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = icmp slt i64 %29, 0
  br i1 %30, label %31, label %40

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

34:                                               ; preds = %31
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = icmp eq i64 %35, -9223372036854775787
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  store i64 0, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %56

38:                                               ; preds = %34, %31
  %39 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %39, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %56

40:                                               ; preds = %23
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %44

43:                                               ; preds = %40
  store i64 -9223372036854775794, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %56

44:                                               ; preds = %40
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._IP4_PROTOCOL, ptr %45, i32 0, i32 7
  %47 = call zeroext i8 @NetMapIsEmpty(ptr noundef %46)
  %48 = icmp ne i8 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %44
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._IP4_PROTOCOL, ptr %50, i32 0, i32 6
  %52 = call zeroext i8 @NetMapIsEmpty(ptr noundef %51)
  %53 = icmp ne i8 %52, 0
  br i1 %53, label %55, label %54

54:                                               ; preds = %49, %44
  store i64 -9223372036854775801, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %56

55:                                               ; preds = %49
  store i64 0, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %56

56:                                               ; preds = %55, %54, %43, %38, %37, %21, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %57 = load i64, ptr %3, align 8
  ret i64 %57
}

declare i64 @DispatchDpc() #2

declare i64 @NetMapIterate(ptr noundef, ptr noundef, ptr noundef) #2

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

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

declare zeroext i8 @NetMapIsEmpty(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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}


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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @Ip4Cancel(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 152
  %4 = tail call i64 @NetMapIterate(ptr noundef nonnull %3, ptr noundef nonnull @Ip4CancelTxTokens, ptr noundef %1) #2
  %5 = icmp slt i64 %4, 0
  br i1 %5, label %6, label %9

6:                                                ; preds = %2
  %7 = icmp ne ptr %1, null
  %8 = icmp eq i64 %4, -9223372036854775787
  %or.cond = and i1 %7, %8
  %. = select i1 %or.cond, i64 0, i64 %4
  br label %22

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 112
  %11 = tail call i64 @NetMapIterate(ptr noundef nonnull %10, ptr noundef nonnull @Ip4CancelRxTokens, ptr noundef %1) #2
  %12 = tail call i64 @DispatchDpc() #2
  %13 = icmp slt i64 %11, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %9
  %15 = icmp ne ptr %1, null
  %16 = icmp eq i64 %11, -9223372036854775787
  %or.cond3 = select i1 %15, i1 %16, i1 false
  %.22 = select i1 %or.cond3, i64 0, i64 %11
  br label %22

17:                                               ; preds = %9
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %18, label %22

18:                                               ; preds = %17
  %19 = tail call zeroext i8 @NetMapIsEmpty(ptr noundef nonnull %3) #2
  %.not20 = icmp eq i8 %19, 0
  br i1 %.not20, label %22, label %20

20:                                               ; preds = %18
  %21 = tail call zeroext i8 @NetMapIsEmpty(ptr noundef nonnull %10) #2
  %.not21 = icmp eq i8 %21, 0
  %spec.select = select i1 %.not21, i64 -9223372036854775801, i64 0
  br label %22

22:                                               ; preds = %20, %18, %17, %14, %6
  %.0 = phi i64 [ %., %6 ], [ %.22, %14 ], [ -9223372036854775794, %17 ], [ -9223372036854775801, %18 ], [ %spec.select, %20 ]
  ret i64 %.0
}

declare i64 @DispatchDpc() local_unnamed_addr #1

declare i64 @NetMapIterate(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

declare zeroext i8 @NetMapIsEmpty(ptr noundef) local_unnamed_addr #1

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 = { "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)"}


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