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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @Mtftp6RrqOackValid(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.MTFTP6_EXT_OPTION_INFO, ptr %8, i32 0, i32 6
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.MTFTP6_EXT_OPTION_INFO, ptr %11, i32 0, i32 6
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = xor i32 %13, -1
  %15 = and i32 %10, %14
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  store i8 0, ptr %4, align 1
  br label %94

18:                                               ; preds = %3
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.MTFTP6_EXT_OPTION_INFO, ptr %19, i32 0, i32 6
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = and i32 %21, 1
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %34

24:                                               ; preds = %18
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.MTFTP6_EXT_OPTION_INFO, ptr %25, i32 0, i32 0
  %27 = load i16, ptr %26, align 4, !tbaa !14
  %28 = zext i16 %27 to i32
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.MTFTP6_EXT_OPTION_INFO, ptr %29, i32 0, i32 0
  %31 = load i16, ptr %30, align 4, !tbaa !14
  %32 = zext i16 %31 to i32
  %33 = icmp sgt i32 %28, %32
  br i1 %33, label %50, label %34

34:                                               ; preds = %24, %18
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.MTFTP6_EXT_OPTION_INFO, ptr %35, i32 0, i32 6
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = and i32 %37, 2
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %51

40:                                               ; preds = %34
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.MTFTP6_EXT_OPTION_INFO, ptr %41, i32 0, i32 1
  %43 = load i8, ptr %42, align 2, !tbaa !15
  %44 = zext i8 %43 to i32
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.MTFTP6_EXT_OPTION_INFO, ptr %45, i32 0, i32 1
  %47 = load i8, ptr %46, align 2, !tbaa !15
  %48 = zext i8 %47 to i32
  %49 = icmp ne i32 %44, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %40, %24
  store i8 0, ptr %4, align 1
  br label %94

51:                                               ; preds = %40, %34
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.MTFTP6_EXT_OPTION_INFO, ptr %52, i32 0, i32 6
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = and i32 %54, 8
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %93

57:                                               ; preds = %51
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %58, i32 0, i32 15
  %60 = call zeroext i8 @NetIp6IsUnspecifiedAddr(ptr noundef %59)
  %61 = icmp ne i8 %60, 0
  br i1 %61, label %93, label %62

62:                                               ; preds = %57
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.MTFTP6_EXT_OPTION_INFO, ptr %63, i32 0, i32 3
  %65 = call zeroext i8 @NetIp6IsUnspecifiedAddr(ptr noundef %64)
  %66 = icmp ne i8 %65, 0
  br i1 %66, label %75, label %67

67:                                               ; preds = %62
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.MTFTP6_EXT_OPTION_INFO, ptr %68, i32 0, i32 3
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %70, i32 0, i32 15
  %72 = call i64 @CompareMem(ptr noundef %69, ptr noundef %71, i64 noundef 16)
  %73 = icmp ne i64 %72, 0
  br i1 %73, label %74, label %75

74:                                               ; preds = %67
  store i8 0, ptr %4, align 1
  br label %94

75:                                               ; preds = %67, %62
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.MTFTP6_EXT_OPTION_INFO, ptr %76, i32 0, i32 4
  %78 = load i16, ptr %77, align 4, !tbaa !16
  %79 = zext i16 %78 to i32
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %92

81:                                               ; preds = %75
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.MTFTP6_EXT_OPTION_INFO, ptr %82, i32 0, i32 4
  %84 = load i16, ptr %83, align 4, !tbaa !16
  %85 = zext i16 %84 to i32
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %86, i32 0, i32 16
  %88 = load i16, ptr %87, align 8, !tbaa !17
  %89 = zext i16 %88 to i32
  %90 = icmp ne i32 %85, %89
  br i1 %90, label %91, label %92

91:                                               ; preds = %81
  store i8 0, ptr %4, align 1
  br label %94

92:                                               ; preds = %81, %75
  br label %93

93:                                               ; preds = %92, %57, %51
  store i8 1, ptr %4, align 1
  br label %94

94:                                               ; preds = %93, %91, %74, %50, %17
  %95 = load i8, ptr %4, align 1
  ret i8 %95
}

declare zeroext i8 @NetIp6IsUnspecifiedAddr(ptr noundef) #1

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

!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, !12, i64 28}
!10 = !{!"", !11, i64 0, !7, i64 2, !12, i64 4, !13, i64 8, !11, i64 24, !7, i64 26, !12, i64 28}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !7, i64 0}
!14 = !{!10, !11, i64 0}
!15 = !{!10, !7, i64 2}
!16 = !{!10, !11, i64 24}
!17 = !{!18, !11, i64 224}
!18 = !{!"_MTFTP6_INSTANCE", !12, i64 0, !6, i64 8, !19, i64 16, !20, i64 32, !6, i64 96, !6, i64 104, !6, i64 112, !10, i64 120, !11, i64 152, !11, i64 154, !19, i64 160, !13, i64 176, !11, i64 192, !11, i64 194, !6, i64 200, !13, i64 208, !11, i64 224, !6, i64 232, !6, i64 240, !12, i64 248, !12, i64 252, !12, i64 256, !12, i64 260, !21, i64 264, !7, i64 272, !7, i64 273, !7, i64 274}
!19 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!20 = !{!"_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}
!21 = !{!"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 zeroext range(i8 0, 2) i8 @Mtftp6RrqOackValid(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 28
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %2, i64 28
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = xor i32 %7, -1
  %9 = and i32 %5, %8
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %40

10:                                               ; preds = %3
  %11 = and i32 %5, 1
  %.not17 = icmp eq i32 %11, 0
  br i1 %.not17, label %16, label %12

12:                                               ; preds = %10
  %13 = load i16, ptr %1, align 4, !tbaa !12
  %14 = load i16, ptr %2, align 4, !tbaa !12
  %15 = icmp ugt i16 %13, %14
  br i1 %15, label %40, label %16

16:                                               ; preds = %12, %10
  %17 = and i32 %5, 2
  %.not18 = icmp eq i32 %17, 0
  br i1 %.not18, label %23, label %18

18:                                               ; preds = %16
  %19 = getelementptr inbounds i8, ptr %1, i64 2
  %20 = load i8, ptr %19, align 2, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %2, i64 2
  %22 = load i8, ptr %21, align 2, !tbaa !13
  %.not19 = icmp eq i8 %20, %22
  br i1 %.not19, label %23, label %40

23:                                               ; preds = %18, %16
  %24 = and i32 %5, 8
  %.not20 = icmp eq i32 %24, 0
  br i1 %.not20, label %39, label %25

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %0, i64 208
  %27 = tail call zeroext i8 @NetIp6IsUnspecifiedAddr(ptr noundef nonnull %26) #2
  %.not21 = icmp eq i8 %27, 0
  br i1 %.not21, label %28, label %39

28:                                               ; preds = %25
  %29 = getelementptr inbounds i8, ptr %1, i64 8
  %30 = tail call zeroext i8 @NetIp6IsUnspecifiedAddr(ptr noundef nonnull %29) #2
  %.not22 = icmp eq i8 %30, 0
  br i1 %.not22, label %31, label %33

31:                                               ; preds = %28
  %32 = tail call i64 @CompareMem(ptr noundef nonnull %29, ptr noundef nonnull %26, i64 noundef 16) #2
  %.not23 = icmp eq i64 %32, 0
  br i1 %.not23, label %33, label %40

33:                                               ; preds = %31, %28
  %34 = getelementptr inbounds i8, ptr %1, i64 24
  %35 = load i16, ptr %34, align 4, !tbaa !14
  %.not24 = icmp eq i16 %35, 0
  br i1 %.not24, label %39, label %36

36:                                               ; preds = %33
  %37 = getelementptr inbounds i8, ptr %0, i64 224
  %38 = load i16, ptr %37, align 8, !tbaa !15
  %.not25 = icmp eq i16 %35, %38
  br i1 %.not25, label %39, label %40

39:                                               ; preds = %33, %36, %25, %23
  br label %40

40:                                               ; preds = %36, %31, %12, %18, %3, %39
  %.0 = phi i8 [ 1, %39 ], [ 0, %3 ], [ 0, %18 ], [ 0, %12 ], [ 0, %31 ], [ 0, %36 ]
  ret i8 %.0
}

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

declare i64 @CompareMem(ptr noundef, 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, !10, i64 28}
!6 = !{!"", !7, i64 0, !8, i64 2, !10, i64 4, !11, i64 8, !7, i64 24, !8, i64 26, !10, i64 28}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !8, i64 2}
!14 = !{!6, !7, i64 24}
!15 = !{!16, !7, i64 224}
!16 = !{!"_MTFTP6_INSTANCE", !10, i64 0, !17, i64 8, !18, i64 16, !19, i64 32, !17, i64 96, !17, i64 104, !17, i64 112, !6, i64 120, !7, i64 152, !7, i64 154, !18, i64 160, !11, i64 176, !7, i64 192, !7, i64 194, !17, i64 200, !11, i64 208, !7, i64 224, !17, i64 232, !17, i64 240, !10, i64 248, !10, i64 252, !10, i64 256, !10, i64 260, !20, i64 264, !8, i64 272, !8, i64 273, !8, i64 274}
!17 = !{!"any pointer", !8, i64 0}
!18 = !{!"_LIST_ENTRY", !17, i64 0, !17, i64 8}
!19 = !{!"_EFI_MTFTP6_PROTOCOL", !17, i64 0, !17, i64 8, !17, i64 16, !17, i64 24, !17, i64 32, !17, i64 40, !17, i64 48, !17, i64 56}
!20 = !{!"long long", !8, i64 0}


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