; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/ShellPkg/Library (DevicePathCompare)

; 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.GUID = type { i32, i16, i16, [8 x i8] }
%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_UNICODE_COLLATION_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [144 x i8], align 1
@mUnicodeCollation = external hidden global ptr, align 8
@gBS = external global ptr, align 8
@gEfiUnicodeCollation2ProtocolGuid = external global %struct.GUID, align 4
@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [20 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

declare zeroext i8 @DebugAssertEnabled() #1

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

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

declare void @FreePool(ptr noundef) #1

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

19:                                               ; preds = %2
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i64 0, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %101

23:                                               ; preds = %19
  store i64 -1, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %101

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

27:                                               ; preds = %24
  store i64 1, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %101

28:                                               ; preds = %24
  %29 = load ptr, ptr @mUnicodeCollation, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %62

31:                                               ; preds = %28
  %32 = load ptr, ptr @gBS, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %32, i32 0, i32 38
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = call i64 %34(ptr noundef @gEfiUnicodeCollation2ProtocolGuid, ptr noundef null, ptr noundef @mUnicodeCollation)
  store i64 %35, ptr %10, align 8, !tbaa !14
  br label %36

36:                                               ; preds = %31
  %37 = call zeroext i8 @DebugAssertEnabled()
  %38 = icmp ne i8 %37, 0
  br i1 %38, label %39, label %59

39:                                               ; preds = %36
  %40 = load i64, ptr %10, align 8, !tbaa !14
  %41 = icmp slt i64 %40, 0
  br i1 %41, label %42, label %58

42:                                               ; preds = %39
  br label %43

43:                                               ; preds = %42
  %44 = call zeroext i8 @DebugPrintEnabled()
  %45 = icmp ne i8 %44, 0
  br i1 %45, label %46, label %55

46:                                               ; preds = %43
  br label %47

47:                                               ; preds = %46
  %48 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %49 = icmp ne i8 %48, 0
  br i1 %49, label %50, label %52

50:                                               ; preds = %47
  %51 = load i64, ptr %10, align 8, !tbaa !14
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.4, i64 noundef %51)
  br label %52

52:                                               ; preds = %50, %47
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54, %43
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  call void @DebugAssert(ptr noundef @.str, i64 noundef 232, ptr noundef @.str.5)
  br label %58

58:                                               ; preds = %57, %39
  br label %59

59:                                               ; preds = %58, %36
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61, %28
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = call ptr @ConvertDevicePathToText(ptr noundef %63, i8 noundef zeroext 0, i8 noundef zeroext 0)
  store ptr %64, ptr %8, align 8, !tbaa !5
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = call ptr @ConvertDevicePathToText(ptr noundef %65, i8 noundef zeroext 0, i8 noundef zeroext 0)
  store ptr %66, ptr %9, align 8, !tbaa !5
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = icmp eq ptr %67, null
  br i1 %68, label %69, label %70

69:                                               ; preds = %62
  store i64 -1, ptr %11, align 8, !tbaa !14
  br label %83

70:                                               ; preds = %62
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = icmp eq ptr %71, null
  br i1 %72, label %73, label %74

73:                                               ; preds = %70
  store i64 1, ptr %11, align 8, !tbaa !14
  br label %82

74:                                               ; preds = %70
  %75 = load ptr, ptr @mUnicodeCollation, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._EFI_UNICODE_COLLATION_PROTOCOL, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !15
  %78 = load ptr, ptr @mUnicodeCollation, align 8, !tbaa !5
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = call i64 %77(ptr noundef %78, ptr noundef %79, ptr noundef %80)
  store i64 %81, ptr %11, align 8, !tbaa !14
  br label %82

82:                                               ; preds = %74, %73
  br label %83

83:                                               ; preds = %82, %69
  br label %84

84:                                               ; preds = %83
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  %86 = icmp ne ptr %85, null
  br i1 %86, label %87, label %89

87:                                               ; preds = %84
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  call void @FreePool(ptr noundef %88)
  store ptr null, ptr %8, align 8, !tbaa !5
  br label %89

89:                                               ; preds = %87, %84
  br label %90

90:                                               ; preds = %89
  br label %91

91:                                               ; preds = %90
  br label %92

92:                                               ; preds = %91
  %93 = load ptr, ptr %9, align 8, !tbaa !5
  %94 = icmp ne ptr %93, null
  br i1 %94, label %95, label %97

95:                                               ; preds = %92
  %96 = load ptr, ptr %9, align 8, !tbaa !5
  call void @FreePool(ptr noundef %96)
  store ptr null, ptr %9, align 8, !tbaa !5
  br label %97

97:                                               ; preds = %95, %92
  br label %98

