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

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

; 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 void @FreePool(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @IsGopSibling(ptr noundef, ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i64 @ConPlatformMatchDevicePaths(ptr noundef %0, ptr noundef %1, ptr noundef %2, i8 noundef zeroext %3) #2 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i8 %3, ptr %9, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %21, label %18

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

21:                                               ; preds = %18, %4
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %78

22:                                               ; preds = %18
  %23 = load i8, ptr %9, align 1, !tbaa !9
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %25, label %30

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

28:                                               ; preds = %25
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %78

29:                                               ; preds = %25
  br label %30

30:                                               ; preds = %29, %22
  store ptr null, ptr %11, align 8, !tbaa !5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %31, ptr %10, align 8, !tbaa !5
  %32 = call ptr @GetNextDevicePathInstance(ptr noundef %10, ptr noundef %14)
  store ptr %32, ptr %13, align 8, !tbaa !5
  br label %33

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

36:                                               ; preds = %33
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = load i64, ptr %14, align 8, !tbaa !10
  %40 = call i64 @CompareMem(ptr noundef %37, ptr noundef %38, i64 noundef %39)
  %41 = icmp eq i64 %40, 0
  br i1 %41, label %48, label %42

42:                                               ; preds = %36
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  %45 = call zeroext i8 @IsGopSibling(ptr noundef %43, ptr noundef %44)
  %46 = zext i8 %45 to i32
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %54

48:                                               ; preds = %42, %36
  %49 = load i8, ptr %9, align 1, !tbaa !9
  %50 = icmp ne i8 %49, 0
  br i1 %50, label %53, label %51

51:                                               ; preds = %48
  %52 = load ptr, ptr %13, align 8, !tbaa !5
  call void @FreePool(ptr noundef %52)
  store i64 0, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %78

53:                                               ; preds = %48
  br label %68

54:                                               ; preds = %42
  %55 = load i8, ptr %9, align 1, !tbaa !9
  %56 = icmp ne i8 %55, 0
  br i1 %56, label %57, label %67

57:                                               ; preds = %54
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = call ptr @AppendDevicePathInstance(ptr noundef %58, ptr noundef %59)
  store ptr %60, ptr %12, align 8, !tbaa !5
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %65

63:                                               ; preds = %57
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  call void @FreePool(ptr noundef %64)
  br label %65

65:                                               ; preds = %63, %57
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %66, ptr %11, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %65, %54
  br label %68

68:                                               ; preds = %67, %53
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  call void @FreePool(ptr noundef %69)
  %70 = call ptr @GetNextDevicePathInstance(ptr noundef %10, ptr noundef %14)
  store ptr %70, ptr %13, align 8, !tbaa !5
  br label %33, !llvm.loop !12

71:                                               ; preds = %33
  %72 = load i8, ptr %9, align 1, !tbaa !9
  %73 = icmp ne i8 %72, 0
  br i1 %73, label %74, label %77

74:                                               ; preds = %71
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %75, ptr %76, align 8, !tbaa !5
  store i64 0, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %78

77:                                               ; preds = %71
  store i64 -9223372036854775794, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %78

78:                                               ; preds = %77, %74, %51, %28, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %79 = load i64, ptr %5, align 8
  ret i64 %79
}

declare ptr @GetNextDevicePathInstance(ptr noundef, ptr noundef) #1

declare ptr @AppendDevicePathInstance(ptr noundef, 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

declare void @FreePool(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @IsGopSibling(ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @ConPlatformMatchDevicePaths(ptr noundef %0, ptr noundef %1, ptr noundef writeonly %2, i8 noundef zeroext %3) local_unnamed_addr #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %7 = icmp eq ptr %0, null
  %8 = icmp eq ptr %1, null
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %32, label %9

9:                                                ; preds = %4
  %10 = icmp ne i8 %3, 0
  %11 = icmp eq ptr %2, null
  %or.cond3 = and i1 %11, %10
  br i1 %or.cond3, label %32, label %12

12:                                               ; preds = %9
  store ptr %0, ptr %5, align 8, !tbaa !5
  %13 = call ptr @GetNextDevicePathInstance(ptr noundef nonnull %5, ptr noundef nonnull %6) #3
  %.not33 = icmp eq ptr %13, null
  br i1 %.not33, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %12
  br i1 %10, label %.lr.ph.split.us.split, label %.lr.ph.split

.lr.ph.split.us.split:                            ; preds = %.lr.ph, %22
  %.035.us = phi ptr [ %23, %22 ], [ %13, %.lr.ph ]
  %.02634.us = phi ptr [ %.1.us, %22 ], [ null, %.lr.ph ]
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = call i64 @CompareMem(ptr noundef %1, ptr noundef nonnull %.035.us, i64 noundef %14) #3
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %22, label %17

17:                                               ; preds = %.lr.ph.split.us.split
  %18 = call zeroext i8 @IsGopSibling(ptr noundef %1, ptr noundef nonnull %.035.us)
  %.not29.us = icmp eq i8 %18, 0
  br i1 %.not29.us, label %19, label %22

19:                                               ; preds = %17
  %20 = call ptr @AppendDevicePathInstance(ptr noundef %.02634.us, ptr noundef nonnull %.035.us) #3
  %.not30.us = icmp eq ptr %.02634.us, null
  br i1 %.not30.us, label %22, label %21

21:                                               ; preds = %19
  call void @FreePool(ptr noundef nonnull %.02634.us) #3
  br label %22

22:                                               ; preds = %.lr.ph.split.us.split, %17, %21, %19
  %.1.us = phi ptr [ %20, %21 ], [ %20, %19 ], [ %.02634.us, %17 ], [ %.02634.us, %.lr.ph.split.us.split ]
  call void @FreePool(ptr noundef nonnull %.035.us) #3
  %23 = call ptr @GetNextDevicePathInstance(ptr noundef nonnull %5, ptr noundef nonnull %6) #3
  %.not.us = icmp eq ptr %23, null
  br i1 %.not.us, label %._crit_edge, label %.lr.ph.split.us.split, !llvm.loop !11

.lr.ph.split:                                     ; preds = %.lr.ph, %29
  %.035 = phi ptr [ %30, %29 ], [ %13, %.lr.ph ]
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = call i64 @CompareMem(ptr noundef %1, ptr noundef nonnull %.035, i64 noundef %24) #3
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %.split, label %27

27:                                               ; preds = %.lr.ph.split
  %28 = call zeroext i8 @IsGopSibling(ptr noundef %1, ptr noundef nonnull %.035)
  %.not29 = icmp eq i8 %28, 0
  br i1 %.not29, label %29, label %.split

.split:                                           ; preds = %27, %.lr.ph.split
  call void @FreePool(ptr noundef nonnull %.035) #3
  br label %32

29:                                               ; preds = %27
  call void @FreePool(ptr noundef nonnull %.035) #3
  %30 = call ptr @GetNextDevicePathInstance(ptr noundef nonnull %5, ptr noundef nonnull %6) #3
  %.not = icmp eq ptr %30, null
  br i1 %.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !11

._crit_edge:                                      ; preds = %29, %22, %12
  %.026.lcssa = phi ptr [ null, %12 ], [ %.1.us, %22 ], [ null, %29 ]
  br i1 %10, label %31, label %32

31:                                               ; preds = %._crit_edge
  store ptr %.026.lcssa, ptr %2, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %._crit_edge, %9, %4, %31, %.split
  %.025 = phi i64 [ 0, %.split ], [ 0, %31 ], [ -9223372036854775806, %4 ], [ -9223372036854775806, %9 ], [ -9223372036854775794, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  ret i64 %.025
}

declare ptr @GetNextDevicePathInstance(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @AppendDevicePathInstance(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass