; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/OptionRomPkg/Bus/Usb (MCastIPtoMAC)

; 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.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct._EFI_SIMPLE_NETWORK_PROTOCOL = type { i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_SIMPLE_NETWORK_MODE = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x %struct.EFI_MAC_ADDRESS], %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, i8, i8, i8, i8, i8 }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }

@gBS = external global ptr, align 8

; 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 @SN_MCastIPtoMAC(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i8 %1, ptr %7, align 1, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %13 = load ptr, ptr @gBS, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !10
  %16 = call i64 %15(i64 noundef 8)
  store i64 %16, ptr %11, align 8, !tbaa !15
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %24

19:                                               ; preds = %4
  %20 = load ptr, ptr @gBS, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = load i64, ptr %11, align 8, !tbaa !15
  call void %22(i64 noundef %23)
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %111

24:                                               ; preds = %4
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %30, label %27

27:                                               ; preds = %24
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %35

30:                                               ; preds = %27, %24
  %31 = load ptr, ptr @gBS, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  %34 = load i64, ptr %11, align 8, !tbaa !15
  call void %33(i64 noundef %34)
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %111

35:                                               ; preds = %27
  %36 = load i8, ptr %7, align 1, !tbaa !9
  %37 = icmp ne i8 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  store i64 -9223372036854775805, ptr %10, align 8, !tbaa !15
  br label %109

39:                                               ; preds = %35
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.EFI_IPv4_ADDRESS, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds [4 x i8], ptr %41, i64 0, i64 0
  %43 = load i8, ptr %42, align 4, !tbaa !9
  %44 = zext i8 %43 to i32
  %45 = and i32 %44, 240
  %46 = icmp ne i32 %45, 224
  br i1 %46, label %47, label %52

47:                                               ; preds = %39
  %48 = load ptr, ptr @gBS, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !16
  %51 = load i64, ptr %11, align 8, !tbaa !15
  call void %50(i64 noundef %51)
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %111

52:                                               ; preds = %39
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._EFI_SIMPLE_NETWORK_PROTOCOL, ptr %53, i32 0, i32 15
  %55 = load ptr, ptr %54, align 8, !tbaa !17
  %56 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 4, !tbaa !19
  %58 = icmp eq i32 %57, 2
  br i1 %58, label %59, label %93

59:                                               ; preds = %52
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds [32 x i8], ptr %61, i64 0, i64 0
  store i8 1, ptr %62, align 1, !tbaa !9
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds [32 x i8], ptr %64, i64 0, i64 1
  store i8 0, ptr %65, align 1, !tbaa !9
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %66, i32 0, i32 0
  %68 = getelementptr inbounds [32 x i8], ptr %67, i64 0, i64 2
  store i8 94, ptr %68, align 1, !tbaa !9
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.EFI_IPv4_ADDRESS, ptr %69, i32 0, i32 0
  %71 = getelementptr inbounds [4 x i8], ptr %70, i64 0, i64 1
  %72 = load i8, ptr %71, align 1, !tbaa !9
  %73 = zext i8 %72 to i32
  %74 = and i32 %73, 127
  %75 = trunc i32 %74 to i8
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %76, i32 0, i32 0
  %78 = getelementptr inbounds [32 x i8], ptr %77, i64 0, i64 3
  store i8 %75, ptr %78, align 1, !tbaa !9
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.EFI_IPv4_ADDRESS, ptr %79, i32 0, i32 0
  %81 = getelementptr inbounds [4 x i8], ptr %80, i64 0, i64 2
  %82 = load i8, ptr %81, align 2, !tbaa !9
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %83, i32 0, i32 0
  %85 = getelementptr inbounds [32 x i8], ptr %84, i64 0, i64 4
  store i8 %82, ptr %85, align 1, !tbaa !9
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.EFI_IPv4_ADDRESS, ptr %86, i32 0, i32 0
  %88 = getelementptr inbounds [4 x i8], ptr %87, i64 0, i64 3
  %89 = load i8, ptr %88, align 1, !tbaa !9
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %90, i32 0, i32 0
  %92 = getelementptr inbounds [32 x i8], ptr %91, i64 0, i64 5
  store i8 %89, ptr %92, align 1, !tbaa !9
  store i64 0, ptr %10, align 8, !tbaa !15
  br label %103

93:                                               ; preds = %52
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct._EFI_SIMPLE_NETWORK_PROTOCOL, ptr %94, i32 0, i32 15
  %96 = load ptr, ptr %95, align 8, !tbaa !17
  %97 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %96, i32 0, i32 0
  %98 = load i32, ptr %97, align 4, !tbaa !19
  %99 = icmp eq i32 %98, 1
  br i1 %99, label %100, label %101

100:                                              ; preds = %93
  store i64 -9223372036854775801, ptr %10, align 8, !tbaa !15
  br label %102

101:                                              ; preds = %93
  store i64 -9223372036854775789, ptr %10, align 8, !tbaa !15
  br label %102

102:                                              ; preds = %101, %100
  br label %103

103:                                              ; preds = %102, %59
  %104 = load ptr, ptr @gBS, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %104, i32 0, i32 2
  %106 = load ptr, ptr %105, align 8, !tbaa !16
  %107 = load i64, ptr %11, align 8, !tbaa !15
  call void %106(i64 noundef %107)
  br label %108

108:                                              ; preds = %103
  br label %109

109:                                              ; preds = %108, %38
  %110 = load i64, ptr %10, align 8, !tbaa !15
  store i64 %110, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %111

111:                                              ; preds = %109, %47, %30, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %112 = load i64, ptr %5, align 8
  ret i64 %112
}

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 = { 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 24}
!11 = !{!"", !12, 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}
!12 = !{!"", !13, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!11, !6, i64 32}
!17 = !{!18, !6, i64 120}
!18 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !13, 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, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120}
!19 = !{!20, !14, i64 0}
!20 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !7, i64 40, !21, i64 552, !21, i64 584, !21, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!21 = !{!"", !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"

@gBS = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @SN_MCastIPtoMAC(ptr noundef readonly %0, i8 noundef zeroext %1, ptr noundef readonly %2, ptr noundef writeonly %3) local_unnamed_addr #0 {
  %5 = load ptr, ptr @gBS, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = tail call i64 %7(i64 noundef 8) #1
  %9 = icmp eq ptr %0, null
  br i1 %9, label %.sink.split, label %10

10:                                               ; preds = %4
  %11 = icmp eq ptr %2, null
  %12 = icmp eq ptr %3, null
  %or.cond = or i1 %11, %12
  br i1 %or.cond, label %.sink.split, label %13

13:                                               ; preds = %10
  %.not = icmp eq i8 %1, 0
  br i1 %.not, label %14, label %38

14:                                               ; preds = %13
  %15 = load i8, ptr %2, align 4, !tbaa !14
  %16 = and i8 %15, -16
  %.not27 = icmp eq i8 %16, -32
  br i1 %.not27, label %17, label %.sink.split

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %0, i64 120
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = load i32, ptr %19, align 4, !tbaa !17
  switch i32 %20, label %34 [
    i32 2, label %21
    i32 1, label %.sink.split
  ]

21:                                               ; preds = %17
  store i8 1, ptr %3, align 1, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 0, ptr %22, align 1, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %3, i64 2
  store i8 94, ptr %23, align 1, !tbaa !14
  %24 = getelementptr inbounds i8, ptr %2, i64 1
  %25 = load i8, ptr %24, align 1, !tbaa !14
  %26 = and i8 %25, 127
  %27 = getelementptr inbounds i8, ptr %3, i64 3
  store i8 %26, ptr %27, align 1, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %2, i64 2
  %29 = load i8, ptr %28, align 2, !tbaa !14
  %30 = getelementptr inbounds i8, ptr %3, i64 4
  store i8 %29, ptr %30, align 1, !tbaa !14
  %31 = getelementptr inbounds i8, ptr %2, i64 3
  %32 = load i8, ptr %31, align 1, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %3, i64 5
  store i8 %32, ptr %33, align 1, !tbaa !14
  br label %.sink.split

34:                                               ; preds = %17
  br label %.sink.split

.sink.split:                                      ; preds = %21, %34, %17, %14, %10, %4
  %.0.ph = phi i64 [ -9223372036854775806, %4 ], [ -9223372036854775806, %10 ], [ -9223372036854775806, %14 ], [ 0, %21 ], [ -9223372036854775789, %34 ], [ -9223372036854775801, %17 ]
  %35 = load ptr, ptr @gBS, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 32
  %37 = load ptr, ptr %36, align 8, !tbaa !20
  tail call void %37(i64 noundef %8) #1
  br label %38

38:                                               ; preds = %.sink.split, %13
  %.0 = phi i64 [ -9223372036854775805, %13 ], [ %.0.ph, %.sink.split ]
  ret i64 %.0
}

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 = { 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 = !{!7, !7, i64 0}
!15 = !{!16, !6, i64 120}
!16 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !12, 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, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120}
!17 = !{!18, !13, i64 0}
!18 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !7, i64 40, !19, i64 552, !19, i64 584, !19, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!19 = !{!"", !7, i64 0}
!20 = !{!10, !6, i64 32}


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