98:                                               ; preds = %97
  br label %99

99:                                               ; preds = %98
  %100 = load i64, ptr %11, align 8, !tbaa !14
  store i64 %100, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %101

101:                                              ; preds = %99, %27, %23, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %102 = load i64, ptr %3, align 8
  ret i64 %102
}

declare zeroext i8 @DebugPrintEnabled() #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #1

declare void @DebugPrint(i64 noundef, ptr noundef, ...) #1

declare ptr @ConvertDevicePathToText(ptr noundef, i8 noundef zeroext, i8 noundef zeroext) #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, !6, i64 320}
!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, !6, i64 0}
!16 = !{!"_EFI_UNICODE_COLLATION_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}


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

%struct.GUID = type { i32, i16, i16, [8 x i8] }

@.str = external hidden unnamed_addr constant [144 x i8], align 1
@mUnicodeCollation = external hidden global ptr, align 8
@gBS = external local_unnamed_addr global ptr, align 8
@gEfiUnicodeCollation2ProtocolGuid = external global %struct.GUID, align 4
@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [20 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

declare void @FreePool(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @DevicePathCompare(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = load ptr, ptr %1, align 8, !tbaa !5
  %5 = icmp eq ptr %3, null
  br i1 %5, label %6, label %8

6:                                                ; preds = %2
  %7 = icmp ne ptr %4, null
  %. = sext i1 %7 to i64
  br label %40

8:                                                ; preds = %2
  %9 = icmp eq ptr %4, null
  br i1 %9, label %40, label %10

10:                                               ; preds = %8
  %11 = load ptr, ptr @mUnicodeCollation, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %27

13:                                               ; preds = %10
  %14 = load ptr, ptr @gBS, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 320
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = tail call i64 %16(ptr noundef nonnull @gEfiUnicodeCollation2ProtocolGuid, ptr noundef null, ptr noundef nonnull @mUnicodeCollation) #2
  %18 = tail call zeroext i8 @DebugAssertEnabled() #2
  %19 = icmp ne i8 %18, 0
  %20 = icmp slt i64 %17, 0
  %or.cond = select i1 %19, i1 %20, i1 false
  br i1 %or.cond, label %21, label %27

21:                                               ; preds = %13
  %22 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not = icmp eq i8 %22, 0
  br i1 %.not, label %26, label %23

23:                                               ; preds = %21
  %24 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not26 = icmp eq i8 %24, 0
  br i1 %.not26, label %26, label %25

25:                                               ; preds = %23
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.4, i64 noundef %17) #2
  br label %26

26:                                               ; preds = %23, %25, %21
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 232, ptr noundef nonnull @.str.5) #2
  br label %27

27:                                               ; preds = %13, %26, %10
  %28 = tail call ptr @ConvertDevicePathToText(ptr noundef nonnull %3, i8 noundef zeroext 0, i8 noundef zeroext 0) #2
  %29 = tail call ptr @ConvertDevicePathToText(ptr noundef nonnull %4, i8 noundef zeroext 0, i8 noundef zeroext 0) #2
  %30 = icmp eq ptr %28, null
  br i1 %30, label %38, label %31

31:                                               ; preds = %27
  %32 = icmp eq ptr %29, null
  br i1 %32, label %37, label %33

33:                                               ; preds = %31
  %34 = load ptr, ptr @mUnicodeCollation, align 8, !tbaa !5
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = tail call i64 %35(ptr noundef nonnull %34, ptr noundef nonnull %28, ptr noundef nonnull %29) #2
  br label %37

37:                                               ; preds = %31, %33
  %.0.ph = phi i64 [ 1, %31 ], [ %36, %33 ]
  tail call void @FreePool(ptr noundef nonnull %28) #2
  br label %38

38:                                               ; preds = %27, %37
  %.031 = phi i64 [ %.0.ph, %37 ], [ -1, %27 ]
  %.not28 = icmp eq ptr %29, null
  br i1 %.not28, label %40, label %39

39:                                               ; preds = %38
  tail call void @FreePool(ptr noundef nonnull %29) #2
  br label %40

40:                                               ; preds = %38, %39, %8, %6
  %.019 = phi i64 [ %., %6 ], [ 1, %8 ], [ %.031, %39 ], [ %.031, %38 ]
  ret i64 %.019
}

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #0

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #0

declare void @DebugPrint(i64 noundef, ptr noundef, ...) local_unnamed_addr #0

declare ptr @ConvertDevicePathToText(ptr noundef, i8 noundef zeroext, i8 noundef zeroext) 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)"}
!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 320}
!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, !6, i64 0}
!15 = !{!"_EFI_UNICODE_COLLATION_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}


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