; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Bus/Pci (NvmExpressGetNamespace)

; 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.NVME_NAMESPACE_DEVICE_PATH = type { %struct.EFI_DEVICE_PATH_PROTOCOL, i32, i64 }

; 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 @NvmExpressGetNamespace(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = 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 ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %23, label %14

14:                                               ; preds = %4
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %23, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %23, label %20

20:                                               ; preds = %17
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %24

23:                                               ; preds = %20, %17, %14, %4
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %53

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

30:                                               ; preds = %24
  store i64 -9223372036854775805, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %53

31:                                               ; preds = %24
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %32, ptr %10, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.EFI_DEVICE_PATH_PROTOCOL, ptr %33, i32 0, i32 1
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = zext i8 %35 to i32
  %37 = icmp eq i32 %36, 23
  br i1 %37, label %38, label %52

38:                                               ; preds = %31
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = call i64 @DevicePathNodeLength(ptr noundef %39)
  %41 = icmp ne i64 %40, 16
  br i1 %41, label %42, label %43

42:                                               ; preds = %38
  store i64 -9223372036854775794, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %53

43:                                               ; preds = %38
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.NVME_NAMESPACE_DEVICE_PATH, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 1, !tbaa !12
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %46, ptr %47, align 4, !tbaa !16
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.NVME_NAMESPACE_DEVICE_PATH, ptr %48, i32 0, i32 2
  %50 = load i64, ptr %49, align 1, !tbaa !17
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %50, ptr %51, align 8, !tbaa !18
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %53

52:                                               ; preds = %31
  store i64 -9223372036854775805, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %53

53:                                               ; preds = %52, %43, %42, %30, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %54 = load i64, ptr %5, align 8
  ret i64 %54
}

declare i64 @DevicePathNodeLength(ptr noundef) #2

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 = { "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, !15, i64 8}
!14 = !{!"int", !7, i64 0}
!15 = !{!"long long", !7, i64 0}
!16 = !{!14, !14, i64 0}
!17 = !{!13, !15, i64 8}
!18 = !{!15, !15, 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 range(i64 -9223372036854775806, 1) i64 @NvmExpressGetNamespace(ptr noundef readnone %0, ptr noundef %1, ptr noundef writeonly %2, ptr noundef writeonly %3) local_unnamed_addr #0 {
  %5 = insertelement <4 x ptr> poison, ptr %0, i64 0
  %6 = insertelement <4 x ptr> %5, ptr %1, i64 1
  %7 = insertelement <4 x ptr> %6, ptr %2, i64 2
  %8 = insertelement <4 x ptr> %7, ptr %3, i64 3
  %9 = icmp eq <4 x ptr> %8, zeroinitializer
  %10 = bitcast <4 x i1> %9 to i4
  %.not21 = icmp eq i4 %10, 0
  br i1 %.not21, label %11, label %24

11:                                               ; preds = %4
  %12 = load i8, ptr %1, align 1, !tbaa !5
  %.not = icmp eq i8 %12, 3
  br i1 %.not, label %13, label %24

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %1, i64 1
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = icmp eq i8 %15, 23
  br i1 %16, label %17, label %24

17:                                               ; preds = %13
  %18 = tail call i64 @DevicePathNodeLength(ptr noundef nonnull %1) #2
  %.not20 = icmp eq i64 %18, 16
  br i1 %.not20, label %19, label %24

19:                                               ; preds = %17
  %20 = getelementptr inbounds i8, ptr %1, i64 4
  %21 = load i32, ptr %20, align 1, !tbaa !10
  store i32 %21, ptr %2, align 4, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %1, i64 8
  %23 = load i64, ptr %22, align 1, !tbaa !15
  store i64 %23, ptr %3, align 8, !tbaa !16
  br label %24

24:                                               ; preds = %13, %17, %11, %4, %19
  %.0 = phi i64 [ 0, %19 ], [ -9223372036854775806, %4 ], [ -9223372036854775805, %11 ], [ -9223372036854775794, %17 ], [ -9223372036854775805, %13 ]
  ret i64 %.0
}

declare i64 @DevicePathNodeLength(ptr 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, !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, !13, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!11, !13, i64 8}
!16 = !{!13, !13, i64 0}


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