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

; 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_DEVICE_PATH_PROTOCOL = type { i8, i8, [2 x i8] }
%struct.VLAN_DEVICE_PATH = type { %struct.EFI_DEVICE_PATH_PROTOCOL, i16 }

; 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 zeroext i8 @IsDevicePathEnd(ptr noundef) #1

declare ptr @NextDevicePathNode(ptr noundef) #1

declare ptr @DevicePathFromHandle(ptr noundef) #1

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

11:                                               ; preds = %1
  store i16 0, ptr %2, align 2
  store i32 1, ptr %6, align 4
  br label %39

12:                                               ; preds = %1
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %13, ptr %5, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %35, %12
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call zeroext i8 @IsDevicePathEnd(ptr noundef %15)
  %17 = icmp ne i8 %16, 0
  %18 = xor i1 %17, true
  br i1 %18, label %19, label %38

19:                                               ; preds = %14
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.EFI_DEVICE_PATH_PROTOCOL, ptr %20, i32 0, i32 0
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = zext i8 %22 to i32
  %24 = icmp eq i32 %23, 3
  br i1 %24, label %25, label %35

25:                                               ; preds = %19
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.EFI_DEVICE_PATH_PROTOCOL, ptr %26, i32 0, i32 1
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = zext i8 %28 to i32
  %30 = icmp eq i32 %29, 20
  br i1 %30, label %31, label %35

31:                                               ; preds = %25
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.VLAN_DEVICE_PATH, ptr %32, i32 0, i32 1
  %34 = load i16, ptr %33, align 1, !tbaa !12
  store i16 %34, ptr %2, align 2
  store i32 1, ptr %6, align 4
  br label %39

35:                                               ; preds = %25, %19
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call ptr @NextDevicePathNode(ptr noundef %36)
  store ptr %37, ptr %5, align 8, !tbaa !5
  br label %14, !llvm.loop !15

38:                                               ; preds = %14
  store i16 0, ptr %2, align 2
  store i32 1, ptr %6, align 4
  br label %39

39:                                               ; preds = %38, %31, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %40 = load i16, ptr %2, align 2
  ret i16 %40
}

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, !7, i64 0}
!10 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!11 = !{!10, !7, i64 1}
!12 = !{!13, !14, i64 4}
!13 = !{!"", !10, i64 0, !14, i64 4}
!14 = !{!"short", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

declare zeroext i8 @IsDevicePathEnd(ptr noundef) local_unnamed_addr #0

declare ptr @NextDevicePathNode(ptr noundef) local_unnamed_addr #0

declare ptr @DevicePathFromHandle(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @NetLibGetVlanId(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call ptr @DevicePathFromHandle(ptr noundef %0) #2
  %3 = icmp eq ptr %2, null
  br i1 %3, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %4 = tail call zeroext i8 @IsDevicePathEnd(ptr noundef nonnull %2) #2
  %.not11 = icmp eq i8 %4, 0
  br i1 %.not11, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %14
  %.012 = phi ptr [ %15, %14 ], [ %2, %.preheader ]
  %5 = load i8, ptr %.012, align 1, !tbaa !5
  %6 = icmp eq i8 %5, 3
  br i1 %6, label %7, label %14

7:                                                ; preds = %.lr.ph
  %8 = getelementptr inbounds i8, ptr %.012, i64 1
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %10 = icmp eq i8 %9, 20
  br i1 %10, label %11, label %14

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %.012, i64 4
  %13 = load i16, ptr %12, align 1, !tbaa !10
  br label %.loopexit

14:                                               ; preds = %7, %.lr.ph
  %15 = tail call ptr @NextDevicePathNode(ptr noundef nonnull %.012) #2
  %16 = tail call zeroext i8 @IsDevicePathEnd(ptr noundef %15) #2
  %.not = icmp eq i8 %16, 0
  br i1 %.not, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %14, %.preheader, %1, %11
  %.08 = phi i16 [ %13, %11 ], [ 0, %1 ], [ 0, %.preheader ], [ 0, %14 ]
  ret i16 %.08
}

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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!6, !7, i64 1}
!10 = !{!11, !12, i64 4}
!11 = !{!"", !6, i64 0, !12, i64 4}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass