; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/Mtftp6Dxe (EfiMtftp6GetModeData)

; 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.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._MTFTP6_INSTANCE = type { i32, ptr, %struct._LIST_ENTRY, %struct._EFI_MTFTP6_PROTOCOL, ptr, ptr, ptr, %struct.MTFTP6_EXT_OPTION_INFO, i16, i16, %struct._LIST_ENTRY, %struct.EFI_IPv6_ADDRESS, i16, i16, ptr, %struct.EFI_IPv6_ADDRESS, i16, ptr, ptr, i32, i32, i32, i32, i64, i8, i8, i8 }
%struct._EFI_MTFTP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.MTFTP6_EXT_OPTION_INFO = type { i16, i8, i32, %struct.EFI_IPv6_ADDRESS, i16, i8, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct.EFI_MTFTP6_MODE_DATA = type { %struct.EFI_MTFTP6_CONFIG_DATA, i8, ptr }
%struct.EFI_MTFTP6_CONFIG_DATA = type { %struct.EFI_IPv6_ADDRESS, i16, %struct.EFI_IPv6_ADDRESS, i16, i16, i16 }

@gBS = external global ptr, align 8
@.str = external hidden unnamed_addr constant [135 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@mMtftp6SupportedOptions = external global [4 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local i64 @EfiMtftp6GetModeData(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %14, label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %2
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %64

15:                                               ; preds = %11
  %16 = load ptr, ptr @gBS, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = call i64 %18(i64 noundef 8)
  store i64 %19, ptr %7, align 8, !tbaa !14
  %20 = call zeroext i8 @DebugAssertEnabled()
  %21 = zext i8 %20 to i32
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %33

23:                                               ; preds = %15
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = ptrtoint ptr %24 to i64
  %26 = sub i64 %25, ptrtoint (ptr getelementptr inbounds (%struct._MTFTP6_INSTANCE, ptr null, i32 0, i32 3) to i64)
  %27 = inttoptr i64 %26 to ptr
  %28 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !15
  %30 = icmp ne i32 %29, 1228293709
  br i1 %30, label %31, label %33

31:                                               ; preds = %23
  call void @DebugAssert(ptr noundef @.str, i64 noundef 66, ptr noundef @.str.1)
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  br label %38

33:                                               ; preds = %23, %15
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = ptrtoint ptr %34 to i64
  %36 = sub i64 %35, ptrtoint (ptr getelementptr inbounds (%struct._MTFTP6_INSTANCE, ptr null, i32 0, i32 3) to i64)
  %37 = inttoptr i64 %36 to ptr
  br label %38

38:                                               ; preds = %33, %31
  %39 = phi ptr [ %32, %31 ], [ %37, %33 ]
  store ptr %39, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %40, i32 0, i32 5
  %42 = load ptr, ptr %41, align 8, !tbaa !22
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %51

44:                                               ; preds = %38
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.EFI_MTFTP6_MODE_DATA, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %47, i32 0, i32 5
  %49 = load ptr, ptr %48, align 8, !tbaa !22
  %50 = call ptr @CopyMem(ptr noundef %46, ptr noundef %49, i64 noundef 40)
  br label %55

51:                                               ; preds = %38
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.EFI_MTFTP6_MODE_DATA, ptr %52, i32 0, i32 0
  %54 = call ptr @ZeroMem(ptr noundef %53, i64 noundef 40)
  br label %55

55:                                               ; preds = %51, %44
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.EFI_MTFTP6_MODE_DATA, ptr %56, i32 0, i32 1
  store i8 4, ptr %57, align 8, !tbaa !23
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.EFI_MTFTP6_MODE_DATA, ptr %58, i32 0, i32 2
  store ptr @mMtftp6SupportedOptions, ptr %59, align 8, !tbaa !26
  %60 = load ptr, ptr @gBS, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !27
  %63 = load i64, ptr %7, align 8, !tbaa !14
  call void %62(i64 noundef %63)
  store i64 0, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %64

64:                                               ; preds = %55, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %65 = load i64, ptr %3, align 8
  ret i64 %65
}

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

declare zeroext i8 @DebugAssertEnabled() #2

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = !{!10, !6, i64 24}
!10 = !{!"", !11, 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}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!16, !13, i64 0}
!16 = !{!"_MTFTP6_INSTANCE", !13, i64 0, !6, i64 8, !17, i64 16, !18, i64 32, !6, i64 96, !6, i64 104, !6, i64 112, !19, i64 120, !20, i64 152, !20, i64 154, !17, i64 160, !21, i64 176, !20, i64 192, !20, i64 194, !6, i64 200, !21, i64 208, !20, i64 224, !6, i64 232, !6, i64 240, !13, i64 248, !13, i64 252, !13, i64 256, !13, i64 260, !12, i64 264, !7, i64 272, !7, i64 273, !7, i64 274}
!17 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!18 = !{!"_EFI_MTFTP6_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, i64 0, !7, i64 2, !13, i64 4, !21, i64 8, !20, i64 24, !7, i64 26, !13, i64 28}
!20 = !{!"short", !7, i64 0}
!21 = !{!"", !7, i64 0}
!22 = !{!16, !6, i64 104}
!23 = !{!24, !7, i64 40}
!24 = !{!"", !25, i64 0, !7, i64 40, !6, i64 48}
!25 = !{!"", !21, i64 0, !20, i64 16, !21, i64 18, !20, i64 34, !20, i64 36, !20, i64 38}
!26 = !{!24, !6, i64 48}
!27 = !{!10, !6, i64 32}


; 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 [135 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@mMtftp6SupportedOptions = external global [4 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @EfiMtftp6GetModeData(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %27, label %5

5:                                                ; preds = %2
  %6 = load ptr, ptr @gBS, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = tail call i64 %8(i64 noundef 8) #2
  %10 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %10, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre18 = add i64 %.pre, -32
  %.pre20 = inttoptr i64 %.pre18 to ptr
  br i1 %.not, label %._crit_edge, label %11

11:                                               ; preds = %5
  %12 = load i32, ptr %.pre20, align 8, !tbaa !14
  %.not16 = icmp eq i32 %12, 1228293709
  br i1 %.not16, label %._crit_edge, label %13

13:                                               ; preds = %11
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 66, ptr noundef nonnull @.str.1) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %5, %11, %13
  %14 = phi ptr [ %0, %13 ], [ %.pre20, %11 ], [ %.pre20, %5 ]
  %15 = getelementptr inbounds i8, ptr %14, i64 104
  %16 = load ptr, ptr %15, align 8, !tbaa !21
  %.not17 = icmp eq ptr %16, null
  br i1 %.not17, label %19, label %17

17:                                               ; preds = %._crit_edge
  %18 = tail call ptr @CopyMem(ptr noundef nonnull %1, ptr noundef nonnull %16, i64 noundef 40) #2
  br label %21

19:                                               ; preds = %._crit_edge
  %20 = tail call ptr @ZeroMem(ptr noundef nonnull %1, i64 noundef 40) #2
  br label %21

21:                                               ; preds = %19, %17
  %22 = getelementptr inbounds i8, ptr %1, i64 40
  store i8 4, ptr %22, align 8, !tbaa !22
  %23 = getelementptr inbounds i8, ptr %1, i64 48
  store ptr @mMtftp6SupportedOptions, ptr %23, align 8, !tbaa !25
  %24 = load ptr, ptr @gBS, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 32
  %26 = load ptr, ptr %25, align 8, !tbaa !26
  tail call void %26(i64 noundef %9) #2
  br label %27

27:                                               ; preds = %2, %21
  %.0 = phi i64 [ 0, %21 ], [ -9223372036854775806, %2 ]
  ret i64 %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

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

declare ptr @ZeroMem(ptr noundef, i64 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)"}
!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 24}
!10 = !{!"", !11, 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}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"_MTFTP6_INSTANCE", !13, i64 0, !6, i64 8, !16, i64 16, !17, i64 32, !6, i64 96, !6, i64 104, !6, i64 112, !18, i64 120, !19, i64 152, !19, i64 154, !16, i64 160, !20, i64 176, !19, i64 192, !19, i64 194, !6, i64 200, !20, i64 208, !19, i64 224, !6, i64 232, !6, i64 240, !13, i64 248, !13, i64 252, !13, i64 256, !13, i64 260, !12, i64 264, !7, i64 272, !7, i64 273, !7, i64 274}
!16 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!17 = !{!"_EFI_MTFTP6_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}
!18 = !{!"", !19, i64 0, !7, i64 2, !13, i64 4, !20, i64 8, !19, i64 24, !7, i64 26, !13, i64 28}
!19 = !{!"short", !7, i64 0}
!20 = !{!"", !7, i64 0}
!21 = !{!15, !6, i64 104}
!22 = !{!23, !7, i64 40}
!23 = !{!"", !24, i64 0, !7, i64 40, !6, i64 48}
!24 = !{!"", !20, i64 0, !19, i64 16, !20, i64 18, !19, i64 34, !19, i64 36, !19, i64 38}
!25 = !{!23, !6, i64 48}
!26 = !{!10, !6, i64 32}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass