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

; 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._UDP4_INSTANCE_DATA_ = type { i32, %struct._LIST_ENTRY, ptr, %struct._EFI_UDP4_PROTOCOL, %struct.EFI_UDP4_CONFIG_DATA, ptr, i8, i8, %struct.NET_MAP, %struct.NET_MAP, %struct.NET_MAP, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i16, i64, ptr, i8 }
%struct._EFI_UDP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_UDP4_CONFIG_DATA = type { i8, i8, i8, i8, i8, i8, i8, i32, i32, i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, %struct.EFI_IPv4_ADDRESS, i16 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct._LIST_ENTRY = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [120 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 i64 @Udp4CancelTokens(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @Udp4InstanceCancelToken(ptr noundef %0, ptr noundef %1) #2 {
  %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._UDP4_INSTANCE_DATA_, ptr %8, i32 0, i32 8
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = call i64 @NetMapIterate(ptr noundef %9, ptr noundef @Udp4CancelTokens, ptr noundef %10)
  store i64 %11, ptr %6, align 8, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %18

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

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

18:                                               ; preds = %14, %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._UDP4_INSTANCE_DATA_, ptr %19, i32 0, i32 9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call i64 @NetMapIterate(ptr noundef %20, ptr noundef @Udp4CancelTokens, ptr noundef %21)
  store i64 %22, ptr %6, align 8, !tbaa !9
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %29

25:                                               ; preds = %18
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  store i64 -9223372036854775794, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %51

29:                                               ; preds = %25, %18
  br label %30

30:                                               ; preds = %29
  %31 = call zeroext i8 @DebugAssertEnabled()
  %32 = icmp ne i8 %31, 0
  br i1 %32, label %33, label %48

33:                                               ; preds = %30
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %47, label %36

36:                                               ; preds = %33
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._UDP4_INSTANCE_DATA_, ptr %37, i32 0, i32 8
  %39 = call i64 @NetMapGetCount(ptr noundef %38)
  %40 = icmp eq i64 0, %39
  br i1 %40, label %41, label %46

41:                                               ; preds = %36
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._UDP4_INSTANCE_DATA_, ptr %42, i32 0, i32 9
  %44 = call i64 @NetMapGetCount(ptr noundef %43)
  %45 = icmp eq i64 0, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %41, %36
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1255, ptr noundef @.str.4)
  br label %47

47:                                               ; preds = %46, %41, %33
  br label %48

48:                                               ; preds = %47, %30
  br label %49

49:                                               ; preds = %48
  br label %50

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

51:                                               ; preds = %50, %28, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %52 = load i64, ptr %3, align 8
  ret i64 %52
}

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

declare i64 @NetMapGetCount(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}


; 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 [151 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [120 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 i64 @Udp4CancelTokens(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775794, 1) i64 @Udp4InstanceCancelToken(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 152
  %4 = tail call i64 @NetMapIterate(ptr noundef nonnull %3, ptr noundef nonnull @Udp4CancelTokens, ptr noundef %1) #2
  %5 = icmp ne ptr %1, null
  %6 = icmp eq i64 %4, -9223372036854775787
  %or.cond = select i1 %5, i1 %6, i1 false
  br i1 %or.cond, label %21, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 192
  %9 = tail call i64 @NetMapIterate(ptr noundef nonnull %8, ptr noundef nonnull @Udp4CancelTokens, ptr noundef %1) #2
  %10 = icmp eq i64 %9, 0
  %or.cond3 = select i1 %5, i1 %10, i1 false
  br i1 %or.cond3, label %21, label %11

11:                                               ; preds = %7
  %12 = tail call zeroext i8 @DebugAssertEnabled() #2
  %13 = icmp eq i8 %12, 0
  %or.cond5 = or i1 %5, %13
  br i1 %or.cond5, label %21, label %14

14:                                               ; preds = %11
  %15 = tail call i64 @NetMapGetCount(ptr noundef nonnull %3) #2
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %14
  %18 = tail call i64 @NetMapGetCount(ptr noundef nonnull %8) #2
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %17, %14
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1255, ptr noundef nonnull @.str.4) #2
  br label %21

21:                                               ; preds = %11, %20, %17, %7, %2
  %.0 = phi i64 [ 0, %2 ], [ -9223372036854775794, %7 ], [ 0, %17 ], [ 0, %20 ], [ 0, %11 ]
  ret i64 %.0
}

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

declare i64 @NetMapGetCount(ptr noundef) local_unnamed_addr #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)"}


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